Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import com.nextroom.nextroom.data.db.dataStore
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.runBlocking
import javax.inject.Inject

class SettingDataSource @Inject constructor(
Expand Down Expand Up @@ -41,17 +40,17 @@ class SettingDataSource @Inject constructor(
}
}

fun setLastLaunchDate() = runBlocking {
suspend fun setLastLaunchDate() {
dataStore.updateData {
it.copy(lastLaunchDate = System.currentTimeMillis())
}
}

fun getLastLaunchDate(): Long = runBlocking {
data.first().lastLaunchDate
suspend fun getLastLaunchDate(): Long {
return data.first().lastLaunchDate
}

fun setNetworkDisconnectedCount(count: Int) = runBlocking {
suspend fun setNetworkDisconnectedCount(count: Int) {
dataStore.updateData {
it.copy(networkDisconnectedCount = count)
}
Expand Down Expand Up @@ -79,32 +78,32 @@ class SettingDataSource @Inject constructor(
}
}

fun setEmailSaveChecked(emailSaveChecked: Boolean) = runBlocking {
suspend fun setEmailSaveChecked(emailSaveChecked: Boolean) {
dataStore.updateData {
it.copy(emailSaveChecked = emailSaveChecked)
}
}

fun getEmailSaveChecked() = runBlocking {
data.first().emailSaveChecked
suspend fun getEmailSaveChecked(): Boolean {
return data.first().emailSaveChecked
}

fun saveUserEmail(userEmail: String) = runBlocking {
suspend fun saveUserEmail(userEmail: String) {
dataStore.updateData {
it.copy(userEmail = userEmail)
}
}

fun getUserEmail() = runBlocking {
data.first().userEmail
suspend fun getUserEmail(): String {
return data.first().userEmail
}

fun setRecommendBackgroundCustomDialogHidden(time: Long) = runBlocking {
suspend fun setRecommendBackgroundCustomDialogHidden(time: Long) {
dataStore.updateData { it.copy(backgroundCustomDialogHideUntil = time) }
}

fun getRecommendBackgroundCustomDialogHiddenUntil() = runBlocking {
data.first().backgroundCustomDialogHideUntil
suspend fun getRecommendBackgroundCustomDialogHiddenUntil(): Long {
return data.first().backgroundCustomDialogHideUntil
}

suspend fun saveAppPassword(password: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,30 @@ import javax.inject.Inject
class DataStoreRepositoryImpl @Inject constructor(
private val settingDataSource: SettingDataSource,
) : DataStoreRepository {
override val isFirstInitOfDay: Boolean
get() = run {
val util = DateTimeUtil()
val pattern = "yyyy-MM-dd"
val today = util.longToDateString(System.currentTimeMillis(), pattern)
val lastLaunchedDate = util.longToDateString(settingDataSource.getLastLaunchDate(), pattern)
Timber.tag("MANGBAAM-DataStoreRepositoryImpl()").d("마지막 접속 일자: $lastLaunchedDate")
today != lastLaunchedDate
}.also { firstInit ->
if (firstInit) settingDataSource.setLastLaunchDate()
}

override fun setRecommendBackgroundCustomDialogHidden(time: Long) {
override suspend fun isFirstInitOfDay(): Boolean {
val util = DateTimeUtil()
val pattern = "yyyy-MM-dd"
val today = util.longToDateString(System.currentTimeMillis(), pattern)
val lastLaunchedDate = util.longToDateString(settingDataSource.getLastLaunchDate(), pattern)
Timber.tag("MANGBAAM-DataStoreRepositoryImpl()").d("마지막 접속 일자: $lastLaunchedDate")
val firstInit = today != lastLaunchedDate
if (firstInit) settingDataSource.setLastLaunchDate()
return firstInit
}

override suspend fun setRecommendBackgroundCustomDialogHidden(time: Long) {
settingDataSource.setRecommendBackgroundCustomDialogHidden(time)
}

override fun getRecommendBackgroundCustomDialogHiddenUntil(): Long {
override suspend fun getRecommendBackgroundCustomDialogHiddenUntil(): Long {
return settingDataSource.getRecommendBackgroundCustomDialogHiddenUntil()
}

override suspend fun getNetworkDisconnectedCount(): Int {
return settingDataSource.getNetworkDisconnectedCount()
}

override fun setNetworkDisconnectedCount(count: Int) {
override suspend fun setNetworkDisconnectedCount(count: Int) {
settingDataSource.setNetworkDisconnectedCount(count)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package com.nextroom.nextroom.domain.repository

interface DataStoreRepository {
suspend fun getNetworkDisconnectedCount(): Int
fun setNetworkDisconnectedCount(count: Int)
suspend fun setNetworkDisconnectedCount(count: Int)

val isFirstInitOfDay: Boolean
suspend fun isFirstInitOfDay(): Boolean

fun setRecommendBackgroundCustomDialogHidden(time: Long)
fun getRecommendBackgroundCustomDialogHiddenUntil(): Long
suspend fun setRecommendBackgroundCustomDialogHidden(time: Long)
suspend fun getRecommendBackgroundCustomDialogHiddenUntil(): Long

suspend fun setHasSeenGuidePopup()
suspend fun getHasSeenGuidePopup(): Boolean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.nextroom.nextroom.presentation.ui.theme_select

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.nextroom.nextroom.domain.repository.DataStoreRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
Expand All @@ -12,6 +14,8 @@ class RecommendBackgroundCustomViewModel @Inject constructor(

fun onDismissClicked() {
val oneWeekLater = System.currentTimeMillis() + (7 * 24 * 60 * 60 * 1000) // 일주일 밀리세컨드 표시
dataStoreRepository.setRecommendBackgroundCustomDialogHidden(oneWeekLater)
viewModelScope.launch {
dataStoreRepository.setRecommendBackgroundCustomDialogHidden(oneWeekLater)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class ThemeSelectViewModel @Inject constructor(
}.onFailure(::handleResultError)
}

private fun shouldHideRecommendBackgroundCustomDialogUntil(): Boolean {
private suspend fun shouldHideRecommendBackgroundCustomDialogUntil(): Boolean {
val hideUntil = dataStoreRepository.getRecommendBackgroundCustomDialogHiddenUntil()
return System.currentTimeMillis() < hideUntil
}
Expand Down
Loading