-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
completely revamp application structure
- Loading branch information
Showing
145 changed files
with
2,513 additions
and
2,631 deletions.
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
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
30 changes: 29 additions & 1 deletion
30
app/src/main/java/com/devdunnapps/amplify/AmplifyApplication.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,7 +1,35 @@ | ||
package com.devdunnapps.amplify | ||
|
||
import android.app.Application | ||
import androidx.appcompat.app.AppCompatDelegate | ||
import com.devdunnapps.amplify.domain.models.ThemeConfig | ||
import com.devdunnapps.amplify.domain.repository.PreferencesRepository | ||
import dagger.hilt.android.HiltAndroidApp | ||
import kotlinx.coroutines.MainScope | ||
import kotlinx.coroutines.launch | ||
import javax.inject.Inject | ||
|
||
@HiltAndroidApp | ||
class AmplifyApplication : Application() | ||
class AmplifyApplication : Application() { | ||
|
||
@Inject | ||
lateinit var preferencesRepository: PreferencesRepository | ||
|
||
private val applicationScope = MainScope() | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
|
||
// Set the application theme | ||
applicationScope.launch { | ||
preferencesRepository.userData.collect { | ||
when (it.themeConfig) { | ||
ThemeConfig.DARK -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES) | ||
ThemeConfig.LIGHT -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO) | ||
ThemeConfig.FOLLOW_SYSTEM -> | ||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) | ||
} | ||
} | ||
} | ||
} | ||
} |
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
50 changes: 25 additions & 25 deletions
50
app/src/main/java/com/devdunnapps/amplify/data/PreferencesRepositoryImpl.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,39 +1,39 @@ | ||
package com.devdunnapps.amplify.data | ||
|
||
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.core.stringPreferencesKey | ||
import androidx.datastore.preferences.preferencesDataStore | ||
import com.devdunnapps.amplify.ThemeConfigProto | ||
import com.devdunnapps.amplify.UserPreferences | ||
import com.devdunnapps.amplify.copy | ||
import com.devdunnapps.amplify.domain.models.Preferences | ||
import com.devdunnapps.amplify.domain.models.ThemeConfig | ||
import com.devdunnapps.amplify.domain.repository.PreferencesRepository | ||
import kotlinx.coroutines.flow.first | ||
import kotlinx.coroutines.flow.map | ||
import javax.inject.Inject | ||
|
||
class PreferencesRepositoryImpl @Inject constructor ( | ||
private val context: Context | ||
private val preferences: DataStore<UserPreferences> | ||
): PreferencesRepository { | ||
|
||
private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = "amplify_settings") | ||
|
||
override suspend fun write(key: String, value: String) { | ||
context.dataStore.edit { preferences -> | ||
preferences[stringPreferencesKey(key)] = value | ||
override val userData = preferences.data | ||
.map { | ||
Preferences( | ||
themeConfig = when (it.themeConfig) { | ||
ThemeConfigProto.DARK_THEME_CONFIG_DARK -> ThemeConfig.DARK | ||
ThemeConfigProto.DARK_THEME_CONFIG_LIGHT -> ThemeConfig.LIGHT | ||
else -> ThemeConfig.FOLLOW_SYSTEM | ||
} | ||
) | ||
} | ||
} | ||
|
||
override suspend fun writeBoolean(key: String, value: Boolean) { | ||
context.dataStore.edit { preferences -> | ||
preferences[booleanPreferencesKey(key)] = value | ||
override suspend fun setTheme(themeConfig: ThemeConfig) { | ||
preferences.updateData { | ||
it.copy { | ||
this.themeConfig = when (themeConfig) { | ||
ThemeConfig.FOLLOW_SYSTEM -> ThemeConfigProto.DARK_THEME_CONFIG_FOLLOW_SYSTEM | ||
ThemeConfig.LIGHT -> ThemeConfigProto.DARK_THEME_CONFIG_LIGHT | ||
ThemeConfig.DARK -> ThemeConfigProto.DARK_THEME_CONFIG_DARK | ||
} | ||
} | ||
} | ||
} | ||
|
||
override suspend fun read(key: String): String? { | ||
return context.dataStore.data.first()[stringPreferencesKey(key)] | ||
} | ||
|
||
override suspend fun readBoolean(key: String): Boolean { | ||
return context.dataStore.data.first()[booleanPreferencesKey(key)] ?: true | ||
} | ||
} |
Oops, something went wrong.