Migrate wallpaper preferences
This commit is contained in:
parent
11017f46bc
commit
85b8f3f615
@ -280,7 +280,7 @@
|
||||
<string name="provider_here">HERE</string>
|
||||
<string name="preference_icon_shape_pentagon">Fünfeck</string>
|
||||
<string name="preference_category_wallpaper">Hintergrund</string>
|
||||
<string name="preference_wallpaper_summary">Hintergrundbild setzen</string>
|
||||
<string name="preference_wallpaper_summary">Hintergrundbild auswählen</string>
|
||||
<string name="preference_dim_wallpaper">Hintergrund dimmen</string>
|
||||
<string name="preference_dim_wallpaper_summary">Hintergrundbild bei Verwendung von dunklen Desings abdunkeln</string>
|
||||
<string name="preference_screen_badges">Plaketten</string>
|
||||
|
||||
@ -9,6 +9,7 @@ fun createFactorySettings(context: Context): Settings {
|
||||
.newBuilder()
|
||||
.setTheme(Settings.AppearanceSettings.Theme.System)
|
||||
.setColorScheme(Settings.AppearanceSettings.ColorScheme.Default)
|
||||
.setDimWallpaper(false)
|
||||
.build()
|
||||
)
|
||||
.setWeather(
|
||||
|
||||
@ -17,6 +17,7 @@ message Settings {
|
||||
BlackAndWhite = 1;
|
||||
}
|
||||
ColorScheme color_scheme = 6;
|
||||
bool dim_wallpaper = 7;
|
||||
}
|
||||
AppearanceSettings appearance = 2;
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@ package de.mm20.launcher2.ui.launcher
|
||||
|
||||
import android.app.WallpaperManager
|
||||
import android.content.Intent
|
||||
import android.content.res.Configuration
|
||||
import android.os.Bundle
|
||||
import android.view.*
|
||||
import androidx.activity.viewModels
|
||||
@ -13,6 +14,7 @@ import com.afollestad.materialdialogs.callbacks.onDismiss
|
||||
import com.afollestad.materialdialogs.customview.customView
|
||||
import de.mm20.launcher2.icons.DynamicIconController
|
||||
import de.mm20.launcher2.icons.IconRepository
|
||||
import de.mm20.launcher2.ktx.dp
|
||||
import de.mm20.launcher2.legacy.helper.ActivityStarter
|
||||
import de.mm20.launcher2.preferences.LauncherPreferences
|
||||
import de.mm20.launcher2.ui.R
|
||||
@ -38,9 +40,23 @@ class LauncherActivity : BaseActivity() {
|
||||
|
||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||
|
||||
viewModel.setDarkMode(resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES)
|
||||
|
||||
binding = ActivityLauncherBinding.inflate(LayoutInflater.from(this))
|
||||
setContentView(binding.root)
|
||||
|
||||
viewModel.dimBackground.observe(this) { dim ->
|
||||
window.attributes = window.attributes.also {
|
||||
if (dim) {
|
||||
it.dimAmount = 0.3f
|
||||
it.flags = it.flags or WindowManager.LayoutParams.FLAG_DIM_BEHIND
|
||||
} else {
|
||||
it.dimAmount = 0f
|
||||
it.flags = it.flags and WindowManager.LayoutParams.FLAG_DIM_BEHIND.inv()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var editFavoritesDialog: MaterialDialog? = null
|
||||
viewModel.isEditFavoritesShown.observe(this) {
|
||||
if (it) {
|
||||
@ -83,10 +99,6 @@ class LauncherActivity : BaseActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
if (LauncherPreferences.instance.dimWallpaper) {
|
||||
binding.dimWallpaper.setBackgroundColor(getColor(R.color.wallpaper_dim))
|
||||
}
|
||||
|
||||
val dynamicIconController: DynamicIconController by inject()
|
||||
|
||||
lifecycle.addObserver(dynamicIconController)
|
||||
|
||||
@ -2,11 +2,40 @@ package de.mm20.launcher2.ui.launcher
|
||||
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.asLiveData
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import de.mm20.launcher2.preferences.LauncherDataStore
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.launch
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.inject
|
||||
|
||||
class LauncherActivityVM : ViewModel(), KoinComponent {
|
||||
private val dataStore: LauncherDataStore by inject()
|
||||
|
||||
class LauncherActivityVM : ViewModel() {
|
||||
val isHiddenItemsShown = MutableLiveData(false)
|
||||
val isEditFavoritesShown = MutableLiveData(false)
|
||||
val dimBackground = MutableLiveData(false)
|
||||
|
||||
private var isDarkInMode = MutableStateFlow(false)
|
||||
|
||||
val dimBackground = combine(
|
||||
dataStore.data.map { it.appearance.dimWallpaper },
|
||||
isDarkInMode
|
||||
) { dim, darkMode ->
|
||||
dim && darkMode
|
||||
}.asLiveData()
|
||||
|
||||
init {
|
||||
viewModelScope.launch {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
fun setDarkMode(darkMode: Boolean) {
|
||||
isDarkInMode.value = darkMode
|
||||
}
|
||||
|
||||
fun showEditFavorites() {
|
||||
isEditFavoritesShown.value = true
|
||||
|
||||
@ -1,19 +1,20 @@
|
||||
package de.mm20.launcher2.ui.settings.appearance
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.runtime.livedata.observeAsState
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import de.mm20.launcher2.preferences.Settings.AppearanceSettings.ColorScheme
|
||||
import de.mm20.launcher2.preferences.Settings.AppearanceSettings.Theme
|
||||
import de.mm20.launcher2.ui.R
|
||||
import de.mm20.launcher2.ui.component.preferences.ListPreference
|
||||
import de.mm20.launcher2.ui.component.preferences.PreferenceCategory
|
||||
import de.mm20.launcher2.ui.component.preferences.PreferenceScreen
|
||||
import de.mm20.launcher2.ui.component.preferences.*
|
||||
|
||||
@Composable
|
||||
fun AppearanceSettingsScreen() {
|
||||
val viewModel: AppearanceSettingsScreenVM = viewModel()
|
||||
val context = LocalContext.current
|
||||
PreferenceScreen(title = stringResource(id = R.string.preference_screen_appearance)) {
|
||||
item {
|
||||
PreferenceCategory {
|
||||
@ -58,6 +59,25 @@ fun AppearanceSettingsScreen() {
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
PreferenceCategory(stringResource(id = R.string.preference_category_wallpaper)) {
|
||||
Preference(
|
||||
title = stringResource(R.string.wallpaper),
|
||||
summary = stringResource(R.string.preference_wallpaper_summary),
|
||||
onClick = {
|
||||
viewModel.openWallpaperChooser(context as AppCompatActivity)
|
||||
}
|
||||
)
|
||||
val dimWallpaper by viewModel.dimWallpaper.observeAsState()
|
||||
SwitchPreference(
|
||||
title = stringResource(R.string.preference_dim_wallpaper),
|
||||
summary = stringResource(R.string.preference_dim_wallpaper_summary),
|
||||
value = dimWallpaper == true,
|
||||
onValueChanged = {
|
||||
viewModel.setDimWallpaper(it)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,7 @@
|
||||
package de.mm20.launcher2.ui.settings.appearance
|
||||
|
||||
import android.content.Intent
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.asLiveData
|
||||
import androidx.lifecycle.viewModelScope
|
||||
@ -46,4 +48,19 @@ class AppearanceSettingsScreenVM : ViewModel(), KoinComponent {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val dimWallpaper = dataStore.data.map { it.appearance.dimWallpaper }.asLiveData()
|
||||
fun setDimWallpaper(dimWallpaper: Boolean) {
|
||||
viewModelScope.launch {
|
||||
dataStore.updateData {
|
||||
it.toBuilder()
|
||||
.setAppearance(it.appearance.toBuilder().setDimWallpaper(dimWallpaper))
|
||||
.build()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun openWallpaperChooser(context: AppCompatActivity) {
|
||||
context.startActivity(Intent.createChooser(Intent(Intent.ACTION_SET_WALLPAPER), null))
|
||||
}
|
||||
}
|
||||
@ -5,11 +5,6 @@
|
||||
android:layout_height="match_parent"
|
||||
android:clipChildren="false">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/dimWallpaper"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<de.mm20.launcher2.ui.legacy.view.BatteryChargingView
|
||||
android:id="@+id/batteryAnimationView"
|
||||
android:layout_width="48dp"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user