Hide a stub Download the file UI from File sends

This commit is contained in:
Artem Chepurnoy 2024-01-31 00:01:55 +02:00
parent 3204d96d4c
commit 509a127551
No known key found for this signature in database
GPG Key ID: FAC37D0CF674043E
2 changed files with 21 additions and 112 deletions

View File

@ -1,35 +1,15 @@
package com.artemchep.keyguard.feature.attachments.util package com.artemchep.keyguard.feature.attachments.util
import arrow.core.partially1
import com.artemchep.keyguard.android.downloader.journal.room.DownloadInfoEntity2
import com.artemchep.keyguard.common.io.IO
import com.artemchep.keyguard.common.model.DSend import com.artemchep.keyguard.common.model.DSend
import com.artemchep.keyguard.common.service.download.DownloadManager
import com.artemchep.keyguard.common.util.flow.persistingStateIn
import com.artemchep.keyguard.feature.attachments.FooStatus
import com.artemchep.keyguard.feature.attachments.LaunchViewCipherData
import com.artemchep.keyguard.feature.attachments.SelectableItemState import com.artemchep.keyguard.feature.attachments.SelectableItemState
import com.artemchep.keyguard.feature.attachments.SelectableItemStateRaw
import com.artemchep.keyguard.feature.attachments.foo
import com.artemchep.keyguard.feature.attachments.model.AttachmentItem import com.artemchep.keyguard.feature.attachments.model.AttachmentItem
import com.artemchep.keyguard.feature.filepicker.humanReadableByteCountSI import com.artemchep.keyguard.feature.filepicker.humanReadableByteCountSI
import com.artemchep.keyguard.feature.navigation.state.RememberStateFlowScope import com.artemchep.keyguard.feature.navigation.state.RememberStateFlowScope
import com.artemchep.keyguard.ui.selection.SelectionHandle import com.artemchep.keyguard.ui.ContextItem
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
suspend fun RememberStateFlowScope.createAttachmentItem( suspend fun RememberStateFlowScope.createAttachmentItem(
attachment: DSend.File, attachment: DSend.File,
tag: DownloadInfoEntity2.AttachmentDownloadTag,
selectionHandle: SelectionHandle,
sharingScope: CoroutineScope,
launchViewCipherData: LaunchViewCipherData?,
downloadManager: DownloadManager,
downloadIo: IO<Unit>,
removeIo: IO<Unit>,
): AttachmentItem { ): AttachmentItem {
val fileName = attachment.fileName val fileName = attachment.fileName
val fileExt = attachment.fileName val fileExt = attachment.fileName
@ -37,74 +17,24 @@ suspend fun RememberStateFlowScope.createAttachmentItem(
.size .size
?.let(::humanReadableByteCountSI) ?.let(::humanReadableByteCountSI)
val downloadStatusState = downloadManager val downloadStatusState = kotlin.run {
.statusByTag(tag) val value = AttachmentItem.Status.None
.map { downloadStatus -> MutableStateFlow(value)
AttachmentItem.Status.of(
downloadStatus = downloadStatus,
)
} }
.persistingStateIn( val actionsState = kotlin.run {
scope = sharingScope, val value = emptyList<ContextItem>()
started = SharingStarted.WhileSubscribed(1000L), MutableStateFlow(value)
)
val actionsState = downloadStatusState
.map { attachmentStatus ->
FooStatus.of(
attachmentStatus = attachmentStatus,
)
} }
.distinctUntilChanged() val selectableState = kotlin.run {
.map { actionsStatus -> val value = SelectableItemState(
val actions = foo( selecting = false,
translatorScope = this, selected = false,
fileName = fileName, can = false,
launchViewCipherData = launchViewCipherData, onClick = null,
status = actionsStatus, onLongClick = null,
downloadIo = downloadIo,
removeIo = removeIo,
navigate = ::navigate,
) )
actions MutableStateFlow(value)
} }
.persistingStateIn(
scope = sharingScope,
started = SharingStarted.WhileSubscribed(1000L),
)
val selectableState = selectionHandle
.idsFlow
.map { selectedIds ->
SelectableItemStateRaw(
selecting = selectedIds.isNotEmpty(),
selected = attachment.id in selectedIds,
)
}
.distinctUntilChanged()
.map { raw ->
val onClick = if (raw.selecting) {
// lambda
selectionHandle::toggleSelection.partially1(
attachment.id,
)
} else {
null
}
val onLongClick = if (raw.selecting) {
null
} else {
// lambda
selectionHandle::toggleSelection.partially1(
attachment.id,
)
}
SelectableItemState(
selecting = raw.selecting,
selected = raw.selected,
onClick = onClick,
onLongClick = onLongClick,
)
}
.stateIn(sharingScope)
return AttachmentItem( return AttachmentItem(
key = "attachment.${attachment.id}", key = "attachment.${attachment.id}",
name = fileName, name = fileName,

View File

@ -63,10 +63,12 @@ import com.artemchep.keyguard.common.usecase.RestoreCipherById
import com.artemchep.keyguard.common.usecase.RetryCipher import com.artemchep.keyguard.common.usecase.RetryCipher
import com.artemchep.keyguard.common.usecase.TrashCipherById import com.artemchep.keyguard.common.usecase.TrashCipherById
import com.artemchep.keyguard.common.usecase.WindowCoroutineScope import com.artemchep.keyguard.common.usecase.WindowCoroutineScope
import com.artemchep.keyguard.feature.attachments.model.AttachmentItem
import com.artemchep.keyguard.feature.attachments.util.createAttachmentItem import com.artemchep.keyguard.feature.attachments.util.createAttachmentItem
import com.artemchep.keyguard.feature.barcodetype.BarcodeTypeRoute import com.artemchep.keyguard.feature.barcodetype.BarcodeTypeRoute
import com.artemchep.keyguard.feature.favicon.FaviconImage import com.artemchep.keyguard.feature.favicon.FaviconImage
import com.artemchep.keyguard.feature.favicon.FaviconUrl import com.artemchep.keyguard.feature.favicon.FaviconUrl
import com.artemchep.keyguard.feature.filepicker.humanReadableByteCountSI
import com.artemchep.keyguard.feature.home.vault.model.VaultViewItem import com.artemchep.keyguard.feature.home.vault.model.VaultViewItem
import com.artemchep.keyguard.feature.largetype.LargeTypeRoute import com.artemchep.keyguard.feature.largetype.LargeTypeRoute
import com.artemchep.keyguard.feature.navigation.NavigationIntent import com.artemchep.keyguard.feature.navigation.NavigationIntent
@ -223,7 +225,6 @@ fun sendViewScreenState(
clipboardService = clipboardService, clipboardService = clipboardService,
) )
val selectionHandle = selectionHandle("selection")
val markdown = getMarkdown().first() val markdown = getMarkdown().first()
val accountFlow = getAccounts() val accountFlow = getAccounts()
@ -296,8 +297,6 @@ fun sendViewScreenState(
null null
}, },
items = oh( items = oh(
sharingScope = screenScope,
selectionHandle = selectionHandle,
canEdit = canAddSecret, canEdit = canAddSecret,
contentColor = contentColor, contentColor = contentColor,
disabledContentColor = disabledContentColor, disabledContentColor = disabledContentColor,
@ -324,8 +323,6 @@ fun sendViewScreenState(
} }
private fun RememberStateFlowScope.oh( private fun RememberStateFlowScope.oh(
sharingScope: CoroutineScope,
selectionHandle: SelectionHandle,
canEdit: Boolean, canEdit: Boolean,
contentColor: Color, contentColor: Color,
disabledContentColor: Color, disabledContentColor: Color,
@ -365,26 +362,8 @@ private fun RememberStateFlowScope.oh(
val file = send.file val file = send.file
if (file != null) { if (file != null) {
val downloadIo = kotlin.run {
ioRaise<Unit>(RuntimeException("Downloading sends is not implemented yet."))
}
val removeIo = kotlin.run {
ioUnit()
}
val actualItem = createAttachmentItem( val actualItem = createAttachmentItem(
tag = DownloadInfoEntity2.AttachmentDownloadTag(
localCipherId = "cipher.id",
remoteCipherId = "cipher.service.remote?.id",
attachmentId = file.id,
),
selectionHandle = selectionHandle,
sharingScope = sharingScope,
attachment = file, attachment = file,
launchViewCipherData = null,
downloadManager = downloadManager,
downloadIo = downloadIo,
removeIo = removeIo,
) )
val model = VaultViewItem.Attachment( val model = VaultViewItem.Attachment(
id = "file.file", id = "file.file",