Add new drawable resources for icons and themes

- Created `archive_filled.xml` for filled archive icon.
- Added `bookmark_outlined.xml` for outlined bookmark icon.
- Introduced `day_theme_filled.xml` for day theme icon.
- Added `folder_outlined.xml` for outlined folder icon.
- Created `gear_outlined.xml` for outlined gear icon.
- Introduced `night_mode.xml` for night mode icon.
This commit is contained in:
2026-02-13 17:37:03 +05:00
parent e17b03c1c5
commit 93ce53d3d5
30 changed files with 1269 additions and 147 deletions

View File

@@ -9,9 +9,13 @@ import androidx.datastore.preferences.core.intPreferencesKey
import androidx.datastore.preferences.core.stringPreferencesKey
import androidx.datastore.preferences.core.stringSetPreferencesKey
import androidx.datastore.preferences.preferencesDataStore
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
private val Context.dataStore: DataStore<Preferences> by
preferencesDataStore(name = "rosetta_preferences")
@@ -75,13 +79,23 @@ class PreferencesManager(private val context: Context) {
context.dataStore.edit { preferences -> preferences[IS_DARK_THEME] = value }
}
val themeMode: Flow<String> =
context.dataStore.data.map { preferences ->
preferences[THEME_MODE] ?: "dark" // Default to dark theme
}
// In-memory cache for instant theme switching (no DataStore disk I/O delay)
private val _themeMode = MutableStateFlow("dark")
private val themeModeInitScope = CoroutineScope(Dispatchers.IO)
init {
// Load persisted value on startup
themeModeInitScope.launch {
val persisted = context.dataStore.data.first()[THEME_MODE] ?: "dark"
_themeMode.value = persisted
}
}
val themeMode: Flow<String> = _themeMode
suspend fun setThemeMode(value: String) {
context.dataStore.edit { preferences -> preferences[THEME_MODE] = value }
_themeMode.value = value // Instant in-memory update
context.dataStore.edit { preferences -> preferences[THEME_MODE] = value } // Persist
}
// ═════════════════════════════════════════════════════════════