mirror of
https://github.com/awfixers-stuff/OwnDroid.git
synced 2026-03-23 19:15:58 +00:00
Set Dark theme in Settings
Add MyViewModel to keep ThemeSettings state Use ListItem to display SSIDs in WiFi SSID Policy Use green color scheme as default color scheme Add Compose BOM dependency, update dependencies
This commit is contained in:
37
app/src/main/java/com/bintianqi/owndroid/MyViewModel.kt
Normal file
37
app/src/main/java/com/bintianqi/owndroid/MyViewModel.kt
Normal file
@@ -0,0 +1,37 @@
|
||||
package com.bintianqi.owndroid
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class MyViewModel: ViewModel() {
|
||||
val theme = MutableStateFlow(ThemeSettings())
|
||||
|
||||
var initialized = false
|
||||
fun initialize(context: Context) {
|
||||
val sharedPrefs = context.getSharedPreferences("data", Context.MODE_PRIVATE)
|
||||
theme.value = ThemeSettings(
|
||||
materialYou = sharedPrefs.getBoolean("material_you", Build.VERSION.SDK_INT >= 31),
|
||||
darkTheme = if(sharedPrefs.contains("dark_theme")) sharedPrefs.getBoolean("dark_theme", false) else null,
|
||||
blackTheme = sharedPrefs.getBoolean("black_theme", false)
|
||||
)
|
||||
viewModelScope.launch {
|
||||
theme.collect {
|
||||
val editor = sharedPrefs.edit()
|
||||
editor.putBoolean("material_you", it.materialYou)
|
||||
if(it.darkTheme == null) editor.remove("dark_theme") else editor.putBoolean("dark_theme", it.darkTheme)
|
||||
editor.putBoolean("black_theme", it.blackTheme)
|
||||
editor.commit()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data class ThemeSettings(
|
||||
val materialYou: Boolean = false,
|
||||
val darkTheme: Boolean? = null,
|
||||
val blackTheme: Boolean = false
|
||||
)
|
||||
Reference in New Issue
Block a user