Skip to content

Commit

Permalink
add time started calculation from previous record if adding record on…
Browse files Browse the repository at this point in the history
… today
  • Loading branch information
Razeeman committed Nov 26, 2023
1 parent 9c4848d commit 7fb6d25
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class ChangeRecordViewModel @Inject constructor(
timeStarted = newTimeStarted,
timeEnded = newTimeEnded,
comment = newComment,
tagIds = newCategoryIds
tagIds = newCategoryIds,
).let {
addRecordMediator.add(it)
if (newTypeId != originalTypeId) {
Expand Down Expand Up @@ -143,7 +143,7 @@ class ChangeRecordViewModel @Inject constructor(
timeStarted = newTimeStarted,
timeEnded = newTimeEnded,
comment = newComment,
tagIds = newCategoryIds
tagIds = newCategoryIds,
).let {
addRecordMediator.add(it)
}
Expand All @@ -166,10 +166,23 @@ class ChangeRecordViewModel @Inject constructor(
super.onTimeStartedChanged()
}

private fun getInitialDate(daysFromToday: Int): Long {
private fun getInitialTimeEnded(daysFromToday: Int): Long {
return timeMapper.toTimestampShifted(daysFromToday, RangeLength.Day)
}

private suspend fun getInitialTimeStarted(daysFromToday: Int): Long {
val default = newTimeEnded - ONE_HOUR

return if (daysFromToday == 0) {
recordInteractor.getPrev(newTimeEnded, limit = 1)
.firstOrNull()
?.timeEnded
?: default
} else {
default
}
}

override suspend fun updatePreview() {
(record as MutableLiveData).value = loadPreviewViewData()
}
Expand All @@ -190,8 +203,9 @@ class ChangeRecordViewModel @Inject constructor(
newTimeEnded = (extra as ChangeRecordParams.Untracked).timeEnded
}
is ChangeRecordParams.New -> {
newTimeEnded = getInitialDate((extra as ChangeRecordParams.New).daysFromToday)
newTimeStarted = newTimeEnded - ONE_HOUR
val daysFromToday = (extra as ChangeRecordParams.New).daysFromToday
newTimeEnded = getInitialTimeEnded(daysFromToday)
newTimeStarted = getInitialTimeStarted(daysFromToday)
}
}
newTimeSplit = newTimeStarted
Expand All @@ -207,7 +221,7 @@ class ChangeRecordViewModel @Inject constructor(
timeStarted = newTimeStarted,
timeEnded = newTimeEnded,
comment = newComment,
tagIds = newCategoryIds
tagIds = newCategoryIds,
)

return changeRecordViewDataInteractor.getPreviewViewData(record)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package com.example.util.simpletimetracker.feature_change_record_type.view

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.cardview.widget.CardView
import androidx.core.view.isVisible
import androidx.core.view.updatePadding
import androidx.core.widget.doAfterTextChanged
Expand All @@ -21,7 +19,6 @@ import com.example.util.simpletimetracker.core.extension.showKeyboard
import com.example.util.simpletimetracker.core.extension.toViewData
import com.example.util.simpletimetracker.core.repo.DeviceRepo
import com.example.util.simpletimetracker.core.utils.fragmentArgumentDelegate
import com.example.util.simpletimetracker.core.utils.setChooserColor
import com.example.util.simpletimetracker.core.view.buttonsRowView.ButtonsRowViewData
import com.example.util.simpletimetracker.domain.model.IconEmojiType
import com.example.util.simpletimetracker.domain.model.IconType
Expand Down Expand Up @@ -57,8 +54,6 @@ import com.example.util.simpletimetracker.feature_change_record_type.viewModel.C
import com.example.util.simpletimetracker.feature_views.extension.addOnScrollListenerAdapter
import com.example.util.simpletimetracker.feature_views.extension.dpToPx
import com.example.util.simpletimetracker.feature_views.extension.pxToDp
import com.example.util.simpletimetracker.feature_views.extension.rotateDown
import com.example.util.simpletimetracker.feature_views.extension.rotateUp
import com.example.util.simpletimetracker.feature_views.extension.setOnClick
import com.example.util.simpletimetracker.feature_views.extension.setSpanSizeLookup
import com.example.util.simpletimetracker.feature_views.extension.visible
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ data class ChangeRecordTypeChooserState(
object Icon : State
object Category : State
object GoalTime : State
object Type: State
object Type : State
}
}

0 comments on commit 7fb6d25

Please sign in to comment.