From 509a1275511a30cff531222a821797617fd67651 Mon Sep 17 00:00:00 2001 From: Artem Chepurnoy Date: Wed, 31 Jan 2024 00:01:55 +0200 Subject: [PATCH] Hide a stub Download the file UI from File sends --- .../util/CreateSendAttachmentItem.kt | 108 +++--------------- .../send/view/SendViewStateProducer.kt | 25 +--- 2 files changed, 21 insertions(+), 112 deletions(-) diff --git a/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/attachments/util/CreateSendAttachmentItem.kt b/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/attachments/util/CreateSendAttachmentItem.kt index 55de7531..62177560 100644 --- a/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/attachments/util/CreateSendAttachmentItem.kt +++ b/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/attachments/util/CreateSendAttachmentItem.kt @@ -1,35 +1,15 @@ 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.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.SelectableItemStateRaw -import com.artemchep.keyguard.feature.attachments.foo import com.artemchep.keyguard.feature.attachments.model.AttachmentItem import com.artemchep.keyguard.feature.filepicker.humanReadableByteCountSI import com.artemchep.keyguard.feature.navigation.state.RememberStateFlowScope -import com.artemchep.keyguard.ui.selection.SelectionHandle -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.flow.SharingStarted -import kotlinx.coroutines.flow.distinctUntilChanged -import kotlinx.coroutines.flow.map -import kotlinx.coroutines.flow.stateIn +import com.artemchep.keyguard.ui.ContextItem +import kotlinx.coroutines.flow.MutableStateFlow suspend fun RememberStateFlowScope.createAttachmentItem( attachment: DSend.File, - tag: DownloadInfoEntity2.AttachmentDownloadTag, - selectionHandle: SelectionHandle, - sharingScope: CoroutineScope, - launchViewCipherData: LaunchViewCipherData?, - downloadManager: DownloadManager, - downloadIo: IO, - removeIo: IO, ): AttachmentItem { val fileName = attachment.fileName val fileExt = attachment.fileName @@ -37,74 +17,24 @@ suspend fun RememberStateFlowScope.createAttachmentItem( .size ?.let(::humanReadableByteCountSI) - val downloadStatusState = downloadManager - .statusByTag(tag) - .map { downloadStatus -> - AttachmentItem.Status.of( - downloadStatus = downloadStatus, - ) - } - .persistingStateIn( - scope = sharingScope, - started = SharingStarted.WhileSubscribed(1000L), + val downloadStatusState = kotlin.run { + val value = AttachmentItem.Status.None + MutableStateFlow(value) + } + val actionsState = kotlin.run { + val value = emptyList() + MutableStateFlow(value) + } + val selectableState = kotlin.run { + val value = SelectableItemState( + selecting = false, + selected = false, + can = false, + onClick = null, + onLongClick = null, ) - val actionsState = downloadStatusState - .map { attachmentStatus -> - FooStatus.of( - attachmentStatus = attachmentStatus, - ) - } - .distinctUntilChanged() - .map { actionsStatus -> - val actions = foo( - translatorScope = this, - fileName = fileName, - launchViewCipherData = launchViewCipherData, - status = actionsStatus, - downloadIo = downloadIo, - removeIo = removeIo, - navigate = ::navigate, - ) - actions - } - .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) + MutableStateFlow(value) + } return AttachmentItem( key = "attachment.${attachment.id}", name = fileName, diff --git a/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/send/view/SendViewStateProducer.kt b/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/send/view/SendViewStateProducer.kt index 3bf4121e..c8273cb1 100644 --- a/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/send/view/SendViewStateProducer.kt +++ b/common/src/commonMain/kotlin/com/artemchep/keyguard/feature/send/view/SendViewStateProducer.kt @@ -63,10 +63,12 @@ import com.artemchep.keyguard.common.usecase.RestoreCipherById import com.artemchep.keyguard.common.usecase.RetryCipher import com.artemchep.keyguard.common.usecase.TrashCipherById 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.barcodetype.BarcodeTypeRoute import com.artemchep.keyguard.feature.favicon.FaviconImage 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.largetype.LargeTypeRoute import com.artemchep.keyguard.feature.navigation.NavigationIntent @@ -223,7 +225,6 @@ fun sendViewScreenState( clipboardService = clipboardService, ) - val selectionHandle = selectionHandle("selection") val markdown = getMarkdown().first() val accountFlow = getAccounts() @@ -296,8 +297,6 @@ fun sendViewScreenState( null }, items = oh( - sharingScope = screenScope, - selectionHandle = selectionHandle, canEdit = canAddSecret, contentColor = contentColor, disabledContentColor = disabledContentColor, @@ -324,8 +323,6 @@ fun sendViewScreenState( } private fun RememberStateFlowScope.oh( - sharingScope: CoroutineScope, - selectionHandle: SelectionHandle, canEdit: Boolean, contentColor: Color, disabledContentColor: Color, @@ -365,26 +362,8 @@ private fun RememberStateFlowScope.oh( val file = send.file if (file != null) { - val downloadIo = kotlin.run { - ioRaise(RuntimeException("Downloading sends is not implemented yet.")) - } - val removeIo = kotlin.run { - ioUnit() - } - val actualItem = createAttachmentItem( - tag = DownloadInfoEntity2.AttachmentDownloadTag( - localCipherId = "cipher.id", - remoteCipherId = "cipher.service.remote?.id", - attachmentId = file.id, - ), - selectionHandle = selectionHandle, - sharingScope = sharingScope, attachment = file, - launchViewCipherData = null, - downloadManager = downloadManager, - downloadIo = downloadIo, - removeIo = removeIo, ) val model = VaultViewItem.Attachment( id = "file.file",