From 5834ba755af59c30c4d05a8ce72a6697cc86a02d Mon Sep 17 00:00:00 2001 From: razeeman Date: Sat, 7 Dec 2024 08:57:43 +0300 Subject: [PATCH] add colors to record change actions --- .../core/mapper/RecordQuickActionMapper.kt | 54 +++++++++++++ .../domain/model/RecordQuickAction.kt | 12 +++ .../ChangeRecordButtonAdapterDelegate.kt | 14 ++-- .../mapper/ChangeRecordViewDataMapper.kt | 33 ++++++++ .../ChangeRecordActionsAdjustDelegate.kt | 10 +-- .../ChangeRecordActionsContinueDelegate.kt | 13 ++-- .../ChangeRecordActionsDuplicateDelegate.kt | 13 ++-- .../ChangeRecordActionsMergeDelegate.kt | 11 +-- .../ChangeRecordActionsRepeatDelegate.kt | 13 ++-- .../ChangeRecordActionsSplitDelegate.kt | 13 ++-- .../res/layout/change_record_button_item.xml | 65 +++++++++++++--- ...RecordQuickActionsButtonAdapterDelegate.kt | 2 +- .../RecordQuickActionsViewDataInteractor.kt | 78 +++++++++---------- .../record_quick_actions_button_item.xml | 2 +- .../mapper/StatisticsDetailViewDataMapper.kt | 4 +- 15 files changed, 235 insertions(+), 102 deletions(-) create mode 100644 core/src/main/java/com/example/util/simpletimetracker/core/mapper/RecordQuickActionMapper.kt create mode 100644 domain/src/main/java/com/example/util/simpletimetracker/domain/model/RecordQuickAction.kt diff --git a/core/src/main/java/com/example/util/simpletimetracker/core/mapper/RecordQuickActionMapper.kt b/core/src/main/java/com/example/util/simpletimetracker/core/mapper/RecordQuickActionMapper.kt new file mode 100644 index 000000000..87482b8f4 --- /dev/null +++ b/core/src/main/java/com/example/util/simpletimetracker/core/mapper/RecordQuickActionMapper.kt @@ -0,0 +1,54 @@ +package com.example.util.simpletimetracker.core.mapper + +import androidx.annotation.ColorInt +import androidx.annotation.DrawableRes +import com.example.util.simpletimetracker.core.R +import com.example.util.simpletimetracker.core.repo.ResourceRepo +import com.example.util.simpletimetracker.domain.model.RecordQuickAction +import javax.inject.Inject + +class RecordQuickActionMapper @Inject constructor( + private val resourceRepo: ResourceRepo, +) { + + fun mapText(data: RecordQuickAction): String { + return when (data) { + RecordQuickAction.CONTINUE -> R.string.change_record_continue + RecordQuickAction.REPEAT -> R.string.change_record_repeat + RecordQuickAction.DUPLICATE -> R.string.change_record_duplicate + RecordQuickAction.MERGE -> R.string.change_record_merge + RecordQuickAction.SPLIT -> R.string.change_record_split + RecordQuickAction.ADJUST -> R.string.change_record_adjust + RecordQuickAction.STOP -> R.string.notification_record_type_stop + RecordQuickAction.CHANGE_ACTIVITY -> R.string.data_edit_change_activity + }.let(resourceRepo::getString) + } + + @DrawableRes + fun mapIcon(data: RecordQuickAction): Int { + return when (data) { + RecordQuickAction.CONTINUE -> R.drawable.action_continue + RecordQuickAction.REPEAT -> R.drawable.repeat + RecordQuickAction.DUPLICATE -> R.drawable.action_copy + RecordQuickAction.MERGE -> R.drawable.action_merge + RecordQuickAction.SPLIT -> R.drawable.action_divide + RecordQuickAction.ADJUST -> R.drawable.action_change + RecordQuickAction.STOP -> R.drawable.action_stop + RecordQuickAction.CHANGE_ACTIVITY -> R.drawable.action_change_item + } + } + + @ColorInt + fun mapColor(data: RecordQuickAction): Int { + return when (data) { + RecordQuickAction.CONTINUE -> R.color.red_300 + RecordQuickAction.REPEAT -> R.color.purple_300 + RecordQuickAction.DUPLICATE -> R.color.indigo_300 + RecordQuickAction.MERGE -> R.color.light_blue_300 + RecordQuickAction.STOP -> R.color.teal_300 + RecordQuickAction.CHANGE_ACTIVITY -> R.color.green_300 + RecordQuickAction.SPLIT -> R.color.pink_300 + RecordQuickAction.ADJUST -> R.color.amber_300 + }.let(resourceRepo::getColor) + } +} \ No newline at end of file diff --git a/domain/src/main/java/com/example/util/simpletimetracker/domain/model/RecordQuickAction.kt b/domain/src/main/java/com/example/util/simpletimetracker/domain/model/RecordQuickAction.kt new file mode 100644 index 000000000..3933da82f --- /dev/null +++ b/domain/src/main/java/com/example/util/simpletimetracker/domain/model/RecordQuickAction.kt @@ -0,0 +1,12 @@ +package com.example.util.simpletimetracker.domain.model + +enum class RecordQuickAction { + CONTINUE, + REPEAT, + DUPLICATE, + MERGE, + SPLIT, + ADJUST, + STOP, + CHANGE_ACTIVITY, +} \ No newline at end of file diff --git a/features/feature_change_record/src/main/java/com/example/util/simpletimetracker/feature_change_record/adapter/ChangeRecordButtonAdapterDelegate.kt b/features/feature_change_record/src/main/java/com/example/util/simpletimetracker/feature_change_record/adapter/ChangeRecordButtonAdapterDelegate.kt index 0acf465a7..5c70ce056 100644 --- a/features/feature_change_record/src/main/java/com/example/util/simpletimetracker/feature_change_record/adapter/ChangeRecordButtonAdapterDelegate.kt +++ b/features/feature_change_record/src/main/java/com/example/util/simpletimetracker/feature_change_record/adapter/ChangeRecordButtonAdapterDelegate.kt @@ -1,10 +1,10 @@ package com.example.util.simpletimetracker.feature_change_record.adapter +import androidx.annotation.ColorInt import androidx.annotation.DrawableRes import com.example.util.simpletimetracker.feature_base_adapter.ViewHolderType import com.example.util.simpletimetracker.feature_base_adapter.createRecyclerBindingAdapterDelegate import com.example.util.simpletimetracker.feature_change_record.model.ChangeRecordActionsBlock -import com.example.util.simpletimetracker.feature_views.extension.dpToPx import com.example.util.simpletimetracker.feature_views.extension.setOnClickWith import com.example.util.simpletimetracker.feature_change_record.adapter.ChangeRecordButtonViewData as ViewData import com.example.util.simpletimetracker.feature_change_record.databinding.ChangeRecordButtonItemBinding as Binding @@ -18,11 +18,11 @@ fun createChangeRecordButtonAdapterDelegate( with(binding) { item as ViewData - btnChangeRecordButtonItem.text = item.text - btnChangeRecordButtonItem.setIconResource(item.icon) - btnChangeRecordButtonItem.iconSize = item.iconSizeDp.dpToPx() - btnChangeRecordButtonItem.isEnabled = item.isEnabled - btnChangeRecordButtonItem.setOnClickWith(item, onClick) + tvRecordQuickActionsButton.text = item.text + ivRecordQuickActionsButton.setImageResource(item.icon) + cardChangeRecordActionsButton.setCardBackgroundColor(item.iconColor) + itemRecordQuickActionsButton.isEnabled = item.isEnabled + itemRecordQuickActionsButton.setOnClickWith(item, onClick) } } @@ -30,7 +30,7 @@ data class ChangeRecordButtonViewData( val block: ChangeRecordActionsBlock, val text: String, @DrawableRes val icon: Int, - val iconSizeDp: Int, + @ColorInt val iconColor: Int, val isEnabled: Boolean, ) : ViewHolderType { diff --git a/features/feature_change_record/src/main/java/com/example/util/simpletimetracker/feature_change_record/mapper/ChangeRecordViewDataMapper.kt b/features/feature_change_record/src/main/java/com/example/util/simpletimetracker/feature_change_record/mapper/ChangeRecordViewDataMapper.kt index fbc5de879..aed25e565 100644 --- a/features/feature_change_record/src/main/java/com/example/util/simpletimetracker/feature_change_record/mapper/ChangeRecordViewDataMapper.kt +++ b/features/feature_change_record/src/main/java/com/example/util/simpletimetracker/feature_change_record/mapper/ChangeRecordViewDataMapper.kt @@ -3,14 +3,18 @@ package com.example.util.simpletimetracker.feature_change_record.mapper import com.example.util.simpletimetracker.core.mapper.ChangeRecordDateTimeMapper import com.example.util.simpletimetracker.core.mapper.ColorMapper import com.example.util.simpletimetracker.core.mapper.IconMapper +import com.example.util.simpletimetracker.core.mapper.RecordQuickActionMapper import com.example.util.simpletimetracker.core.mapper.RecordViewDataMapper import com.example.util.simpletimetracker.core.mapper.TimeMapper import com.example.util.simpletimetracker.core.repo.ResourceRepo import com.example.util.simpletimetracker.domain.extension.getFullName import com.example.util.simpletimetracker.domain.model.Record +import com.example.util.simpletimetracker.domain.model.RecordQuickAction import com.example.util.simpletimetracker.domain.model.RecordTag import com.example.util.simpletimetracker.domain.model.RecordType import com.example.util.simpletimetracker.feature_change_record.R +import com.example.util.simpletimetracker.feature_change_record.adapter.ChangeRecordButtonViewData +import com.example.util.simpletimetracker.feature_change_record.model.ChangeRecordActionsBlock import com.example.util.simpletimetracker.feature_change_record.model.ChangeRecordDateTimeFieldsState import com.example.util.simpletimetracker.feature_change_record.viewData.ChangeRecordSimpleViewData import com.example.util.simpletimetracker.feature_change_record.viewData.ChangeRecordViewData @@ -23,6 +27,7 @@ class ChangeRecordViewDataMapper @Inject constructor( private val resourceRepo: ResourceRepo, private val recordViewDataMapper: RecordViewDataMapper, private val changeRecordDateTimeMapper: ChangeRecordDateTimeMapper, + private val recordQuickActionMapper: RecordQuickActionMapper, ) { fun map( @@ -114,4 +119,32 @@ class ChangeRecordViewDataMapper @Inject constructor( color = preview.color, ) } + + fun mapRecordActionButton( + action: RecordQuickAction, + isEnabled: Boolean, + ): ChangeRecordButtonViewData? { + return ChangeRecordButtonViewData( + block = mapRecordAction(action) ?: return null, + text = recordQuickActionMapper.mapText(action), + icon = recordQuickActionMapper.mapIcon(action), + iconColor = recordQuickActionMapper.mapColor(action), + isEnabled = isEnabled, + ) + } + + private fun mapRecordAction( + action: RecordQuickAction, + ): ChangeRecordActionsBlock? { + return when (action) { + RecordQuickAction.CONTINUE -> ChangeRecordActionsBlock.ContinueButton + RecordQuickAction.REPEAT -> ChangeRecordActionsBlock.RepeatButton + RecordQuickAction.DUPLICATE -> ChangeRecordActionsBlock.DuplicateButton + RecordQuickAction.MERGE -> ChangeRecordActionsBlock.MergeButton + RecordQuickAction.SPLIT -> ChangeRecordActionsBlock.SplitButton + RecordQuickAction.ADJUST -> ChangeRecordActionsBlock.AdjustButton + RecordQuickAction.STOP -> null + RecordQuickAction.CHANGE_ACTIVITY -> null + } + } } \ No newline at end of file diff --git a/features/feature_change_record/src/main/java/com/example/util/simpletimetracker/feature_change_record/viewModel/ChangeRecordActionsAdjustDelegate.kt b/features/feature_change_record/src/main/java/com/example/util/simpletimetracker/feature_change_record/viewModel/ChangeRecordActionsAdjustDelegate.kt index b596b3beb..4420aef0d 100644 --- a/features/feature_change_record/src/main/java/com/example/util/simpletimetracker/feature_change_record/viewModel/ChangeRecordActionsAdjustDelegate.kt +++ b/features/feature_change_record/src/main/java/com/example/util/simpletimetracker/feature_change_record/viewModel/ChangeRecordActionsAdjustDelegate.kt @@ -4,17 +4,18 @@ import com.example.util.simpletimetracker.core.base.ViewModelDelegate import com.example.util.simpletimetracker.domain.extension.addOrRemove import com.example.util.simpletimetracker.core.mapper.TimeMapper import com.example.util.simpletimetracker.core.repo.ResourceRepo +import com.example.util.simpletimetracker.domain.extension.plusAssign import com.example.util.simpletimetracker.domain.interactor.AddRecordMediator import com.example.util.simpletimetracker.domain.interactor.PrefsInteractor import com.example.util.simpletimetracker.domain.interactor.RecordInteractor import com.example.util.simpletimetracker.domain.interactor.RemoveRecordMediator import com.example.util.simpletimetracker.domain.model.Range import com.example.util.simpletimetracker.domain.model.Record +import com.example.util.simpletimetracker.domain.model.RecordQuickAction import com.example.util.simpletimetracker.feature_base_adapter.ViewHolderType import com.example.util.simpletimetracker.feature_base_adapter.hint.HintAccentViewData import com.example.util.simpletimetracker.feature_base_adapter.hint.HintViewData import com.example.util.simpletimetracker.feature_change_record.R -import com.example.util.simpletimetracker.feature_change_record.adapter.ChangeRecordButtonViewData import com.example.util.simpletimetracker.feature_change_record.adapter.ChangeRecordChangePreviewViewData import com.example.util.simpletimetracker.feature_change_record.adapter.ChangeRecordTimeAdjustmentViewData import com.example.util.simpletimetracker.feature_change_record.adapter.ChangeRecordTimeDoublePreviewViewData @@ -140,11 +141,8 @@ class ChangeRecordActionsAdjustDelegate @Inject constructor( ) } result += state.changesPreview - result += ChangeRecordButtonViewData( - block = ChangeRecordActionsBlock.AdjustButton, - text = resourceRepo.getString(R.string.change_record_adjust), - icon = R.drawable.action_change, - iconSizeDp = 28, + result += changeRecordViewDataMapper.mapRecordActionButton( + action = RecordQuickAction.ADJUST, isEnabled = params.isButtonEnabled, ) return result diff --git a/features/feature_change_record/src/main/java/com/example/util/simpletimetracker/feature_change_record/viewModel/ChangeRecordActionsContinueDelegate.kt b/features/feature_change_record/src/main/java/com/example/util/simpletimetracker/feature_change_record/viewModel/ChangeRecordActionsContinueDelegate.kt index 7aa314cfe..6e86962c4 100644 --- a/features/feature_change_record/src/main/java/com/example/util/simpletimetracker/feature_change_record/viewModel/ChangeRecordActionsContinueDelegate.kt +++ b/features/feature_change_record/src/main/java/com/example/util/simpletimetracker/feature_change_record/viewModel/ChangeRecordActionsContinueDelegate.kt @@ -1,13 +1,14 @@ package com.example.util.simpletimetracker.feature_change_record.viewModel import com.example.util.simpletimetracker.core.repo.ResourceRepo +import com.example.util.simpletimetracker.domain.extension.plusAssign import com.example.util.simpletimetracker.domain.interactor.PrefsInteractor import com.example.util.simpletimetracker.domain.interactor.RecordActionContinueMediator +import com.example.util.simpletimetracker.domain.model.RecordQuickAction import com.example.util.simpletimetracker.feature_base_adapter.ViewHolderType import com.example.util.simpletimetracker.feature_base_adapter.hint.HintViewData import com.example.util.simpletimetracker.feature_change_record.R -import com.example.util.simpletimetracker.feature_change_record.adapter.ChangeRecordButtonViewData -import com.example.util.simpletimetracker.feature_change_record.model.ChangeRecordActionsBlock +import com.example.util.simpletimetracker.feature_change_record.mapper.ChangeRecordViewDataMapper import com.example.util.simpletimetracker.navigation.Router import javax.inject.Inject @@ -16,6 +17,7 @@ class ChangeRecordActionsContinueDelegate @Inject constructor( private val resourceRepo: ResourceRepo, private val prefsInteractor: PrefsInteractor, private val recordActionContinueMediator: RecordActionContinueMediator, + private val changeRecordViewDataMapper: ChangeRecordViewDataMapper, ) : ChangeRecordActionsSubDelegate { private var parent: Parent? = null @@ -69,11 +71,8 @@ class ChangeRecordActionsContinueDelegate @Inject constructor( result += HintViewData( text = resourceRepo.getString(R.string.change_record_continue_hint), ) - result += ChangeRecordButtonViewData( - block = ChangeRecordActionsBlock.ContinueButton, - text = resourceRepo.getString(R.string.change_record_continue), - icon = R.drawable.action_continue, - iconSizeDp = 24, + result += changeRecordViewDataMapper.mapRecordActionButton( + action = RecordQuickAction.CONTINUE, isEnabled = params.isButtonEnabled, ) return result diff --git a/features/feature_change_record/src/main/java/com/example/util/simpletimetracker/feature_change_record/viewModel/ChangeRecordActionsDuplicateDelegate.kt b/features/feature_change_record/src/main/java/com/example/util/simpletimetracker/feature_change_record/viewModel/ChangeRecordActionsDuplicateDelegate.kt index 1c6f62ba9..403c42bf6 100644 --- a/features/feature_change_record/src/main/java/com/example/util/simpletimetracker/feature_change_record/viewModel/ChangeRecordActionsDuplicateDelegate.kt +++ b/features/feature_change_record/src/main/java/com/example/util/simpletimetracker/feature_change_record/viewModel/ChangeRecordActionsDuplicateDelegate.kt @@ -1,17 +1,19 @@ package com.example.util.simpletimetracker.feature_change_record.viewModel import com.example.util.simpletimetracker.core.repo.ResourceRepo +import com.example.util.simpletimetracker.domain.extension.plusAssign import com.example.util.simpletimetracker.domain.interactor.RecordActionDuplicateMediator +import com.example.util.simpletimetracker.domain.model.RecordQuickAction import com.example.util.simpletimetracker.feature_base_adapter.ViewHolderType import com.example.util.simpletimetracker.feature_base_adapter.hint.HintViewData import com.example.util.simpletimetracker.feature_change_record.R -import com.example.util.simpletimetracker.feature_change_record.adapter.ChangeRecordButtonViewData -import com.example.util.simpletimetracker.feature_change_record.model.ChangeRecordActionsBlock +import com.example.util.simpletimetracker.feature_change_record.mapper.ChangeRecordViewDataMapper import javax.inject.Inject class ChangeRecordActionsDuplicateDelegate @Inject constructor( private val resourceRepo: ResourceRepo, private val recordActionDuplicateMediator: RecordActionDuplicateMediator, + private val changeRecordViewDataMapper: ChangeRecordViewDataMapper, ) : ChangeRecordActionsSubDelegate { private var parent: Parent? = null @@ -51,11 +53,8 @@ class ChangeRecordActionsDuplicateDelegate @Inject constructor( result += HintViewData( text = resourceRepo.getString(R.string.change_record_duplicate_hint), ) - result += ChangeRecordButtonViewData( - block = ChangeRecordActionsBlock.DuplicateButton, - text = resourceRepo.getString(R.string.change_record_duplicate), - icon = R.drawable.action_copy, - iconSizeDp = 20, + result += changeRecordViewDataMapper.mapRecordActionButton( + action = RecordQuickAction.DUPLICATE, isEnabled = params.isButtonEnabled, ) return result diff --git a/features/feature_change_record/src/main/java/com/example/util/simpletimetracker/feature_change_record/viewModel/ChangeRecordActionsMergeDelegate.kt b/features/feature_change_record/src/main/java/com/example/util/simpletimetracker/feature_change_record/viewModel/ChangeRecordActionsMergeDelegate.kt index a81604e70..e05287d73 100644 --- a/features/feature_change_record/src/main/java/com/example/util/simpletimetracker/feature_change_record/viewModel/ChangeRecordActionsMergeDelegate.kt +++ b/features/feature_change_record/src/main/java/com/example/util/simpletimetracker/feature_change_record/viewModel/ChangeRecordActionsMergeDelegate.kt @@ -1,16 +1,16 @@ package com.example.util.simpletimetracker.feature_change_record.viewModel import com.example.util.simpletimetracker.core.repo.ResourceRepo +import com.example.util.simpletimetracker.domain.extension.plusAssign import com.example.util.simpletimetracker.domain.interactor.RecordActionMergeMediator import com.example.util.simpletimetracker.domain.model.Record +import com.example.util.simpletimetracker.domain.model.RecordQuickAction import com.example.util.simpletimetracker.feature_base_adapter.ViewHolderType import com.example.util.simpletimetracker.feature_base_adapter.hint.HintViewData import com.example.util.simpletimetracker.feature_change_record.R -import com.example.util.simpletimetracker.feature_change_record.adapter.ChangeRecordButtonViewData import com.example.util.simpletimetracker.feature_change_record.adapter.ChangeRecordChangePreviewViewData import com.example.util.simpletimetracker.feature_change_record.interactor.ChangeRecordViewDataInteractor import com.example.util.simpletimetracker.feature_change_record.mapper.ChangeRecordViewDataMapper -import com.example.util.simpletimetracker.feature_change_record.model.ChangeRecordActionsBlock import com.example.util.simpletimetracker.feature_change_record.model.ChangeRecordDateTimeFieldsState import com.example.util.simpletimetracker.feature_change_record.viewData.ChangeRecordPreview import com.example.util.simpletimetracker.navigation.Router @@ -64,11 +64,8 @@ class ChangeRecordActionsMergeDelegate @Inject constructor( isCheckVisible = false, isCompareVisible = true, ) - result += ChangeRecordButtonViewData( - block = ChangeRecordActionsBlock.MergeButton, - text = resourceRepo.getString(R.string.change_record_merge), - icon = R.drawable.action_merge, - iconSizeDp = 24, + result += changeRecordViewDataMapper.mapRecordActionButton( + action = RecordQuickAction.MERGE, isEnabled = params.isButtonEnabled, ) } diff --git a/features/feature_change_record/src/main/java/com/example/util/simpletimetracker/feature_change_record/viewModel/ChangeRecordActionsRepeatDelegate.kt b/features/feature_change_record/src/main/java/com/example/util/simpletimetracker/feature_change_record/viewModel/ChangeRecordActionsRepeatDelegate.kt index 079eb8807..d1bc7b5d5 100644 --- a/features/feature_change_record/src/main/java/com/example/util/simpletimetracker/feature_change_record/viewModel/ChangeRecordActionsRepeatDelegate.kt +++ b/features/feature_change_record/src/main/java/com/example/util/simpletimetracker/feature_change_record/viewModel/ChangeRecordActionsRepeatDelegate.kt @@ -1,17 +1,19 @@ package com.example.util.simpletimetracker.feature_change_record.viewModel import com.example.util.simpletimetracker.core.repo.ResourceRepo +import com.example.util.simpletimetracker.domain.extension.plusAssign import com.example.util.simpletimetracker.domain.interactor.RecordActionRepeatMediator +import com.example.util.simpletimetracker.domain.model.RecordQuickAction import com.example.util.simpletimetracker.feature_base_adapter.ViewHolderType import com.example.util.simpletimetracker.feature_base_adapter.hint.HintViewData import com.example.util.simpletimetracker.feature_change_record.R -import com.example.util.simpletimetracker.feature_change_record.adapter.ChangeRecordButtonViewData -import com.example.util.simpletimetracker.feature_change_record.model.ChangeRecordActionsBlock +import com.example.util.simpletimetracker.feature_change_record.mapper.ChangeRecordViewDataMapper import javax.inject.Inject class ChangeRecordActionsRepeatDelegate @Inject constructor( private val resourceRepo: ResourceRepo, private val recordActionRepeatMediator: RecordActionRepeatMediator, + private val changeRecordViewDataMapper: ChangeRecordViewDataMapper, ) : ChangeRecordActionsSubDelegate { private var parent: Parent? = null @@ -53,11 +55,8 @@ class ChangeRecordActionsRepeatDelegate @Inject constructor( result += HintViewData( text = resourceRepo.getString(R.string.change_record_repeat_hint), ) - result += ChangeRecordButtonViewData( - block = ChangeRecordActionsBlock.RepeatButton, - text = resourceRepo.getString(R.string.change_record_repeat), - icon = R.drawable.repeat, - iconSizeDp = 24, + result += changeRecordViewDataMapper.mapRecordActionButton( + action = RecordQuickAction.REPEAT, isEnabled = params.isButtonEnabled, ) return result diff --git a/features/feature_change_record/src/main/java/com/example/util/simpletimetracker/feature_change_record/viewModel/ChangeRecordActionsSplitDelegate.kt b/features/feature_change_record/src/main/java/com/example/util/simpletimetracker/feature_change_record/viewModel/ChangeRecordActionsSplitDelegate.kt index febbf2712..d8147e84c 100644 --- a/features/feature_change_record/src/main/java/com/example/util/simpletimetracker/feature_change_record/viewModel/ChangeRecordActionsSplitDelegate.kt +++ b/features/feature_change_record/src/main/java/com/example/util/simpletimetracker/feature_change_record/viewModel/ChangeRecordActionsSplitDelegate.kt @@ -1,12 +1,13 @@ package com.example.util.simpletimetracker.feature_change_record.viewModel import com.example.util.simpletimetracker.core.repo.ResourceRepo +import com.example.util.simpletimetracker.domain.extension.plusAssign import com.example.util.simpletimetracker.domain.interactor.AddRecordMediator import com.example.util.simpletimetracker.domain.model.Record +import com.example.util.simpletimetracker.domain.model.RecordQuickAction import com.example.util.simpletimetracker.feature_base_adapter.ViewHolderType import com.example.util.simpletimetracker.feature_base_adapter.hint.HintViewData import com.example.util.simpletimetracker.feature_change_record.R -import com.example.util.simpletimetracker.feature_change_record.adapter.ChangeRecordButtonViewData import com.example.util.simpletimetracker.feature_change_record.adapter.ChangeRecordChangePreviewViewData import com.example.util.simpletimetracker.feature_change_record.adapter.ChangeRecordSliderViewData import com.example.util.simpletimetracker.feature_change_record.adapter.ChangeRecordTimeAdjustmentViewData @@ -71,7 +72,6 @@ class ChangeRecordActionsSplitDelegate @Inject constructor( val newTimeStarted = params.newTimeStarted val newTimeEnded = params.splitPreviewTimeEnded val showTimeEnded = params.showTimeEndedOnSplitPreview - val isButtonEnabled = params.isButtonEnabled val result = mutableListOf() result += HintViewData(resourceRepo.getString(R.string.change_record_split_hint)) @@ -106,12 +106,9 @@ class ChangeRecordActionsSplitDelegate @Inject constructor( isCheckVisible = false, isCompareVisible = false, ) - result += ChangeRecordButtonViewData( - block = ChangeRecordActionsBlock.SplitButton, - text = resourceRepo.getString(R.string.change_record_split), - icon = R.drawable.action_divide, - iconSizeDp = 18, - isEnabled = isButtonEnabled, + result += changeRecordViewDataMapper.mapRecordActionButton( + action = RecordQuickAction.SPLIT, + isEnabled = params.isButtonEnabled, ) return result } diff --git a/features/feature_change_record/src/main/res/layout/change_record_button_item.xml b/features/feature_change_record/src/main/res/layout/change_record_button_item.xml index caa0c92ce..f569b2e66 100644 --- a/features/feature_change_record/src/main/res/layout/change_record_button_item.xml +++ b/features/feature_change_record/src/main/res/layout/change_record_button_item.xml @@ -1,13 +1,60 @@ - + android:layout_height="@dimen/button_height" + android:layout_marginHorizontal="4dp" + android:layout_weight="1" + app:cardBackgroundColor="?appActiveColor"> + + + + + + + + + + + + + + diff --git a/features/feature_dialogs/src/main/java/com/example/util/simpletimetracker/feature_dialogs/recordQuickActions/adapter/RecordQuickActionsButtonAdapterDelegate.kt b/features/feature_dialogs/src/main/java/com/example/util/simpletimetracker/feature_dialogs/recordQuickActions/adapter/RecordQuickActionsButtonAdapterDelegate.kt index 2bb213566..5d3187e98 100644 --- a/features/feature_dialogs/src/main/java/com/example/util/simpletimetracker/feature_dialogs/recordQuickActions/adapter/RecordQuickActionsButtonAdapterDelegate.kt +++ b/features/feature_dialogs/src/main/java/com/example/util/simpletimetracker/feature_dialogs/recordQuickActions/adapter/RecordQuickActionsButtonAdapterDelegate.kt @@ -22,7 +22,7 @@ fun createRecordQuickActionsButtonAdapterDelegate( tvRecordQuickActionsButton.text = item.text ivRecordQuickActionsButton.setImageResource(item.icon) cardRecordQuickActionsButton.setCardBackgroundColor(item.iconColor) - btnRecordQuickActionsButton.setOnClickWith(item.block, onClick) + itemRecordQuickActionsButton.setOnClickWith(item.block, onClick) } } diff --git a/features/feature_dialogs/src/main/java/com/example/util/simpletimetracker/feature_dialogs/recordQuickActions/interactor/RecordQuickActionsViewDataInteractor.kt b/features/feature_dialogs/src/main/java/com/example/util/simpletimetracker/feature_dialogs/recordQuickActions/interactor/RecordQuickActionsViewDataInteractor.kt index 7ab1b0d8a..3d5edd3cb 100644 --- a/features/feature_dialogs/src/main/java/com/example/util/simpletimetracker/feature_dialogs/recordQuickActions/interactor/RecordQuickActionsViewDataInteractor.kt +++ b/features/feature_dialogs/src/main/java/com/example/util/simpletimetracker/feature_dialogs/recordQuickActions/interactor/RecordQuickActionsViewDataInteractor.kt @@ -1,7 +1,9 @@ package com.example.util.simpletimetracker.feature_dialogs.recordQuickActions.interactor +import com.example.util.simpletimetracker.core.mapper.RecordQuickActionMapper import com.example.util.simpletimetracker.core.repo.ResourceRepo import com.example.util.simpletimetracker.domain.interactor.PrefsInteractor +import com.example.util.simpletimetracker.domain.model.RecordQuickAction import com.example.util.simpletimetracker.feature_base_adapter.ViewHolderType import com.example.util.simpletimetracker.feature_dialogs.R import com.example.util.simpletimetracker.feature_dialogs.recordQuickActions.adapter.RecordQuickActionsBlockHolder @@ -17,6 +19,7 @@ import javax.inject.Inject class RecordQuickActionsViewDataInteractor @Inject constructor( private val resourceRepo: ResourceRepo, private val prefsInteractor: PrefsInteractor, + private val recordQuickActionMapper: RecordQuickActionMapper, ) { suspend fun getViewData( @@ -36,6 +39,14 @@ class RecordQuickActionsViewDataInteractor @Inject constructor( } private fun getAllButtons(): List { + val allActions = listOf( + RecordQuickActionsButton.CONTINUE, + RecordQuickActionsButton.REPEAT, + RecordQuickActionsButton.DUPLICATE, + RecordQuickActionsButton.MERGE, + RecordQuickActionsButton.STOP, + RecordQuickActionsButton.CHANGE_ACTIVITY, + ) return listOf( RecordQuickActionsButtonBigViewData( block = RecordQuickActionsButton.STATISTICS, @@ -47,43 +58,15 @@ class RecordQuickActionsViewDataInteractor @Inject constructor( text = R.string.archive_dialog_delete.let(resourceRepo::getString), icon = R.drawable.delete, ), + ) + allActions.mapNotNull { + val action = mapAction(it) ?: return@mapNotNull null RecordQuickActionsButtonViewData( - block = RecordQuickActionsButton.CONTINUE, - text = R.string.change_record_continue.let(resourceRepo::getString), - icon = R.drawable.action_continue, - iconColor = resourceRepo.getColor(R.color.red_300), - ), - RecordQuickActionsButtonViewData( - block = RecordQuickActionsButton.REPEAT, - text = R.string.change_record_repeat.let(resourceRepo::getString), - icon = R.drawable.repeat, - iconColor = resourceRepo.getColor(R.color.purple_300), - ), - RecordQuickActionsButtonViewData( - block = RecordQuickActionsButton.DUPLICATE, - text = R.string.change_record_duplicate.let(resourceRepo::getString), - icon = R.drawable.action_copy, - iconColor = resourceRepo.getColor(R.color.indigo_300), - ), - RecordQuickActionsButtonViewData( - block = RecordQuickActionsButton.MERGE, - text = R.string.change_record_merge.let(resourceRepo::getString), - icon = R.drawable.action_merge, - iconColor = resourceRepo.getColor(R.color.light_blue_300), - ), - RecordQuickActionsButtonViewData( - block = RecordQuickActionsButton.STOP, - text = R.string.notification_record_type_stop.let(resourceRepo::getString), - icon = R.drawable.action_stop, - iconColor = resourceRepo.getColor(R.color.teal_300), - ), - RecordQuickActionsButtonViewData( - block = RecordQuickActionsButton.CHANGE_ACTIVITY, - text = resourceRepo.getString(R.string.data_edit_change_activity), - icon = R.drawable.action_change_item, - iconColor = resourceRepo.getColor(R.color.green_300), - ), - ) + block = it, + text = recordQuickActionMapper.mapText(action), + icon = recordQuickActionMapper.mapIcon(action), + iconColor = recordQuickActionMapper.mapColor(action), + ) + } } private fun getAllowedButtons( @@ -127,17 +110,32 @@ class RecordQuickActionsViewDataInteractor @Inject constructor( .indexOfLast { it is RecordQuickActionsButtonViewData } return buttons.mapIndexed { index, button -> + val isBigButtonFullWidth = bigButtonsCount % 2 != 0 && index == bigButtonLastIndex + val isSmallButtonFullWidth = smallButtonsCount % 2 != 0 && index == smallButtonLastIndex when { - button is RecordQuickActionsButtonBigViewData && - bigButtonsCount % 2 != 0 && index == bigButtonLastIndex -> { + button is RecordQuickActionsButtonBigViewData && isBigButtonFullWidth -> { button.copy(width = RecordQuickActionsWidthHolder.Width.Full) } - button is RecordQuickActionsButtonViewData && - smallButtonsCount % 2 != 0 && index == smallButtonLastIndex -> { + button is RecordQuickActionsButtonViewData && isSmallButtonFullWidth -> { button.copy(width = RecordQuickActionsWidthHolder.Width.Full) } else -> button } } } + + private fun mapAction( + action: RecordQuickActionsButton, + ): RecordQuickAction? { + return when (action) { + RecordQuickActionsButton.STATISTICS -> null + RecordQuickActionsButton.DELETE -> null + RecordQuickActionsButton.CONTINUE -> RecordQuickAction.CONTINUE + RecordQuickActionsButton.REPEAT -> RecordQuickAction.REPEAT + RecordQuickActionsButton.DUPLICATE -> RecordQuickAction.DUPLICATE + RecordQuickActionsButton.MERGE -> RecordQuickAction.MERGE + RecordQuickActionsButton.STOP -> RecordQuickAction.STOP + RecordQuickActionsButton.CHANGE_ACTIVITY -> RecordQuickAction.CHANGE_ACTIVITY + } + } } \ No newline at end of file diff --git a/features/feature_dialogs/src/main/res/layout/record_quick_actions_button_item.xml b/features/feature_dialogs/src/main/res/layout/record_quick_actions_button_item.xml index 0702a6e6f..2d651e950 100644 --- a/features/feature_dialogs/src/main/res/layout/record_quick_actions_button_item.xml +++ b/features/feature_dialogs/src/main/res/layout/record_quick_actions_button_item.xml @@ -2,7 +2,7 @@ = 3) 12 else null + textSizeSp = if (availableChartGroupings.size >= 3) 12 else null, ) } }