Просмотр исходного кода

Update wallpaper logic to set the wallpaper by default (#125)

Joshua Kuestersteffen 3 лет назад
Родитель
Сommit
de4b3a8379

+ 2 - 2
app/src/main/java/com/sduduzog/slimlauncher/datasource/coreprefs/CorePreferencesRepository.kt

@@ -50,10 +50,10 @@ class CorePreferencesRepository(
         }
     }
 
-    fun updateSetAutomaticDeviceWallpaper(setDeviceWallpaper: Boolean) {
+    fun updateKeepDeviceWallpaper(keepDeviceWallpaper: Boolean) {
         lifecycleScope.launch {
             corePreferencesStore.updateData {
-                it.toBuilder().setSetThemeWallpaper(setDeviceWallpaper).build()
+                it.toBuilder().setKeepDeviceWallpaper(keepDeviceWallpaper).build()
             }
         }
     }

+ 2 - 2
app/src/main/java/com/sduduzog/slimlauncher/ui/options/OptionsFragment.kt

@@ -79,10 +79,10 @@ class OptionsFragment : BaseFragment() {
 
         prefsRepo.liveData().observe(viewLifecycleOwner) {
             // always uncheck once app isn't default launcher
-            options_fragment_auto_device_theme_wallpaper.isChecked = appIsDefaultLauncher && it.setThemeWallpaper
+            options_fragment_auto_device_theme_wallpaper.isChecked = appIsDefaultLauncher && !it.keepDeviceWallpaper
         }
         options_fragment_auto_device_theme_wallpaper.setOnCheckedChangeListener { _, checked ->
-            prefsRepo.updateSetAutomaticDeviceWallpaper(checked)
+            prefsRepo.updateKeepDeviceWallpaper(!checked)
         }
     }
 

+ 4 - 1
app/src/main/java/com/sduduzog/slimlauncher/utils/WallpaperManager.kt

@@ -16,10 +16,13 @@ import java.io.IOException
 
 class WallpaperManager(private val mainActivity: MainActivity) {
     fun onApplyThemeResource(theme: Resources.Theme?, @StyleRes resid: Int) {
+        if(!isActivityDefaultLauncher(mainActivity)) {
+            return
+        }
         // Cannot inject here because this is called too early in the lifecycle
         val unlauncherDataSource = UnlauncherDataSource(mainActivity, mainActivity.lifecycleScope)
         unlauncherDataSource.corePreferencesRepo.liveData().observe(mainActivity) {
-            if (!it.setThemeWallpaper && mainActivity.getUserSelectedThemeRes() == resid) {
+            if (it.keepDeviceWallpaper && mainActivity.getUserSelectedThemeRes() == resid) {
                 // only change the wallpaper when user has allowed it and
                 // preventing to change the wallpaper multiple times once it is rechecked in the settings
                 return@observe

+ 1 - 1
app/src/main/proto/core_preferences.proto

@@ -5,5 +5,5 @@ option java_multiple_files = true;
 
 message CorePreferences {
   bool activate_keyboard_in_drawer = 1;
-  bool set_theme_wallpaper = 2;
+  bool keep_device_wallpaper = 2;
 }