-
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
1 parent
a9a2712
commit 1229e5a
Showing
62 changed files
with
997 additions
and
578 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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
28 changes: 17 additions & 11 deletions
28
app/src/main/java/com/rey/newskatta/data/manager/LocalUserManagerImpl.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 |
---|---|---|
@@ -1,36 +1,42 @@ | ||
package com.rey.newskatta.data.manager | ||
|
||
import android.app.Application | ||
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 com.rey.newskatta.domain.manager.LocalUserManager | ||
|
||
import com.rey.newskatta.domain.manager.LocalUserManger | ||
import com.rey.newskatta.util.Constants | ||
import com.rey.newskatta.util.Constants.USER_SETTINGS | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.combine | ||
import kotlinx.coroutines.flow.map | ||
import javax.inject.Inject | ||
|
||
class LocalUserMangerImpl @Inject constructor( | ||
private val application: Application | ||
) : LocalUserManger { | ||
|
||
class LocalUserManagerImpl( | ||
private val context: Context | ||
): LocalUserManager { | ||
override suspend fun saveAppEntry() { | ||
context.dataStore.edit { settings -> | ||
settings[PrefencesKeys.APP_ENTRY] = true | ||
application.dataStore.edit { settings -> | ||
settings[PreferenceKeys.APP_ENTRY] = true | ||
} | ||
} | ||
|
||
override fun readAppEntry(): Flow<Boolean> { | ||
return context.dataStore.data.map { preferences -> | ||
preferences[PrefencesKeys.APP_ENTRY] ?: false | ||
return application.dataStore.data.map { preferences -> | ||
preferences[PreferenceKeys.APP_ENTRY] ?: false | ||
} | ||
} | ||
} | ||
|
||
private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = USER_SETTINGS) | ||
private val readOnlyProperty = preferencesDataStore(name = USER_SETTINGS) | ||
|
||
val Context.dataStore: DataStore<Preferences> by readOnlyProperty | ||
|
||
private object PrefencesKeys { | ||
val APP_ENTRY = booleanPreferencesKey(name = Constants.APP_ENTRY) | ||
private object PreferenceKeys { | ||
val APP_ENTRY = booleanPreferencesKey(Constants.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
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
Oops, something went wrong.