Skip to content

Commit

Permalink
add colors to record change actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Razeeman committed Dec 7, 2024
1 parent c7b1411 commit 5834ba7
Show file tree
Hide file tree
Showing 15 changed files with 235 additions and 102 deletions.
Original file line number Diff line number Diff line change
@@ -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)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.example.util.simpletimetracker.domain.model

enum class RecordQuickAction {
CONTINUE,
REPEAT,
DUPLICATE,
MERGE,
SPLIT,
ADJUST,
STOP,
CHANGE_ACTIVITY,
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -18,19 +18,19 @@ 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)
}
}

data class ChangeRecordButtonViewData(
val block: ChangeRecordActionsBlock,
val text: String,
@DrawableRes val icon: Int,
val iconSizeDp: Int,
@ColorInt val iconColor: Int,
val isEnabled: Boolean,
) : ViewHolderType {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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<ChangeRecordActionsContinueDelegate.Parent> {

private var parent: Parent? = null
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ChangeRecordActionsDuplicateDelegate.Parent> {

private var parent: Parent? = null
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ChangeRecordActionsRepeatDelegate.Parent> {

private var parent: Parent? = null
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 5834ba7

Please sign in to comment.