Skip to content

Commit

Permalink
Merge pull request #159 from TimerTiTi/fix-double-toast
Browse files Browse the repository at this point in the history
Fix double toast
  • Loading branch information
koreatlwls authored Jun 29, 2024
2 parents d81b2ec + c028a39 commit cb5683e
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 24 deletions.
2 changes: 1 addition & 1 deletion build-logic/src/main/kotlin/com/titi/common/BuildInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,8 @@ interface DailyRepository {
suspend fun getAllDailies(): List<DailyRepositoryModel>?

suspend fun upsert(dailyRepositoryModel: DailyRepositoryModel)

suspend fun setResetDailyEvent(daily: String)

suspend fun getResetDailyEvent(): String?
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
Original file line number Diff line number Diff line change
@@ -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<Preferences> = 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<Preferences> by preferencesDataStore(
name = DAILY_RESET_PREF_NAME,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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()
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<StopWatchUiState>(initialState) {

private lateinit var prevStopWatchColor: StopWatchColor
Expand Down Expand Up @@ -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,
Expand All @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<TimerUiState>(initialState) {

private lateinit var prevTimerColor: TimerColor
Expand Down Expand Up @@ -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,
Expand All @@ -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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion release-note.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
TiTi android dev 1.2.0(33)
TiTi android dev 1.2.0(34)
- 백그라운드에서 재진입 시 타이머 또는 스탑워치 화면으로 이동되는 이슈 #137
- 데일리 6시 기준 자동화 및 토스트 띄우기 #147
- TimeTable 같은 task는 같은 색상으로 수정 #148
Expand Down

0 comments on commit cb5683e

Please sign in to comment.