Skip to content

Commit

Permalink
remove unnecessary id from change record type params
Browse files Browse the repository at this point in the history
  • Loading branch information
Razeeman committed Aug 28, 2021
1 parent 83b1ed4 commit 72dd84e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import com.example.util.simpletimetracker.core.extension.visible
import com.example.util.simpletimetracker.core.repo.DeviceRepo
import com.example.util.simpletimetracker.core.utils.BuildVersions
import com.example.util.simpletimetracker.core.utils.setFlipChooserColor
import com.example.util.simpletimetracker.core.view.TransitionNames
import com.example.util.simpletimetracker.core.viewData.RecordTypeViewData
import com.example.util.simpletimetracker.domain.model.IconEmojiType
import com.example.util.simpletimetracker.feature_change_record_type.R
Expand Down Expand Up @@ -113,10 +112,8 @@ class ChangeRecordTypeFragment :
.inflateTransition(android.R.transition.move)
}

ViewCompat.setTransitionName(
previewChangeRecordType,
TransitionNames.RECORD_TYPE + params.id
)
val transitionName: String = (params as? ChangeRecordTypeParams.Change)?.transitionName.orEmpty()
ViewCompat.setTransitionName(previewChangeRecordType, transitionName)

rvChangeRecordTypeColor.apply {
layoutManager = FlexboxLayoutManager(requireContext()).apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.example.util.simpletimetracker.core.viewData.EmojiViewData
import com.example.util.simpletimetracker.core.viewData.RecordTypeViewData
import com.example.util.simpletimetracker.domain.extension.flip
import com.example.util.simpletimetracker.domain.extension.orTrue
import com.example.util.simpletimetracker.domain.extension.orZero
import com.example.util.simpletimetracker.domain.interactor.PrefsInteractor
import com.example.util.simpletimetracker.domain.interactor.RecordInteractor
import com.example.util.simpletimetracker.domain.interactor.RecordTypeCategoryInteractor
Expand Down Expand Up @@ -117,10 +118,11 @@ class ChangeRecordTypeViewModel @Inject constructor(
val flipCategoryChooser: LiveData<Boolean> = MutableLiveData()
val deleteButtonEnabled: LiveData<Boolean> = MutableLiveData(true)
val saveButtonEnabled: LiveData<Boolean> = MutableLiveData(true)
val deleteIconVisibility: LiveData<Boolean> by lazy { MutableLiveData(extra.id != 0L) }
val keyboardVisibility: LiveData<Boolean> by lazy { MutableLiveData(extra.id == 0L) }
val deleteIconVisibility: LiveData<Boolean> by lazy { MutableLiveData(recordTypeId != 0L) }
val keyboardVisibility: LiveData<Boolean> by lazy { MutableLiveData(recordTypeId == 0L) }
val iconsScrollPosition: LiveData<ChangeRecordTypeScrollViewData> = MutableLiveData()

private val recordTypeId: Long get() = (extra as? ChangeRecordTypeParams.Change)?.id.orZero()
private var iconType: IconType = IconType.IMAGE
private var initialCategories: List<Long> = emptyList()
private var newName: String = ""
Expand Down Expand Up @@ -277,16 +279,16 @@ class ChangeRecordTypeViewModel @Inject constructor(
fun onDeleteClick() {
(deleteButtonEnabled as MutableLiveData).value = false
viewModelScope.launch {
if (extra.id != 0L) {
recordTypeInteractor.archive(extra.id)
runningRecordInteractor.get(extra.id)?.let { runningRecord ->
if (recordTypeId != 0L) {
recordTypeInteractor.archive(recordTypeId)
runningRecordInteractor.get(recordTypeId)?.let { runningRecord ->
recordInteractor.add(
typeId = runningRecord.id,
timeStarted = runningRecord.timeStarted,
comment = runningRecord.comment,
tagId = runningRecord.tagId
)
removeRunningRecordMediator.remove(extra.id)
removeRunningRecordMediator.remove(recordTypeId)
}
showMessage(R.string.change_record_type_archived)
(keyboardVisibility as MutableLiveData).value = false
Expand All @@ -304,8 +306,8 @@ class ChangeRecordTypeViewModel @Inject constructor(
viewModelScope.launch {
val addedId = saveRecordType()
saveCategories(addedId)
notificationTypeInteractor.checkAndShow(extra.id)
notificationGoalTimeInteractor.checkAndReschedule(extra.id)
notificationTypeInteractor.checkAndShow(recordTypeId)
notificationGoalTimeInteractor.checkAndReschedule(recordTypeId)
widgetInteractor.updateWidgets()
(keyboardVisibility as MutableLiveData).value = false
router.back()
Expand All @@ -330,7 +332,7 @@ class ChangeRecordTypeViewModel @Inject constructor(

private suspend fun saveRecordType(): Long {
val recordType = RecordType(
id = extra.id,
id = recordTypeId,
name = newName,
icon = newIconName,
color = newColorId,
Expand All @@ -349,7 +351,7 @@ class ChangeRecordTypeViewModel @Inject constructor(
}

private suspend fun initializeRecordTypeData() {
recordTypeInteractor.get(extra.id)
recordTypeInteractor.get(recordTypeId)
?.let {
newName = it.name
newIconName = it.icon
Expand All @@ -361,7 +363,7 @@ class ChangeRecordTypeViewModel @Inject constructor(
}

private suspend fun initializeSelectedCategories() {
recordTypeCategoryInteractor.getCategories(extra.id)
recordTypeCategoryInteractor.getCategories(recordTypeId)
.let {
newCategories = it.toMutableList()
initialCategories = it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.example.util.simpletimetracker.core.adapter.loader.LoaderViewData
import com.example.util.simpletimetracker.core.extension.toParams
import com.example.util.simpletimetracker.core.interactor.AddRunningRecordMediator
import com.example.util.simpletimetracker.core.interactor.RemoveRunningRecordMediator
import com.example.util.simpletimetracker.core.view.TransitionNames
import com.example.util.simpletimetracker.core.viewData.RecordTypeViewData
import com.example.util.simpletimetracker.domain.interactor.RunningRecordInteractor
import com.example.util.simpletimetracker.feature_running_records.interactor.RunningRecordsViewDataInteractor
Expand Down Expand Up @@ -54,6 +55,7 @@ class RunningRecordsViewModel @Inject constructor(
router.navigate(
screen = Screen.CHANGE_RECORD_TYPE,
data = ChangeRecordTypeParams.Change(
transitionName = TransitionNames.RECORD_TYPE + item.id,
id = item.id,
sizePreview = ChangeRecordTypeParams.SizePreview(
width = item.width,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import androidx.annotation.ColorInt
import kotlinx.parcelize.Parcelize

sealed class ChangeRecordTypeParams : Parcelable {
abstract val id: Long
abstract val sizePreview: SizePreview

@Parcelize
data class Change(
override val id: Long,
val transitionName: String,
val id: Long,
override val sizePreview: SizePreview,
val preview: Preview
) : ChangeRecordTypeParams() {
Expand All @@ -26,9 +26,7 @@ sealed class ChangeRecordTypeParams : Parcelable {
@Parcelize
data class New(
override val sizePreview: SizePreview
) : ChangeRecordTypeParams() {
override val id: Long get() = 0 // TODO remove
}
) : ChangeRecordTypeParams()

@Parcelize
data class SizePreview(
Expand Down

0 comments on commit 72dd84e

Please sign in to comment.