From cfebb0433e2fc9afd126efd75bf3a6d127ea45d2 Mon Sep 17 00:00:00 2001 From: koreatlwls Date: Sat, 29 Jun 2024 16:12:45 +0900 Subject: [PATCH 1/3] feat : dailyreset --- .../app/data/daily/api/DailyRepository.kt | 4 +++ .../app/data/daily/impl/di/DataBaseModule.kt | 5 ++++ .../impl/local/datastore/DailyDataStore.kt | 27 +++++++++++++++++++ .../impl/repository/DailyRepositoryImpl.kt | 10 +++++++ .../usecase/GetResetDailyEventUseCase.kt | 26 ++++++++++++++++++ .../time/ui/stopwatch/StopWatchViewModel.kt | 22 +++++++-------- .../feature/time/ui/timer/TimerViewModel.kt | 22 +++++++-------- 7 files changed, 94 insertions(+), 22 deletions(-) create mode 100644 data/daily/impl/src/main/kotlin/com/titi/app/data/daily/impl/local/datastore/DailyDataStore.kt create mode 100644 domain/daily/src/main/kotlin/com/titi/app/doamin/daily/usecase/GetResetDailyEventUseCase.kt diff --git a/data/daily/api/src/main/kotlin/com/titi/app/data/daily/api/DailyRepository.kt b/data/daily/api/src/main/kotlin/com/titi/app/data/daily/api/DailyRepository.kt index a67e3b22..70473af9 100644 --- a/data/daily/api/src/main/kotlin/com/titi/app/data/daily/api/DailyRepository.kt +++ b/data/daily/api/src/main/kotlin/com/titi/app/data/daily/api/DailyRepository.kt @@ -42,4 +42,8 @@ interface DailyRepository { suspend fun getAllDailies(): List? suspend fun upsert(dailyRepositoryModel: DailyRepositoryModel) + + suspend fun setResetDailyEvent(daily: String) + + suspend fun getResetDailyEvent(): String? } diff --git a/data/daily/impl/src/main/kotlin/com/titi/app/data/daily/impl/di/DataBaseModule.kt b/data/daily/impl/src/main/kotlin/com/titi/app/data/daily/impl/di/DataBaseModule.kt index 6193a77b..14518c18 100644 --- a/data/daily/impl/src/main/kotlin/com/titi/app/data/daily/impl/di/DataBaseModule.kt +++ b/data/daily/impl/src/main/kotlin/com/titi/app/data/daily/impl/di/DataBaseModule.kt @@ -4,6 +4,7 @@ import android.content.Context import androidx.room.Room.databaseBuilder import com.titi.app.data.daily.impl.local.DailyDataBase import com.titi.app.data.daily.impl.local.dao.DailyDao +import com.titi.app.data.daily.impl.local.datastore.DailyDataStore import dagger.Module import dagger.Provides import dagger.hilt.InstallIn @@ -25,4 +26,8 @@ internal object DataBaseModule { @Singleton @Provides fun provideDailyDao(dailyDataBase: DailyDataBase): DailyDao = dailyDataBase.getDailyDao() + + @Singleton + @Provides + fun provideDailyDataStore(@ApplicationContext context: Context) = DailyDataStore(context) } diff --git a/data/daily/impl/src/main/kotlin/com/titi/app/data/daily/impl/local/datastore/DailyDataStore.kt b/data/daily/impl/src/main/kotlin/com/titi/app/data/daily/impl/local/datastore/DailyDataStore.kt new file mode 100644 index 00000000..77a8be82 --- /dev/null +++ b/data/daily/impl/src/main/kotlin/com/titi/app/data/daily/impl/local/datastore/DailyDataStore.kt @@ -0,0 +1,27 @@ +package com.titi.app.data.daily.impl.local.datastore + +import android.content.Context +import androidx.datastore.core.DataStore +import androidx.datastore.preferences.core.Preferences +import androidx.datastore.preferences.core.stringPreferencesKey +import androidx.datastore.preferences.preferencesDataStore +import com.titi.app.core.util.readValue +import com.titi.app.core.util.storeValue + +internal class DailyDataStore(context: Context) { + private val dataStore: DataStore = context.dataStore + + suspend fun setResetDailyEvent(daily: String) { + dataStore.storeValue(DAILY_RESET__KEY, daily) + } + + suspend fun getResetDailyEvent(): String? = dataStore.readValue(DAILY_RESET__KEY) + + companion object { + private const val DAILY_RESET_PREF_NAME = "dailyPrefName" + private val DAILY_RESET__KEY = stringPreferencesKey("dailyKey") + private val Context.dataStore: DataStore by preferencesDataStore( + name = DAILY_RESET_PREF_NAME, + ) + } +} diff --git a/data/daily/impl/src/main/kotlin/com/titi/app/data/daily/impl/repository/DailyRepositoryImpl.kt b/data/daily/impl/src/main/kotlin/com/titi/app/data/daily/impl/repository/DailyRepositoryImpl.kt index e1464ddc..29909a00 100644 --- a/data/daily/impl/src/main/kotlin/com/titi/app/data/daily/impl/repository/DailyRepositoryImpl.kt +++ b/data/daily/impl/src/main/kotlin/com/titi/app/data/daily/impl/repository/DailyRepositoryImpl.kt @@ -3,6 +3,7 @@ package com.titi.app.data.daily.impl.repository import com.titi.app.data.daily.api.DailyRepository import com.titi.app.data.daily.api.model.DailyRepositoryModel import com.titi.app.data.daily.impl.local.dao.DailyDao +import com.titi.app.data.daily.impl.local.datastore.DailyDataStore import com.titi.app.data.daily.impl.mapper.toLocalModel import com.titi.app.data.daily.impl.mapper.toRepositoryModel import javax.inject.Inject @@ -11,6 +12,7 @@ import kotlinx.coroutines.flow.map internal class DailyRepositoryImpl @Inject constructor( private val dailyDao: DailyDao, + private val dailyDataStore: DailyDataStore, ) : DailyRepository { override suspend fun getDateDaily( startDateTime: String, @@ -49,4 +51,12 @@ internal class DailyRepositoryImpl @Inject constructor( override suspend fun upsert(dailyRepositoryModel: DailyRepositoryModel) { dailyDao.upsert(dailyRepositoryModel.toLocalModel()) } + + override suspend fun setResetDailyEvent(daily: String) { + dailyDataStore.setResetDailyEvent(daily) + } + + override suspend fun getResetDailyEvent(): String? { + return dailyDataStore.getResetDailyEvent() + } } diff --git a/domain/daily/src/main/kotlin/com/titi/app/doamin/daily/usecase/GetResetDailyEventUseCase.kt b/domain/daily/src/main/kotlin/com/titi/app/doamin/daily/usecase/GetResetDailyEventUseCase.kt new file mode 100644 index 00000000..d67888dd --- /dev/null +++ b/domain/daily/src/main/kotlin/com/titi/app/doamin/daily/usecase/GetResetDailyEventUseCase.kt @@ -0,0 +1,26 @@ +package com.titi.app.doamin.daily.usecase + +import com.titi.app.core.util.getDailyDayWithHour +import com.titi.app.data.daily.api.DailyRepository +import javax.inject.Inject + +class GetResetDailyEventUseCase @Inject constructor( + private val dailyRepository: DailyRepository, +) { + suspend operator fun invoke(): Boolean { + val resetDaily = dailyRepository.getResetDailyEvent() + val today = getDailyDayWithHour(6).first + + return if (resetDaily != null) { + if (resetDaily != today) { + dailyRepository.setResetDailyEvent(today) + true + } else { + false + } + } else { + dailyRepository.setResetDailyEvent(today) + true + } + } +} diff --git a/feature/time/src/main/kotlin/com/titi/app/feature/time/ui/stopwatch/StopWatchViewModel.kt b/feature/time/src/main/kotlin/com/titi/app/feature/time/ui/stopwatch/StopWatchViewModel.kt index 7db8de59..8748c365 100644 --- a/feature/time/src/main/kotlin/com/titi/app/feature/time/ui/stopwatch/StopWatchViewModel.kt +++ b/feature/time/src/main/kotlin/com/titi/app/feature/time/ui/stopwatch/StopWatchViewModel.kt @@ -8,6 +8,7 @@ import com.airbnb.mvrx.hilt.hiltMavericksViewModelFactory import com.titi.app.core.util.isAfterH import com.titi.app.core.util.toJson import com.titi.app.doamin.daily.model.Daily +import com.titi.app.doamin.daily.usecase.GetResetDailyEventUseCase import com.titi.app.doamin.daily.usecase.GetTodayDailyFlowUseCase import com.titi.app.domain.color.usecase.GetTimeColorFlowUseCase import com.titi.app.domain.color.usecase.UpdateColorUseCase @@ -38,6 +39,7 @@ class StopWatchViewModel @AssistedInject constructor( private val updateSetGoalTimeUseCase: UpdateSetGoalTimeUseCase, private val updateRecordTimesUseCase: UpdateRecordTimesUseCase, private val updateSavedStopWatchTimeUseCase: UpdateSavedStopWatchTimeUseCase, + private val getResetDailyEventUseCase: GetResetDailyEventUseCase, ) : MavericksViewModel(initialState) { private lateinit var prevStopWatchColor: StopWatchColor @@ -66,8 +68,8 @@ class StopWatchViewModel @AssistedInject constructor( fun updateDailyRecordTimesAfterH() { withState { - if (it.daily.day.isAfterH(6)) { - viewModelScope.launch { + viewModelScope.launch { + if (getResetDailyEventUseCase()) { updateRecordTimesUseCase( recordTimes = it.recordTimes.copy( recordingMode = 2, @@ -77,16 +79,14 @@ class StopWatchViewModel @AssistedInject constructor( savedGoalTime = it.recordTimes.setGoalTime, ), ) - } - setState { - copy( - daily = Daily(), - showResetDailySnackBar = true, - ) - } - } else { - viewModelScope.launch { + setState { + copy( + daily = Daily(), + showResetDailySnackBar = true, + ) + } + } else { updateRecordingModeUseCase(2) } } diff --git a/feature/time/src/main/kotlin/com/titi/app/feature/time/ui/timer/TimerViewModel.kt b/feature/time/src/main/kotlin/com/titi/app/feature/time/ui/timer/TimerViewModel.kt index ec5d53c9..3ca8078e 100644 --- a/feature/time/src/main/kotlin/com/titi/app/feature/time/ui/timer/TimerViewModel.kt +++ b/feature/time/src/main/kotlin/com/titi/app/feature/time/ui/timer/TimerViewModel.kt @@ -8,6 +8,7 @@ import com.airbnb.mvrx.hilt.hiltMavericksViewModelFactory import com.titi.app.core.util.isAfterH import com.titi.app.core.util.toJson import com.titi.app.doamin.daily.model.Daily +import com.titi.app.doamin.daily.usecase.GetResetDailyEventUseCase import com.titi.app.doamin.daily.usecase.GetTodayDailyFlowUseCase import com.titi.app.domain.color.usecase.GetTimeColorFlowUseCase import com.titi.app.domain.color.usecase.UpdateColorUseCase @@ -38,6 +39,7 @@ class TimerViewModel @AssistedInject constructor( private val updateSetGoalTimeUseCase: UpdateSetGoalTimeUseCase, private val updateRecordTimesUseCase: UpdateRecordTimesUseCase, private val updateSetTimerTimeUseCase: UpdateSetTimerTimeUseCase, + private val getResetDailyEventUseCase: GetResetDailyEventUseCase, ) : MavericksViewModel(initialState) { private lateinit var prevTimerColor: TimerColor @@ -67,8 +69,8 @@ class TimerViewModel @AssistedInject constructor( fun updateDailyRecordTimesAfterH() { withState { - if (it.daily.day.isAfterH(6)) { - viewModelScope.launch { + viewModelScope.launch { + if (getResetDailyEventUseCase()) { updateRecordTimesUseCase( recordTimes = it.recordTimes.copy( recordingMode = 1, @@ -78,16 +80,14 @@ class TimerViewModel @AssistedInject constructor( savedGoalTime = it.recordTimes.setGoalTime, ), ) - } - setState { - copy( - daily = Daily(), - showResetDailySnackBar = true, - ) - } - } else { - viewModelScope.launch { + setState { + copy( + daily = Daily(), + showResetDailySnackBar = true, + ) + } + } else { updateRecordingModeUseCase(1) } } From ecbbc3e9677fb01ffbd9e52cadf35ac946490f1a Mon Sep 17 00:00:00 2001 From: koreatlwls Date: Sat, 29 Jun 2024 16:13:02 +0900 Subject: [PATCH 2/3] update : version code --- build-logic/src/main/kotlin/com/titi/common/BuildInfo.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-logic/src/main/kotlin/com/titi/common/BuildInfo.kt b/build-logic/src/main/kotlin/com/titi/common/BuildInfo.kt index 6f03fd12..b554fcbd 100644 --- a/build-logic/src/main/kotlin/com/titi/common/BuildInfo.kt +++ b/build-logic/src/main/kotlin/com/titi/common/BuildInfo.kt @@ -10,6 +10,6 @@ object BuildType { object AppConfig { const val APP_ID = "com.titi.app" const val APP_VERSION_NAME = "1.2.0" - const val APP_VERSION_CODE = 33 + const val APP_VERSION_CODE = 34 const val APP_NAME = "TiTi" } \ No newline at end of file From c028a393a8340efb5aa423a4a868d18f3a2dda5b Mon Sep 17 00:00:00 2001 From: koreatlwls Date: Sat, 29 Jun 2024 16:13:54 +0900 Subject: [PATCH 3/3] docs : release-note --- release-note.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release-note.txt b/release-note.txt index fc4fc464..856d21e1 100644 --- a/release-note.txt +++ b/release-note.txt @@ -1,4 +1,4 @@ -TiTi android dev 1.2.0(33) +TiTi android dev 1.2.0(34) - 백그라운드에서 재진입 시 타이머 또는 스탑워치 화면으로 이동되는 이슈 #137 - 데일리 6시 기준 자동화 및 토스트 띄우기 #147 - TimeTable 같은 task는 같은 색상으로 수정 #148