@@ -5,24 +5,28 @@ package com.artemchep.keyguard.feature.home.vault.add
55import androidx.compose.foundation.layout.Arrangement
66import androidx.compose.foundation.layout.Column
77import androidx.compose.foundation.layout.Row
8+ import androidx.compose.foundation.layout.RowScope
89import androidx.compose.foundation.layout.Spacer
910import androidx.compose.foundation.layout.fillMaxWidth
1011import androidx.compose.foundation.layout.height
1112import androidx.compose.foundation.layout.padding
1213import androidx.compose.foundation.layout.width
1314import androidx.compose.foundation.lazy.LazyListScope
1415import androidx.compose.material.icons.Icons
16+ import androidx.compose.material.icons.outlined.Archive
17+ import androidx.compose.material.icons.outlined.Delete
1518import androidx.compose.material.icons.outlined.Save
16- import androidx.compose.material3.Checkbox
1719import androidx.compose.material3.ExperimentalMaterial3Api
1820import androidx.compose.material3.Icon
21+ import androidx.compose.material3.MaterialTheme
1922import androidx.compose.material3.Text
2023import androidx.compose.runtime.*
2124import androidx.compose.ui.Alignment
2225import androidx.compose.ui.Modifier
2326import androidx.compose.ui.input.nestedscroll.nestedScroll
2427import androidx.compose.ui.unit.dp
2528import com.artemchep.keyguard.common.model.Loadable
29+ import com.artemchep.keyguard.common.model.create.CreateRequest
2630import com.artemchep.keyguard.common.model.fold
2731import com.artemchep.keyguard.common.model.getOrNull
2832import com.artemchep.keyguard.feature.add.AddScreenItems
@@ -34,23 +38,30 @@ import com.artemchep.keyguard.feature.add.getAnyFieldShapeState
3438import com.artemchep.keyguard.feature.filepicker.FileDropOverlay
3539import com.artemchep.keyguard.feature.filepicker.FilePickerEffect
3640import com.artemchep.keyguard.feature.filepicker.fileDropTarget
41+ import com.artemchep.keyguard.feature.home.vault.component.FlatDropdownSimpleExpressive
3742import com.artemchep.keyguard.feature.home.vault.component.Section
43+ import com.artemchep.keyguard.feature.localization.TextHolder
3844import com.artemchep.keyguard.feature.navigation.NavigationIcon
3945import com.artemchep.keyguard.res.Res
4046import com.artemchep.keyguard.res.*
4147import com.artemchep.keyguard.ui.DefaultFab
4248import com.artemchep.keyguard.ui.ExpandedIfNotEmpty
4349import com.artemchep.keyguard.ui.FabState
44- import com.artemchep.keyguard.ui.FlatItemLayout
50+ import com.artemchep.keyguard.ui.FlatItemAction
51+ import com.artemchep.keyguard.ui.FlatItemTextContent
4552import com.artemchep.keyguard.ui.FlatSimpleNote
4653import com.artemchep.keyguard.ui.OptionsButton
4754import com.artemchep.keyguard.ui.ScaffoldLazyColumn
4855import com.artemchep.keyguard.ui.button.FavouriteToggleButton
56+ import com.artemchep.keyguard.ui.icons.DropdownIcon
57+ import com.artemchep.keyguard.ui.icons.Stub
58+ import com.artemchep.keyguard.ui.icons.icon
4959import com.artemchep.keyguard.ui.shimmer.shimmer
5060import com.artemchep.keyguard.ui.skeleton.SkeletonText
5161import com.artemchep.keyguard.ui.theme.Dimens
5262import com.artemchep.keyguard.ui.toolbar.LargeToolbar
5363import com.artemchep.keyguard.ui.toolbar.util.ToolbarBehavior
64+ import kotlinx.collections.immutable.toImmutableList
5465import org.jetbrains.compose.resources.stringResource
5566
5667@Composable
@@ -384,21 +395,63 @@ private fun AddScreenMergeItem(
384395 modifier = Modifier
385396 .height(8 .dp),
386397 )
387- FlatItemLayout (
388- leading = {
389- Checkbox (
390- checked = state.removeOrigin.checked,
391- onCheckedChange = null ,
392- )
393- },
398+
399+ val updatedOnChangeState by rememberUpdatedState(state.onChangePostAction)
400+ val postActionIconImageVector = remember(state.postAction) {
401+ state.postAction.iconImageVector()
402+ .takeIf { it != = Icons .Stub }
403+ }
404+ val postActionTitleStringRes = remember(state.postAction) {
405+ state.postAction.titleStringRes()
406+ }
407+ val postActionDropdown = remember {
408+ sequence {
409+ yield (null )
410+ yieldAll(CreateRequest .Merge .PostAction .entries)
411+ }
412+ .map { postAction ->
413+ val titleRes = postAction.titleStringRes()
414+ val icon = postAction.iconImageVector()
415+ FlatItemAction (
416+ icon = icon,
417+ title = TextHolder .Res (titleRes),
418+ onClick = {
419+ updatedOnChangeState?.invoke(postAction)
420+ },
421+ )
422+ }
423+ .toImmutableList()
424+ }
425+ FlatDropdownSimpleExpressive (
426+ dropdown = postActionDropdown,
427+ leading = postActionIconImageVector
428+ ?.let { icon ->
429+ icon<RowScope >(icon)
430+ },
394431 content = {
395- Text (
396- text = stringResource(Res .string.additem_merge_remove_origin_ciphers_title),
432+ FlatItemTextContent (
433+ title = {
434+ Text (
435+ text = stringResource(postActionTitleStringRes),
436+ style = MaterialTheme .typography.titleMedium,
437+ )
438+ },
397439 )
398440 },
399- onClick = {
400- val newValue = ! state.removeOrigin.checked
401- state.removeOrigin.onChange?.invoke(newValue)
441+ trailing = {
442+ DropdownIcon ()
402443 },
403444 )
404445}
446+
447+ private fun CreateRequest.Merge.PostAction?.titleStringRes () = when (this ) {
448+ null -> Res .string.additem_merge_keep_origin_ciphers_title
449+ CreateRequest .Merge .PostAction .TRASH -> Res .string.additem_merge_remove_origin_ciphers_title
450+ CreateRequest .Merge .PostAction .ARCHIVE -> Res .string.additem_merge_archive_origin_ciphers_title
451+ }
452+
453+ private fun CreateRequest.Merge.PostAction?.iconImageVector () = when (this ) {
454+ null -> Icons .Stub
455+ CreateRequest .Merge .PostAction .TRASH -> Icons .Outlined .Delete
456+ CreateRequest .Merge .PostAction .ARCHIVE -> Icons .Outlined .Archive
457+ }
0 commit comments