-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
116 additions
and
1 deletion.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
...re/src/main/java/com/easyhz/noffice/core/datastore/datasource/user/UserLocalDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.easyhz.noffice.core.datastore.datasource.user | ||
|
||
interface UserLocalDataSource { | ||
suspend fun getFirstRun(): Result<Boolean> | ||
suspend fun updateFirstRun(newValue: Boolean) | ||
} |
39 changes: 39 additions & 0 deletions
39
...rc/main/java/com/easyhz/noffice/core/datastore/datasource/user/UserLocalDataSourceImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.easyhz.noffice.core.datastore.datasource.user | ||
|
||
import androidx.datastore.core.DataStore | ||
import androidx.datastore.preferences.core.Preferences | ||
import androidx.datastore.preferences.core.booleanPreferencesKey | ||
import androidx.datastore.preferences.core.edit | ||
import com.easyhz.noffice.core.common.di.Dispatcher | ||
import com.easyhz.noffice.core.common.di.NofficeDispatchers | ||
import com.easyhz.noffice.core.datastore.di.UserDataStore | ||
import com.easyhz.noffice.core.datastore.util.UserKey | ||
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.coroutines.flow.first | ||
import kotlinx.coroutines.withContext | ||
import javax.inject.Inject | ||
|
||
class UserLocalDataSourceImpl @Inject constructor( | ||
@Dispatcher(NofficeDispatchers.IO) private val dispatcher: CoroutineDispatcher, | ||
@UserDataStore private val dataStore: DataStore<Preferences> | ||
) : UserLocalDataSource { | ||
private val isFirstRun = booleanPreferencesKey(UserKey.IS_FIRST_RUN.key) | ||
|
||
override suspend fun getFirstRun(): Result<Boolean> = withContext(dispatcher) { | ||
runCatching { | ||
val preferences = dataStore.data.first() | ||
return@runCatching preferences[isFirstRun] | ||
?: throw generateNullException(UserKey.IS_FIRST_RUN) | ||
} | ||
} | ||
|
||
override suspend fun updateFirstRun(newValue: Boolean): Unit = withContext(dispatcher) { | ||
dataStore.edit { preferences -> | ||
preferences[isFirstRun] = newValue | ||
} | ||
} | ||
|
||
private fun generateNullException(userKey: UserKey): Exception { | ||
return Exception("${userKey.key} is null") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
core/model/src/main/java/com/easyhz/noffice/core/model/splash/EnterScreenType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.easyhz.noffice.core.model.splash | ||
|
||
enum class EnterScreenType { | ||
ONBOARDING, LOGIN, HOME | ||
} |
17 changes: 17 additions & 0 deletions
17
...member/src/main/java/com/easyhz/noffice/data/member/di/repository/UserRepositoryModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.easyhz.noffice.data.member.di.repository | ||
|
||
import com.easyhz.noffice.data.member.repository.user.UserRepository | ||
import com.easyhz.noffice.data.member.repository.user.UserRepositoryImpl | ||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
interface UserRepositoryModule { | ||
@Binds | ||
fun bindUserRepository( | ||
userRepositoryImpl: UserRepositoryImpl | ||
): UserRepository | ||
} |
5 changes: 5 additions & 0 deletions
5
data/member/src/main/java/com/easyhz/noffice/data/member/repository/user/UserRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.easyhz.noffice.data.member.repository.user | ||
|
||
interface UserRepository { | ||
suspend fun getIsFirstRun(): Result<Boolean> | ||
} |
12 changes: 12 additions & 0 deletions
12
...member/src/main/java/com/easyhz/noffice/data/member/repository/user/UserRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.easyhz.noffice.data.member.repository.user | ||
|
||
import com.easyhz.noffice.core.datastore.datasource.user.UserLocalDataSource | ||
import javax.inject.Inject | ||
|
||
class UserRepositoryImpl @Inject constructor( | ||
private val userLocalDataSource: UserLocalDataSource | ||
): UserRepository { | ||
override suspend fun getIsFirstRun(): Result<Boolean> { | ||
return userLocalDataSource.getFirstRun() | ||
} | ||
} |