-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
466 additions
and
260 deletions.
There are no files selected for viewing
201 changes: 201 additions & 0 deletions
201
.../util/simpletimetracker/feature_change_record/mapper/ChangeRecordActionsDelegateMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,201 @@ | ||
package com.example.util.simpletimetracker.feature_change_record.mapper | ||
|
||
import com.example.util.simpletimetracker.feature_change_record.viewModel.ChangeRecordActionsAdjustDelegate | ||
import com.example.util.simpletimetracker.feature_change_record.viewModel.ChangeRecordActionsContinueDelegate | ||
import com.example.util.simpletimetracker.feature_change_record.viewModel.ChangeRecordActionsDelegate | ||
import com.example.util.simpletimetracker.feature_change_record.viewModel.ChangeRecordActionsDelegate.Parent.ViewDataParams | ||
import com.example.util.simpletimetracker.feature_change_record.viewModel.ChangeRecordActionsDuplicateDelegate | ||
import com.example.util.simpletimetracker.feature_change_record.viewModel.ChangeRecordActionsMergeDelegate | ||
import com.example.util.simpletimetracker.feature_change_record.viewModel.ChangeRecordActionsRepeatDelegate | ||
import com.example.util.simpletimetracker.feature_change_record.viewModel.ChangeRecordActionsSplitDelegate | ||
import javax.inject.Inject | ||
|
||
class ChangeRecordActionsDelegateMapper @Inject constructor() { | ||
|
||
fun getSplitDelegateParent( | ||
parent: ChangeRecordActionsDelegate.Parent?, | ||
updateViewData: () -> Unit, | ||
): ChangeRecordActionsSplitDelegate.Parent { | ||
return object : ChangeRecordActionsSplitDelegate.Parent { | ||
override fun getViewDataParams(): ChangeRecordActionsSplitDelegate.Parent.ViewDataParams? { | ||
return parent?.getViewDataParams()?.mapSplitParams() | ||
} | ||
|
||
override fun update() { | ||
updateViewData() | ||
} | ||
|
||
override suspend fun onSplitComplete() { | ||
parent?.onSplitComplete() | ||
} | ||
} | ||
} | ||
|
||
fun getAdjustDelegateParent( | ||
parent: ChangeRecordActionsDelegate.Parent?, | ||
updateViewData: () -> Unit, | ||
): ChangeRecordActionsAdjustDelegate.Parent { | ||
return object : ChangeRecordActionsAdjustDelegate.Parent { | ||
override fun getViewDataParams(): ChangeRecordActionsAdjustDelegate.Parent.ViewDataParams? { | ||
return parent?.getViewDataParams()?.mapAdjustParams() | ||
} | ||
|
||
override fun update() { | ||
updateViewData() | ||
} | ||
|
||
override suspend fun onAdjustComplete() { | ||
parent?.onSaveClickDelegate() | ||
} | ||
} | ||
} | ||
|
||
fun getContinueActionsDelegateParent( | ||
parent: ChangeRecordActionsDelegate.Parent?, | ||
updateViewData: () -> Unit, | ||
): ChangeRecordActionsContinueDelegate.Parent { | ||
return object : ChangeRecordActionsContinueDelegate.Parent { | ||
override fun getViewDataParams(): ChangeRecordActionsContinueDelegate.Parent.ViewDataParams? { | ||
return parent?.getViewDataParams()?.mapContinueParams() | ||
} | ||
|
||
override fun update() { | ||
updateViewData() | ||
} | ||
|
||
override suspend fun onSaveClickDelegate() { | ||
parent?.onSaveClickDelegate() | ||
} | ||
|
||
override fun showMessage(stringResId: Int) { | ||
parent?.showMessage(stringResId) | ||
} | ||
} | ||
} | ||
|
||
fun getRepeatActionsDelegateParent( | ||
parent: ChangeRecordActionsDelegate.Parent?, | ||
updateViewData: () -> Unit, | ||
): ChangeRecordActionsRepeatDelegate.Parent { | ||
return object : ChangeRecordActionsRepeatDelegate.Parent { | ||
override fun getViewDataParams(): ChangeRecordActionsRepeatDelegate.Parent.ViewDataParams? { | ||
return parent?.getViewDataParams()?.mapRepeatParams() | ||
} | ||
|
||
override fun update() { | ||
updateViewData() | ||
} | ||
|
||
override suspend fun onSaveClickDelegate() { | ||
parent?.onSaveClickDelegate() | ||
} | ||
} | ||
} | ||
|
||
fun getDuplicateActionsDelegateParent( | ||
parent: ChangeRecordActionsDelegate.Parent?, | ||
updateViewData: () -> Unit, | ||
): ChangeRecordActionsDuplicateDelegate.Parent { | ||
return object : ChangeRecordActionsDuplicateDelegate.Parent { | ||
override fun getViewDataParams(): ChangeRecordActionsDuplicateDelegate.Parent.ViewDataParams? { | ||
return parent?.getViewDataParams()?.mapDuplicateParams() | ||
} | ||
|
||
override fun update() { | ||
updateViewData() | ||
} | ||
|
||
override suspend fun onSaveClickDelegate() { | ||
parent?.onSaveClickDelegate() | ||
} | ||
} | ||
} | ||
|
||
fun getMergeDelegateParent( | ||
parent: ChangeRecordActionsDelegate.Parent?, | ||
updateViewData: () -> Unit, | ||
): ChangeRecordActionsMergeDelegate.Parent { | ||
return object : ChangeRecordActionsMergeDelegate.Parent { | ||
override fun getViewDataParams(): ChangeRecordActionsMergeDelegate.Parent.ViewDataParams? { | ||
return parent?.getViewDataParams()?.mapMergeParams() | ||
} | ||
|
||
override fun update() { | ||
updateViewData() | ||
} | ||
} | ||
} | ||
|
||
private fun ViewDataParams.mapSplitParams(): ChangeRecordActionsSplitDelegate.Parent.ViewDataParams { | ||
return ChangeRecordActionsSplitDelegate.Parent.ViewDataParams( | ||
newTimeSplit = splitParams.newTimeSplit, | ||
newTypeId = baseParams.newTypeId, | ||
newTimeStarted = baseParams.newTimeStarted, | ||
splitPreviewTimeEnded = splitParams.splitPreviewTimeEnded, | ||
newComment = baseParams.newComment, | ||
newCategoryIds = baseParams.newCategoryIds, | ||
showTimeEndedOnSplitPreview = splitParams.showTimeEndedOnSplitPreview, | ||
isButtonEnabled = baseParams.isButtonEnabled, | ||
) | ||
} | ||
|
||
private fun ViewDataParams.mapAdjustParams(): ChangeRecordActionsAdjustDelegate.Parent.ViewDataParams { | ||
return ChangeRecordActionsAdjustDelegate.Parent.ViewDataParams( | ||
originalRecordId = adjustParams.originalRecordId, | ||
adjustNextRecordAvailable = adjustParams.adjustNextRecordAvailable, | ||
newTypeId = baseParams.newTypeId, | ||
newTimeStarted = baseParams.newTimeStarted, | ||
newTimeEnded = baseParams.newTimeEnded, | ||
adjustPreviewTimeEnded = adjustParams.adjustPreviewTimeEnded, | ||
originalTypeId = adjustParams.originalTypeId, | ||
originalTimeStarted = adjustParams.originalTimeStarted, | ||
adjustPreviewOriginalTimeEnded = adjustParams.adjustPreviewOriginalTimeEnded, | ||
showTimeEndedOnAdjustPreview = adjustParams.showTimeEndedOnAdjustPreview, | ||
isTimeEndedAvailable = adjustParams.isTimeEndedAvailable, | ||
isButtonEnabled = baseParams.isButtonEnabled, | ||
) | ||
} | ||
|
||
private fun ViewDataParams.mapContinueParams(): ChangeRecordActionsContinueDelegate.Parent.ViewDataParams { | ||
return ChangeRecordActionsContinueDelegate.Parent.ViewDataParams( | ||
originalRecordId = continueParams.originalRecordId, | ||
newTypeId = baseParams.newTypeId, | ||
newTimeStarted = baseParams.newTimeStarted, | ||
newComment = baseParams.newComment, | ||
newCategoryIds = baseParams.newCategoryIds, | ||
isAdditionalActionsAvailable = continueParams.isAdditionalActionsAvailable, | ||
isButtonEnabled = baseParams.isButtonEnabled, | ||
) | ||
} | ||
|
||
private fun ViewDataParams.mapRepeatParams(): ChangeRecordActionsRepeatDelegate.Parent.ViewDataParams { | ||
return ChangeRecordActionsRepeatDelegate.Parent.ViewDataParams( | ||
newTypeId = baseParams.newTypeId, | ||
newComment = baseParams.newComment, | ||
newCategoryIds = baseParams.newCategoryIds, | ||
isAdditionalActionsAvailable = repeatParams.isAdditionalActionsAvailable, | ||
isButtonEnabled = baseParams.isButtonEnabled, | ||
) | ||
} | ||
|
||
private fun ViewDataParams.mapDuplicateParams(): ChangeRecordActionsDuplicateDelegate.Parent.ViewDataParams { | ||
return ChangeRecordActionsDuplicateDelegate.Parent.ViewDataParams( | ||
newTypeId = baseParams.newTypeId, | ||
newTimeStarted = baseParams.newTimeStarted, | ||
newTimeEnded = baseParams.newTimeEnded, | ||
newComment = baseParams.newComment, | ||
newCategoryIds = baseParams.newCategoryIds, | ||
isAdditionalActionsAvailable = duplicateParams.isAdditionalActionsAvailable, | ||
isButtonEnabled = baseParams.isButtonEnabled, | ||
) | ||
} | ||
|
||
private fun ViewDataParams.mapMergeParams(): ChangeRecordActionsMergeDelegate.Parent.ViewDataParams { | ||
return ChangeRecordActionsMergeDelegate.Parent.ViewDataParams( | ||
mergeAvailable = mergeParams.mergeAvailable, | ||
prevRecord = mergeParams.prevRecord, | ||
newTimeEnded = baseParams.newTimeEnded, | ||
isButtonEnabled = baseParams.isButtonEnabled, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...ple/util/simpletimetracker/feature_change_record/viewModel/ChangeRecordActionsDelegate.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package com.example.util.simpletimetracker.feature_change_record.viewModel | ||
|
||
import androidx.lifecycle.LiveData | ||
import com.example.util.simpletimetracker.domain.model.Record | ||
import com.example.util.simpletimetracker.feature_base_adapter.ViewHolderType | ||
|
||
interface ChangeRecordActionsDelegate { | ||
val actionsViewData: LiveData<List<ViewHolderType>> | ||
|
||
interface Parent { | ||
fun getViewDataParams(): ViewDataParams | ||
|
||
fun updateViewData() | ||
|
||
fun onRecordChangeButtonClick( | ||
onProceed: suspend () -> Unit, | ||
checkTypeSelected: Boolean = true, | ||
) | ||
|
||
suspend fun onSaveClickDelegate() | ||
|
||
suspend fun onSplitComplete() | ||
|
||
fun showMessage(stringResId: Int) | ||
|
||
data class ViewDataParams( | ||
val baseParams: BaseParams, | ||
val splitParams: SplitParams, | ||
val duplicateParams: DuplicateParams, | ||
val continueParams: ContinueParams, | ||
val repeatParams: RepeatParams, | ||
val adjustParams: AdjustParams, | ||
val mergeParams: MergeParams, | ||
) { | ||
|
||
data class BaseParams( | ||
val newTypeId: Long, | ||
val newTimeStarted: Long, | ||
val newTimeEnded: Long, | ||
val newComment: String, | ||
val newCategoryIds: List<Long>, | ||
val isButtonEnabled: Boolean, | ||
) | ||
|
||
data class SplitParams( | ||
val newTimeSplit: Long, | ||
val splitPreviewTimeEnded: Long, | ||
val showTimeEndedOnSplitPreview: Boolean, | ||
) | ||
|
||
data class DuplicateParams( | ||
val isAdditionalActionsAvailable: Boolean, | ||
) | ||
|
||
data class ContinueParams( | ||
val originalRecordId: Long, | ||
val isAdditionalActionsAvailable: Boolean, | ||
) | ||
|
||
data class RepeatParams( | ||
val isAdditionalActionsAvailable: Boolean, | ||
) | ||
|
||
data class AdjustParams( | ||
val originalRecordId: Long, | ||
val originalTypeId: Long, | ||
val originalTimeStarted: Long, | ||
val adjustNextRecordAvailable: Boolean, | ||
val adjustPreviewTimeEnded: Long, | ||
val adjustPreviewOriginalTimeEnded: Long, | ||
val showTimeEndedOnAdjustPreview: Boolean, | ||
val isTimeEndedAvailable: Boolean, | ||
) | ||
|
||
data class MergeParams( | ||
val mergeAvailable: Boolean, | ||
val prevRecord: Record?, | ||
) | ||
} | ||
} | ||
} |
28 changes: 0 additions & 28 deletions
28
...util/simpletimetracker/feature_change_record/viewModel/ChangeRecordActionsDelegateBase.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.