Hide a stub Download the file UI from File sends
This commit is contained in:
parent
3204d96d4c
commit
509a127551
|
@ -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<Unit>,
|
||||
removeIo: IO<Unit>,
|
||||
): 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<ContextItem>()
|
||||
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,
|
||||
|
|
|
@ -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<Unit>(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",
|
||||
|
|
Loading…
Reference in New Issue