-
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.
feat(architecture): basic clean architecture setup (#5)
- Loading branch information
Showing
8 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
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
37 changes: 37 additions & 0 deletions
37
app/src/main/java/us/kikin/android/gamingbacklog/data/manager/LocalUserManager.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,37 @@ | ||
package us.kikin.android.gamingbacklog.data.manager | ||
|
||
import android.content.Context | ||
import androidx.datastore.core.DataStore | ||
import androidx.datastore.preferences.core.Preferences | ||
import androidx.datastore.preferences.core.booleanPreferencesKey | ||
import androidx.datastore.preferences.core.edit | ||
import androidx.datastore.preferences.preferencesDataStore | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.map | ||
import us.kikin.android.gamingbacklog.domain.manager.LocalUserManager | ||
import us.kikin.android.gamingbacklog.utils.Constants | ||
import us.kikin.android.gamingbacklog.utils.Constants.USER_SETTINGS | ||
|
||
|
||
class LocalUserManagerImpl( | ||
private val context: Context | ||
) : LocalUserManager { | ||
|
||
override suspend fun saveAppEntry() { | ||
context.dataStore.edit { settings -> | ||
settings[PreferencesKeys.APP_ENTRY] = true | ||
} | ||
} | ||
|
||
override fun readAppEntry(): Flow<Boolean> { | ||
return context.dataStore.data.map { settings -> | ||
settings[PreferencesKeys.APP_ENTRY] ?: false | ||
} | ||
} | ||
} | ||
|
||
private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = USER_SETTINGS) | ||
|
||
private object PreferencesKeys { | ||
val APP_ENTRY = booleanPreferencesKey(name = Constants.APP_ENTRY) | ||
} |
10 changes: 10 additions & 0 deletions
10
app/src/main/java/us/kikin/android/gamingbacklog/domain/manager/LocalUserManager.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,10 @@ | ||
package us.kikin.android.gamingbacklog.domain.manager | ||
|
||
import kotlinx.coroutines.flow.Flow | ||
|
||
interface LocalUserManager { | ||
|
||
suspend fun saveAppEntry() | ||
|
||
fun readAppEntry(): Flow<Boolean> | ||
} |
12 changes: 12 additions & 0 deletions
12
app/src/main/java/us/kikin/android/gamingbacklog/domain/usecase/ReadAppEntry.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 us.kikin.android.gamingbacklog.domain.usecase | ||
|
||
import kotlinx.coroutines.flow.Flow | ||
import us.kikin.android.gamingbacklog.domain.manager.LocalUserManager | ||
|
||
class ReadAppEntry( | ||
private val localUserManager: LocalUserManager | ||
) { | ||
|
||
suspend operator fun invoke(): Flow<Boolean> = | ||
localUserManager.readAppEntry() | ||
} |
12 changes: 12 additions & 0 deletions
12
app/src/main/java/us/kikin/android/gamingbacklog/domain/usecase/SaveAppEntry.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 us.kikin.android.gamingbacklog.domain.usecase | ||
|
||
import us.kikin.android.gamingbacklog.domain.manager.LocalUserManager | ||
|
||
class SaveAppEntry( | ||
private val localUserManager: LocalUserManager | ||
) { | ||
|
||
suspend operator fun invoke() { | ||
localUserManager.saveAppEntry() | ||
} | ||
} |
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
6 changes: 6 additions & 0 deletions
6
app/src/main/java/us/kikin/android/gamingbacklog/utils/Constants.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 us.kikin.android.gamingbacklog.utils | ||
|
||
object Constants { | ||
const val USER_SETTINGS: String = "user_settings" | ||
const val APP_ENTRY: String = "app_entry" | ||
} |
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