From 68e6544da8fb6f8a4889152d485e972d6fdd1cdf Mon Sep 17 00:00:00 2001 From: Anthony La Date: Sun, 3 Nov 2024 16:52:54 -0800 Subject: [PATCH] chore/Refactor code --- app/build.gradle.kts | 4 +- .../data/settings/SettingsDataStore.kt | 1 + .../data/settings/SettingsDataStoreImpl.kt | 14 +- .../wallpaper/presentation/MainActivity.kt | 211 +++--- .../wallpaper/presentation/PaperizeApp.kt | 603 ++++++----------- .../presentation/home_screen/HomeScreen.kt | 91 +-- .../library_screen/LibraryScreen.kt | 10 +- .../NotificationScreen.kt | 9 +- .../settings_screen/SettingsScreen.kt | 253 ++++--- .../settings_screen/SettingsState.kt | 87 ++- .../settings_screen/SettingsViewModel.kt | 635 +++++++++--------- .../startup_screen/StartupScreen.kt | 28 +- .../wallpaper_screen/WallpaperScreen.kt | 190 +++--- .../util/navigation/AnimatedScreen.kt | 42 ++ .../wallpaper/util/navigation/NavScreens.kt | 2 +- 15 files changed, 1001 insertions(+), 1179 deletions(-) create mode 100644 app/src/main/java/com/anthonyla/paperize/feature/wallpaper/util/navigation/AnimatedScreen.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 126f2f92..e83a601d 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -19,9 +19,9 @@ android { defaultConfig { applicationId = "com.anthonyla.paperize" minSdk = 26 - targetSdk = 35 + targetSdk = 36 versionCode = 35 - versionName = "2.3.3" + versionName = "2.4.0" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" vectorDrawables { useSupportLibrary = true diff --git a/app/src/main/java/com/anthonyla/paperize/data/settings/SettingsDataStore.kt b/app/src/main/java/com/anthonyla/paperize/data/settings/SettingsDataStore.kt index b7cbd870..3fdfb8a4 100644 --- a/app/src/main/java/com/anthonyla/paperize/data/settings/SettingsDataStore.kt +++ b/app/src/main/java/com/anthonyla/paperize/data/settings/SettingsDataStore.kt @@ -13,5 +13,6 @@ interface SettingsDataStore { suspend fun deleteBoolean(key: String) suspend fun deleteString(key: String) suspend fun deleteInt(key: String) + suspend fun clear(keys: List) suspend fun clearPreferences() } \ No newline at end of file diff --git a/app/src/main/java/com/anthonyla/paperize/data/settings/SettingsDataStoreImpl.kt b/app/src/main/java/com/anthonyla/paperize/data/settings/SettingsDataStoreImpl.kt index 53ac7995..b085a2f6 100644 --- a/app/src/main/java/com/anthonyla/paperize/data/settings/SettingsDataStoreImpl.kt +++ b/app/src/main/java/com/anthonyla/paperize/data/settings/SettingsDataStoreImpl.kt @@ -9,7 +9,6 @@ import androidx.datastore.preferences.core.stringPreferencesKey import androidx.datastore.preferences.preferencesDataStore import com.anthonyla.paperize.core.SettingsConstants.SETTINGS_DATASTORE import kotlinx.coroutines.flow.first -import javax.inject.Inject private val Context.dataStore: DataStore by preferencesDataStore(name = SETTINGS_DATASTORE) @@ -95,4 +94,17 @@ class SettingsDataStoreImpl(private val context: Context) : SettingsDataStore { it.clear() } } + + override suspend fun clear(keys: List) { + context.dataStore.edit { preferences -> + keys.forEach { key -> + if (preferences.contains(booleanPreferencesKey(key))) { + preferences.remove(booleanPreferencesKey(key)) + } + else if (preferences.contains(stringPreferencesKey(key))) { + preferences.remove(stringPreferencesKey(key)) + } + } + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/MainActivity.kt b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/MainActivity.kt index f8336234..e5b46e6f 100644 --- a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/MainActivity.kt +++ b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/MainActivity.kt @@ -35,6 +35,7 @@ import com.anthonyla.paperize.data.settings.SettingsDataStore import com.anthonyla.paperize.feature.wallpaper.presentation.album.AlbumsEvent import com.anthonyla.paperize.feature.wallpaper.presentation.album.AlbumsViewModel import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsEvent +import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsState import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsViewModel import com.anthonyla.paperize.feature.wallpaper.presentation.themes.PaperizeTheme import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.WallpaperEvent @@ -79,99 +80,24 @@ class MainActivity : ComponentActivity() { splashScreen.setKeepOnScreenCondition { settingsViewModel.setKeepOnScreenCondition } setContent { - val scheduler = WallpaperAlarmSchedulerImpl(context) val settingsState = settingsViewModel.state.collectAsStateWithLifecycle() val isFirstLaunch = runBlocking { settingsDataStoreImpl.getBoolean(SettingsConstants.FIRST_LAUNCH) } ?: true + val scheduler = WallpaperAlarmSchedulerImpl(context) if (isFirstLaunch) { - scheduler.cancelWallpaperAlarm() - wallpaperScreenViewModel.onEvent(WallpaperEvent.Reset()) - settingsViewModel.onEvent(SettingsEvent.Reset) - albumsViewModel.onEvent(AlbumsEvent.Reset) - val contentResolver = context.contentResolver - val persistedUris = contentResolver.persistedUriPermissions - for (permission in persistedUris) { - contentResolver.releasePersistableUriPermission(permission.uri, Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION) - } + handleFirstLaunch(scheduler) } + LifecycleEventEffect(Lifecycle.Event.ON_CREATE) { lifecycleScope.launch { - if (settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_CHANGER) == true) { - val homeAlbumName = settingsDataStoreImpl.getString(SettingsConstants.HOME_ALBUM_NAME) - val lockAlbumName = settingsDataStoreImpl.getString(SettingsConstants.LOCK_ALBUM_NAME) - if (homeAlbumName.isNullOrEmpty() || lockAlbumName.isNullOrEmpty()) { - settingsViewModel.onEvent(SettingsEvent.SetChangerToggle(false)) - } - else { - val shouldScheduleSeparately = settingsDataStoreImpl.getBoolean(SettingsConstants.SCHEDULE_SEPARATELY) ?: false - val shouldScheduleAlarm = if (shouldScheduleSeparately) { - !(isPendingIntentSet(Type.HOME.ordinal) && isPendingIntentSet(Type.LOCK.ordinal)) - } else { - !isPendingIntentSet(Type.SINGLE.ordinal) - } - if (shouldScheduleAlarm) { - scheduler.scheduleWallpaperAlarm( - WallpaperAlarmItem( - homeInterval = settingsDataStoreImpl.getInt(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT, - lockInterval = settingsDataStoreImpl.getInt(SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT, - setLock = settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_LOCK_WALLPAPER) ?: false, - setHome = settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_HOME_WALLPAPER) ?: false, - scheduleSeparately = shouldScheduleSeparately, - changeStartTime = settingsDataStoreImpl.getBoolean(SettingsConstants.CHANGE_START_TIME) ?: false, - startTime = Pair( - settingsDataStoreImpl.getInt(SettingsConstants.START_HOUR) ?: 0, - settingsDataStoreImpl.getInt(SettingsConstants.START_MINUTE) ?: 0 - ), - ), - origin = null, - changeImmediate = true, - cancelImmediate = true, - firstLaunch = true - ) - settingsViewModel.onEvent(SettingsEvent.RefreshNextSetTime) - val selectedState = wallpaperScreenViewModel.state.value - val currentHomeAlbum = selectedState.selectedAlbum?.find { it.album.initialAlbumName == settingsState.value.homeAlbumName } - val currentLockAlbum = selectedState.selectedAlbum?.find { it.album.initialAlbumName == settingsState.value.lockAlbumName } - when { - settingsState.value.scheduleSeparately && settingsState.value.setHomeWallpaper && settingsState.value.setLockWallpaper -> { - if (currentHomeAlbum != null && currentLockAlbum != null) { - settingsViewModel.onEvent(SettingsEvent.SetCurrentWallpaper( - currentHomeWallpaper = currentHomeAlbum.album.homeWallpapersInQueue.firstOrNull() ?: currentHomeAlbum.wallpapers.firstOrNull()?.wallpaperUri, - currentLockWallpaper = currentLockAlbum.album.lockWallpapersInQueue.firstOrNull() ?: currentLockAlbum.wallpapers.firstOrNull()?.wallpaperUri - )) - } - } - !settingsState.value.scheduleSeparately && settingsState.value.setHomeWallpaper && settingsState.value.setLockWallpaper -> { - if (currentHomeAlbum != null && currentLockAlbum != null) { - settingsViewModel.onEvent(SettingsEvent.SetCurrentWallpaper( - currentHomeWallpaper = currentHomeAlbum.album.homeWallpapersInQueue.firstOrNull() ?: currentHomeAlbum.wallpapers.firstOrNull()?.wallpaperUri, - currentLockWallpaper = currentHomeAlbum.album.homeWallpapersInQueue.firstOrNull() ?: currentHomeAlbum.wallpapers.firstOrNull()?.wallpaperUri - )) - } - } - settingsState.value.setHomeWallpaper -> { - if (currentHomeAlbum != null) { - settingsViewModel.onEvent(SettingsEvent.SetCurrentWallpaper( - currentHomeWallpaper = currentHomeAlbum.album.homeWallpapersInQueue.firstOrNull() ?: currentHomeAlbum.wallpapers.firstOrNull()?.wallpaperUri, - currentLockWallpaper = if (settingsState.value.scheduleSeparately) null else currentHomeAlbum.album.homeWallpapersInQueue.firstOrNull() ?: currentHomeAlbum.wallpapers.firstOrNull()?.wallpaperUri - )) - } - } - settingsState.value.setLockWallpaper -> { - if (currentLockAlbum != null) { - settingsViewModel.onEvent(SettingsEvent.SetCurrentWallpaper( - currentHomeWallpaper = if (settingsState.value.scheduleSeparately) null else currentLockAlbum.album.lockWallpapersInQueue.firstOrNull() ?: currentLockAlbum.wallpapers.firstOrNull()?.wallpaperUri, - currentLockWallpaper = currentLockAlbum.album.lockWallpapersInQueue.firstOrNull() ?: currentLockAlbum.wallpapers.firstOrNull()?.wallpaperUri - )) - } - } - } - } - } - } + handleWallpaperScheduling(settingsState.value, scheduler) } } - PaperizeTheme(settingsState.value.darkMode, settingsState.value.amoledTheme, settingsState.value.dynamicTheming) { + PaperizeTheme( + darkMode = settingsState.value.themeSettings.darkMode, + amoledMode = settingsState.value.themeSettings.amoledTheme, + dynamicTheming = settingsState.value.themeSettings.dynamicTheming + ) { Surface(tonalElevation = 5.dp) { PaperizeApp(isFirstLaunch, scheduler) } @@ -179,6 +105,123 @@ class MainActivity : ComponentActivity() { } } + private fun handleFirstLaunch(scheduler: WallpaperAlarmSchedulerImpl) { + scheduler.cancelWallpaperAlarm() + wallpaperScreenViewModel.onEvent(WallpaperEvent.Reset()) + settingsViewModel.onEvent(SettingsEvent.Reset) + albumsViewModel.onEvent(AlbumsEvent.Reset) + clearPersistedUriPermissions() + } + + private fun clearPersistedUriPermissions() { + val contentResolver = context.contentResolver + val persistedUris = contentResolver.persistedUriPermissions + for (permission in persistedUris) { + contentResolver.releasePersistableUriPermission( + permission.uri, + Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION + ) + } + } + + private fun handleWallpaperScheduling( + settings: SettingsState, + scheduler: WallpaperAlarmSchedulerImpl + ) { + val wallpaperSettings = settings.wallpaperSettings + val scheduleSettings = settings.scheduleSettings + + if (!wallpaperSettings.enableChanger) return + if (wallpaperSettings.homeAlbumName.isNullOrEmpty() || wallpaperSettings.lockAlbumName.isNullOrEmpty()) { + settingsViewModel.onEvent(SettingsEvent.SetChangerToggle(false)) + return + } + + val shouldScheduleAlarm = if (scheduleSettings.scheduleSeparately) { + !(isPendingIntentSet(Type.HOME.ordinal) && isPendingIntentSet(Type.LOCK.ordinal)) + } else { + !isPendingIntentSet(Type.SINGLE.ordinal) + } + + if (shouldScheduleAlarm) { + scheduleWallpaperAlarm(settings, scheduler) + updateCurrentWallpapers(settings) + } + } + + private fun scheduleWallpaperAlarm( + settings: SettingsState, + scheduler: WallpaperAlarmSchedulerImpl + ) { + val scheduleSettings = settings.scheduleSettings + val wallpaperSettings = settings.wallpaperSettings + + scheduler.scheduleWallpaperAlarm( + WallpaperAlarmItem( + homeInterval = scheduleSettings.homeInterval, + lockInterval = scheduleSettings.lockInterval, + setLock = wallpaperSettings.setLockWallpaper, + setHome = wallpaperSettings.setHomeWallpaper, + scheduleSeparately = scheduleSettings.scheduleSeparately, + changeStartTime = scheduleSettings.changeStartTime, + startTime = scheduleSettings.startTime + ), + origin = null, + changeImmediate = true, + cancelImmediate = true, + firstLaunch = true + ) + settingsViewModel.onEvent(SettingsEvent.RefreshNextSetTime) + } + + private fun updateCurrentWallpapers(settings: SettingsState) { + val selectedState = wallpaperScreenViewModel.state.value + val currentHomeAlbum = selectedState.selectedAlbum?.find { + it.album.initialAlbumName == settings.wallpaperSettings.homeAlbumName + } + val currentLockAlbum = selectedState.selectedAlbum?.find { + it.album.initialAlbumName == settings.wallpaperSettings.lockAlbumName + } + + val wallpaperSettings = settings.wallpaperSettings + val scheduleSettings = settings.scheduleSettings + + when { + scheduleSettings.scheduleSeparately && wallpaperSettings.setHomeWallpaper && wallpaperSettings.setLockWallpaper -> { + if (currentHomeAlbum != null && currentLockAlbum != null) { + settingsViewModel.onEvent(SettingsEvent.SetCurrentWallpaper( + currentHomeWallpaper = currentHomeAlbum.album.homeWallpapersInQueue.firstOrNull() ?: currentHomeAlbum.wallpapers.firstOrNull()?.wallpaperUri, + currentLockWallpaper = currentLockAlbum.album.lockWallpapersInQueue.firstOrNull() ?: currentLockAlbum.wallpapers.firstOrNull()?.wallpaperUri + )) + } + } + !scheduleSettings.scheduleSeparately && wallpaperSettings.setHomeWallpaper && wallpaperSettings.setLockWallpaper -> { + if (currentHomeAlbum != null && currentLockAlbum != null) { + settingsViewModel.onEvent(SettingsEvent.SetCurrentWallpaper( + currentHomeWallpaper = currentHomeAlbum.album.homeWallpapersInQueue.firstOrNull() ?: currentHomeAlbum.wallpapers.firstOrNull()?.wallpaperUri, + currentLockWallpaper = currentHomeAlbum.album.homeWallpapersInQueue.firstOrNull() ?: currentHomeAlbum.wallpapers.firstOrNull()?.wallpaperUri + )) + } + } + wallpaperSettings.setHomeWallpaper -> { + if (currentHomeAlbum != null) { + settingsViewModel.onEvent(SettingsEvent.SetCurrentWallpaper( + currentHomeWallpaper = currentHomeAlbum.album.homeWallpapersInQueue.firstOrNull() ?: currentHomeAlbum.wallpapers.firstOrNull()?.wallpaperUri, + currentLockWallpaper = if (scheduleSettings.scheduleSeparately) null else currentHomeAlbum.album.homeWallpapersInQueue.firstOrNull() ?: currentHomeAlbum.wallpapers.firstOrNull()?.wallpaperUri + )) + } + } + wallpaperSettings.setLockWallpaper -> { + if (currentLockAlbum != null) { + settingsViewModel.onEvent(SettingsEvent.SetCurrentWallpaper( + currentHomeWallpaper = if (scheduleSettings.scheduleSeparately) null else currentLockAlbum.album.lockWallpapersInQueue.firstOrNull() ?: currentLockAlbum.wallpapers.firstOrNull()?.wallpaperUri, + currentLockWallpaper = currentLockAlbum.album.lockWallpapersInQueue.firstOrNull() ?: currentLockAlbum.wallpapers.firstOrNull()?.wallpaperUri + )) + } + } + } + } + override fun onResume() { super.onResume() if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { diff --git a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/PaperizeApp.kt b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/PaperizeApp.kt index 478467c3..24b79cb1 100644 --- a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/PaperizeApp.kt +++ b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/PaperizeApp.kt @@ -18,7 +18,6 @@ import androidx.core.content.ContextCompat import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.navigation.compose.NavHost -import androidx.navigation.compose.composable import androidx.navigation.compose.rememberNavController import androidx.navigation.toRoute import com.anthonyla.paperize.data.SendContactIntent @@ -41,19 +40,17 @@ import com.anthonyla.paperize.feature.wallpaper.presentation.startup_screen.Star import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.WallpaperEvent import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.WallpaperScreenViewModel import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_view_screen.WallpaperViewScreen -import com.anthonyla.paperize.feature.wallpaper.util.navigation.AddEdit +import com.anthonyla.paperize.feature.wallpaper.util.navigation.AddAlbum import com.anthonyla.paperize.feature.wallpaper.util.navigation.AlbumView import com.anthonyla.paperize.feature.wallpaper.util.navigation.FolderView import com.anthonyla.paperize.feature.wallpaper.util.navigation.Home import com.anthonyla.paperize.feature.wallpaper.util.navigation.Licenses -import com.anthonyla.paperize.feature.wallpaper.util.navigation.NavConstants.INITIAL_OFFSET import com.anthonyla.paperize.feature.wallpaper.util.navigation.Notification import com.anthonyla.paperize.feature.wallpaper.util.navigation.Privacy import com.anthonyla.paperize.feature.wallpaper.util.navigation.Settings import com.anthonyla.paperize.feature.wallpaper.util.navigation.Startup import com.anthonyla.paperize.feature.wallpaper.util.navigation.WallpaperView -import com.anthonyla.paperize.feature.wallpaper.util.navigation.sharedXTransitionIn -import com.anthonyla.paperize.feature.wallpaper.util.navigation.sharedXTransitionOut +import com.anthonyla.paperize.feature.wallpaper.util.navigation.animatedScreen import com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager.WallpaperAlarmItem import com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager.WallpaperAlarmSchedulerImpl import kotlinx.coroutines.Dispatchers @@ -84,32 +81,42 @@ fun PaperizeApp( // React to albumState changes and change selectedAlbum's details to keep it from being stale LaunchedEffect(albumState.value) { withContext(Dispatchers.IO) { - albumState.value.albumsWithWallpapers.asSequence().forEach { albumWithWallpapers -> - if (!albumWithWallpapers.album.initialized && (albumWithWallpapers.wallpapers.isNotEmpty() || albumWithWallpapers.folders.isNotEmpty())) { - albumsViewModel.onEvent(AlbumsEvent.InitializeAlbum(albumWithWallpapers)) + // Process albums that need initialization or deletion + albumState.value.albumsWithWallpapers.asSequence() + .filter { album -> + (!album.album.initialized && (album.wallpapers.isNotEmpty() || album.folders.isNotEmpty())) || + (album.wallpapers.isEmpty() && album.folders.isEmpty() && album.album.initialized) } - else if (albumWithWallpapers.wallpapers.isEmpty() && albumWithWallpapers.folders.isEmpty() && albumWithWallpapers.album.initialized) { - if (navController.currentDestination?.route == Home::class.simpleName) { - try { - navController.popBackStack(inclusive = false) - } catch (_: Exception) { - navController.navigate(Home) + .forEach { album -> + when { + !album.album.initialized -> { + albumsViewModel.onEvent(AlbumsEvent.InitializeAlbum(album)) + } + else -> { + if (navController.currentDestination?.route == Home::class.simpleName) { + try { + navController.popBackStack(inclusive = false) + } catch (_: Exception) { + navController.navigate(Home) + } + } + albumsViewModel.onEvent(AlbumsEvent.DeleteAlbumWithWallpapers(album)) } } - albumsViewModel.onEvent(AlbumsEvent.DeleteAlbumWithWallpapers(albumWithWallpapers)) } - } + // Update or reset selected albums selectedState.value.selectedAlbum?.forEach { selectedAlbum -> - val album = albumState.value.albumsWithWallpapers.find { it.album.initialAlbumName == selectedAlbum.album.initialAlbumName } - if (album != null) { - if (selectedAlbum.album.displayedAlbumName != album.album.displayedAlbumName || - selectedAlbum.album.coverUri != album.album.coverUri || - selectedAlbum.wallpapers.size != album.wallpapers.size + album.folders.sumOf { it.wallpapers.size }) - { + val matchingAlbum = albumState.value.albumsWithWallpapers + .find { it.album.initialAlbumName == selectedAlbum.album.initialAlbumName } + matchingAlbum?.let { album -> + val needsUpdate = selectedAlbum.album.displayedAlbumName != album.album.displayedAlbumName || + selectedAlbum.album.coverUri != album.album.coverUri || + selectedAlbum.wallpapers.size != album.wallpapers.size + album.folders.sumOf { it.wallpapers.size } + + if (needsUpdate) { wallpaperScreenViewModel.onEvent(WallpaperEvent.AddSelectedAlbum(album, selectedAlbum.album.initialAlbumName)) } - } - else { + } ?: run { wallpaperScreenViewModel.onEvent(WallpaperEvent.Reset(selectedAlbum)) settingsViewModel.onEvent(SettingsEvent.RemoveSelectedAlbumAsName(selectedAlbum.album.initialAlbumName)) scheduler.cancelWallpaperAlarm() @@ -121,31 +128,10 @@ fun PaperizeApp( NavHost( navController = navController, startDestination = if (firstLaunch) Startup else Home, - modifier = Modifier.navigationBarsPadding() + modifier = Modifier.navigationBarsPadding(), ) { // Navigate to the startup screen to show the privacy policy and notification screen - composable ( - enterTransition = { - if (settingsState.value.animate) { - sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() }) - } else { null } - }, - exitTransition = { - if (settingsState.value.animate) { - sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() }) - } else { null } - }, - popEnterTransition = { - if (settingsState.value.animate) { - sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() }) - } else { null } - }, - popExitTransition = { - if (settingsState.value.animate) { - sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() }) - } else { null } - } - ) { + animatedScreen(animate = settingsState.value.themeSettings.animate) { StartupScreen( onAgree = { if (ContextCompat.checkSelfPermission(context, Manifest.permission.POST_NOTIFICATIONS) == PackageManager.PERMISSION_GRANTED) { @@ -155,106 +141,41 @@ fun PaperizeApp( } ) } + // Navigate to the notification screen to ask for notification permission - composable ( - enterTransition = { - if (settingsState.value.animate) { - sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() }) - } else { null } - }, - exitTransition = { - if (settingsState.value.animate) { - sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() }) - } else { null } - }, - popEnterTransition = { - if (settingsState.value.animate) { - sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() }) - } else { null } - }, - popExitTransition = { - if (settingsState.value.animate) { - sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() }) - } else { null } - } - ) { + animatedScreen(animate = settingsState.value.themeSettings.animate) { NotificationScreen( onAgree = { settingsViewModel.onEvent(SettingsEvent.SetFirstLaunch) } ) } + // Navigate to the home screen to view all albums and wallpapers - composable ( - enterTransition = { - if (settingsState.value.animate) { - sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() }) - } else { null } - }, - exitTransition = { - if (settingsState.value.animate) { - sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() }) - } else { null } - }, - popEnterTransition = { - if (settingsState.value.animate) { - sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() }) - } else { null } - }, - popExitTransition = { - if (settingsState.value.animate) { - sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() }) - } else { null } - } - ) { + animatedScreen(animate = settingsState.value.themeSettings.animate) { HomeScreen( albums = albumState.value.albumsWithWallpapers, - animate = settingsState.value.animate, - homeInterval = settingsState.value.homeInterval, - lockInterval = settingsState.value.lockInterval, - lastSetTime = settingsState.value.lastSetTime, - nextSetTime = settingsState.value.nextSetTime, - homeSelectedAlbum = selectedState.value.selectedAlbum?.find { it.album.initialAlbumName == settingsState.value.homeAlbumName }, - lockSelectedAlbum = selectedState.value.selectedAlbum?.find { it.album.initialAlbumName == settingsState.value.lockAlbumName }, - enableChanger = settingsState.value.enableChanger, - homeDarkenPercentage = settingsState.value.homeDarkenPercentage, - lockDarkenPercentage = settingsState.value.lockDarkenPercentage, - darken = settingsState.value.darken, - homeEnabled = settingsState.value.setHomeWallpaper, - lockEnabled = settingsState.value.setLockWallpaper, - scheduleSeparately = settingsState.value.scheduleSeparately, - blur = settingsState.value.blur, - homeBlurPercentage = settingsState.value.homeBlurPercentage, - lockBlurPercentage = settingsState.value.lockBlurPercentage, - currentHomeWallpaper = settingsState.value.currentHomeWallpaper, - currentLockWallpaper = settingsState.value.currentLockWallpaper, - vignette = settingsState.value.vignette, - homeVignettePercentage = settingsState.value.homeVignettePercentage, - lockVignettePercentage = settingsState.value.lockVignettePercentage, - grayscale = settingsState.value.grayscale, - homeGrayscalePercentage = settingsState.value.homeGrayscalePercentage, - lockGrayscalePercentage = settingsState.value.lockGrayscalePercentage, - changeStartTime = settingsState.value.changeStartTime, - startingTime = settingsState.value.startTime, + homeSelectedAlbum = selectedState.value.selectedAlbum?.find { it.album.initialAlbumName == settingsState.value.wallpaperSettings.homeAlbumName }, + lockSelectedAlbum = selectedState.value.selectedAlbum?.find { it.album.initialAlbumName == settingsState.value.wallpaperSettings.lockAlbumName }, + themeSettings = settingsState.value.themeSettings, + wallpaperSettings = settingsState.value.wallpaperSettings, + scheduleSettings = settingsState.value.scheduleSettings, + effectSettings = settingsState.value.effectSettings, onSettingsClick = { navController.navigate(Settings) }, - navigateToAddWallpaperScreen = { - navController.navigate(AddEdit(it)) - }, - onViewAlbum = { - navController.navigate(AlbumView(it)) - }, + onNavigateAddWallpaper = { navController.navigate(AddAlbum(it)) }, + onViewAlbum = { navController.navigate(AlbumView(it)) }, onScheduleWallpaperChanger = { - if (settingsState.value.enableChanger) { + if (settingsState.value.wallpaperSettings.enableChanger) { settingsViewModel.onEvent(SettingsEvent.RefreshNextSetTime) job?.cancel() job = scope.launch { delay(1000) val alarmItem = WallpaperAlarmItem( - homeInterval = settingsState.value.homeInterval, - lockInterval = settingsState.value.lockInterval, - scheduleSeparately = settingsState.value.scheduleSeparately, - setHome = settingsState.value.setHomeWallpaper, - setLock = settingsState.value.setLockWallpaper, - changeStartTime = settingsState.value.changeStartTime, - startTime = settingsState.value.startTime + homeInterval = settingsState.value.scheduleSettings.homeInterval, + lockInterval = settingsState.value.scheduleSettings.lockInterval, + scheduleSeparately = settingsState.value.scheduleSettings.scheduleSeparately, + setHome = settingsState.value.wallpaperSettings.setHomeWallpaper, + setLock = settingsState.value.wallpaperSettings.setLockWallpaper, + changeStartTime = settingsState.value.scheduleSettings.changeStartTime, + startTime = settingsState.value.scheduleSettings.startTime ) alarmItem.let{scheduler.scheduleWallpaperAlarm( wallpaperAlarmItem = it, @@ -269,18 +190,18 @@ fun PaperizeApp( }, onHomeTimeChange = { timeInMinutes -> settingsViewModel.onEvent(SettingsEvent.SetHomeWallpaperInterval(timeInMinutes)) - if (settingsState.value.enableChanger) { + if (settingsState.value.wallpaperSettings.enableChanger) { job?.cancel() job = scope.launch { delay(3000) val alarmItem = WallpaperAlarmItem( homeInterval = timeInMinutes, - lockInterval = settingsState.value.lockInterval, - scheduleSeparately = settingsState.value.scheduleSeparately, - setHome = settingsState.value.setHomeWallpaper, - setLock = settingsState.value.setLockWallpaper, - changeStartTime = settingsState.value.changeStartTime, - startTime = settingsState.value.startTime + lockInterval = settingsState.value.scheduleSettings.lockInterval, + scheduleSeparately = settingsState.value.scheduleSettings.scheduleSeparately, + setHome = settingsState.value.wallpaperSettings.setHomeWallpaper, + setLock = settingsState.value.wallpaperSettings.setLockWallpaper, + changeStartTime = settingsState.value.scheduleSettings.changeStartTime, + startTime = settingsState.value.scheduleSettings.startTime ) alarmItem.let{scheduler.updateWallpaperAlarm(it)} scheduler.scheduleRefresh() @@ -289,18 +210,18 @@ fun PaperizeApp( }, onLockTimeChange = { timeInMinutes -> settingsViewModel.onEvent(SettingsEvent.SetLockWallpaperInterval(timeInMinutes)) - if (settingsState.value.enableChanger) { + if (settingsState.value.wallpaperSettings.enableChanger) { job?.cancel() job = scope.launch { delay(3000) val alarmItem = WallpaperAlarmItem( - homeInterval = settingsState.value.homeInterval, + homeInterval = settingsState.value.scheduleSettings.homeInterval, lockInterval = timeInMinutes, - scheduleSeparately = settingsState.value.scheduleSeparately, - setHome = settingsState.value.setHomeWallpaper, - setLock = settingsState.value.setLockWallpaper, - changeStartTime = settingsState.value.changeStartTime, - startTime = settingsState.value.startTime + scheduleSeparately = settingsState.value.scheduleSettings.scheduleSeparately, + setHome = settingsState.value.wallpaperSettings.setHomeWallpaper, + setLock = settingsState.value.wallpaperSettings.setLockWallpaper, + changeStartTime = settingsState.value.scheduleSettings.changeStartTime, + startTime = settingsState.value.scheduleSettings.startTime ) alarmItem.let{scheduler.updateWallpaperAlarm(it)} scheduler.scheduleRefresh() @@ -310,16 +231,16 @@ fun PaperizeApp( }, onStop = { lock, home -> if (!selectedState.value.selectedAlbum.isNullOrEmpty()) { - val notSameAlbum = settingsState.value.homeAlbumName != settingsState.value.lockAlbumName + val notSameAlbum = settingsState.value.wallpaperSettings.homeAlbumName != settingsState.value.wallpaperSettings.lockAlbumName when { lock && home -> { - wallpaperScreenViewModel.onEvent(WallpaperEvent.Reset(selectedState.value.selectedAlbum!!.find { it.album.initialAlbumName == settingsState.value.homeAlbumName})) + wallpaperScreenViewModel.onEvent(WallpaperEvent.Reset(selectedState.value.selectedAlbum!!.find { it.album.initialAlbumName == settingsState.value.wallpaperSettings.homeAlbumName})) } lock -> { - if (notSameAlbum) wallpaperScreenViewModel.onEvent(WallpaperEvent.Reset(selectedState.value.selectedAlbum!!.find { it.album.initialAlbumName == settingsState.value.lockAlbumName})) + if (notSameAlbum) wallpaperScreenViewModel.onEvent(WallpaperEvent.Reset(selectedState.value.selectedAlbum!!.find { it.album.initialAlbumName == settingsState.value.wallpaperSettings.lockAlbumName})) } home -> { - if (notSameAlbum) wallpaperScreenViewModel.onEvent(WallpaperEvent.Reset(selectedState.value.selectedAlbum!!.find { it.album.initialAlbumName == settingsState.value.homeAlbumName})) + if (notSameAlbum) wallpaperScreenViewModel.onEvent(WallpaperEvent.Reset(selectedState.value.selectedAlbum!!.find { it.album.initialAlbumName == settingsState.value.wallpaperSettings.homeAlbumName})) } } settingsViewModel.onEvent(SettingsEvent.RemoveSelectedAlbumAsType(lock, home)) @@ -327,7 +248,7 @@ fun PaperizeApp( } }, onToggleChanger = { enableWallpaperChanger -> - if (!selectedState.value.selectedAlbum.isNullOrEmpty() && !settingsState.value.homeAlbumName.isNullOrEmpty() && !settingsState.value.lockAlbumName.isNullOrEmpty()) { + if (!selectedState.value.selectedAlbum.isNullOrEmpty() && !settingsState.value.wallpaperSettings.homeAlbumName.isNullOrEmpty() && !settingsState.value.wallpaperSettings.lockAlbumName.isNullOrEmpty()) { settingsViewModel.onEvent(SettingsEvent.SetChangerToggle(enableWallpaperChanger)) if (enableWallpaperChanger) { job?.cancel() @@ -336,13 +257,13 @@ fun PaperizeApp( settingsViewModel.onEvent(SettingsEvent.RefreshNextWallpaper) delay(1000) val alarmItem = WallpaperAlarmItem( - homeInterval = settingsState.value.homeInterval, - lockInterval = settingsState.value.lockInterval, - scheduleSeparately = settingsState.value.scheduleSeparately, - setHome = settingsState.value.setHomeWallpaper, - setLock = settingsState.value.setLockWallpaper, - changeStartTime = settingsState.value.changeStartTime, - startTime = settingsState.value.startTime + homeInterval = settingsState.value.scheduleSettings.homeInterval, + lockInterval = settingsState.value.scheduleSettings.lockInterval, + scheduleSeparately = settingsState.value.scheduleSettings.scheduleSeparately, + setHome = settingsState.value.wallpaperSettings.setHomeWallpaper, + setLock = settingsState.value.wallpaperSettings.setLockWallpaper, + changeStartTime = settingsState.value.scheduleSettings.changeStartTime, + startTime = settingsState.value.scheduleSettings.startTime ) alarmItem.let{scheduler.scheduleWallpaperAlarm( wallpaperAlarmItem = it, @@ -358,7 +279,7 @@ fun PaperizeApp( } }, onSelectAlbum = {album, lock, home -> - val notSameAlbum = settingsState.value.homeAlbumName != settingsState.value.lockAlbumName + val notSameAlbum = settingsState.value.wallpaperSettings.homeAlbumName != settingsState.value.wallpaperSettings.lockAlbumName when { lock && home -> { settingsViewModel.onEvent(SettingsEvent.SetAlbumName( @@ -367,7 +288,7 @@ fun PaperizeApp( )) wallpaperScreenViewModel.onEvent(WallpaperEvent.AddSelectedAlbum( album = album, - deleteAlbumName = if (notSameAlbum) settingsState.value.lockAlbumName else null) + deleteAlbumName = if (notSameAlbum) settingsState.value.wallpaperSettings.lockAlbumName else null) ) } lock -> { @@ -377,7 +298,7 @@ fun PaperizeApp( )) wallpaperScreenViewModel.onEvent(WallpaperEvent.AddSelectedAlbum( album = album, - deleteAlbumName = if (notSameAlbum) settingsState.value.lockAlbumName else null) + deleteAlbumName = if (notSameAlbum) settingsState.value.wallpaperSettings.lockAlbumName else null) ) } home -> { @@ -387,18 +308,18 @@ fun PaperizeApp( )) wallpaperScreenViewModel.onEvent(WallpaperEvent.AddSelectedAlbum( album = album, - deleteAlbumName = if (notSameAlbum) settingsState.value.homeAlbumName else null) + deleteAlbumName = if (notSameAlbum) settingsState.value.wallpaperSettings.homeAlbumName else null) ) } } scope.launch { settingsViewModel.onEvent(SettingsEvent.RefreshNextSetTime) delay(1000) // Delay for enableChanger to refresh - if (settingsState.value.enableChanger) { - val currentHomeAlbum = selectedState.value.selectedAlbum?.find { it.album.initialAlbumName == settingsState.value.homeAlbumName } - val currentLockAlbum = selectedState.value.selectedAlbum?.find { it.album.initialAlbumName == settingsState.value.lockAlbumName } + if (settingsState.value.wallpaperSettings.enableChanger) { + val currentHomeAlbum = selectedState.value.selectedAlbum?.find { it.album.initialAlbumName == settingsState.value.wallpaperSettings.homeAlbumName } + val currentLockAlbum = selectedState.value.selectedAlbum?.find { it.album.initialAlbumName == settingsState.value.wallpaperSettings.lockAlbumName } when { - settingsState.value.scheduleSeparately && settingsState.value.setHomeWallpaper && settingsState.value.setLockWallpaper -> { + settingsState.value.scheduleSettings.scheduleSeparately && settingsState.value.wallpaperSettings.setHomeWallpaper && settingsState.value.wallpaperSettings.setLockWallpaper -> { if (currentHomeAlbum != null && currentLockAlbum != null) { settingsViewModel.onEvent( SettingsEvent.SetCurrentWallpaper( @@ -415,7 +336,7 @@ fun PaperizeApp( } } - !settingsState.value.scheduleSeparately && settingsState.value.setHomeWallpaper && settingsState.value.setLockWallpaper -> { + !settingsState.value.scheduleSettings.scheduleSeparately && settingsState.value.wallpaperSettings.setHomeWallpaper && settingsState.value.wallpaperSettings.setLockWallpaper -> { if (currentHomeAlbum != null && currentLockAlbum != null) { settingsViewModel.onEvent( SettingsEvent.SetCurrentWallpaper( @@ -432,34 +353,34 @@ fun PaperizeApp( } } - settingsState.value.setHomeWallpaper -> { + settingsState.value.wallpaperSettings.setHomeWallpaper -> { if (currentHomeAlbum != null) { settingsViewModel.onEvent( SettingsEvent.SetCurrentWallpaper( currentHomeWallpaper = currentHomeAlbum.album.homeWallpapersInQueue.firstOrNull(), - currentLockWallpaper = if (settingsState.value.scheduleSeparately) null else currentHomeAlbum.album.homeWallpapersInQueue.firstOrNull() + currentLockWallpaper = if (settingsState.value.scheduleSettings.scheduleSeparately) null else currentHomeAlbum.album.homeWallpapersInQueue.firstOrNull() ) ) settingsViewModel.onEvent( SettingsEvent.SetNextWallpaper( nextHomeWallpaper = if (currentHomeAlbum.album.homeWallpapersInQueue.size > 1) currentHomeAlbum.album.homeWallpapersInQueue[1] else currentHomeAlbum.album.homeWallpapersInQueue.firstOrNull(), - nextLockWallpaper = if (settingsState.value.scheduleSeparately) null else if (currentHomeAlbum.album.homeWallpapersInQueue.size > 1) currentHomeAlbum.album.homeWallpapersInQueue[1] else currentHomeAlbum.album.homeWallpapersInQueue.firstOrNull() + nextLockWallpaper = if (settingsState.value.scheduleSettings.scheduleSeparately) null else if (currentHomeAlbum.album.homeWallpapersInQueue.size > 1) currentHomeAlbum.album.homeWallpapersInQueue[1] else currentHomeAlbum.album.homeWallpapersInQueue.firstOrNull() ) ) } } - settingsState.value.setLockWallpaper -> { + settingsState.value.wallpaperSettings.setLockWallpaper -> { if (currentLockAlbum != null) { settingsViewModel.onEvent( SettingsEvent.SetCurrentWallpaper( - currentHomeWallpaper = if (settingsState.value.scheduleSeparately) null else currentLockAlbum.album.lockWallpapersInQueue.firstOrNull(), + currentHomeWallpaper = if (settingsState.value.scheduleSettings.scheduleSeparately) null else currentLockAlbum.album.lockWallpapersInQueue.firstOrNull(), currentLockWallpaper = currentLockAlbum.album.lockWallpapersInQueue.firstOrNull() ) ) settingsViewModel.onEvent( SettingsEvent.SetNextWallpaper( - nextHomeWallpaper = if (settingsState.value.scheduleSeparately) null else if (currentLockAlbum.album.lockWallpapersInQueue.size > 1) currentLockAlbum.album.lockWallpapersInQueue[1] else currentLockAlbum.album.lockWallpapersInQueue.firstOrNull(), + nextHomeWallpaper = if (settingsState.value.scheduleSettings.scheduleSeparately) null else if (currentLockAlbum.album.lockWallpapersInQueue.size > 1) currentLockAlbum.album.lockWallpapersInQueue[1] else currentLockAlbum.album.lockWallpapersInQueue.firstOrNull(), nextLockWallpaper = if (currentLockAlbum.album.lockWallpapersInQueue.size > 1) currentLockAlbum.album.lockWallpapersInQueue[1] else currentLockAlbum.album.lockWallpapersInQueue.firstOrNull() ) ) @@ -467,13 +388,13 @@ fun PaperizeApp( } } val alarmItem = WallpaperAlarmItem( - homeInterval = settingsState.value.homeInterval, - lockInterval = settingsState.value.lockInterval, - scheduleSeparately = settingsState.value.scheduleSeparately, - setHome = settingsState.value.setHomeWallpaper, - setLock = settingsState.value.setLockWallpaper, - changeStartTime = settingsState.value.changeStartTime, - startTime = settingsState.value.startTime + homeInterval = settingsState.value.scheduleSettings.homeInterval, + lockInterval = settingsState.value.scheduleSettings.lockInterval, + scheduleSeparately = settingsState.value.scheduleSettings.scheduleSeparately, + setHome = settingsState.value.wallpaperSettings.setHomeWallpaper, + setLock = settingsState.value.wallpaperSettings.setLockWallpaper, + changeStartTime = settingsState.value.scheduleSettings.changeStartTime, + startTime = settingsState.value.scheduleSettings.startTime ) alarmItem.let { scheduler.scheduleWallpaperAlarm( @@ -490,49 +411,48 @@ fun PaperizeApp( }, onDarkenPercentage = { home, lock -> settingsViewModel.onEvent(SettingsEvent.SetDarkenPercentage(home, lock)) - if (settingsState.value.enableChanger && settingsState.value.darken) { + if (settingsState.value.wallpaperSettings.enableChanger && settingsState.value.effectSettings.darken) { job?.cancel() job = scope.launch { delay(3000) - scheduler.updateWallpaper(settingsState.value.scheduleSeparately, settingsState.value.setHomeWallpaper, settingsState.value.setLockWallpaper) + scheduler.updateWallpaper(settingsState.value.scheduleSettings.scheduleSeparately, settingsState.value.wallpaperSettings.setHomeWallpaper, settingsState.value.wallpaperSettings.setLockWallpaper) } } }, onDarkCheck = { settingsViewModel.onEvent(SettingsEvent.SetDarken(it)) - if (settingsState.value.enableChanger) { + if (settingsState.value.wallpaperSettings.enableChanger) { job?.cancel() job = scope.launch { delay(1000) - scheduler.updateWallpaper(settingsState.value.scheduleSeparately, settingsState.value.setHomeWallpaper, settingsState.value.setLockWallpaper) + scheduler.updateWallpaper(settingsState.value.scheduleSettings.scheduleSeparately, settingsState.value.wallpaperSettings.setHomeWallpaper, settingsState.value.wallpaperSettings.setLockWallpaper) } } }, - scaling = settingsState.value.wallpaperScaling, onScalingChange = { - if (settingsState.value.wallpaperScaling != it) { + if (settingsState.value.wallpaperSettings.wallpaperScaling != it) { settingsViewModel.onEvent(SettingsEvent.SetWallpaperScaling(it)) - if (settingsState.value.enableChanger) { + if (settingsState.value.wallpaperSettings.enableChanger) { job?.cancel() job = scope.launch { delay(1000) - scheduler.updateWallpaper(settingsState.value.scheduleSeparately, settingsState.value.setHomeWallpaper, settingsState.value.setLockWallpaper) + scheduler.updateWallpaper(settingsState.value.scheduleSettings.scheduleSeparately, settingsState.value.wallpaperSettings.setHomeWallpaper, settingsState.value.wallpaperSettings.setLockWallpaper) } } } }, onHomeCheckedChange = { setHome -> settingsViewModel.onEvent(SettingsEvent.SetHome(setHome)) - if (!selectedState.value.selectedAlbum.isNullOrEmpty() && !setHome && !settingsState.value.setLockWallpaper) { + if (!selectedState.value.selectedAlbum.isNullOrEmpty() && !setHome && !settingsState.value.wallpaperSettings.setLockWallpaper) { settingsViewModel.onEvent(SettingsEvent.SetChangerToggle(false)) selectedState.value.selectedAlbum?.let { wallpaperScreenViewModel.onEvent(WallpaperEvent.Reset()) } scheduler.cancelWallpaperAlarm() } - else if (!selectedState.value.selectedAlbum.isNullOrEmpty() && (setHome && !settingsState.value.setLockWallpaper) || (!setHome && settingsState.value.setLockWallpaper)) { + else if (!selectedState.value.selectedAlbum.isNullOrEmpty() && (setHome && !settingsState.value.wallpaperSettings.setLockWallpaper) || (!setHome && settingsState.value.wallpaperSettings.setLockWallpaper)) { settingsViewModel.onEvent(SettingsEvent.SetScheduleSeparately(false)) job?.cancel() job = scope.launch { - if (!setHome && settingsState.value.setLockWallpaper) { - val homeAlbum = selectedState.value.selectedAlbum?.find { it.album.initialAlbumName == settingsState.value.homeAlbumName } + if (!setHome && settingsState.value.wallpaperSettings.setLockWallpaper) { + val homeAlbum = selectedState.value.selectedAlbum?.find { it.album.initialAlbumName == settingsState.value.wallpaperSettings.homeAlbumName } if (homeAlbum != null) { wallpaperScreenViewModel.onEvent(WallpaperEvent.UpdateSelectedAlbum( album = homeAlbum.copy( @@ -545,15 +465,15 @@ fun PaperizeApp( } } delay(1000) - scheduler.updateWallpaper(false, setHome, settingsState.value.setLockWallpaper) + scheduler.updateWallpaper(false, setHome, settingsState.value.wallpaperSettings.setLockWallpaper) val alarmItem = WallpaperAlarmItem( - homeInterval = settingsState.value.homeInterval, - lockInterval = settingsState.value.lockInterval, + homeInterval = settingsState.value.scheduleSettings.homeInterval, + lockInterval = settingsState.value.scheduleSettings.lockInterval, scheduleSeparately = false, setHome = setHome, - setLock = settingsState.value.setLockWallpaper, - changeStartTime = settingsState.value.changeStartTime, - startTime = settingsState.value.startTime + setLock = settingsState.value.wallpaperSettings.setLockWallpaper, + changeStartTime = settingsState.value.scheduleSettings.changeStartTime, + startTime = settingsState.value.scheduleSettings.startTime ) alarmItem.let{scheduler.scheduleWallpaperAlarm( wallpaperAlarmItem = it, @@ -565,10 +485,10 @@ fun PaperizeApp( scheduler.scheduleRefresh() } } - else if (!selectedState.value.selectedAlbum.isNullOrEmpty() && settingsState.value.enableChanger) { + else if (!selectedState.value.selectedAlbum.isNullOrEmpty() && settingsState.value.wallpaperSettings.enableChanger) { job?.cancel() job = scope.launch { - val homeAlbum = selectedState.value.selectedAlbum?.find { it.album.initialAlbumName == settingsState.value.homeAlbumName } + val homeAlbum = selectedState.value.selectedAlbum?.find { it.album.initialAlbumName == settingsState.value.wallpaperSettings.homeAlbumName } if (homeAlbum != null) { settingsViewModel.onEvent( SettingsEvent.SetNextWallpaper( @@ -578,32 +498,32 @@ fun PaperizeApp( ) } delay(1000) - scheduler.updateWallpaper(settingsState.value.scheduleSeparately, settingsState.value.setHomeWallpaper, settingsState.value.setLockWallpaper) + scheduler.updateWallpaper(settingsState.value.scheduleSettings.scheduleSeparately, settingsState.value.wallpaperSettings.setHomeWallpaper, settingsState.value.wallpaperSettings.setLockWallpaper) } } }, onLockCheckedChange = { setLock -> settingsViewModel.onEvent(SettingsEvent.SetLock(setLock)) - if (selectedState.value.selectedAlbum!= null && !setLock && !settingsState.value.setHomeWallpaper) { + if (selectedState.value.selectedAlbum!= null && !setLock && !settingsState.value.wallpaperSettings.setHomeWallpaper) { settingsViewModel.onEvent(SettingsEvent.SetChangerToggle(false)) selectedState.value.selectedAlbum?.let { wallpaperScreenViewModel.onEvent(WallpaperEvent.Reset()) } scheduler.cancelWallpaperAlarm() } - else if (selectedState.value.selectedAlbum!= null && (setLock && !settingsState.value.setHomeWallpaper) || (!setLock && settingsState.value.setHomeWallpaper)) { + else if (selectedState.value.selectedAlbum!= null && (setLock && !settingsState.value.wallpaperSettings.setHomeWallpaper) || (!setLock && settingsState.value.wallpaperSettings.setHomeWallpaper)) { settingsViewModel.onEvent(SettingsEvent.SetScheduleSeparately(false)) job?.cancel() job = scope.launch { delay(1000) - scheduler.updateWallpaper(settingsState.value.scheduleSeparately, settingsState.value.setHomeWallpaper, setLock) + scheduler.updateWallpaper(settingsState.value.scheduleSettings.scheduleSeparately, settingsState.value.wallpaperSettings.setHomeWallpaper, setLock) val alarmItem = WallpaperAlarmItem( - homeInterval = settingsState.value.homeInterval, - lockInterval = settingsState.value.lockInterval, + homeInterval = settingsState.value.scheduleSettings.homeInterval, + lockInterval = settingsState.value.scheduleSettings.lockInterval, scheduleSeparately = false, - setHome = settingsState.value.setHomeWallpaper, + setHome = settingsState.value.wallpaperSettings.setHomeWallpaper, setLock = setLock, - changeStartTime = settingsState.value.changeStartTime, - startTime = settingsState.value.startTime + changeStartTime = settingsState.value.scheduleSettings.changeStartTime, + startTime = settingsState.value.scheduleSettings.startTime ) alarmItem.let{ scheduler.scheduleWallpaperAlarm( wallpaperAlarmItem = it, @@ -615,10 +535,10 @@ fun PaperizeApp( scheduler.scheduleRefresh() } } - else if (!selectedState.value.selectedAlbum.isNullOrEmpty() && settingsState.value.enableChanger) { + else if (!selectedState.value.selectedAlbum.isNullOrEmpty() && settingsState.value.wallpaperSettings.enableChanger) { job?.cancel() job = scope.launch { - val homeAlbum = selectedState.value.selectedAlbum?.find { it.album.initialAlbumName == settingsState.value.homeAlbumName } + val homeAlbum = selectedState.value.selectedAlbum?.find { it.album.initialAlbumName == settingsState.value.wallpaperSettings.homeAlbumName } if (homeAlbum != null) { settingsViewModel.onEvent( SettingsEvent.SetNextWallpaper( @@ -628,17 +548,17 @@ fun PaperizeApp( ) } delay(1000) - scheduler.updateWallpaper(settingsState.value.scheduleSeparately, settingsState.value.setHomeWallpaper, settingsState.value.setLockWallpaper) + scheduler.updateWallpaper(settingsState.value.scheduleSettings.scheduleSeparately, settingsState.value.wallpaperSettings.setHomeWallpaper, settingsState.value.wallpaperSettings.setLockWallpaper) } } }, onScheduleSeparatelyChange = { changeSeparately -> settingsViewModel.onEvent(SettingsEvent.SetScheduleSeparately(changeSeparately)) - if (!selectedState.value.selectedAlbum.isNullOrEmpty() && settingsState.value.enableChanger) { - val currentHomeAlbum = selectedState.value.selectedAlbum?.find { it.album.initialAlbumName == settingsState.value.homeAlbumName } - val currentLockAlbum = selectedState.value.selectedAlbum?.find { it.album.initialAlbumName == settingsState.value.lockAlbumName } + if (!selectedState.value.selectedAlbum.isNullOrEmpty() && settingsState.value.wallpaperSettings.enableChanger) { + val currentHomeAlbum = selectedState.value.selectedAlbum?.find { it.album.initialAlbumName == settingsState.value.wallpaperSettings.homeAlbumName } + val currentLockAlbum = selectedState.value.selectedAlbum?.find { it.album.initialAlbumName == settingsState.value.wallpaperSettings.lockAlbumName } when { - changeSeparately && settingsState.value.setHomeWallpaper && settingsState.value.setLockWallpaper -> { + changeSeparately && settingsState.value.wallpaperSettings.setHomeWallpaper && settingsState.value.wallpaperSettings.setLockWallpaper -> { if (currentHomeAlbum != null && currentLockAlbum != null) { settingsViewModel.onEvent(SettingsEvent.SetCurrentWallpaper( currentHomeWallpaper = currentHomeAlbum.album.homeWallpapersInQueue.firstOrNull() ?: currentHomeAlbum.wallpapers.firstOrNull()?.wallpaperUri, @@ -646,7 +566,7 @@ fun PaperizeApp( )) } } - !changeSeparately && settingsState.value.setHomeWallpaper && settingsState.value.setLockWallpaper -> { + !changeSeparately && settingsState.value.wallpaperSettings.setHomeWallpaper && settingsState.value.wallpaperSettings.setLockWallpaper -> { if (currentHomeAlbum != null && currentLockAlbum != null) { settingsViewModel.onEvent(SettingsEvent.SetCurrentWallpaper( currentHomeWallpaper = currentHomeAlbum.album.homeWallpapersInQueue.firstOrNull() ?: currentHomeAlbum.wallpapers.firstOrNull()?.wallpaperUri, @@ -654,7 +574,7 @@ fun PaperizeApp( )) } } - settingsState.value.setHomeWallpaper -> { + settingsState.value.wallpaperSettings.setHomeWallpaper -> { if (currentHomeAlbum != null) { settingsViewModel.onEvent(SettingsEvent.SetCurrentWallpaper( currentHomeWallpaper = currentHomeAlbum.album.homeWallpapersInQueue.firstOrNull() ?: currentHomeAlbum.wallpapers.firstOrNull()?.wallpaperUri, @@ -662,7 +582,7 @@ fun PaperizeApp( )) } } - settingsState.value.setLockWallpaper -> { + settingsState.value.wallpaperSettings.setLockWallpaper -> { if (currentLockAlbum != null) { settingsViewModel.onEvent(SettingsEvent.SetCurrentWallpaper( currentHomeWallpaper = null, @@ -675,13 +595,13 @@ fun PaperizeApp( job = scope.launch { delay(1000) val alarmItem = WallpaperAlarmItem( - homeInterval = settingsState.value.homeInterval, - lockInterval = settingsState.value.lockInterval, + homeInterval = settingsState.value.scheduleSettings.homeInterval, + lockInterval = settingsState.value.scheduleSettings.lockInterval, scheduleSeparately = changeSeparately, - setHome = settingsState.value.setHomeWallpaper, - setLock = settingsState.value.setLockWallpaper, - changeStartTime = settingsState.value.changeStartTime, - startTime = settingsState.value.startTime + setHome = settingsState.value.wallpaperSettings.setHomeWallpaper, + setLock = settingsState.value.wallpaperSettings.setLockWallpaper, + changeStartTime = settingsState.value.scheduleSettings.changeStartTime, + startTime = settingsState.value.scheduleSettings.startTime ) alarmItem.let{scheduler.scheduleWallpaperAlarm( wallpaperAlarmItem = it, @@ -696,76 +616,76 @@ fun PaperizeApp( }, onBlurChange = { settingsViewModel.onEvent(SettingsEvent.SetBlur(it)) - if (settingsState.value.enableChanger) { + if (settingsState.value.wallpaperSettings.enableChanger) { job?.cancel() job = scope.launch { delay(1000) - scheduler.updateWallpaper(settingsState.value.scheduleSeparately, settingsState.value.setHomeWallpaper, settingsState.value.setLockWallpaper) + scheduler.updateWallpaper(settingsState.value.scheduleSettings.scheduleSeparately, settingsState.value.wallpaperSettings.setHomeWallpaper, settingsState.value.wallpaperSettings.setLockWallpaper) } } }, onBlurPercentageChange = { home, lock -> settingsViewModel.onEvent(SettingsEvent.SetBlurPercentage(home, lock)) - if (settingsState.value.enableChanger && settingsState.value.blur) { + if (settingsState.value.wallpaperSettings.enableChanger && settingsState.value.effectSettings.blur) { job?.cancel() job = scope.launch { delay(3000) - scheduler.updateWallpaper(settingsState.value.scheduleSeparately, settingsState.value.setHomeWallpaper, settingsState.value.setLockWallpaper) + scheduler.updateWallpaper(settingsState.value.scheduleSettings.scheduleSeparately, settingsState.value.wallpaperSettings.setHomeWallpaper, settingsState.value.wallpaperSettings.setLockWallpaper) } } }, onVignetteChange = { settingsViewModel.onEvent(SettingsEvent.SetVignette(it)) - if (settingsState.value.enableChanger) { + if (settingsState.value.wallpaperSettings.enableChanger) { job?.cancel() job = scope.launch { delay(1000) - scheduler.updateWallpaper(settingsState.value.scheduleSeparately, settingsState.value.setHomeWallpaper, settingsState.value.setLockWallpaper) + scheduler.updateWallpaper(settingsState.value.scheduleSettings.scheduleSeparately, settingsState.value.wallpaperSettings.setHomeWallpaper, settingsState.value.wallpaperSettings.setLockWallpaper) } } }, onVignettePercentageChange = { home, lock -> settingsViewModel.onEvent(SettingsEvent.SetVignettePercentage(home, lock)) - if (settingsState.value.enableChanger && settingsState.value.vignette) { + if (settingsState.value.wallpaperSettings.enableChanger && settingsState.value.effectSettings.vignette) { job?.cancel() job = scope.launch { delay(3000) - scheduler.updateWallpaper(settingsState.value.scheduleSeparately, settingsState.value.setHomeWallpaper, settingsState.value.setLockWallpaper) + scheduler.updateWallpaper(settingsState.value.scheduleSettings.scheduleSeparately, settingsState.value.wallpaperSettings.setHomeWallpaper, settingsState.value.wallpaperSettings.setLockWallpaper) } } }, onGrayscaleChange = { settingsViewModel.onEvent(SettingsEvent.SetGrayscale(it)) - if (settingsState.value.enableChanger) { + if (settingsState.value.wallpaperSettings.enableChanger) { job?.cancel() job = scope.launch { delay(1000) - scheduler.updateWallpaper(settingsState.value.scheduleSeparately, settingsState.value.setHomeWallpaper, settingsState.value.setLockWallpaper) + scheduler.updateWallpaper(settingsState.value.scheduleSettings.scheduleSeparately, settingsState.value.wallpaperSettings.setHomeWallpaper, settingsState.value.wallpaperSettings.setLockWallpaper) } } }, onGrayscalePercentageChange = { home, lock -> settingsViewModel.onEvent(SettingsEvent.SetGrayscalePercentage(home, lock)) - if (settingsState.value.enableChanger && settingsState.value.grayscale) { + if (settingsState.value.wallpaperSettings.enableChanger && settingsState.value.effectSettings.grayscale) { job?.cancel() job = scope.launch { delay(3000) - scheduler.updateWallpaper(settingsState.value.scheduleSeparately, settingsState.value.setHomeWallpaper, settingsState.value.setLockWallpaper) + scheduler.updateWallpaper(settingsState.value.scheduleSettings.scheduleSeparately, settingsState.value.wallpaperSettings.setHomeWallpaper, settingsState.value.wallpaperSettings.setLockWallpaper) } } }, onStartTimeChange = { time -> settingsViewModel.onEvent(SettingsEvent.SetStartTime(time.hour, time.minute)) - if (settingsState.value.enableChanger) { + if (settingsState.value.wallpaperSettings.enableChanger) { job?.cancel() job = scope.launch { delay(1000) val alarmItem = WallpaperAlarmItem( - homeInterval = settingsState.value.homeInterval, - lockInterval = settingsState.value.lockInterval, - scheduleSeparately = settingsState.value.scheduleSeparately, - setHome = settingsState.value.setHomeWallpaper, - setLock = settingsState.value.setLockWallpaper, + homeInterval = settingsState.value.scheduleSettings.homeInterval, + lockInterval = settingsState.value.scheduleSettings.lockInterval, + scheduleSeparately = settingsState.value.scheduleSettings.scheduleSeparately, + setHome = settingsState.value.wallpaperSettings.setHomeWallpaper, + setLock = settingsState.value.wallpaperSettings.setLockWallpaper, changeStartTime = true, startTime = Pair(time.hour, time.minute) ) @@ -776,18 +696,18 @@ fun PaperizeApp( }, onChangeStartTimeToggle = { changeStartTime -> settingsViewModel.onEvent(SettingsEvent.SetChangeStartTime(changeStartTime)) - if (settingsState.value.enableChanger) { + if (settingsState.value.wallpaperSettings.enableChanger) { job?.cancel() job = scope.launch { delay(1000) val alarmItem = WallpaperAlarmItem( - homeInterval = settingsState.value.homeInterval, - lockInterval = settingsState.value.lockInterval, - scheduleSeparately = settingsState.value.scheduleSeparately, - setHome = settingsState.value.setHomeWallpaper, - setLock = settingsState.value.setLockWallpaper, + homeInterval = settingsState.value.scheduleSettings.homeInterval, + lockInterval = settingsState.value.scheduleSettings.lockInterval, + scheduleSeparately = settingsState.value.scheduleSettings.scheduleSeparately, + setHome = settingsState.value.wallpaperSettings.setHomeWallpaper, + setLock = settingsState.value.wallpaperSettings.setLockWallpaper, changeStartTime = changeStartTime, - startTime = settingsState.value.startTime + startTime = settingsState.value.scheduleSettings.startTime ) alarmItem.let{scheduler.updateWallpaperAlarm(it, true)} scheduler.scheduleRefresh() @@ -796,32 +716,12 @@ fun PaperizeApp( }, ) } + // Navigate to the add album screen to create a new album and add wallpapers to it - composable( - enterTransition = { - if (settingsState.value.animate) { - sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() }) - } else { null } - }, - exitTransition = { - if (settingsState.value.animate) { - sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() }) - } else { null } - }, - popEnterTransition = { - if (settingsState.value.animate) { - sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() }) - } else { null } - }, - popExitTransition = { - if (settingsState.value.animate) { - sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() }) - } else { null } - } - ) { backStackEntry -> - val addEdit: AddEdit = backStackEntry.toRoute() + animatedScreen(animate = settingsState.value.themeSettings.animate) { backStackEntry -> + val addAlbum: AddAlbum = backStackEntry.toRoute() AddAlbumScreen( - initialAlbumName = addEdit.wallpaper, + initialAlbumName = addAlbum.wallpaper, onBackClick = { navController.navigateUp() }, onConfirmation = { navController.navigateUp() }, onShowWallpaperView = { @@ -832,61 +732,22 @@ fun PaperizeApp( folderViewModel.wallpapers.value = wallpapers navController.navigate(FolderView) }, - animate = settingsState.value.animate + animate = settingsState.value.themeSettings.animate ) } + // Navigate to wallpaper view screen to view individual wallpapers in full screen - composable ( - enterTransition = { - if (settingsState.value.animate) { - sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() }) - } else { null } - }, - exitTransition = { - if (settingsState.value.animate) { - sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() }) - } else { null } - }, - popEnterTransition = { - if (settingsState.value.animate) { - sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() }) - } else { null } - }, - popExitTransition = { - if (settingsState.value.animate) { - sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() }) - } else { null } - } - ) { backStackEntry -> + animatedScreen(animate = settingsState.value.themeSettings.animate) { backStackEntry -> val wallpaperView: WallpaperView = backStackEntry.toRoute() WallpaperViewScreen( wallpaperUri = wallpaperView.wallpaper, onBackClick = { navController.navigateUp() }, - animate = settingsState.value.animate + animate = settingsState.value.themeSettings.animate ) } - composable( - enterTransition = { - if (settingsState.value.animate) { - sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() }) - } else { null } - }, - exitTransition = { - if (settingsState.value.animate) { - sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() }) - } else { null } - }, - popEnterTransition = { - if (settingsState.value.animate) { - sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() }) - } else { null } - }, - popExitTransition = { - if (settingsState.value.animate) { - sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() }) - } else { null } - } - ) { + + // Navigate to the folder view screen to view wallpapers in a folder + animatedScreen(animate = settingsState.value.themeSettings.animate) { backStackEntry -> val folderName = folderViewModel.folderName.value val wallpapers = folderViewModel.wallpapers.value if (wallpapers != null) { @@ -898,42 +759,22 @@ fun PaperizeApp( onShowWallpaperView = { navController.navigate(WallpaperView(it)) }, - animate = settingsState.value.animate + animate = settingsState.value.themeSettings.animate ) } else { navController.navigateUp() } } } + // Navigate to the album view screen to view folders and wallpapers in an album - composable ( - enterTransition = { - if (settingsState.value.animate) { - sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() }) - } else { null } - }, - exitTransition = { - if (settingsState.value.animate) { - sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() }) - } else { null } - }, - popEnterTransition = { - if (settingsState.value.animate) { - sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() }) - } else { null } - }, - popExitTransition = { - if (settingsState.value.animate) { - sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() }) - } else { null } - } - ) { backStackEntry -> + animatedScreen(animate = settingsState.value.themeSettings.animate) { backStackEntry -> val albumView: AlbumView = backStackEntry.toRoute() val albumWithWallpaper = albumState.value.albumsWithWallpapers.find { it.album.initialAlbumName == albumView.initialAlbumName } if (albumWithWallpaper != null) { AlbumViewScreen( album = albumWithWallpaper, - animate = settingsState.value.animate, + animate = settingsState.value.themeSettings.animate, onBackClick = { navController.navigateUp() }, onShowWallpaperView = { navController.navigate(WallpaperView(it)) @@ -956,31 +797,11 @@ fun PaperizeApp( ) } else { navController.navigateUp() } } + // Navigate to the settings screen to change app settings - composable ( - enterTransition = { - if (settingsState.value.animate) { - sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() }) - } else { null } - }, - exitTransition = { - if (settingsState.value.animate) { - sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() }) - } else { null } - }, - popEnterTransition = { - if (settingsState.value.animate) { - sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() }) - } else { null } - }, - popExitTransition = { - if (settingsState.value.animate) { - sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() }) - } else { null } - } - ) { + animatedScreen(animate = settingsState.value.themeSettings.animate) { SettingsScreen( - settingsState = settingsViewModel.state, + themeSettings = settingsState.value.themeSettings, onBackClick = { navController.navigateUp() }, onDarkModeClick = { settingsViewModel.onEvent(SettingsEvent.SetDarkMode(it)) @@ -1017,56 +838,16 @@ fun PaperizeApp( } ) } + // Navigate to the privacy screen to view the privacy policy - composable ( - enterTransition = { - if (settingsState.value.animate) { - sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() }) - } else { null } - }, - exitTransition = { - if (settingsState.value.animate) { - sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() }) - } else { null } - }, - popEnterTransition = { - if (settingsState.value.animate) { - sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() }) - } else { null } - }, - popExitTransition = { - if (settingsState.value.animate) { - sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() }) - } else { null } - } - ) { + animatedScreen(animate = settingsState.value.themeSettings.animate) { PrivacyScreen( onBackClick = { navController.navigateUp() }, ) } + // Navigate to the licenses screen to view the licenses of the libraries used - composable ( - enterTransition = { - if (settingsState.value.animate) { - sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() }) - } else { null } - }, - exitTransition = { - if (settingsState.value.animate) { - sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() }) - } else { null } - }, - popEnterTransition = { - if (settingsState.value.animate) { - sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() }) - } else { null } - }, - popExitTransition = { - if (settingsState.value.animate) { - sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() }) - } else { null } - } - ) { + animatedScreen(animate = settingsState.value.themeSettings.animate) { LicensesScreen( onBackClick = { navController.navigateUp() } ) diff --git a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/home_screen/HomeScreen.kt b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/home_screen/HomeScreen.kt index 84a8e671..026affff 100644 --- a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/home_screen/HomeScreen.kt +++ b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/home_screen/HomeScreen.kt @@ -23,9 +23,6 @@ import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier -import androidx.compose.ui.platform.testTag -import androidx.compose.ui.semantics.semantics -import androidx.compose.ui.semantics.testTagsAsResourceId import androidx.compose.ui.unit.dp import com.anthonyla.paperize.core.ScalingConstants import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder @@ -34,24 +31,23 @@ import com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.co import com.anthonyla.paperize.feature.wallpaper.presentation.home_screen.components.HomeTopBar import com.anthonyla.paperize.feature.wallpaper.presentation.home_screen.components.getTabItems import com.anthonyla.paperize.feature.wallpaper.presentation.library_screen.LibraryScreen +import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsState.EffectSettings +import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsState.ScheduleSettings +import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsState.ThemeSettings +import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsState.WallpaperSettings import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.WallpaperScreen @OptIn(ExperimentalMaterial3Api::class, ExperimentalComposeUiApi::class) @Composable fun HomeScreen( albums: List, - animate : Boolean, - darken: Boolean, - homeDarkenPercentage: Int, - lockDarkenPercentage: Int, - enableChanger: Boolean, - homeEnabled : Boolean, - homeInterval: Int, - lockInterval: Int, - lastSetTime: String?, - lockEnabled : Boolean, - navigateToAddWallpaperScreen: (String) -> Unit, - nextSetTime: String?, + homeSelectedAlbum: SelectedAlbum?, + lockSelectedAlbum: SelectedAlbum?, + themeSettings: ThemeSettings, + wallpaperSettings: WallpaperSettings, + scheduleSettings: ScheduleSettings, + effectSettings: EffectSettings, + onNavigateAddWallpaper: (String) -> Unit, onViewAlbum: (String) -> Unit, onDarkCheck: (Boolean) -> Unit, onDarkenPercentage: (Int, Int) -> Unit, @@ -66,31 +62,14 @@ fun HomeScreen( onSettingsClick: () -> Unit, onStop: (Boolean, Boolean) -> Unit, onToggleChanger: (Boolean) -> Unit, - scaling: ScalingConstants, - scheduleSeparately: Boolean, - blur: Boolean, onBlurPercentageChange: (Int, Int) -> Unit, onBlurChange: (Boolean) -> Unit, - homeBlurPercentage: Int, - lockBlurPercentage: Int, - currentHomeWallpaper: String?, - currentLockWallpaper: String?, - homeSelectedAlbum: SelectedAlbum?, - lockSelectedAlbum: SelectedAlbum?, - homeVignettePercentage: Int, - lockVignettePercentage: Int, onVignettePercentageChange: (Int, Int) -> Unit, onVignetteChange: (Boolean) -> Unit, - vignette: Boolean, - homeGrayscalePercentage: Int, - lockGrayscalePercentage: Int, onGrayscalePercentageChange: (Int, Int) -> Unit, onGrayscaleChange: (Boolean) -> Unit, - grayscale: Boolean, - changeStartTime: Boolean, onChangeStartTimeToggle: (Boolean) -> Unit, - onStartTimeChange: (TimePickerState) -> Unit, - startingTime: Pair + onStartTimeChange: (TimePickerState) -> Unit ) { val tabItems = getTabItems() val pagerState = rememberPagerState(0) { tabItems.size } @@ -98,7 +77,7 @@ fun HomeScreen( var addAlbumDialog by rememberSaveable { mutableStateOf(false) } if (addAlbumDialog) AddAlbumDialog( onDismissRequest = { addAlbumDialog = false }, - onConfirmation = { navigateToAddWallpaperScreen(it) } + onConfirmation = { onNavigateAddWallpaper(it) } ) LaunchedEffect(tabIndex) { @@ -109,9 +88,6 @@ fun HomeScreen( } Scaffold ( - modifier = Modifier.semantics { - testTagsAsResourceId = true - }, topBar = { HomeTopBar( showSelectionModeAppBar = false, @@ -148,8 +124,7 @@ fun HomeScreen( imageVector = if (index == tabIndex) item.filledIcon else item.unfilledIcon, contentDescription = item.title ) - }, - modifier = Modifier.testTag("paperize:${item.title}_button"), + } ) } } @@ -160,54 +135,32 @@ fun HomeScreen( when (index.coerceIn(tabItems.indices)) { 0 -> WallpaperScreen( albums = albums, - animate = animate, - darken = darken, - homeDarkenPercentage = homeDarkenPercentage, - lockDarkenPercentage = lockDarkenPercentage, - enableChanger = enableChanger, - homeEnabled = homeEnabled, - homeInterval = homeInterval, - lockInterval = lockInterval, - lastSetTime = lastSetTime, - lockEnabled = lockEnabled, - nextSetTime = nextSetTime, + homeSelectedAlbum = homeSelectedAlbum, + lockSelectedAlbum = lockSelectedAlbum, + themeSettings = themeSettings, + wallpaperSettings = wallpaperSettings, + scheduleSettings = scheduleSettings, + effectSettings = effectSettings, onDarkCheck = onDarkCheck, onDarkenPercentage = onDarkenPercentage, onHomeCheckedChange = onHomeCheckedChange, onLockCheckedChange = onLockCheckedChange, - scheduleSeparately = scheduleSeparately, + onScalingChange = onScalingChange, onScheduleSeparatelyChange = onScheduleSeparatelyChange, onScheduleWallpaperChanger = onScheduleWallpaperChanger, - onScalingChange = onScalingChange, onSelectAlbum = onSelectAlbum, onHomeTimeChange = onHomeTimeChange, onLockTimeChange = onLockTimeChange, onStop = onStop, onToggleChanger = onToggleChanger, - scaling = scaling, - homeSelectedAlbum = homeSelectedAlbum, - lockSelectedAlbum = lockSelectedAlbum, - blur = blur, onBlurPercentageChange = onBlurPercentageChange, onBlurChange = onBlurChange, - homeBlurPercentage = homeBlurPercentage, - lockBlurPercentage = lockBlurPercentage, - currentHomeWallpaper = currentHomeWallpaper, - currentLockWallpaper = currentLockWallpaper, - homeVignettePercentage = homeVignettePercentage, - lockVignettePercentage = lockVignettePercentage, onVignettePercentageChange = onVignettePercentageChange, onVignetteChange = onVignetteChange, - vignette = vignette, - homeGrayscalePercentage = homeGrayscalePercentage, - lockGrayscalePercentage = lockGrayscalePercentage, onGrayscalePercentageChange = onGrayscalePercentageChange, onGrayscaleChange = onGrayscaleChange, - grayscale = grayscale, - changeStartTime = changeStartTime, onChangeStartTimeToggle = onChangeStartTimeToggle, - onStartTimeChange = onStartTimeChange, - startingTime = startingTime + onStartTimeChange = onStartTimeChange ) else -> LibraryScreen( albums = albums, diff --git a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/library_screen/LibraryScreen.kt b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/library_screen/LibraryScreen.kt index d6a346dc..5e281094 100644 --- a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/library_screen/LibraryScreen.kt +++ b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/library_screen/LibraryScreen.kt @@ -17,10 +17,7 @@ import androidx.compose.material3.Scaffold import androidx.compose.runtime.Composable import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier -import androidx.compose.ui.platform.testTag import androidx.compose.ui.res.stringResource -import androidx.compose.ui.semantics.semantics -import androidx.compose.ui.semantics.testTagsAsResourceId import androidx.compose.ui.unit.dp import com.anthonyla.paperize.R import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder @@ -35,17 +32,12 @@ fun LibraryScreen( ) { val lazyListState = rememberLazyGridState() Scaffold( - modifier = Modifier - .fillMaxSize() - .semantics { - testTagsAsResourceId = true - }, + modifier = Modifier.fillMaxSize(), floatingActionButton = { LargeFloatingActionButton( containerColor = MaterialTheme.colorScheme.primaryContainer, contentColor = MaterialTheme.colorScheme.onPrimaryContainer, onClick = onAddNewAlbumClick, - modifier = Modifier.testTag("paperize:library_floating_button") ) { Icon( Icons.Filled.Add, diff --git a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/notifications_screen/NotificationScreen.kt b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/notifications_screen/NotificationScreen.kt index a80adb41..e6d6f623 100644 --- a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/notifications_screen/NotificationScreen.kt +++ b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/notifications_screen/NotificationScreen.kt @@ -28,11 +28,9 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext -import androidx.compose.ui.platform.testTag import androidx.compose.ui.res.stringResource import androidx.compose.ui.semantics.contentDescription import androidx.compose.ui.semantics.semantics -import androidx.compose.ui.semantics.testTagsAsResourceId import androidx.compose.ui.unit.dp import androidx.core.content.ContextCompat import com.airbnb.lottie.compose.LottieAnimation @@ -78,9 +76,6 @@ fun NotificationScreen( } Scaffold( - modifier = Modifier.semantics { - testTagsAsResourceId = true - }, content = { it Column (modifier = Modifier.padding(32.dp)) { Spacer(modifier = Modifier.height(120.dp)) @@ -109,9 +104,7 @@ fun NotificationScreen( }, floatingActionButton = { ExtendedFloatingActionButton( - modifier = Modifier - .padding(8.dp) - .testTag("paperize:floating_notification_button"), + modifier = Modifier.padding(8.dp), onClick = { askPermission.value = true }, icon = { Icon( diff --git a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/settings_screen/SettingsScreen.kt b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/settings_screen/SettingsScreen.kt index 2ed8c565..15fd92ac 100644 --- a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/settings_screen/SettingsScreen.kt +++ b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/settings_screen/SettingsScreen.kt @@ -30,15 +30,12 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext -import androidx.compose.ui.platform.testTag import androidx.compose.ui.res.stringResource -import androidx.compose.ui.semantics.semantics -import androidx.compose.ui.semantics.testTagsAsResourceId import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.lerp import androidx.compose.ui.unit.sp -import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.anthonyla.paperize.R +import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsState.ThemeSettings import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.AmoledListItem import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.AnimationListItem import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.ContactListItem @@ -51,15 +48,40 @@ import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.com import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.PrivacyPolicyListItem import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.ResetListItem import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.TranslateListItem -import kotlinx.coroutines.flow.StateFlow import me.onebone.toolbar.CollapsingToolbarScaffold import me.onebone.toolbar.ScrollStrategy import me.onebone.toolbar.rememberCollapsingToolbarScaffoldState +private object Links { + const val TRANSLATE = "https://crowdin.com/project/paperize/invite?h=d8d7a7513d2beb0c96ba9b2a5f85473e2084922" + const val GITHUB = "https://github.com/Anthonyy232/Paperize" + const val FDROID = "https://f-droid.org/en/packages/com.anthonyla.paperize/" + const val IZZY = "https://apt.izzysoft.de/fdroid/index/apk/com.anthonyla.paperize" +} + +private object ToolbarConfig { + @OptIn(ExperimentalMaterial3Api::class) + val LargeTopAppBarHeight = TopAppBarDefaults.LargeAppBarExpandedHeight + val StartPadding = 64.dp + val EndPadding = 16.dp + const val START = 30 + const val END = 21 + val TitleExtraStartPadding = 32.dp +} + +@Composable +private fun calculateToolbarValues(collapseFraction: Float) = with(ToolbarConfig) { + val firstPaddingInterpolation = lerp((EndPadding * 5 / 4), EndPadding, collapseFraction) + TitleExtraStartPadding + val secondPaddingInterpolation = lerp(StartPadding, (EndPadding * 5 / 4), collapseFraction) + val dynamicPaddingStart = lerp(firstPaddingInterpolation, secondPaddingInterpolation, collapseFraction) + val textSize = (END + (START - END) * collapseFraction).sp + Pair(dynamicPaddingStart, textSize) +} + @OptIn(ExperimentalMaterial3Api::class, ExperimentalComposeUiApi::class) @Composable fun SettingsScreen( - settingsState: StateFlow, + themeSettings: ThemeSettings, onBackClick: () -> Unit, onDarkModeClick: (Boolean?) -> Unit, onAmoledClick: (Boolean) -> Unit, @@ -70,31 +92,11 @@ fun SettingsScreen( onResetClick: () -> Unit, onContactClick: () -> Unit ) { - val topBarState = rememberCollapsingToolbarScaffoldState() - val state = settingsState.collectAsStateWithLifecycle() val context = LocalContext.current + val topBarState = rememberCollapsingToolbarScaffoldState() + val (dynamicPaddingStart, textSize) = calculateToolbarValues(topBarState.toolbarState.progress) - val translateLink = "https://crowdin.com/project/paperize/invite?h=d8d7a7513d2beb0c96ba9b2a5f85473e2084922" - val githubLink = "https://github.com/Anthonyy232/Paperize" - val fdroidLink = "https://f-droid.org/en/packages/com.anthonyla.paperize/" - val izzyOnDroidLink = "https://apt.izzysoft.de/fdroid/index/apk/com.anthonyla.paperize" - - // Collapsing top bar - val largeTopAppBarHeight = TopAppBarDefaults.LargeAppBarExpandedHeight - val startPadding = 64.dp - val endPadding = 16.dp - val titleFontScaleStart = 30 - val titleFontScaleEnd = 21 - val titleExtraStartPadding = 32.dp - val collapseFraction = topBarState.toolbarState.progress - val firstPaddingInterpolation = lerp((endPadding * 5 / 4), endPadding, collapseFraction) + titleExtraStartPadding - val secondPaddingInterpolation = lerp(startPadding, (endPadding * 5 / 4), collapseFraction) - val dynamicPaddingStart = lerp(firstPaddingInterpolation, secondPaddingInterpolation, collapseFraction) - val textSize = (titleFontScaleEnd + (titleFontScaleStart - titleFontScaleEnd) * collapseFraction).sp - - Scaffold( - modifier = Modifier.semantics { testTagsAsResourceId = true }, - ) { + Scaffold { CollapsingToolbarScaffold( state = topBarState, modifier = Modifier.fillMaxSize().padding(it), @@ -103,7 +105,7 @@ fun SettingsScreen( Box( modifier = Modifier .fillMaxWidth() - .height(largeTopAppBarHeight) + .height(ToolbarConfig.LargeTopAppBarHeight) .background(MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp)) .pin() ) @@ -112,7 +114,6 @@ fun SettingsScreen( modifier = Modifier .padding(16.dp) .size(24.dp) - .testTag("paperize:settings_to_home_button"), ) { Icon( imageVector = Icons.AutoMirrored.Filled.ArrowBack, @@ -130,86 +131,116 @@ fun SettingsScreen( ) } ) { - Column( - horizontalAlignment = Alignment.Start, - verticalArrangement = Arrangement.Top, - modifier = Modifier - .verticalScroll(rememberScrollState()) - .fillMaxSize() - .padding(horizontal = 24.dp) - .testTag("paperize:settings_column"), - ) { - ListSectionTitle(stringResource(R.string.appearance)) - Spacer(modifier = Modifier.height(16.dp)) - DarkModeListItem( - darkMode = state.value.darkMode, - onDarkModeClick = { onDarkModeClick(it) } - ) - Spacer(modifier = Modifier.height(16.dp)) - if (state.value.darkMode == null || state.value.darkMode == true) { - AmoledListItem( - amoledMode = state.value.amoledTheme, - onAmoledClick = { onAmoledClick(it) } - ) - Spacer(modifier = Modifier.height(16.dp)) - } - DynamicThemingListItem( - dynamicTheming = state.value.dynamicTheming, - onDynamicThemingClick = { onDynamicThemingClick(it) } - ) - Spacer(modifier = Modifier.height(16.dp)) - AnimationListItem( - animate = state.value.animate, - onAnimateClick = { onAnimateClick(it) } - ) - Spacer(modifier = Modifier.height(16.dp)) - ListSectionTitle(stringResource(R.string.about)) - Spacer(modifier = Modifier.height(16.dp)) - NotificationListItem( - onClick = { - val intent = Intent().apply { - action = Settings.ACTION_APP_NOTIFICATION_SETTINGS - putExtra(Settings.EXTRA_APP_PACKAGE, context.packageName) - } - context.startActivity(intent) - } - ) - Spacer(modifier = Modifier.height(16.dp)) - TranslateListItem( - onClick = { - val openURL = Intent(Intent.ACTION_VIEW) - openURL.data = Uri.parse(translateLink) - context.startActivity(openURL) - } - ) - Spacer(modifier = Modifier.height(16.dp)) - PrivacyPolicyListItem (onPrivacyPolicyClick = onPrivacyClick) - Spacer(modifier = Modifier.height(16.dp)) - LicenseListItem(onLicenseClick = onLicenseClick) - Spacer(modifier = Modifier.height(16.dp)) - ContactListItem(onContactClick = onContactClick) - Spacer(modifier = Modifier.height(16.dp)) - PaperizeListItem( - onGitHubClick = { - val openURL = Intent(Intent.ACTION_VIEW) - openURL.data = Uri.parse(githubLink) - context.startActivity(openURL) - }, - onFdroidClick = { - val openURL = Intent(Intent.ACTION_VIEW) - openURL.data = Uri.parse(fdroidLink) - context.startActivity(openURL) - }, - onIzzyOnDroidClick = { - val openURL = Intent(Intent.ACTION_VIEW) - openURL.data = Uri.parse(izzyOnDroidLink) - context.startActivity(openURL) - }, - ) - Spacer(modifier = Modifier.height(16.dp)) - ResetListItem(onResetClick = onResetClick) - Spacer(modifier = Modifier.height(16.dp)) - } + SettingsContent( + themeSettings = themeSettings, + onDarkModeClick = onDarkModeClick, + onAmoledClick = onAmoledClick, + onDynamicThemingClick = onDynamicThemingClick, + onAnimateClick = onAnimateClick, + onPrivacyClick = onPrivacyClick, + onLicenseClick = onLicenseClick, + onResetClick = onResetClick, + onContactClick = onContactClick, + context = context + ) } } +} + +@Composable +private fun SettingsContent( + themeSettings: ThemeSettings, + onDarkModeClick: (Boolean?) -> Unit, + onAmoledClick: (Boolean) -> Unit, + onDynamicThemingClick: (Boolean) -> Unit, + onAnimateClick: (Boolean) -> Unit, + onPrivacyClick: () -> Unit, + onLicenseClick: () -> Unit, + onResetClick: () -> Unit, + onContactClick: () -> Unit, + context: android.content.Context +) { + Column( + horizontalAlignment = Alignment.Start, + verticalArrangement = Arrangement.Top, + modifier = Modifier + .verticalScroll(rememberScrollState()) + .fillMaxSize() + .padding(horizontal = 24.dp) + ) { + AppearanceSection(themeSettings, onDarkModeClick, onAmoledClick, onDynamicThemingClick, onAnimateClick) + AboutSection(context, onPrivacyClick, onLicenseClick, onContactClick, onResetClick) + } +} + +@Composable +private fun AppearanceSection( + themeSettings: ThemeSettings, + onDarkModeClick: (Boolean?) -> Unit, + onAmoledClick: (Boolean) -> Unit, + onDynamicThemingClick: (Boolean) -> Unit, + onAnimateClick: (Boolean) -> Unit +) { + ListSectionTitle(stringResource(R.string.appearance)) + Spacer(modifier = Modifier.height(16.dp)) + DarkModeListItem( + darkMode = themeSettings.darkMode, + onDarkModeClick = onDarkModeClick + ) + Spacer(modifier = Modifier.height(16.dp)) + if (themeSettings.darkMode == null || themeSettings.darkMode == true) { + AmoledListItem( + amoledMode = themeSettings.amoledTheme, + onAmoledClick = onAmoledClick + ) + Spacer(modifier = Modifier.height(16.dp)) + } + DynamicThemingListItem( + dynamicTheming = themeSettings.dynamicTheming, + onDynamicThemingClick = onDynamicThemingClick + ) + Spacer(modifier = Modifier.height(16.dp)) + AnimationListItem( + animate = themeSettings.animate, + onAnimateClick = onAnimateClick + ) + Spacer(modifier = Modifier.height(16.dp)) +} + +@Composable +private fun AboutSection( + context: android.content.Context, + onPrivacyClick: () -> Unit, + onLicenseClick: () -> Unit, + onContactClick: () -> Unit, + onResetClick: () -> Unit +) { + ListSectionTitle(stringResource(R.string.about)) + Spacer(modifier = Modifier.height(16.dp)) + NotificationListItem { + val intent = Intent().apply { + action = Settings.ACTION_APP_NOTIFICATION_SETTINGS + putExtra(Settings.EXTRA_APP_PACKAGE, context.packageName) + } + context.startActivity(intent) + } + Spacer(modifier = Modifier.height(16.dp)) + TranslateListItem { + context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(Links.TRANSLATE))) + } + Spacer(modifier = Modifier.height(16.dp)) + PrivacyPolicyListItem(onPrivacyClick) + Spacer(modifier = Modifier.height(16.dp)) + LicenseListItem(onLicenseClick) + Spacer(modifier = Modifier.height(16.dp)) + ContactListItem(onContactClick) + Spacer(modifier = Modifier.height(16.dp)) + PaperizeListItem( + onGitHubClick = { context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(Links.GITHUB))) }, + onFdroidClick = { context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(Links.FDROID))) }, + onIzzyOnDroidClick = { context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(Links.IZZY))) } + ) + Spacer(modifier = Modifier.height(16.dp)) + ResetListItem(onResetClick) + Spacer(modifier = Modifier.height(16.dp)) } \ No newline at end of file diff --git a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/settings_screen/SettingsState.kt b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/settings_screen/SettingsState.kt index 596e8571..b38cedbb 100644 --- a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/settings_screen/SettingsState.kt +++ b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/settings_screen/SettingsState.kt @@ -1,42 +1,57 @@ package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen + import com.anthonyla.paperize.core.ScalingConstants import com.anthonyla.paperize.core.SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT data class SettingsState( val firstLaunch: Boolean = true, - // App settings - val darkMode: Boolean? = null, - val amoledTheme: Boolean = false, - val dynamicTheming: Boolean = false, - val animate: Boolean = true, - // Wallpaper settings - val enableChanger: Boolean = false, - val setHomeWallpaper: Boolean = false, - val setLockWallpaper: Boolean = false, - val currentHomeWallpaper: String? = null, - val currentLockWallpaper: String? = null, - val homeAlbumName: String? = null, - val lockAlbumName: String? = null, - val scheduleSeparately: Boolean = false, - val homeInterval: Int = WALLPAPER_CHANGE_INTERVAL_DEFAULT, - val lockInterval: Int = WALLPAPER_CHANGE_INTERVAL_DEFAULT, - val lastSetTime: String? = null, - val nextSetTime: String? = null, - val homeDarkenPercentage: Int = 100, - val lockDarkenPercentage: Int = 100, - val darken: Boolean = false, - val blur: Boolean = false, - val homeBlurPercentage: Int = 0, - val lockBlurPercentage: Int = 0, - val vignette: Boolean = false, - val homeVignettePercentage: Int = 0, - val lockVignettePercentage: Int = 0, - val grayscale: Boolean = false, - val homeGrayscalePercentage: Int = 0, - val lockGrayscalePercentage: Int = 0, - val wallpaperScaling: ScalingConstants = ScalingConstants.FILL, - val nextHomeWallpaper: String? = null, - val nextLockWallpaper: String? = null, - val changeStartTime: Boolean = false, - val startTime: Pair = Pair(0, 0) -) \ No newline at end of file + val themeSettings: ThemeSettings = ThemeSettings(), + val wallpaperSettings: WallpaperSettings = WallpaperSettings(), + val scheduleSettings: ScheduleSettings = ScheduleSettings(), + val effectSettings: EffectSettings = EffectSettings() +) { + data class ThemeSettings( + val darkMode: Boolean? = null, + val amoledTheme: Boolean = false, + val dynamicTheming: Boolean = false, + val animate: Boolean = true + ) + + data class WallpaperSettings( + val enableChanger: Boolean = false, + val setHomeWallpaper: Boolean = false, + val setLockWallpaper: Boolean = false, + val currentHomeWallpaper: String? = null, + val currentLockWallpaper: String? = null, + val nextHomeWallpaper: String? = null, + val nextLockWallpaper: String? = null, + val homeAlbumName: String? = null, + val lockAlbumName: String? = null, + val wallpaperScaling: ScalingConstants = ScalingConstants.FILL + ) + + data class ScheduleSettings( + val scheduleSeparately: Boolean = false, + val homeInterval: Int = WALLPAPER_CHANGE_INTERVAL_DEFAULT, + val lockInterval: Int = WALLPAPER_CHANGE_INTERVAL_DEFAULT, + val lastSetTime: String? = null, + val nextSetTime: String? = null, + val changeStartTime: Boolean = false, + val startTime: Pair = Pair(0, 0) + ) + + data class EffectSettings( + val darken: Boolean = false, + val homeDarkenPercentage: Int = 100, + val lockDarkenPercentage: Int = 100, + val blur: Boolean = false, + val homeBlurPercentage: Int = 0, + val lockBlurPercentage: Int = 0, + val vignette: Boolean = false, + val homeVignettePercentage: Int = 0, + val lockVignettePercentage: Int = 0, + val grayscale: Boolean = false, + val homeGrayscalePercentage: Int = 0, + val lockGrayscalePercentage: Int = 0 + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/settings_screen/SettingsViewModel.kt b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/settings_screen/SettingsViewModel.kt index 4cf7488f..1091b59e 100644 --- a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/settings_screen/SettingsViewModel.kt +++ b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/settings_screen/SettingsViewModel.kt @@ -4,7 +4,12 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.anthonyla.paperize.core.ScalingConstants import com.anthonyla.paperize.core.SettingsConstants +import com.anthonyla.paperize.core.SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT import com.anthonyla.paperize.data.settings.SettingsDataStore +import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsState.EffectSettings +import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsState.ScheduleSettings +import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsState.ThemeSettings +import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsState.WallpaperSettings import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job @@ -35,81 +40,81 @@ class SettingsViewModel @Inject constructor ( init { currentGetJob = viewModelScope.launch(Dispatchers.IO) { val firstLaunch = async { settingsDataStoreImpl.getBoolean(SettingsConstants.FIRST_LAUNCH) ?: true } - val darkMode = async { settingsDataStoreImpl.getBoolean(SettingsConstants.DARK_MODE_TYPE) } - val amoledTheme = async { settingsDataStoreImpl.getBoolean(SettingsConstants.AMOLED_THEME_TYPE) ?: false } - val dynamicTheming = async { settingsDataStoreImpl.getBoolean(SettingsConstants.DYNAMIC_THEME_TYPE) ?: false } - val enableChanger = async { settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_CHANGER) ?: false } - val setHomeWallpaper = async { settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_HOME_WALLPAPER) ?: false } - val setLockWallpaper = async { settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_LOCK_WALLPAPER) ?: false } - val setCurrentHomeWallpaper = async { settingsDataStoreImpl.getString(SettingsConstants.CURRENT_HOME_WALLPAPER) } - val setCurrentLockWallpaper = async { settingsDataStoreImpl.getString(SettingsConstants.CURRENT_LOCK_WALLPAPER) } - val homeWallpaperInterval = async { settingsDataStoreImpl.getInt(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT } - val lockWallpaperInterval = async { settingsDataStoreImpl.getInt(SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT } - val homeAlbumName = async { settingsDataStoreImpl.getString(SettingsConstants.HOME_ALBUM_NAME) } - val lockAlbumName = async { settingsDataStoreImpl.getString(SettingsConstants.LOCK_ALBUM_NAME) } - val lastSetTime = async { settingsDataStoreImpl.getString(SettingsConstants.LAST_SET_TIME) } - val nextSetTime = async { settingsDataStoreImpl.getString(SettingsConstants.NEXT_SET_TIME) } - val animate = async { settingsDataStoreImpl.getBoolean(SettingsConstants.ANIMATE_TYPE) ?: true } - val homeDarkenPercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.HOME_DARKEN_PERCENTAGE) ?: 100 } - val lockDarkenPercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.LOCK_DARKEN_PERCENTAGE) ?: 100 } - val darken = async { settingsDataStoreImpl.getBoolean(SettingsConstants.DARKEN) ?: false } - val wallpaperScaling = async { ScalingConstants.valueOf(settingsDataStoreImpl.getString(SettingsConstants.WALLPAPER_SCALING) ?: ScalingConstants.FILL.name) } - val scheduleSeparately = async { settingsDataStoreImpl.getBoolean(SettingsConstants.SCHEDULE_SEPARATELY) ?: false } - val blur = async { settingsDataStoreImpl.getBoolean(SettingsConstants.BLUR) ?: false } - val homeBlurPercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.HOME_BLUR_PERCENTAGE) ?: 0 } - val lockBlurPercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.LOCK_BLUR_PERCENTAGE) ?: 0 } - val vignette = async { settingsDataStoreImpl.getBoolean(SettingsConstants.VIGNETTE) ?: false } - val homeVignettePercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.HOME_VIGNETTE_PERCENTAGE) ?: 0 } - val lockVignettePercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.LOCK_VIGNETTE_PERCENTAGE) ?: 0 } - val grayscale = async { settingsDataStoreImpl.getBoolean(SettingsConstants.GRAYSCALE) ?: false } - val homeGrayscalePercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.HOME_GRAYSCALE_PERCENTAGE) ?: 0 } - val lockGrayscalePercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.LOCK_GRAYSCALE_PERCENTAGE) ?: 0 } - val nextHomeWallpaper = async { settingsDataStoreImpl.getString(SettingsConstants.HOME_NEXT_SET_TIME) } - val nextLockWallpaper = async { settingsDataStoreImpl.getString(SettingsConstants.LOCK_NEXT_SET_TIME) } - val changeStartTime = async { settingsDataStoreImpl.getBoolean(SettingsConstants.CHANGE_START_TIME) ?: false } - val startTime = async { Pair(settingsDataStoreImpl.getInt(SettingsConstants.START_HOUR) ?: 0, settingsDataStoreImpl.getInt(SettingsConstants.START_MINUTE) ?: 0) } - + val themeSettings = async { loadThemeSettings() } + val wallpaperSettings = async { loadWallpaperSettings() } + val scheduleSettings = async { loadScheduleSettings() } + val effectSettings = async { loadEffectSettings() } _state.update { it.copy( - darkMode = darkMode.await(), - amoledTheme = amoledTheme.await(), - dynamicTheming = dynamicTheming.await(), - homeInterval = homeWallpaperInterval.await(), - lockInterval = lockWallpaperInterval.await(), - homeAlbumName = homeAlbumName.await(), - lockAlbumName = lockAlbumName.await(), firstLaunch = firstLaunch.await(), - lastSetTime = lastSetTime.await(), - nextSetTime = nextSetTime.await(), - animate = animate.await(), - enableChanger = enableChanger.await(), - homeDarkenPercentage = homeDarkenPercentage.await(), - lockDarkenPercentage = lockDarkenPercentage.await(), - darken = darken.await(), - wallpaperScaling = wallpaperScaling.await(), - setHomeWallpaper = setHomeWallpaper.await(), - setLockWallpaper = setLockWallpaper.await(), - currentHomeWallpaper = setCurrentHomeWallpaper.await(), - currentLockWallpaper = setCurrentLockWallpaper.await(), - scheduleSeparately = scheduleSeparately.await(), - blur = blur.await(), - homeBlurPercentage = homeBlurPercentage.await(), - lockBlurPercentage = lockBlurPercentage.await(), - nextHomeWallpaper = nextHomeWallpaper.await(), - nextLockWallpaper = nextLockWallpaper.await(), - vignette = vignette.await(), - homeVignettePercentage = homeVignettePercentage.await(), - lockVignettePercentage = lockVignettePercentage.await(), - grayscale = grayscale.await(), - homeGrayscalePercentage = homeGrayscalePercentage.await(), - lockGrayscalePercentage = lockGrayscalePercentage.await(), - changeStartTime = changeStartTime.await(), - startTime = startTime.await() + themeSettings = themeSettings.await(), + wallpaperSettings = wallpaperSettings.await(), + scheduleSettings = scheduleSettings.await(), + effectSettings = effectSettings.await() ) } setKeepOnScreenCondition = false } } + + private suspend fun loadThemeSettings(): ThemeSettings { + return ThemeSettings( + darkMode = settingsDataStoreImpl.getBoolean(SettingsConstants.DARK_MODE_TYPE), + amoledTheme = settingsDataStoreImpl.getBoolean(SettingsConstants.AMOLED_THEME_TYPE) ?: false, + dynamicTheming = settingsDataStoreImpl.getBoolean(SettingsConstants.DYNAMIC_THEME_TYPE) ?: false, + animate = settingsDataStoreImpl.getBoolean(SettingsConstants.ANIMATE_TYPE) ?: true + ) + } + + private suspend fun loadWallpaperSettings(): WallpaperSettings { + return WallpaperSettings( + enableChanger = settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_CHANGER) ?: false, + setHomeWallpaper = settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_HOME_WALLPAPER) ?: false, + setLockWallpaper = settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_LOCK_WALLPAPER) ?: false, + currentHomeWallpaper = settingsDataStoreImpl.getString(SettingsConstants.CURRENT_HOME_WALLPAPER), + currentLockWallpaper = settingsDataStoreImpl.getString(SettingsConstants.CURRENT_LOCK_WALLPAPER), + nextHomeWallpaper = settingsDataStoreImpl.getString(SettingsConstants.HOME_NEXT_SET_TIME), + nextLockWallpaper = settingsDataStoreImpl.getString(SettingsConstants.LOCK_NEXT_SET_TIME), + homeAlbumName = settingsDataStoreImpl.getString(SettingsConstants.HOME_ALBUM_NAME), + lockAlbumName = settingsDataStoreImpl.getString(SettingsConstants.LOCK_ALBUM_NAME), + wallpaperScaling = ScalingConstants.valueOf( + settingsDataStoreImpl.getString(SettingsConstants.WALLPAPER_SCALING) + ?: ScalingConstants.FILL.name + ) + ) + } + + private suspend fun loadScheduleSettings(): ScheduleSettings { + return ScheduleSettings( + scheduleSeparately = settingsDataStoreImpl.getBoolean(SettingsConstants.SCHEDULE_SEPARATELY) ?: false, + homeInterval = settingsDataStoreImpl.getInt(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL) ?: WALLPAPER_CHANGE_INTERVAL_DEFAULT, + lockInterval = settingsDataStoreImpl.getInt(SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL) ?: WALLPAPER_CHANGE_INTERVAL_DEFAULT, + lastSetTime = settingsDataStoreImpl.getString(SettingsConstants.LAST_SET_TIME), + nextSetTime = settingsDataStoreImpl.getString(SettingsConstants.NEXT_SET_TIME), + changeStartTime = settingsDataStoreImpl.getBoolean(SettingsConstants.CHANGE_START_TIME) ?: false, + startTime = Pair( + settingsDataStoreImpl.getInt(SettingsConstants.START_HOUR) ?: 0, + settingsDataStoreImpl.getInt(SettingsConstants.START_MINUTE) ?: 0 + ) + ) + } + + private suspend fun loadEffectSettings(): EffectSettings { + return EffectSettings( + darken = settingsDataStoreImpl.getBoolean(SettingsConstants.DARKEN) ?: false, + homeDarkenPercentage = settingsDataStoreImpl.getInt(SettingsConstants.HOME_DARKEN_PERCENTAGE) ?: 100, + lockDarkenPercentage = settingsDataStoreImpl.getInt(SettingsConstants.LOCK_DARKEN_PERCENTAGE) ?: 100, + blur = settingsDataStoreImpl.getBoolean(SettingsConstants.BLUR) ?: false, + homeBlurPercentage = settingsDataStoreImpl.getInt(SettingsConstants.HOME_BLUR_PERCENTAGE) ?: 0, + lockBlurPercentage = settingsDataStoreImpl.getInt(SettingsConstants.LOCK_BLUR_PERCENTAGE) ?: 0, + vignette = settingsDataStoreImpl.getBoolean(SettingsConstants.VIGNETTE) ?: false, + homeVignettePercentage = settingsDataStoreImpl.getInt(SettingsConstants.HOME_VIGNETTE_PERCENTAGE) ?: 0, + lockVignettePercentage = settingsDataStoreImpl.getInt(SettingsConstants.LOCK_VIGNETTE_PERCENTAGE) ?: 0, + grayscale = settingsDataStoreImpl.getBoolean(SettingsConstants.GRAYSCALE) ?: false, + homeGrayscalePercentage = settingsDataStoreImpl.getInt(SettingsConstants.HOME_GRAYSCALE_PERCENTAGE) ?: 0, + lockGrayscalePercentage = settingsDataStoreImpl.getInt(SettingsConstants.LOCK_GRAYSCALE_PERCENTAGE) ?: 0 + ) + } fun onEvent(event: SettingsEvent) { when (event) { @@ -117,9 +122,7 @@ class SettingsViewModel @Inject constructor ( viewModelScope.launch(Dispatchers.IO) { settingsDataStoreImpl.putBoolean(SettingsConstants.FIRST_LAUNCH, false) _state.update { - it.copy( - firstLaunch = false - ) + it.copy(firstLaunch = false) } } } @@ -127,11 +130,13 @@ class SettingsViewModel @Inject constructor ( is SettingsEvent.SetChangerToggle -> { viewModelScope.launch(Dispatchers.IO) { settingsDataStoreImpl.putBoolean(SettingsConstants.ENABLE_CHANGER, event.toggle) - _state.update { - it.copy( - enableChanger = event.toggle, - currentHomeWallpaper = if (!event.toggle) null else it.currentHomeWallpaper, - currentLockWallpaper = if (!event.toggle) null else it.currentLockWallpaper + _state.update { currentState -> + currentState.copy( + wallpaperSettings = currentState.wallpaperSettings.copy( + enableChanger = event.toggle, + currentHomeWallpaper = if (!event.toggle) null else currentState.wallpaperSettings.currentHomeWallpaper, + currentLockWallpaper = if (!event.toggle) null else currentState.wallpaperSettings.currentLockWallpaper + ) ) } } @@ -139,75 +144,19 @@ class SettingsViewModel @Inject constructor ( is SettingsEvent.Refresh -> { currentGetJob = viewModelScope.launch(Dispatchers.IO) { - val darkMode = async { settingsDataStoreImpl.getBoolean(SettingsConstants.DARK_MODE_TYPE) } - val amoledTheme = async { settingsDataStoreImpl.getBoolean(SettingsConstants.AMOLED_THEME_TYPE) ?: false } - val dynamicTheming = async { settingsDataStoreImpl.getBoolean(SettingsConstants.DYNAMIC_THEME_TYPE) ?: false } + val themeSettings = async { loadThemeSettings() } + val wallpaperSettings = async { loadWallpaperSettings() } + val scheduleSettings = async { loadScheduleSettings() } + val effectSettings = async { loadEffectSettings() } val firstLaunch = async { settingsDataStoreImpl.getBoolean(SettingsConstants.FIRST_LAUNCH) ?: true } - val lastSetTime = async { settingsDataStoreImpl.getString(SettingsConstants.LAST_SET_TIME) } - val nextSetTime = async { settingsDataStoreImpl.getString(SettingsConstants.NEXT_SET_TIME) } - val animate = async { settingsDataStoreImpl.getBoolean(SettingsConstants.ANIMATE_TYPE) ?: true } - val enableChanger = async { settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_CHANGER) ?: false } - val homeDarkenPercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.HOME_DARKEN_PERCENTAGE) ?: 0 } - val lockDarkenPercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.LOCK_DARKEN_PERCENTAGE) ?: 0 } - val darken = async { settingsDataStoreImpl.getBoolean(SettingsConstants.DARKEN) ?: false } - val setHomeWallpaper = async { settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_HOME_WALLPAPER) ?: false } - val setLockWallpaper = async { settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_LOCK_WALLPAPER) ?: false } - val homeAlbumName = async { settingsDataStoreImpl.getString(SettingsConstants.HOME_ALBUM_NAME) } - val lockAlbumName = async { settingsDataStoreImpl.getString(SettingsConstants.LOCK_ALBUM_NAME) } - val currentHomeWallpaper = async { settingsDataStoreImpl.getString(SettingsConstants.CURRENT_HOME_WALLPAPER) } - val currentLockWallpaper = async { settingsDataStoreImpl.getString(SettingsConstants.CURRENT_LOCK_WALLPAPER) } - val homeWallpaperInterval = async { settingsDataStoreImpl.getInt(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT } - val lockWallpaperInterval = async { settingsDataStoreImpl.getInt(SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT } - val scheduleSeparately = async { settingsDataStoreImpl.getBoolean(SettingsConstants.SCHEDULE_SEPARATELY) ?: false } - val blur = async { settingsDataStoreImpl.getBoolean(SettingsConstants.BLUR) ?: false } - val homeBlurPercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.HOME_BLUR_PERCENTAGE) ?: 0 } - val lockBlurPercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.LOCK_BLUR_PERCENTAGE) ?: 0 } - val nextHomeWallpaper = async { settingsDataStoreImpl.getString(SettingsConstants.HOME_NEXT_SET_TIME) } - val nextLockWallpaper = async { settingsDataStoreImpl.getString(SettingsConstants.LOCK_NEXT_SET_TIME) } - val vignette = async { settingsDataStoreImpl.getBoolean(SettingsConstants.VIGNETTE) ?: false } - val homeVignettePercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.HOME_VIGNETTE_PERCENTAGE) ?: 0 } - val lockVignettePercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.LOCK_VIGNETTE_PERCENTAGE) ?: 0 } - val grayscale = async { settingsDataStoreImpl.getBoolean(SettingsConstants.GRAYSCALE) ?: false } - val homeGrayscalePercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.HOME_GRAYSCALE_PERCENTAGE) ?: 0 } - val lockGrayscalePercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.LOCK_GRAYSCALE_PERCENTAGE) ?: 0 } - val changeStartTime = async { settingsDataStoreImpl.getBoolean(SettingsConstants.CHANGE_START_TIME) ?: false } - val startTime = async { Pair(settingsDataStoreImpl.getInt(SettingsConstants.START_HOUR) ?: 0, settingsDataStoreImpl.getInt(SettingsConstants.START_MINUTE) ?: 0) } - - _state.update { - it.copy( - darkMode = darkMode.await(), - amoledTheme = amoledTheme.await(), - dynamicTheming = dynamicTheming.await(), + + _state.update { + it.copy( firstLaunch = firstLaunch.await(), - lastSetTime = lastSetTime.await(), - nextSetTime = nextSetTime.await(), - animate = animate.await(), - enableChanger = enableChanger.await(), - homeDarkenPercentage = homeDarkenPercentage.await(), - lockDarkenPercentage = lockDarkenPercentage.await(), - darken = darken.await(), - setHomeWallpaper = setHomeWallpaper.await(), - setLockWallpaper = setLockWallpaper.await(), - homeAlbumName = homeAlbumName.await(), - lockAlbumName = lockAlbumName.await(), - currentHomeWallpaper = currentHomeWallpaper.await(), - currentLockWallpaper = currentLockWallpaper.await(), - lockInterval = lockWallpaperInterval.await(), - homeInterval = homeWallpaperInterval.await(), - scheduleSeparately = scheduleSeparately.await(), - blur = blur.await(), - homeBlurPercentage = homeBlurPercentage.await(), - lockBlurPercentage = lockBlurPercentage.await(), - nextHomeWallpaper = nextHomeWallpaper.await(), - nextLockWallpaper = nextLockWallpaper.await(), - vignette = vignette.await(), - homeVignettePercentage = homeVignettePercentage.await(), - lockVignettePercentage = lockVignettePercentage.await(), - grayscale = grayscale.await(), - homeGrayscalePercentage = homeGrayscalePercentage.await(), - lockGrayscalePercentage = lockGrayscalePercentage.await(), - changeStartTime = changeStartTime.await(), - startTime = startTime.await() + themeSettings = themeSettings.await(), + wallpaperSettings = wallpaperSettings.await(), + scheduleSettings = scheduleSettings.await(), + effectSettings = effectSettings.await() ) } } @@ -222,7 +171,9 @@ class SettingsViewModel @Inject constructor ( } _state.update { it.copy( - darkMode = event.darkMode + themeSettings = it.themeSettings.copy( + darkMode = event.darkMode + ) ) } } @@ -236,8 +187,10 @@ class SettingsViewModel @Inject constructor ( } _state.update { it.copy( - amoledTheme = event.amoledTheme, - dynamicTheming = if (event.amoledTheme) false else it.dynamicTheming + themeSettings = it.themeSettings.copy( + amoledTheme = event.amoledTheme, + dynamicTheming = if (event.amoledTheme) false else it.themeSettings.dynamicTheming + ) ) } } @@ -251,8 +204,10 @@ class SettingsViewModel @Inject constructor ( } _state.update { it.copy( - amoledTheme = if (event.dynamicTheming) false else it.amoledTheme, - dynamicTheming = event.dynamicTheming + themeSettings = it.themeSettings.copy( + amoledTheme = if (event.dynamicTheming) false else it.themeSettings.amoledTheme, + dynamicTheming = event.dynamicTheming + ) ) } } @@ -263,7 +218,9 @@ class SettingsViewModel @Inject constructor ( settingsDataStoreImpl.putBoolean(SettingsConstants.ANIMATE_TYPE, event.animate) _state.update { it.copy( - animate = event.animate + themeSettings = it.themeSettings.copy( + animate = event.animate + ) ) } } @@ -273,16 +230,17 @@ class SettingsViewModel @Inject constructor ( viewModelScope.launch(Dispatchers.IO) { settingsDataStoreImpl.putInt(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL, event.interval) val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT) - val currentTime = if (_state.value.changeStartTime) { - LocalDateTime.now().withHour(_state.value.startTime.first).withMinute(_state.value.startTime.second) + val currentTime = if (_state.value.scheduleSettings.changeStartTime) { + LocalDateTime.now().withHour(_state.value.scheduleSettings.startTime.first) + .withMinute(_state.value.scheduleSettings.startTime.second) } else { LocalDateTime.now() } val nextSetTime: String? settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, currentTime.format(formatter)) - if (_state.value.scheduleSeparately) { + if (_state.value.scheduleSettings.scheduleSeparately) { val homeNextSetTime = currentTime.plusMinutes(event.interval.toLong()) - val lockNextSetTime = currentTime.plusMinutes(_state.value.lockInterval.toLong()) + val lockNextSetTime = currentTime.plusMinutes(_state.value.scheduleSettings.lockInterval.toLong()) nextSetTime = (if (homeNextSetTime!!.isBefore(lockNextSetTime)) homeNextSetTime else lockNextSetTime)!!.format(formatter) settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, nextSetTime) settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, homeNextSetTime.toString()) @@ -296,9 +254,11 @@ class SettingsViewModel @Inject constructor ( } _state.update { it.copy( - homeInterval = event.interval, - lastSetTime = currentTime.format(formatter), - nextSetTime = nextSetTime + scheduleSettings = it.scheduleSettings.copy( + homeInterval = event.interval, + lastSetTime = currentTime.format(formatter), + nextSetTime = nextSetTime + ) ) } } @@ -308,15 +268,16 @@ class SettingsViewModel @Inject constructor ( viewModelScope.launch(Dispatchers.IO) { settingsDataStoreImpl.putInt(SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL, event.interval) val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT) - val currentTime = if (_state.value.changeStartTime) { - LocalDateTime.now().withHour(_state.value.startTime.first).withMinute(_state.value.startTime.second) + val currentTime = if (_state.value.scheduleSettings.changeStartTime) { + LocalDateTime.now().withHour(_state.value.scheduleSettings.startTime.first) + .withMinute(_state.value.scheduleSettings.startTime.second) } else { LocalDateTime.now() } val nextSetTime: String? settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, currentTime.format(formatter)) - if (_state.value.scheduleSeparately) { - val nextSetTime1 = currentTime.plusMinutes(_state.value.homeInterval.toLong()) + if (_state.value.scheduleSettings.scheduleSeparately) { + val nextSetTime1 = currentTime.plusMinutes(_state.value.scheduleSettings.homeInterval.toLong()) val nextSetTime2 = currentTime.plusMinutes(event.interval.toLong()) nextSetTime = (if (nextSetTime1!!.isBefore(nextSetTime2)) nextSetTime1 else nextSetTime2)!!.format(formatter) settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, nextSetTime) @@ -331,9 +292,11 @@ class SettingsViewModel @Inject constructor ( } _state.update { it.copy( - lockInterval = event.interval, - lastSetTime = currentTime.format(formatter), - nextSetTime = nextSetTime + scheduleSettings = it.scheduleSettings.copy( + lockInterval = event.interval, + lastSetTime = currentTime.format(formatter), + nextSetTime = nextSetTime + ) ) } } @@ -342,8 +305,10 @@ class SettingsViewModel @Inject constructor ( is SettingsEvent.RefreshNextSetTime -> { viewModelScope.launch { val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT) - val currentTime = if (_state.value.changeStartTime) { - var calculatedTime = LocalDateTime.now().withHour(_state.value.startTime.first).withMinute(_state.value.startTime.second) + val currentTime = if (_state.value.scheduleSettings.changeStartTime) { + var calculatedTime = LocalDateTime.now() + .withHour(_state.value.scheduleSettings.startTime.first) + .withMinute(_state.value.scheduleSettings.startTime.second) if (calculatedTime.isBefore(LocalDateTime.now())) { calculatedTime = calculatedTime.plusDays(1) } @@ -352,28 +317,34 @@ class SettingsViewModel @Inject constructor ( LocalDateTime.now() } val nextSetTime = when { - _state.value.changeStartTime -> { + _state.value.scheduleSettings.changeStartTime -> { settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, currentTime.toString()) settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, currentTime.toString()) currentTime } - _state.value.scheduleSeparately -> { - settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, currentTime.plusMinutes(_state.value.homeInterval.toLong()).toString()) - settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, currentTime.plusMinutes(_state.value.lockInterval.toLong()).toString()) - val nextSetTime1 = currentTime.plusMinutes(_state.value.homeInterval.toLong()) - val nextSetTime2 = currentTime.plusMinutes(_state.value.lockInterval.toLong()) + _state.value.scheduleSettings.scheduleSeparately -> { + settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, + currentTime.plusMinutes(_state.value.scheduleSettings.homeInterval.toLong()).toString()) + settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, + currentTime.plusMinutes(_state.value.scheduleSettings.lockInterval.toLong()).toString()) + val nextSetTime1 = currentTime.plusMinutes(_state.value.scheduleSettings.homeInterval.toLong()) + val nextSetTime2 = currentTime.plusMinutes(_state.value.scheduleSettings.lockInterval.toLong()) if (nextSetTime1.isBefore(nextSetTime2)) nextSetTime1 else nextSetTime2 } else -> { - settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, currentTime.plusMinutes(_state.value.homeInterval.toLong()).toString()) - settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, currentTime.plusMinutes(_state.value.lockInterval.toLong()).toString()) - currentTime.plusMinutes(_state.value.homeInterval.toLong()) + settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, + currentTime.plusMinutes(_state.value.scheduleSettings.homeInterval.toLong()).toString()) + settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, + currentTime.plusMinutes(_state.value.scheduleSettings.lockInterval.toLong()).toString()) + currentTime.plusMinutes(_state.value.scheduleSettings.homeInterval.toLong()) } }.format(formatter) _state.update { it.copy( - lastSetTime = LocalDateTime.now().format(formatter), - nextSetTime = nextSetTime, + scheduleSettings = it.scheduleSettings.copy( + lastSetTime = LocalDateTime.now().format(formatter), + nextSetTime = nextSetTime + ) ) } settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, LocalDateTime.now().format(formatter)) @@ -386,7 +357,9 @@ class SettingsViewModel @Inject constructor ( settingsDataStoreImpl.putBoolean(SettingsConstants.ENABLE_HOME_WALLPAPER, event.home) _state.update { it.copy( - setHomeWallpaper = event.home + wallpaperSettings = it.wallpaperSettings.copy( + setHomeWallpaper = event.home + ) ) } } @@ -397,7 +370,9 @@ class SettingsViewModel @Inject constructor ( settingsDataStoreImpl.putBoolean(SettingsConstants.ENABLE_LOCK_WALLPAPER, event.lock) _state.update { it.copy( - setLockWallpaper = event.lock + wallpaperSettings = it.wallpaperSettings.copy( + setLockWallpaper = event.lock + ) ) } } @@ -408,7 +383,9 @@ class SettingsViewModel @Inject constructor ( settingsDataStoreImpl.putBoolean(SettingsConstants.DARKEN, event.darken) _state.update { it.copy( - darken = event.darken + effectSettings = it.effectSettings.copy( + darken = event.darken + ) ) } } @@ -419,7 +396,9 @@ class SettingsViewModel @Inject constructor ( settingsDataStoreImpl.putString(SettingsConstants.WALLPAPER_SCALING, event.scaling.name) _state.update { it.copy( - wallpaperScaling = event.scaling + wallpaperSettings = it.wallpaperSettings.copy( + wallpaperScaling = event.scaling + ) ) } } @@ -430,7 +409,9 @@ class SettingsViewModel @Inject constructor ( settingsDataStoreImpl.putBoolean(SettingsConstants.SCHEDULE_SEPARATELY, event.scheduleSeparately) _state.update { it.copy( - scheduleSeparately = event.scheduleSeparately + scheduleSettings = it.scheduleSettings.copy( + scheduleSeparately = event.scheduleSeparately + ) ) } } @@ -441,7 +422,9 @@ class SettingsViewModel @Inject constructor ( settingsDataStoreImpl.putBoolean(SettingsConstants.BLUR, event.blur) _state.update { it.copy( - blur = event.blur + effectSettings = it.effectSettings.copy( + blur = event.blur + ) ) } } @@ -457,8 +440,10 @@ class SettingsViewModel @Inject constructor ( } _state.update { it.copy( - homeDarkenPercentage = event.homeDarkenPercentage ?: it.homeDarkenPercentage, - lockDarkenPercentage = event.lockDarkenPercentage ?: it.lockDarkenPercentage + effectSettings = it.effectSettings.copy( + homeDarkenPercentage = event.homeDarkenPercentage ?: it.effectSettings.homeDarkenPercentage, + lockDarkenPercentage = event.lockDarkenPercentage ?: it.effectSettings.lockDarkenPercentage + ) ) } } @@ -474,8 +459,10 @@ class SettingsViewModel @Inject constructor ( } _state.update { it.copy( - homeBlurPercentage = event.homeBlurPercentage ?: it.homeBlurPercentage, - lockBlurPercentage = event.lockBlurPercentage ?: it.lockBlurPercentage + effectSettings = it.effectSettings.copy( + homeBlurPercentage = event.homeBlurPercentage ?: it.effectSettings.homeBlurPercentage, + lockBlurPercentage = event.lockBlurPercentage ?: it.effectSettings.lockBlurPercentage + ) ) } } @@ -486,7 +473,9 @@ class SettingsViewModel @Inject constructor ( settingsDataStoreImpl.putBoolean(SettingsConstants.VIGNETTE, event.vignette) _state.update { it.copy( - vignette = event.vignette + effectSettings = it.effectSettings.copy( + vignette = event.vignette + ) ) } } @@ -502,8 +491,10 @@ class SettingsViewModel @Inject constructor ( } _state.update { it.copy( - homeVignettePercentage = event.homeVignettePercentage ?: it.homeVignettePercentage, - lockVignettePercentage = event.lockVignettePercentage ?: it.lockVignettePercentage + effectSettings = it.effectSettings.copy( + homeVignettePercentage = event.homeVignettePercentage ?: it.effectSettings.homeVignettePercentage, + lockVignettePercentage = event.lockVignettePercentage ?: it.effectSettings.lockVignettePercentage + ) ) } } @@ -514,7 +505,9 @@ class SettingsViewModel @Inject constructor ( settingsDataStoreImpl.putBoolean(SettingsConstants.GRAYSCALE, event.grayscale) _state.update { it.copy( - grayscale = event.grayscale + effectSettings = it.effectSettings.copy( + grayscale = event.grayscale + ) ) } } @@ -530,8 +523,10 @@ class SettingsViewModel @Inject constructor ( } _state.update { it.copy( - homeGrayscalePercentage = event.homeGrayscalePercentage ?: it.homeGrayscalePercentage, - lockGrayscalePercentage = event.lockGrayscalePercentage ?: it.lockGrayscalePercentage + effectSettings = it.effectSettings.copy( + homeGrayscalePercentage = event.homeGrayscalePercentage ?: it.effectSettings.homeGrayscalePercentage, + lockGrayscalePercentage = event.lockGrayscalePercentage ?: it.effectSettings.lockGrayscalePercentage + ) ) } } @@ -544,7 +539,9 @@ class SettingsViewModel @Inject constructor ( } _state.update { it.copy( - currentHomeWallpaper = event.currentHomeWallpaper + wallpaperSettings = it.wallpaperSettings.copy( + currentHomeWallpaper = event.currentHomeWallpaper + ) ) } } @@ -557,7 +554,9 @@ class SettingsViewModel @Inject constructor ( } _state.update { it.copy( - currentLockWallpaper = event.currentLockWallpaper + wallpaperSettings = it.wallpaperSettings.copy( + currentLockWallpaper = event.currentLockWallpaper + ) ) } } @@ -573,8 +572,10 @@ class SettingsViewModel @Inject constructor ( } _state.update { it.copy( - currentLockWallpaper = event.currentLockWallpaper ?: it.currentLockWallpaper, - currentHomeWallpaper = event.currentHomeWallpaper ?: it.currentHomeWallpaper + wallpaperSettings = it.wallpaperSettings.copy( + currentLockWallpaper = event.currentLockWallpaper ?: it.wallpaperSettings.currentLockWallpaper, + currentHomeWallpaper = event.currentHomeWallpaper ?: it.wallpaperSettings.currentHomeWallpaper + ) ) } } @@ -590,16 +591,18 @@ class SettingsViewModel @Inject constructor ( } val enableChanger: Boolean = when { event.homeAlbumName != null && event.lockAlbumName != null -> { true } - event.homeAlbumName != null && !_state.value.lockAlbumName.isNullOrEmpty() -> { true } - event.lockAlbumName != null && !_state.value.homeAlbumName.isNullOrEmpty() -> { true } + event.homeAlbumName != null && !_state.value.wallpaperSettings.lockAlbumName.isNullOrEmpty() -> { true } + event.lockAlbumName != null && !_state.value.wallpaperSettings.homeAlbumName.isNullOrEmpty() -> { true } else -> { false } } settingsDataStoreImpl.putBoolean(SettingsConstants.ENABLE_CHANGER, enableChanger) _state.update { it.copy( - homeAlbumName = event.homeAlbumName ?: it.homeAlbumName, - lockAlbumName = event.lockAlbumName ?: it.lockAlbumName, - enableChanger = enableChanger + wallpaperSettings = it.wallpaperSettings.copy( + homeAlbumName = event.homeAlbumName ?: it.wallpaperSettings.homeAlbumName, + lockAlbumName = event.lockAlbumName ?: it.wallpaperSettings.lockAlbumName, + enableChanger = enableChanger + ) ) } } @@ -607,7 +610,7 @@ class SettingsViewModel @Inject constructor ( is SettingsEvent.RemoveSelectedAlbumAsType -> { viewModelScope.launch(Dispatchers.IO) { - if (_state.value.setLockWallpaper && _state.value.setHomeWallpaper) { + if (_state.value.wallpaperSettings.setLockWallpaper && _state.value.wallpaperSettings.setHomeWallpaper) { if (event.removeLock) { settingsDataStoreImpl.deleteString(SettingsConstants.LOCK_ALBUM_NAME) } @@ -620,15 +623,19 @@ class SettingsViewModel @Inject constructor ( settingsDataStoreImpl.deleteString(SettingsConstants.NEXT_SET_TIME) _state.update { it.copy( - homeAlbumName = if (event.removeHome) null else it.homeAlbumName, - lockAlbumName = if (event.removeLock) null else it.lockAlbumName, - currentHomeWallpaper = null, - currentLockWallpaper = null, - nextHomeWallpaper = null, - nextLockWallpaper = null, - enableChanger = false, - lastSetTime = null, - nextSetTime = null + wallpaperSettings = it.wallpaperSettings.copy( + homeAlbumName = if (event.removeHome) null else it.wallpaperSettings.homeAlbumName, + lockAlbumName = if (event.removeLock) null else it.wallpaperSettings.lockAlbumName, + currentHomeWallpaper = null, + currentLockWallpaper = null, + nextHomeWallpaper = null, + nextLockWallpaper = null, + enableChanger = false + ), + scheduleSettings = it.scheduleSettings.copy( + lastSetTime = null, + nextSetTime = null + ) ) } } @@ -643,11 +650,13 @@ class SettingsViewModel @Inject constructor ( } _state.update { it.copy( - homeAlbumName = if (event.removeHome) null else it.homeAlbumName, - lockAlbumName = if (event.removeLock) null else it.lockAlbumName, - currentHomeWallpaper = if (event.removeHome) null else it.currentHomeWallpaper, - currentLockWallpaper = if (event.removeLock) null else it.currentLockWallpaper, - enableChanger = false + wallpaperSettings = it.wallpaperSettings.copy( + homeAlbumName = if (event.removeHome) null else it.wallpaperSettings.homeAlbumName, + lockAlbumName = if (event.removeLock) null else it.wallpaperSettings.lockAlbumName, + currentHomeWallpaper = if (event.removeHome) null else it.wallpaperSettings.currentHomeWallpaper, + currentLockWallpaper = if (event.removeLock) null else it.wallpaperSettings.currentLockWallpaper, + enableChanger = false + ) ) } } @@ -656,13 +665,13 @@ class SettingsViewModel @Inject constructor ( is SettingsEvent.RemoveSelectedAlbumAsName -> { viewModelScope.launch(Dispatchers.IO) { - var enableChanger = _state.value.enableChanger - if (event.albumName == _state.value.lockAlbumName) { + var enableChanger = _state.value.wallpaperSettings.enableChanger + if (event.albumName == _state.value.wallpaperSettings.lockAlbumName) { settingsDataStoreImpl.deleteString(SettingsConstants.LOCK_ALBUM_NAME) settingsDataStoreImpl.deleteString(SettingsConstants.CURRENT_LOCK_WALLPAPER) enableChanger = false } - if (event.albumName == _state.value.homeAlbumName) { + if (event.albumName == _state.value.wallpaperSettings.homeAlbumName) { settingsDataStoreImpl.deleteString(SettingsConstants.HOME_ALBUM_NAME) settingsDataStoreImpl.deleteString(SettingsConstants.CURRENT_HOME_WALLPAPER) enableChanger = false @@ -670,14 +679,16 @@ class SettingsViewModel @Inject constructor ( settingsDataStoreImpl.putBoolean(SettingsConstants.ENABLE_CHANGER, enableChanger) _state.update { it.copy( - homeAlbumName = if (event.albumName == _state.value.homeAlbumName) null else it.homeAlbumName, - lockAlbumName = if (event.albumName == _state.value.lockAlbumName) null else it.lockAlbumName, - currentHomeWallpaper = if (event.albumName == _state.value.homeAlbumName) null else it.currentHomeWallpaper, - currentLockWallpaper = if (event.albumName == _state.value.lockAlbumName) null else it.currentLockWallpaper, - enableChanger = enableChanger + wallpaperSettings = it.wallpaperSettings.copy( + homeAlbumName = if (event.albumName == _state.value.wallpaperSettings.homeAlbumName) null else it.wallpaperSettings.homeAlbumName, + lockAlbumName = if (event.albumName == _state.value.wallpaperSettings.lockAlbumName) null else it.wallpaperSettings.lockAlbumName, + currentHomeWallpaper = if (event.albumName == _state.value.wallpaperSettings.homeAlbumName) null else it.wallpaperSettings.currentHomeWallpaper, + currentLockWallpaper = if (event.albumName == _state.value.wallpaperSettings.lockAlbumName) null else it.wallpaperSettings.currentLockWallpaper, + enableChanger = enableChanger + ) ) - } + } } } @@ -688,7 +699,9 @@ class SettingsViewModel @Inject constructor ( } _state.update { it.copy( - nextHomeWallpaper = event.nextHomeWallpaper + wallpaperSettings = it.wallpaperSettings.copy( + nextHomeWallpaper = event.nextHomeWallpaper + ) ) } } @@ -701,7 +714,9 @@ class SettingsViewModel @Inject constructor ( } _state.update { it.copy( - nextLockWallpaper = event.nextLockWallpaper + wallpaperSettings = it.wallpaperSettings.copy( + nextLockWallpaper = event.nextLockWallpaper + ) ) } } @@ -717,8 +732,10 @@ class SettingsViewModel @Inject constructor ( } _state.update { it.copy( - nextHomeWallpaper = event.nextHomeWallpaper ?: it.nextHomeWallpaper, - nextLockWallpaper = event.nextLockWallpaper ?: it.nextLockWallpaper + wallpaperSettings = it.wallpaperSettings.copy( + nextHomeWallpaper = event.nextHomeWallpaper ?: it.wallpaperSettings.nextHomeWallpaper, + nextLockWallpaper = event.nextLockWallpaper ?: it.wallpaperSettings.nextLockWallpaper + ) ) } } @@ -730,10 +747,12 @@ class SettingsViewModel @Inject constructor ( val nextLockWallpaper = async { settingsDataStoreImpl.getString(SettingsConstants.NEXT_LOCK_WALLPAPER) } _state.update { it.copy( - nextHomeWallpaper = nextHomeWallpaper.await(), - nextLockWallpaper = nextLockWallpaper.await(), - currentHomeWallpaper = nextHomeWallpaper.await(), - currentLockWallpaper = nextLockWallpaper.await() + wallpaperSettings = it.wallpaperSettings.copy( + nextHomeWallpaper = nextHomeWallpaper.await(), + nextLockWallpaper = nextLockWallpaper.await(), + currentHomeWallpaper = nextHomeWallpaper.await(), + currentLockWallpaper = nextLockWallpaper.await() + ) ) } } @@ -743,9 +762,12 @@ class SettingsViewModel @Inject constructor ( viewModelScope.launch(Dispatchers.IO) { val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT) val currentTime = if (event.changeStartTime) { - LocalDateTime.now().withHour(_state.value.startTime.first).withMinute(_state.value.startTime.second).let { - if (it.isBefore(LocalDateTime.now())) it.plusDays(1) else it - } + LocalDateTime.now() + .withHour(_state.value.scheduleSettings.startTime.first) + .withMinute(_state.value.scheduleSettings.startTime.second) + .let { + if (it.isBefore(LocalDateTime.now())) it.plusDays(1) else it + } } else { LocalDateTime.now() } @@ -755,16 +777,16 @@ class SettingsViewModel @Inject constructor ( settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, currentTime.toString()) currentTime.format(formatter) } - _state.value.scheduleSeparately -> { - val nextSetTime1 = currentTime.plusMinutes(_state.value.homeInterval.toLong()) - val nextSetTime2 = currentTime.plusMinutes(_state.value.lockInterval.toLong()) + _state.value.scheduleSettings.scheduleSeparately -> { + val nextSetTime1 = currentTime.plusMinutes(_state.value.scheduleSettings.homeInterval.toLong()) + val nextSetTime2 = currentTime.plusMinutes(_state.value.scheduleSettings.lockInterval.toLong()) val nextSetTime = if (nextSetTime1.isBefore(nextSetTime2)) nextSetTime1 else nextSetTime2 settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, nextSetTime1.toString()) settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, nextSetTime2.toString()) nextSetTime.format(formatter) } else -> { - val nextSetTime = currentTime.plusMinutes(_state.value.homeInterval.toLong()) + val nextSetTime = currentTime.plusMinutes(_state.value.scheduleSettings.homeInterval.toLong()) settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, nextSetTime.toString()) settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, nextSetTime.toString()) nextSetTime.format(formatter) @@ -772,8 +794,10 @@ class SettingsViewModel @Inject constructor ( } _state.update { it.copy( - changeStartTime = event.changeStartTime, - nextSetTime = nextSetTime + scheduleSettings = it.scheduleSettings.copy( + changeStartTime = event.changeStartTime, + nextSetTime = nextSetTime + ) ) } settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, nextSetTime) @@ -790,9 +814,11 @@ class SettingsViewModel @Inject constructor ( val nextSetTime = currentTime.format(formatter) _state.update { it.copy( - startTime = Pair(event.hour, event.minute), - changeStartTime = true, - nextSetTime = nextSetTime + scheduleSettings = it.scheduleSettings.copy( + startTime = Pair(event.hour, event.minute), + changeStartTime = true, + nextSetTime = nextSetTime + ) ) } settingsDataStoreImpl.run { @@ -808,81 +834,54 @@ class SettingsViewModel @Inject constructor ( is SettingsEvent.Reset -> { viewModelScope.launch(Dispatchers.IO) { - settingsDataStoreImpl.deleteBoolean(SettingsConstants.DARK_MODE_TYPE) - settingsDataStoreImpl.deleteBoolean(SettingsConstants.AMOLED_THEME_TYPE) - settingsDataStoreImpl.deleteBoolean(SettingsConstants.DYNAMIC_THEME_TYPE) - settingsDataStoreImpl.deleteBoolean(SettingsConstants.FIRST_LAUNCH) - settingsDataStoreImpl.deleteString(SettingsConstants.LAST_SET_TIME) - settingsDataStoreImpl.deleteString(SettingsConstants.NEXT_SET_TIME) - settingsDataStoreImpl.deleteBoolean(SettingsConstants.ANIMATE_TYPE) - settingsDataStoreImpl.deleteBoolean(SettingsConstants.ENABLE_CHANGER) - settingsDataStoreImpl.deleteInt(SettingsConstants.HOME_DARKEN_PERCENTAGE) - settingsDataStoreImpl.deleteInt(SettingsConstants.LOCK_DARKEN_PERCENTAGE) - settingsDataStoreImpl.deleteBoolean(SettingsConstants.DARKEN) - settingsDataStoreImpl.deleteString(SettingsConstants.WALLPAPER_SCALING) - settingsDataStoreImpl.deleteBoolean(SettingsConstants.ENABLE_HOME_WALLPAPER) - settingsDataStoreImpl.deleteBoolean(SettingsConstants.ENABLE_LOCK_WALLPAPER) - settingsDataStoreImpl.deleteString(SettingsConstants.CURRENT_HOME_WALLPAPER) - settingsDataStoreImpl.deleteString(SettingsConstants.CURRENT_LOCK_WALLPAPER) - settingsDataStoreImpl.deleteString(SettingsConstants.HOME_ALBUM_NAME) - settingsDataStoreImpl.deleteString(SettingsConstants.LOCK_ALBUM_NAME) - settingsDataStoreImpl.deleteInt(SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL) - settingsDataStoreImpl.deleteInt(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL) - settingsDataStoreImpl.deleteBoolean(SettingsConstants.SCHEDULE_SEPARATELY) - settingsDataStoreImpl.deleteBoolean(SettingsConstants.BLUR) - settingsDataStoreImpl.deleteInt(SettingsConstants.HOME_BLUR_PERCENTAGE) - settingsDataStoreImpl.deleteInt(SettingsConstants.LOCK_BLUR_PERCENTAGE) - settingsDataStoreImpl.deleteBoolean(SettingsConstants.FIRST_SET) - settingsDataStoreImpl.deleteString(SettingsConstants.HOME_NEXT_SET_TIME) - settingsDataStoreImpl.deleteString(SettingsConstants.LOCK_NEXT_SET_TIME) - settingsDataStoreImpl.deleteString(SettingsConstants.NEXT_HOME_WALLPAPER) - settingsDataStoreImpl.deleteString(SettingsConstants.NEXT_LOCK_WALLPAPER) - settingsDataStoreImpl.deleteBoolean(SettingsConstants.VIGNETTE) - settingsDataStoreImpl.deleteInt(SettingsConstants.HOME_VIGNETTE_PERCENTAGE) - settingsDataStoreImpl.deleteInt(SettingsConstants.LOCK_VIGNETTE_PERCENTAGE) - settingsDataStoreImpl.deleteBoolean(SettingsConstants.GRAYSCALE) - settingsDataStoreImpl.deleteInt(SettingsConstants.HOME_GRAYSCALE_PERCENTAGE) - settingsDataStoreImpl.deleteInt(SettingsConstants.LOCK_GRAYSCALE_PERCENTAGE) - settingsDataStoreImpl.deleteBoolean(SettingsConstants.CHANGE_START_TIME) - settingsDataStoreImpl.deleteInt(SettingsConstants.START_HOUR) - settingsDataStoreImpl.deleteInt(SettingsConstants.START_MINUTE) - - _state.update { - it.copy( - darkMode = null, - amoledTheme = false, - dynamicTheming = false, + val keysToDelete = listOf( + SettingsConstants.DARK_MODE_TYPE, + SettingsConstants.AMOLED_THEME_TYPE, + SettingsConstants.DYNAMIC_THEME_TYPE, + SettingsConstants.FIRST_LAUNCH, + SettingsConstants.LAST_SET_TIME, + SettingsConstants.NEXT_SET_TIME, + SettingsConstants.ANIMATE_TYPE, + SettingsConstants.ENABLE_CHANGER, + SettingsConstants.HOME_DARKEN_PERCENTAGE, + SettingsConstants.LOCK_DARKEN_PERCENTAGE, + SettingsConstants.DARKEN, + SettingsConstants.WALLPAPER_SCALING, + SettingsConstants.ENABLE_HOME_WALLPAPER, + SettingsConstants.ENABLE_LOCK_WALLPAPER, + SettingsConstants.CURRENT_HOME_WALLPAPER, + SettingsConstants.CURRENT_LOCK_WALLPAPER, + SettingsConstants.HOME_ALBUM_NAME, + SettingsConstants.LOCK_ALBUM_NAME, + SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL, + SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL, + SettingsConstants.SCHEDULE_SEPARATELY, + SettingsConstants.BLUR, + SettingsConstants.HOME_BLUR_PERCENTAGE, + SettingsConstants.LOCK_BLUR_PERCENTAGE, + SettingsConstants.FIRST_SET, + SettingsConstants.HOME_NEXT_SET_TIME, + SettingsConstants.LOCK_NEXT_SET_TIME, + SettingsConstants.NEXT_HOME_WALLPAPER, + SettingsConstants.NEXT_LOCK_WALLPAPER, + SettingsConstants.VIGNETTE, + SettingsConstants.HOME_VIGNETTE_PERCENTAGE, + SettingsConstants.LOCK_VIGNETTE_PERCENTAGE, + SettingsConstants.GRAYSCALE, + SettingsConstants.HOME_GRAYSCALE_PERCENTAGE, + SettingsConstants.LOCK_GRAYSCALE_PERCENTAGE, + SettingsConstants.CHANGE_START_TIME, + SettingsConstants.START_HOUR, + SettingsConstants.START_MINUTE + ) + settingsDataStoreImpl.clear(keysToDelete) + _state.update { + it.copy( firstLaunch = true, - lastSetTime = null, - nextSetTime = null, - animate = true, - enableChanger = false, - homeDarkenPercentage = 100, - lockDarkenPercentage = 100, - homeBlurPercentage = 0, - lockBlurPercentage = 0, - darken = false, - wallpaperScaling = ScalingConstants.FILL, - setHomeWallpaper = false, - setLockWallpaper = false, - currentHomeWallpaper = null, - currentLockWallpaper = null, - lockInterval = SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT, - homeInterval = SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT, - homeAlbumName = null, - lockAlbumName = null, - scheduleSeparately = false, - blur = false, - nextHomeWallpaper = null, - nextLockWallpaper = null, - vignette = false, - homeVignettePercentage = 0, - lockVignettePercentage = 0, - grayscale = false, - homeGrayscalePercentage = 0, - lockGrayscalePercentage = 0, - changeStartTime = false, - startTime = Pair(0, 0) + themeSettings = ThemeSettings(), + scheduleSettings = ScheduleSettings(), + wallpaperSettings = WallpaperSettings(), + effectSettings = EffectSettings() ) } } diff --git a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/startup_screen/StartupScreen.kt b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/startup_screen/StartupScreen.kt index 0395bd0a..f1f31fb4 100644 --- a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/startup_screen/StartupScreen.kt +++ b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/startup_screen/StartupScreen.kt @@ -37,11 +37,9 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext -import androidx.compose.ui.platform.testTag import androidx.compose.ui.res.stringResource import androidx.compose.ui.semantics.contentDescription import androidx.compose.ui.semantics.semantics -import androidx.compose.ui.semantics.testTagsAsResourceId import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import com.airbnb.lottie.compose.LottieAnimation @@ -75,20 +73,13 @@ fun StartupScreen( } Scaffold( - modifier = Modifier.semantics { - testTagsAsResourceId = true - }, snackbarHost = { SnackbarHost( hostState = snackbarHostState, snackbar = { data -> Snackbar( snackbarData = data, - modifier = Modifier - .padding(PaddingValues(horizontal = 8.dp)) - .semantics { - testTagsAsResourceId = true - }, + modifier = Modifier.padding(PaddingValues(horizontal = 8.dp)), shape = RoundedCornerShape(24.dp) ) } @@ -129,9 +120,7 @@ fun StartupScreen( snackbarHostState.currentSnackbarData?.dismiss() showToS = true } }, - modifier = Modifier - .padding(PaddingValues(vertical = 16.dp)) - .testTag("paperize:privacy_notice_button"), + modifier = Modifier.padding(PaddingValues(vertical = 16.dp)) ) { Text(text = stringResource(R.string.privacy_notice), textAlign = TextAlign.Start) } @@ -140,9 +129,7 @@ fun StartupScreen( }, floatingActionButton = { ExtendedFloatingActionButton( - modifier = Modifier - .padding(8.dp) - .testTag("paperize:floating_agree_button"), + modifier = Modifier.padding(8.dp), onClick = { if (seenToS) { onAgree() @@ -176,11 +163,7 @@ fun StartupScreen( if (showToS) { seenToS = true AlertDialog( - modifier = Modifier - .fillMaxHeight(0.7f) - .semantics { - testTagsAsResourceId = true - }, + modifier = Modifier.fillMaxHeight(0.7f), onDismissRequest = { showToS = false }, title = { Box(modifier = Modifier.fillMaxWidth()) { @@ -194,8 +177,7 @@ fun StartupScreen( text = { PrivacyNoticeText() }, confirmButton = { Button( - onClick = { showToS = false }, - modifier = Modifier.testTag("paperize:dismiss_button"), + onClick = { showToS = false } ) { Text(stringResource(R.string.dismiss)) } diff --git a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/wallpaper_screen/WallpaperScreen.kt b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/wallpaper_screen/WallpaperScreen.kt index 6754f135..0758fc60 100644 --- a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/wallpaper_screen/WallpaperScreen.kt +++ b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/presentation/wallpaper_screen/WallpaperScreen.kt @@ -29,14 +29,16 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext -import androidx.compose.ui.semantics.semantics -import androidx.compose.ui.semantics.testTagsAsResourceId import androidx.compose.ui.unit.dp import androidx.core.content.ContextCompat import com.anthonyla.paperize.R import com.anthonyla.paperize.core.ScalingConstants import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder import com.anthonyla.paperize.feature.wallpaper.domain.model.SelectedAlbum +import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsState.EffectSettings +import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsState.ScheduleSettings +import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsState.ThemeSettings +import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsState.WallpaperSettings import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.AlbumBottomSheet import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.BlurSwitchAndSlider import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.ChangerSelectionRow @@ -54,56 +56,34 @@ import kotlinx.coroutines.launch @Composable fun WallpaperScreen( albums: List, - animate: Boolean, - darken: Boolean, - homeDarkenPercentage: Int, - lockDarkenPercentage: Int, - enableChanger: Boolean, - homeEnabled: Boolean, - homeInterval: Int, - lockInterval: Int, - lastSetTime: String?, - lockEnabled: Boolean, - nextSetTime: String?, - currentHomeWallpaper: String?, - currentLockWallpaper: String?, + homeSelectedAlbum: SelectedAlbum?, + lockSelectedAlbum: SelectedAlbum?, + wallpaperSettings: WallpaperSettings, + scheduleSettings: ScheduleSettings, + themeSettings: ThemeSettings, + effectSettings: EffectSettings, onDarkCheck: (Boolean) -> Unit, onDarkenPercentage: (Int, Int) -> Unit, onHomeCheckedChange: (Boolean) -> Unit, onLockCheckedChange: (Boolean) -> Unit, - scheduleSeparately: Boolean, + onScalingChange: (ScalingConstants) -> Unit, onScheduleSeparatelyChange: (Boolean) -> Unit, onScheduleWallpaperChanger: () -> Unit, - onScalingChange: (ScalingConstants) -> Unit, onSelectAlbum: (AlbumWithWallpaperAndFolder, Boolean, Boolean) -> Unit, onHomeTimeChange: (Int) -> Unit, onLockTimeChange: (Int) -> Unit, onStop: (Boolean, Boolean) -> Unit, onToggleChanger: (Boolean) -> Unit, - scaling: ScalingConstants, - homeSelectedAlbum: SelectedAlbum?, - lockSelectedAlbum: SelectedAlbum?, - blur: Boolean, onBlurPercentageChange: (Int, Int) -> Unit, onBlurChange: (Boolean) -> Unit, - homeBlurPercentage: Int, - lockBlurPercentage: Int, - homeVignettePercentage: Int, - lockVignettePercentage: Int, onVignettePercentageChange: (Int, Int) -> Unit, onVignetteChange: (Boolean) -> Unit, - vignette: Boolean, - homeGrayscalePercentage: Int, - lockGrayscalePercentage: Int, onGrayscalePercentageChange: (Int, Int) -> Unit, onGrayscaleChange: (Boolean) -> Unit, - grayscale: Boolean, - changeStartTime: Boolean, onChangeStartTimeToggle: (Boolean) -> Unit, - onStartTimeChange: (TimePickerState) -> Unit, - startingTime: Pair + onStartTimeChange: (TimePickerState) -> Unit ) { - val shouldShowScreen = homeEnabled || lockEnabled + val shouldShowScreen = wallpaperSettings.setHomeWallpaper || wallpaperSettings.setLockWallpaper val shouldShowSettings = shouldShowScreen && homeSelectedAlbum != null && lockSelectedAlbum != null val scrollState = rememberScrollState() val context = LocalContext.current @@ -111,8 +91,8 @@ fun WallpaperScreen( val scope = rememberCoroutineScope() val snackbarHostState = remember { SnackbarHostState() } val showInterval = rememberSaveable { mutableStateOf(false) } - val lock = rememberSaveable { mutableStateOf(false) } - val home = rememberSaveable { mutableStateOf(false) } + val lockEnabled = rememberSaveable { mutableStateOf(false) } + val homeEnabled = rememberSaveable { mutableStateOf(false) } Scaffold( snackbarHost = { @@ -126,9 +106,7 @@ fun WallpaperScreen( ) } ) }, - modifier = Modifier - .fillMaxSize() - .semantics { testTagsAsResourceId = true }, + modifier = Modifier.fillMaxSize(), content = { padding -> Column( modifier = Modifier @@ -138,27 +116,24 @@ fun WallpaperScreen( horizontalAlignment = Alignment.CenterHorizontally ) { ChangerSelectionRow( - homeEnabled = homeEnabled, - lockEnabled = lockEnabled, onHomeCheckedChange = onHomeCheckedChange, - onLockCheckedChange = onLockCheckedChange + onLockCheckedChange = onLockCheckedChange, + homeEnabled = wallpaperSettings.setHomeWallpaper, + lockEnabled = wallpaperSettings.setLockWallpaper ) - if (homeEnabled && lockEnabled) { + if (wallpaperSettings.setHomeWallpaper && wallpaperSettings.setLockWallpaper) { IndividualSchedulingAndToggleRow( - animate = animate, - scheduleSeparately = scheduleSeparately, - enableChanger = enableChanger, onToggleChanger = onToggleChanger, - onScheduleSeparatelyChange = onScheduleSeparatelyChange + onScheduleSeparatelyChange = onScheduleSeparatelyChange, + scheduleSeparately = scheduleSettings.scheduleSeparately, + enableChanger = wallpaperSettings.enableChanger, + animate = themeSettings.animate ) } - if (homeEnabled || lockEnabled) { + if (wallpaperSettings.setHomeWallpaper || wallpaperSettings.setLockWallpaper) { CurrentSelectedAlbum( homeSelectedAlbum = homeSelectedAlbum, lockSelectedAlbum = lockSelectedAlbum, - scheduleSeparately = scheduleSeparately, - animate = animate, - enableChanger = enableChanger, onToggleChanger = { scope.launch { snackbarHostState.currentSnackbarData?.dismiss() @@ -175,8 +150,8 @@ fun WallpaperScreen( onOpenBottomSheet = { changeLock, changeHome -> if (albums.firstOrNull() != null) { openBottomSheet = true - lock.value = changeLock - home.value = changeHome + lockEnabled.value = changeLock + homeEnabled.value = changeHome } else { scope.launch { snackbarHostState.currentSnackbarData?.dismiss() @@ -208,33 +183,37 @@ fun WallpaperScreen( } onStop(lock, home) } - } + }, + scheduleSeparately = scheduleSettings.scheduleSeparately, + enableChanger = wallpaperSettings.enableChanger, + animate = themeSettings.animate ) if (shouldShowSettings) { WallpaperPreviewAndScale( - currentHomeWallpaper = currentHomeWallpaper, - currentLockWallpaper = currentLockWallpaper, - darken = darken, - homeDarkenPercentage = homeDarkenPercentage, - lockDarkenPercentage = lockDarkenPercentage, - scaling = scaling, + currentHomeWallpaper = wallpaperSettings.currentHomeWallpaper, + currentLockWallpaper = wallpaperSettings.currentLockWallpaper, + scaling = wallpaperSettings.wallpaperScaling, onScalingChange = onScalingChange, - homeEnabled = homeEnabled, - lockEnabled = lockEnabled, - blur = blur, - homeBlurPercentage = homeBlurPercentage, - lockBlurPercentage = lockBlurPercentage, - vignette = vignette, - homeVignettePercentage = homeVignettePercentage, - lockVignettePercentage = lockVignettePercentage, - grayscale = grayscale, - homeGrayscalePercentage = homeGrayscalePercentage, - lockGrayscalePercentage = lockGrayscalePercentage + homeBlurPercentage = effectSettings.homeBlurPercentage, + lockBlurPercentage = effectSettings.lockBlurPercentage, + homeDarkenPercentage = effectSettings.homeDarkenPercentage, + lockDarkenPercentage = effectSettings.lockDarkenPercentage, + homeVignettePercentage = effectSettings.homeVignettePercentage, + lockVignettePercentage = effectSettings.lockVignettePercentage, + homeGrayscalePercentage = effectSettings.homeGrayscalePercentage, + lockGrayscalePercentage = effectSettings.lockGrayscalePercentage, + homeEnabled = wallpaperSettings.setHomeWallpaper, + lockEnabled = wallpaperSettings.setLockWallpaper, + darken = effectSettings.darken, + blur = effectSettings.blur, + vignette = effectSettings.vignette, + grayscale = effectSettings.grayscale ) - CurrentAndNextChange(lastSetTime, nextSetTime) + CurrentAndNextChange(scheduleSettings.lastSetTime, scheduleSettings.nextSetTime) TimeSliders( - homeInterval = homeInterval, - lockInterval = lockInterval, + homeInterval = scheduleSettings.homeInterval, + lockInterval = scheduleSettings.lockInterval, + startingTime = scheduleSettings.startTime, onHomeIntervalChange = { days, hours, minutes -> val totalMinutes = 24 * days * 60 + hours * 60 + minutes onHomeTimeChange(totalMinutes) @@ -243,52 +222,51 @@ fun WallpaperScreen( val totalMinutes = 24 * days * 60 + hours * 60 + minutes onLockTimeChange(totalMinutes) }, - showInterval = showInterval.value, - animate = animate, - onShowIntervalChange = { showInterval.value = it }, - scheduleSeparately = scheduleSeparately, - lockEnabled = lockEnabled, - homeEnabled = homeEnabled, onStartTimeChange = onStartTimeChange, - changeStartTime = changeStartTime, - startingTime = startingTime, - onChangeStartTimeToggle = onChangeStartTimeToggle + onShowIntervalChange = { showInterval.value = it }, + onChangeStartTimeToggle = onChangeStartTimeToggle, + homeEnabled = wallpaperSettings.setHomeWallpaper, + lockEnabled = wallpaperSettings.setLockWallpaper, + showInterval = showInterval.value, + scheduleSeparately = scheduleSettings.scheduleSeparately, + changeStartTime = scheduleSettings.changeStartTime, + animate = themeSettings.animate ) DarkenSwitchAndSlider( + homeDarkenPercentage = effectSettings.homeDarkenPercentage, + lockDarkenPercentage = effectSettings.lockDarkenPercentage, onDarkCheck = onDarkCheck, - darken = darken, onDarkenChange = onDarkenPercentage, - homeDarkenPercentage = homeDarkenPercentage, - lockDarkenPercentage = lockDarkenPercentage, - animate = animate, - bothEnabled = homeEnabled && lockEnabled + darken = effectSettings.darken, + animate = themeSettings.animate, + bothEnabled = wallpaperSettings.setHomeWallpaper && wallpaperSettings.setLockWallpaper ) BlurSwitchAndSlider( + homeBlurPercentage = effectSettings.homeBlurPercentage, + lockBlurPercentage = effectSettings.lockBlurPercentage, onBlurPercentageChange = onBlurPercentageChange, onBlurChange = onBlurChange, - blur = blur, - homeBlurPercentage = homeBlurPercentage, - lockBlurPercentage = lockBlurPercentage, - animate = animate, - bothEnabled = homeEnabled && lockEnabled + blur = effectSettings.blur, + animate = themeSettings.animate, + bothEnabled = wallpaperSettings.setHomeWallpaper && wallpaperSettings.setLockWallpaper ) VignetteSwitchAndSlider( + homeVignettePercentage = effectSettings.homeVignettePercentage, + lockVignettePercentage = effectSettings.lockVignettePercentage, onVignettePercentageChange = onVignettePercentageChange, onVignetteChange = onVignetteChange, - vignette = vignette, - homeVignettePercentage = homeVignettePercentage, - lockVignettePercentage = lockVignettePercentage, - animate = animate, - bothEnabled = homeEnabled && lockEnabled + vignette = effectSettings.vignette, + animate = themeSettings.animate, + bothEnabled = wallpaperSettings.setHomeWallpaper && wallpaperSettings.setLockWallpaper ) GrayscaleSwitchAndSlider( + homeGrayscalePercentage = effectSettings.homeGrayscalePercentage, + lockGrayscalePercentage = effectSettings.lockGrayscalePercentage, onGrayscalePercentageChange = onGrayscalePercentageChange, onGrayscaleChange = onGrayscaleChange, - grayscale = grayscale, - homeGrayscalePercentage = homeGrayscalePercentage, - lockGrayscalePercentage = lockGrayscalePercentage, - animate = animate, - bothEnabled = homeEnabled && lockEnabled + grayscale = effectSettings.grayscale, + animate = themeSettings.animate, + bothEnabled = wallpaperSettings.setHomeWallpaper && wallpaperSettings.setLockWallpaper ) } } @@ -298,7 +276,6 @@ fun WallpaperScreen( albums = albums, homeSelectedAlbum = homeSelectedAlbum, lockSelectedAlbum = lockSelectedAlbum, - onDismiss = { openBottomSheet = false }, onSelect = { album -> openBottomSheet = false if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { @@ -310,16 +287,17 @@ fun WallpaperScreen( } } else { - onSelectAlbum(album, lock.value, home.value) + onSelectAlbum(album, lockEnabled.value, homeEnabled.value) onScheduleWallpaperChanger() } } else { - onSelectAlbum(album, lock.value, home.value) + onSelectAlbum(album, lockEnabled.value, homeEnabled.value) onScheduleWallpaperChanger() } }, - animate = animate + onDismiss = { openBottomSheet = false }, + animate = themeSettings.animate ) } }, diff --git a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/util/navigation/AnimatedScreen.kt b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/util/navigation/AnimatedScreen.kt new file mode 100644 index 00000000..305b98ba --- /dev/null +++ b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/util/navigation/AnimatedScreen.kt @@ -0,0 +1,42 @@ +package com.anthonyla.paperize.feature.wallpaper.util.navigation + +import androidx.compose.animation.AnimatedContentScope +import androidx.compose.runtime.Composable +import androidx.navigation.NavBackStackEntry +import androidx.navigation.NavDeepLink +import androidx.navigation.NavGraphBuilder +import androidx.navigation.NavType +import androidx.navigation.compose.composable +import com.anthonyla.paperize.feature.wallpaper.util.navigation.NavConstants.INITIAL_OFFSET +import kotlin.reflect.KType + +inline fun NavGraphBuilder.animatedScreen( + typeMap: Map> = emptyMap(), + animate: Boolean = true, + deepLinks: List = emptyList(), + noinline content: @Composable AnimatedContentScope.(NavBackStackEntry) -> Unit +) = composable( + typeMap = typeMap, + deepLinks = deepLinks, + enterTransition = { + if (animate) { + sharedXTransitionIn(initial = { (it * INITIAL_OFFSET).toInt() }) + } else { null } + }, + exitTransition = { + if (animate) { + sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() }) + } else { null } + }, + popEnterTransition = { + if (animate) { + sharedXTransitionIn(initial = { -(it * INITIAL_OFFSET).toInt() }) + } else { null } + }, + popExitTransition = { + if (animate) { + sharedXTransitionOut(target = { -(it * INITIAL_OFFSET).toInt() }) + } else { null } + }, + content = content +) \ No newline at end of file diff --git a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/util/navigation/NavScreens.kt b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/util/navigation/NavScreens.kt index 03c56896..037bac70 100644 --- a/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/util/navigation/NavScreens.kt +++ b/app/src/main/java/com/anthonyla/paperize/feature/wallpaper/util/navigation/NavScreens.kt @@ -49,7 +49,7 @@ data class AlbumView(val initialAlbumName: String) * Data class for AddEdit screen */ @Serializable -data class AddEdit(val wallpaper: String) +data class AddAlbum(val wallpaper: String) /** * Data class for WallpaperView screen