Skip to content

Commit

Permalink
Update wallpaper logic to set the wallpaper by default (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkuester authored Sep 11, 2022
1 parent 12f44e6 commit de4b3a8
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/proto/core_preferences.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit de4b3a8

Please sign in to comment.