chore/Refactor code

This commit is contained in:
Anthony La committed 2024-11-03 16:53:14 -08:00
1 parent a26f7e30a4
commit 68e6544da8
15 files changed
+996 -1174

No files matched your search

+2 -2
View File
@@ -19,9 +19,9 @@ android {
defaultConfig { defaultConfig {
applicationId = "com.anthonyla.paperize" applicationId = "com.anthonyla.paperize"
minSdk = 26 minSdk = 26
targetSdk = 35 targetSdk = 36
versionCode = 35 versionCode = 35
versionName = "2.3.3" versionName = "2.4.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables { vectorDrawables {
useSupportLibrary = true useSupportLibrary = true
@@ -13,5 +13,6 @@ interface SettingsDataStore {
suspend fun deleteBoolean(key: String) suspend fun deleteBoolean(key: String)
suspend fun deleteString(key: String) suspend fun deleteString(key: String)
suspend fun deleteInt(key: String) suspend fun deleteInt(key: String)
suspend fun clear(keys: List<String>)
suspend fun clearPreferences() suspend fun clearPreferences()
} }
@@ -9,7 +9,6 @@ import androidx.datastore.preferences.core.stringPreferencesKey
import androidx.datastore.preferences.preferencesDataStore import androidx.datastore.preferences.preferencesDataStore
import com.anthonyla.paperize.core.SettingsConstants.SETTINGS_DATASTORE import com.anthonyla.paperize.core.SettingsConstants.SETTINGS_DATASTORE
import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.first
import javax.inject.Inject
private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = SETTINGS_DATASTORE) private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = SETTINGS_DATASTORE)
@@ -95,4 +94,17 @@ class SettingsDataStoreImpl(private val context: Context) : SettingsDataStore {
it.clear() it.clear()
} }
} }
override suspend fun clear(keys: List<String>) {
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))
}
}
}
}
} }
@@ -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.AlbumsEvent
import com.anthonyla.paperize.feature.wallpaper.presentation.album.AlbumsViewModel 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.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.settings_screen.SettingsViewModel
import com.anthonyla.paperize.feature.wallpaper.presentation.themes.PaperizeTheme import com.anthonyla.paperize.feature.wallpaper.presentation.themes.PaperizeTheme
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.WallpaperEvent import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.WallpaperEvent
@@ -79,99 +80,24 @@ class MainActivity : ComponentActivity() {
splashScreen.setKeepOnScreenCondition { settingsViewModel.setKeepOnScreenCondition } splashScreen.setKeepOnScreenCondition { settingsViewModel.setKeepOnScreenCondition }
setContent { setContent {
val scheduler = WallpaperAlarmSchedulerImpl(context)
val settingsState = settingsViewModel.state.collectAsStateWithLifecycle() val settingsState = settingsViewModel.state.collectAsStateWithLifecycle()
val isFirstLaunch = runBlocking { settingsDataStoreImpl.getBoolean(SettingsConstants.FIRST_LAUNCH) } ?: true val isFirstLaunch = runBlocking { settingsDataStoreImpl.getBoolean(SettingsConstants.FIRST_LAUNCH) } ?: true
val scheduler = WallpaperAlarmSchedulerImpl(context)
if (isFirstLaunch) { if (isFirstLaunch) {
scheduler.cancelWallpaperAlarm() handleFirstLaunch(scheduler)
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)
}
} }
LifecycleEventEffect(Lifecycle.Event.ON_CREATE) { LifecycleEventEffect(Lifecycle.Event.ON_CREATE) {
lifecycleScope.launch { lifecycleScope.launch {
if (settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_CHANGER) == true) { handleWallpaperScheduling(settingsState.value, scheduler)
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
))
}
}
}
}
}
}
} }
} }
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) { Surface(tonalElevation = 5.dp) {
PaperizeApp(isFirstLaunch, scheduler) 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() { override fun onResume() {
super.onResume() super.onResume()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
File diff suppressed because it is too large. Load diff
@@ -23,9 +23,6 @@ import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier 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 androidx.compose.ui.unit.dp
import com.anthonyla.paperize.core.ScalingConstants import com.anthonyla.paperize.core.ScalingConstants
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder 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.HomeTopBar
import com.anthonyla.paperize.feature.wallpaper.presentation.home_screen.components.getTabItems 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.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 import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.WallpaperScreen
@OptIn(ExperimentalMaterial3Api::class, ExperimentalComposeUiApi::class) @OptIn(ExperimentalMaterial3Api::class, ExperimentalComposeUiApi::class)
@Composable @Composable
fun HomeScreen( fun HomeScreen(
albums: List<AlbumWithWallpaperAndFolder>, albums: List<AlbumWithWallpaperAndFolder>,
animate : Boolean, homeSelectedAlbum: SelectedAlbum?,
darken: Boolean, lockSelectedAlbum: SelectedAlbum?,
homeDarkenPercentage: Int, themeSettings: ThemeSettings,
lockDarkenPercentage: Int, wallpaperSettings: WallpaperSettings,
enableChanger: Boolean, scheduleSettings: ScheduleSettings,
homeEnabled : Boolean, effectSettings: EffectSettings,
homeInterval: Int, onNavigateAddWallpaper: (String) -> Unit,
lockInterval: Int,
lastSetTime: String?,
lockEnabled : Boolean,
navigateToAddWallpaperScreen: (String) -> Unit,
nextSetTime: String?,
onViewAlbum: (String) -> Unit, onViewAlbum: (String) -> Unit,
onDarkCheck: (Boolean) -> Unit, onDarkCheck: (Boolean) -> Unit,
onDarkenPercentage: (Int, Int) -> Unit, onDarkenPercentage: (Int, Int) -> Unit,
@@ -66,31 +62,14 @@ fun HomeScreen(
onSettingsClick: () -> Unit, onSettingsClick: () -> Unit,
onStop: (Boolean, Boolean) -> Unit, onStop: (Boolean, Boolean) -> Unit,
onToggleChanger: (Boolean) -> Unit, onToggleChanger: (Boolean) -> Unit,
scaling: ScalingConstants,
scheduleSeparately: Boolean,
blur: Boolean,
onBlurPercentageChange: (Int, Int) -> Unit, onBlurPercentageChange: (Int, Int) -> Unit,
onBlurChange: (Boolean) -> Unit, onBlurChange: (Boolean) -> Unit,
homeBlurPercentage: Int,
lockBlurPercentage: Int,
currentHomeWallpaper: String?,
currentLockWallpaper: String?,
homeSelectedAlbum: SelectedAlbum?,
lockSelectedAlbum: SelectedAlbum?,
homeVignettePercentage: Int,
lockVignettePercentage: Int,
onVignettePercentageChange: (Int, Int) -> Unit, onVignettePercentageChange: (Int, Int) -> Unit,
onVignetteChange: (Boolean) -> Unit, onVignetteChange: (Boolean) -> Unit,
vignette: Boolean,
homeGrayscalePercentage: Int,
lockGrayscalePercentage: Int,
onGrayscalePercentageChange: (Int, Int) -> Unit, onGrayscalePercentageChange: (Int, Int) -> Unit,
onGrayscaleChange: (Boolean) -> Unit, onGrayscaleChange: (Boolean) -> Unit,
grayscale: Boolean,
changeStartTime: Boolean,
onChangeStartTimeToggle: (Boolean) -> Unit, onChangeStartTimeToggle: (Boolean) -> Unit,
onStartTimeChange: (TimePickerState) -> Unit, onStartTimeChange: (TimePickerState) -> Unit
startingTime: Pair<Int, Int>
) { ) {
val tabItems = getTabItems() val tabItems = getTabItems()
val pagerState = rememberPagerState(0) { tabItems.size } val pagerState = rememberPagerState(0) { tabItems.size }
@@ -98,7 +77,7 @@ fun HomeScreen(
var addAlbumDialog by rememberSaveable { mutableStateOf(false) } var addAlbumDialog by rememberSaveable { mutableStateOf(false) }
if (addAlbumDialog) AddAlbumDialog( if (addAlbumDialog) AddAlbumDialog(
onDismissRequest = { addAlbumDialog = false }, onDismissRequest = { addAlbumDialog = false },
onConfirmation = { navigateToAddWallpaperScreen(it) } onConfirmation = { onNavigateAddWallpaper(it) }
) )
LaunchedEffect(tabIndex) { LaunchedEffect(tabIndex) {
@@ -109,9 +88,6 @@ fun HomeScreen(
} }
Scaffold ( Scaffold (
modifier = Modifier.semantics {
testTagsAsResourceId = true
},
topBar = { topBar = {
HomeTopBar( HomeTopBar(
showSelectionModeAppBar = false, showSelectionModeAppBar = false,
@@ -148,8 +124,7 @@ fun HomeScreen(
imageVector = if (index == tabIndex) item.filledIcon else item.unfilledIcon, imageVector = if (index == tabIndex) item.filledIcon else item.unfilledIcon,
contentDescription = item.title contentDescription = item.title
) )
}, }
modifier = Modifier.testTag("paperize:${item.title}_button"),
) )
} }
} }
@@ -160,54 +135,32 @@ fun HomeScreen(
when (index.coerceIn(tabItems.indices)) { when (index.coerceIn(tabItems.indices)) {
0 -> WallpaperScreen( 0 -> WallpaperScreen(
albums = albums, albums = albums,
animate = animate, homeSelectedAlbum = homeSelectedAlbum,
darken = darken, lockSelectedAlbum = lockSelectedAlbum,
homeDarkenPercentage = homeDarkenPercentage, themeSettings = themeSettings,
lockDarkenPercentage = lockDarkenPercentage, wallpaperSettings = wallpaperSettings,
enableChanger = enableChanger, scheduleSettings = scheduleSettings,
homeEnabled = homeEnabled, effectSettings = effectSettings,
homeInterval = homeInterval,
lockInterval = lockInterval,
lastSetTime = lastSetTime,
lockEnabled = lockEnabled,
nextSetTime = nextSetTime,
onDarkCheck = onDarkCheck, onDarkCheck = onDarkCheck,
onDarkenPercentage = onDarkenPercentage, onDarkenPercentage = onDarkenPercentage,
onHomeCheckedChange = onHomeCheckedChange, onHomeCheckedChange = onHomeCheckedChange,
onLockCheckedChange = onLockCheckedChange, onLockCheckedChange = onLockCheckedChange,
scheduleSeparately = scheduleSeparately, onScalingChange = onScalingChange,
onScheduleSeparatelyChange = onScheduleSeparatelyChange, onScheduleSeparatelyChange = onScheduleSeparatelyChange,
onScheduleWallpaperChanger = onScheduleWallpaperChanger, onScheduleWallpaperChanger = onScheduleWallpaperChanger,
onScalingChange = onScalingChange,
onSelectAlbum = onSelectAlbum, onSelectAlbum = onSelectAlbum,
onHomeTimeChange = onHomeTimeChange, onHomeTimeChange = onHomeTimeChange,
onLockTimeChange = onLockTimeChange, onLockTimeChange = onLockTimeChange,
onStop = onStop, onStop = onStop,
onToggleChanger = onToggleChanger, onToggleChanger = onToggleChanger,
scaling = scaling,
homeSelectedAlbum = homeSelectedAlbum,
lockSelectedAlbum = lockSelectedAlbum,
blur = blur,
onBlurPercentageChange = onBlurPercentageChange, onBlurPercentageChange = onBlurPercentageChange,
onBlurChange = onBlurChange, onBlurChange = onBlurChange,
homeBlurPercentage = homeBlurPercentage,
lockBlurPercentage = lockBlurPercentage,
currentHomeWallpaper = currentHomeWallpaper,
currentLockWallpaper = currentLockWallpaper,
homeVignettePercentage = homeVignettePercentage,
lockVignettePercentage = lockVignettePercentage,
onVignettePercentageChange = onVignettePercentageChange, onVignettePercentageChange = onVignettePercentageChange,
onVignetteChange = onVignetteChange, onVignetteChange = onVignetteChange,
vignette = vignette,
homeGrayscalePercentage = homeGrayscalePercentage,
lockGrayscalePercentage = lockGrayscalePercentage,
onGrayscalePercentageChange = onGrayscalePercentageChange, onGrayscalePercentageChange = onGrayscalePercentageChange,
onGrayscaleChange = onGrayscaleChange, onGrayscaleChange = onGrayscaleChange,
grayscale = grayscale,
changeStartTime = changeStartTime,
onChangeStartTimeToggle = onChangeStartTimeToggle, onChangeStartTimeToggle = onChangeStartTimeToggle,
onStartTimeChange = onStartTimeChange, onStartTimeChange = onStartTimeChange
startingTime = startingTime
) )
else -> LibraryScreen( else -> LibraryScreen(
albums = albums, albums = albums,
@@ -17,10 +17,7 @@ import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource 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.dp
import com.anthonyla.paperize.R import com.anthonyla.paperize.R
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
@@ -35,17 +32,12 @@ fun LibraryScreen(
) { ) {
val lazyListState = rememberLazyGridState() val lazyListState = rememberLazyGridState()
Scaffold( Scaffold(
modifier = Modifier modifier = Modifier.fillMaxSize(),
.fillMaxSize()
.semantics {
testTagsAsResourceId = true
},
floatingActionButton = { floatingActionButton = {
LargeFloatingActionButton( LargeFloatingActionButton(
containerColor = MaterialTheme.colorScheme.primaryContainer, containerColor = MaterialTheme.colorScheme.primaryContainer,
contentColor = MaterialTheme.colorScheme.onPrimaryContainer, contentColor = MaterialTheme.colorScheme.onPrimaryContainer,
onClick = onAddNewAlbumClick, onClick = onAddNewAlbumClick,
modifier = Modifier.testTag("paperize:library_floating_button")
) { ) {
Icon( Icon(
Icons.Filled.Add, Icons.Filled.Add,
@@ -28,11 +28,9 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.contentDescription import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.testTagsAsResourceId
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import com.airbnb.lottie.compose.LottieAnimation import com.airbnb.lottie.compose.LottieAnimation
@@ -78,9 +76,6 @@ fun NotificationScreen(
} }
Scaffold( Scaffold(
modifier = Modifier.semantics {
testTagsAsResourceId = true
},
content = { it content = { it
Column (modifier = Modifier.padding(32.dp)) { Column (modifier = Modifier.padding(32.dp)) {
Spacer(modifier = Modifier.height(120.dp)) Spacer(modifier = Modifier.height(120.dp))
@@ -109,9 +104,7 @@ fun NotificationScreen(
}, },
floatingActionButton = { floatingActionButton = {
ExtendedFloatingActionButton( ExtendedFloatingActionButton(
modifier = Modifier modifier = Modifier.padding(8.dp),
.padding(8.dp)
.testTag("paperize:floating_notification_button"),
onClick = { askPermission.value = true }, onClick = { askPermission.value = true },
icon = { icon = {
Icon( Icon(
@@ -30,15 +30,12 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource 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.dp
import androidx.compose.ui.unit.lerp import androidx.compose.ui.unit.lerp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.anthonyla.paperize.R 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.AmoledListItem
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.AnimationListItem import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.AnimationListItem
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.ContactListItem 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.PrivacyPolicyListItem
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.ResetListItem import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.ResetListItem
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.TranslateListItem 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.CollapsingToolbarScaffold
import me.onebone.toolbar.ScrollStrategy import me.onebone.toolbar.ScrollStrategy
import me.onebone.toolbar.rememberCollapsingToolbarScaffoldState 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) @OptIn(ExperimentalMaterial3Api::class, ExperimentalComposeUiApi::class)
@Composable @Composable
fun SettingsScreen( fun SettingsScreen(
settingsState: StateFlow<SettingsState>, themeSettings: ThemeSettings,
onBackClick: () -> Unit, onBackClick: () -> Unit,
onDarkModeClick: (Boolean?) -> Unit, onDarkModeClick: (Boolean?) -> Unit,
onAmoledClick: (Boolean) -> Unit, onAmoledClick: (Boolean) -> Unit,
@@ -70,31 +92,11 @@ fun SettingsScreen(
onResetClick: () -> Unit, onResetClick: () -> Unit,
onContactClick: () -> Unit onContactClick: () -> Unit
) { ) {
val topBarState = rememberCollapsingToolbarScaffoldState()
val state = settingsState.collectAsStateWithLifecycle()
val context = LocalContext.current val context = LocalContext.current
val topBarState = rememberCollapsingToolbarScaffoldState()
val (dynamicPaddingStart, textSize) = calculateToolbarValues(topBarState.toolbarState.progress)
val translateLink = "https://crowdin.com/project/paperize/invite?h=d8d7a7513d2beb0c96ba9b2a5f85473e2084922" Scaffold {
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 },
) {
CollapsingToolbarScaffold( CollapsingToolbarScaffold(
state = topBarState, state = topBarState,
modifier = Modifier.fillMaxSize().padding(it), modifier = Modifier.fillMaxSize().padding(it),
@@ -103,7 +105,7 @@ fun SettingsScreen(
Box( Box(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.height(largeTopAppBarHeight) .height(ToolbarConfig.LargeTopAppBarHeight)
.background(MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp)) .background(MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp))
.pin() .pin()
) )
@@ -112,7 +114,6 @@ fun SettingsScreen(
modifier = Modifier modifier = Modifier
.padding(16.dp) .padding(16.dp)
.size(24.dp) .size(24.dp)
.testTag("paperize:settings_to_home_button"),
) { ) {
Icon( Icon(
imageVector = Icons.AutoMirrored.Filled.ArrowBack, imageVector = Icons.AutoMirrored.Filled.ArrowBack,
@@ -130,86 +131,116 @@ fun SettingsScreen(
) )
} }
) { ) {
Column( SettingsContent(
horizontalAlignment = Alignment.Start, themeSettings = themeSettings,
verticalArrangement = Arrangement.Top, onDarkModeClick = onDarkModeClick,
modifier = Modifier onAmoledClick = onAmoledClick,
.verticalScroll(rememberScrollState()) onDynamicThemingClick = onDynamicThemingClick,
.fillMaxSize() onAnimateClick = onAnimateClick,
.padding(horizontal = 24.dp) onPrivacyClick = onPrivacyClick,
.testTag("paperize:settings_column"), onLicenseClick = onLicenseClick,
) { onResetClick = onResetClick,
ListSectionTitle(stringResource(R.string.appearance)) onContactClick = onContactClick,
Spacer(modifier = Modifier.height(16.dp)) context = context
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))
}
} }
} }
} }
@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))
}
@@ -1,42 +1,57 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen
import com.anthonyla.paperize.core.ScalingConstants import com.anthonyla.paperize.core.ScalingConstants
import com.anthonyla.paperize.core.SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT import com.anthonyla.paperize.core.SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
data class SettingsState( data class SettingsState(
val firstLaunch: Boolean = true, val firstLaunch: Boolean = true,
// App settings val themeSettings: ThemeSettings = ThemeSettings(),
val darkMode: Boolean? = null, val wallpaperSettings: WallpaperSettings = WallpaperSettings(),
val amoledTheme: Boolean = false, val scheduleSettings: ScheduleSettings = ScheduleSettings(),
val dynamicTheming: Boolean = false, val effectSettings: EffectSettings = EffectSettings()
val animate: Boolean = true, ) {
// Wallpaper settings data class ThemeSettings(
val enableChanger: Boolean = false, val darkMode: Boolean? = null,
val setHomeWallpaper: Boolean = false, val amoledTheme: Boolean = false,
val setLockWallpaper: Boolean = false, val dynamicTheming: Boolean = false,
val currentHomeWallpaper: String? = null, val animate: Boolean = true
val currentLockWallpaper: String? = null, )
val homeAlbumName: String? = null,
val lockAlbumName: String? = null, data class WallpaperSettings(
val scheduleSeparately: Boolean = false, val enableChanger: Boolean = false,
val homeInterval: Int = WALLPAPER_CHANGE_INTERVAL_DEFAULT, val setHomeWallpaper: Boolean = false,
val lockInterval: Int = WALLPAPER_CHANGE_INTERVAL_DEFAULT, val setLockWallpaper: Boolean = false,
val lastSetTime: String? = null, val currentHomeWallpaper: String? = null,
val nextSetTime: String? = null, val currentLockWallpaper: String? = null,
val homeDarkenPercentage: Int = 100, val nextHomeWallpaper: String? = null,
val lockDarkenPercentage: Int = 100, val nextLockWallpaper: String? = null,
val darken: Boolean = false, val homeAlbumName: String? = null,
val blur: Boolean = false, val lockAlbumName: String? = null,
val homeBlurPercentage: Int = 0, val wallpaperScaling: ScalingConstants = ScalingConstants.FILL
val lockBlurPercentage: Int = 0, )
val vignette: Boolean = false,
val homeVignettePercentage: Int = 0, data class ScheduleSettings(
val lockVignettePercentage: Int = 0, val scheduleSeparately: Boolean = false,
val grayscale: Boolean = false, val homeInterval: Int = WALLPAPER_CHANGE_INTERVAL_DEFAULT,
val homeGrayscalePercentage: Int = 0, val lockInterval: Int = WALLPAPER_CHANGE_INTERVAL_DEFAULT,
val lockGrayscalePercentage: Int = 0, val lastSetTime: String? = null,
val wallpaperScaling: ScalingConstants = ScalingConstants.FILL, val nextSetTime: String? = null,
val nextHomeWallpaper: String? = null, val changeStartTime: Boolean = false,
val nextLockWallpaper: String? = null, val startTime: Pair<Int, Int> = Pair(0, 0)
val changeStartTime: Boolean = false, )
val startTime: Pair<Int, Int> = 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
)
}
@@ -4,7 +4,12 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.anthonyla.paperize.core.ScalingConstants import com.anthonyla.paperize.core.ScalingConstants
import com.anthonyla.paperize.core.SettingsConstants 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.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 dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
@@ -35,91 +40,89 @@ class SettingsViewModel @Inject constructor (
init { init {
currentGetJob = viewModelScope.launch(Dispatchers.IO) { currentGetJob = viewModelScope.launch(Dispatchers.IO) {
val firstLaunch = async { settingsDataStoreImpl.getBoolean(SettingsConstants.FIRST_LAUNCH) ?: true } val firstLaunch = async { settingsDataStoreImpl.getBoolean(SettingsConstants.FIRST_LAUNCH) ?: true }
val darkMode = async { settingsDataStoreImpl.getBoolean(SettingsConstants.DARK_MODE_TYPE) } val themeSettings = async { loadThemeSettings() }
val amoledTheme = async { settingsDataStoreImpl.getBoolean(SettingsConstants.AMOLED_THEME_TYPE) ?: false } val wallpaperSettings = async { loadWallpaperSettings() }
val dynamicTheming = async { settingsDataStoreImpl.getBoolean(SettingsConstants.DYNAMIC_THEME_TYPE) ?: false } val scheduleSettings = async { loadScheduleSettings() }
val enableChanger = async { settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_CHANGER) ?: false } val effectSettings = async { loadEffectSettings() }
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) }
_state.update { _state.update {
it.copy( 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(), firstLaunch = firstLaunch.await(),
lastSetTime = lastSetTime.await(), themeSettings = themeSettings.await(),
nextSetTime = nextSetTime.await(), wallpaperSettings = wallpaperSettings.await(),
animate = animate.await(), scheduleSettings = scheduleSettings.await(),
enableChanger = enableChanger.await(), effectSettings = effectSettings.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()
) )
} }
setKeepOnScreenCondition = false 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) { fun onEvent(event: SettingsEvent) {
when (event) { when (event) {
is SettingsEvent.SetFirstLaunch -> { is SettingsEvent.SetFirstLaunch -> {
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
settingsDataStoreImpl.putBoolean(SettingsConstants.FIRST_LAUNCH, false) settingsDataStoreImpl.putBoolean(SettingsConstants.FIRST_LAUNCH, false)
_state.update { _state.update {
it.copy( it.copy(firstLaunch = false)
firstLaunch = false
)
} }
} }
} }
@@ -127,11 +130,13 @@ class SettingsViewModel @Inject constructor (
is SettingsEvent.SetChangerToggle -> { is SettingsEvent.SetChangerToggle -> {
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
settingsDataStoreImpl.putBoolean(SettingsConstants.ENABLE_CHANGER, event.toggle) settingsDataStoreImpl.putBoolean(SettingsConstants.ENABLE_CHANGER, event.toggle)
_state.update { _state.update { currentState ->
it.copy( currentState.copy(
enableChanger = event.toggle, wallpaperSettings = currentState.wallpaperSettings.copy(
currentHomeWallpaper = if (!event.toggle) null else it.currentHomeWallpaper, enableChanger = event.toggle,
currentLockWallpaper = if (!event.toggle) null else it.currentLockWallpaper 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 -> { is SettingsEvent.Refresh -> {
currentGetJob = viewModelScope.launch(Dispatchers.IO) { currentGetJob = viewModelScope.launch(Dispatchers.IO) {
val darkMode = async { settingsDataStoreImpl.getBoolean(SettingsConstants.DARK_MODE_TYPE) } val themeSettings = async { loadThemeSettings() }
val amoledTheme = async { settingsDataStoreImpl.getBoolean(SettingsConstants.AMOLED_THEME_TYPE) ?: false } val wallpaperSettings = async { loadWallpaperSettings() }
val dynamicTheming = async { settingsDataStoreImpl.getBoolean(SettingsConstants.DYNAMIC_THEME_TYPE) ?: false } val scheduleSettings = async { loadScheduleSettings() }
val effectSettings = async { loadEffectSettings() }
val firstLaunch = async { settingsDataStoreImpl.getBoolean(SettingsConstants.FIRST_LAUNCH) ?: true } 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 { _state.update {
it.copy( it.copy(
darkMode = darkMode.await(),
amoledTheme = amoledTheme.await(),
dynamicTheming = dynamicTheming.await(),
firstLaunch = firstLaunch.await(), firstLaunch = firstLaunch.await(),
lastSetTime = lastSetTime.await(), themeSettings = themeSettings.await(),
nextSetTime = nextSetTime.await(), wallpaperSettings = wallpaperSettings.await(),
animate = animate.await(), scheduleSettings = scheduleSettings.await(),
enableChanger = enableChanger.await(), effectSettings = effectSettings.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()
) )
} }
} }
@@ -222,7 +171,9 @@ class SettingsViewModel @Inject constructor (
} }
_state.update { _state.update {
it.copy( it.copy(
darkMode = event.darkMode themeSettings = it.themeSettings.copy(
darkMode = event.darkMode
)
) )
} }
} }
@@ -236,8 +187,10 @@ class SettingsViewModel @Inject constructor (
} }
_state.update { _state.update {
it.copy( it.copy(
amoledTheme = event.amoledTheme, themeSettings = it.themeSettings.copy(
dynamicTheming = if (event.amoledTheme) false else it.dynamicTheming amoledTheme = event.amoledTheme,
dynamicTheming = if (event.amoledTheme) false else it.themeSettings.dynamicTheming
)
) )
} }
} }
@@ -251,8 +204,10 @@ class SettingsViewModel @Inject constructor (
} }
_state.update { _state.update {
it.copy( it.copy(
amoledTheme = if (event.dynamicTheming) false else it.amoledTheme, themeSettings = it.themeSettings.copy(
dynamicTheming = event.dynamicTheming 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) settingsDataStoreImpl.putBoolean(SettingsConstants.ANIMATE_TYPE, event.animate)
_state.update { _state.update {
it.copy( it.copy(
animate = event.animate themeSettings = it.themeSettings.copy(
animate = event.animate
)
) )
} }
} }
@@ -273,16 +230,17 @@ class SettingsViewModel @Inject constructor (
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
settingsDataStoreImpl.putInt(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL, event.interval) settingsDataStoreImpl.putInt(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL, event.interval)
val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT) val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
val currentTime = if (_state.value.changeStartTime) { val currentTime = if (_state.value.scheduleSettings.changeStartTime) {
LocalDateTime.now().withHour(_state.value.startTime.first).withMinute(_state.value.startTime.second) LocalDateTime.now().withHour(_state.value.scheduleSettings.startTime.first)
.withMinute(_state.value.scheduleSettings.startTime.second)
} else { } else {
LocalDateTime.now() LocalDateTime.now()
} }
val nextSetTime: String? val nextSetTime: String?
settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, currentTime.format(formatter)) 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 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) nextSetTime = (if (homeNextSetTime!!.isBefore(lockNextSetTime)) homeNextSetTime else lockNextSetTime)!!.format(formatter)
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, nextSetTime) settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, nextSetTime)
settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, homeNextSetTime.toString()) settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, homeNextSetTime.toString())
@@ -296,9 +254,11 @@ class SettingsViewModel @Inject constructor (
} }
_state.update { _state.update {
it.copy( it.copy(
homeInterval = event.interval, scheduleSettings = it.scheduleSettings.copy(
lastSetTime = currentTime.format(formatter), homeInterval = event.interval,
nextSetTime = nextSetTime lastSetTime = currentTime.format(formatter),
nextSetTime = nextSetTime
)
) )
} }
} }
@@ -308,15 +268,16 @@ class SettingsViewModel @Inject constructor (
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
settingsDataStoreImpl.putInt(SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL, event.interval) settingsDataStoreImpl.putInt(SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL, event.interval)
val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT) val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
val currentTime = if (_state.value.changeStartTime) { val currentTime = if (_state.value.scheduleSettings.changeStartTime) {
LocalDateTime.now().withHour(_state.value.startTime.first).withMinute(_state.value.startTime.second) LocalDateTime.now().withHour(_state.value.scheduleSettings.startTime.first)
.withMinute(_state.value.scheduleSettings.startTime.second)
} else { } else {
LocalDateTime.now() LocalDateTime.now()
} }
val nextSetTime: String? val nextSetTime: String?
settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, currentTime.format(formatter)) settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, currentTime.format(formatter))
if (_state.value.scheduleSeparately) { if (_state.value.scheduleSettings.scheduleSeparately) {
val nextSetTime1 = currentTime.plusMinutes(_state.value.homeInterval.toLong()) val nextSetTime1 = currentTime.plusMinutes(_state.value.scheduleSettings.homeInterval.toLong())
val nextSetTime2 = currentTime.plusMinutes(event.interval.toLong()) val nextSetTime2 = currentTime.plusMinutes(event.interval.toLong())
nextSetTime = (if (nextSetTime1!!.isBefore(nextSetTime2)) nextSetTime1 else nextSetTime2)!!.format(formatter) nextSetTime = (if (nextSetTime1!!.isBefore(nextSetTime2)) nextSetTime1 else nextSetTime2)!!.format(formatter)
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, nextSetTime) settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, nextSetTime)
@@ -331,9 +292,11 @@ class SettingsViewModel @Inject constructor (
} }
_state.update { _state.update {
it.copy( it.copy(
lockInterval = event.interval, scheduleSettings = it.scheduleSettings.copy(
lastSetTime = currentTime.format(formatter), lockInterval = event.interval,
nextSetTime = nextSetTime lastSetTime = currentTime.format(formatter),
nextSetTime = nextSetTime
)
) )
} }
} }
@@ -342,8 +305,10 @@ class SettingsViewModel @Inject constructor (
is SettingsEvent.RefreshNextSetTime -> { is SettingsEvent.RefreshNextSetTime -> {
viewModelScope.launch { viewModelScope.launch {
val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT) val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
val currentTime = if (_state.value.changeStartTime) { val currentTime = if (_state.value.scheduleSettings.changeStartTime) {
var calculatedTime = LocalDateTime.now().withHour(_state.value.startTime.first).withMinute(_state.value.startTime.second) var calculatedTime = LocalDateTime.now()
.withHour(_state.value.scheduleSettings.startTime.first)
.withMinute(_state.value.scheduleSettings.startTime.second)
if (calculatedTime.isBefore(LocalDateTime.now())) { if (calculatedTime.isBefore(LocalDateTime.now())) {
calculatedTime = calculatedTime.plusDays(1) calculatedTime = calculatedTime.plusDays(1)
} }
@@ -352,28 +317,34 @@ class SettingsViewModel @Inject constructor (
LocalDateTime.now() LocalDateTime.now()
} }
val nextSetTime = when { val nextSetTime = when {
_state.value.changeStartTime -> { _state.value.scheduleSettings.changeStartTime -> {
settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, currentTime.toString()) settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, currentTime.toString())
settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, currentTime.toString()) settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, currentTime.toString())
currentTime currentTime
} }
_state.value.scheduleSeparately -> { _state.value.scheduleSettings.scheduleSeparately -> {
settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, currentTime.plusMinutes(_state.value.homeInterval.toLong()).toString()) settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME,
settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, currentTime.plusMinutes(_state.value.lockInterval.toLong()).toString()) currentTime.plusMinutes(_state.value.scheduleSettings.homeInterval.toLong()).toString())
val nextSetTime1 = currentTime.plusMinutes(_state.value.homeInterval.toLong()) settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME,
val nextSetTime2 = currentTime.plusMinutes(_state.value.lockInterval.toLong()) 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 if (nextSetTime1.isBefore(nextSetTime2)) nextSetTime1 else nextSetTime2
} }
else -> { else -> {
settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, currentTime.plusMinutes(_state.value.homeInterval.toLong()).toString()) settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME,
settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, currentTime.plusMinutes(_state.value.lockInterval.toLong()).toString()) currentTime.plusMinutes(_state.value.scheduleSettings.homeInterval.toLong()).toString())
currentTime.plusMinutes(_state.value.homeInterval.toLong()) settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME,
currentTime.plusMinutes(_state.value.scheduleSettings.lockInterval.toLong()).toString())
currentTime.plusMinutes(_state.value.scheduleSettings.homeInterval.toLong())
} }
}.format(formatter) }.format(formatter)
_state.update { _state.update {
it.copy( it.copy(
lastSetTime = LocalDateTime.now().format(formatter), scheduleSettings = it.scheduleSettings.copy(
nextSetTime = nextSetTime, lastSetTime = LocalDateTime.now().format(formatter),
nextSetTime = nextSetTime
)
) )
} }
settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, LocalDateTime.now().format(formatter)) 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) settingsDataStoreImpl.putBoolean(SettingsConstants.ENABLE_HOME_WALLPAPER, event.home)
_state.update { _state.update {
it.copy( 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) settingsDataStoreImpl.putBoolean(SettingsConstants.ENABLE_LOCK_WALLPAPER, event.lock)
_state.update { _state.update {
it.copy( 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) settingsDataStoreImpl.putBoolean(SettingsConstants.DARKEN, event.darken)
_state.update { _state.update {
it.copy( 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) settingsDataStoreImpl.putString(SettingsConstants.WALLPAPER_SCALING, event.scaling.name)
_state.update { _state.update {
it.copy( 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) settingsDataStoreImpl.putBoolean(SettingsConstants.SCHEDULE_SEPARATELY, event.scheduleSeparately)
_state.update { _state.update {
it.copy( 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) settingsDataStoreImpl.putBoolean(SettingsConstants.BLUR, event.blur)
_state.update { _state.update {
it.copy( it.copy(
blur = event.blur effectSettings = it.effectSettings.copy(
blur = event.blur
)
) )
} }
} }
@@ -457,8 +440,10 @@ class SettingsViewModel @Inject constructor (
} }
_state.update { _state.update {
it.copy( it.copy(
homeDarkenPercentage = event.homeDarkenPercentage ?: it.homeDarkenPercentage, effectSettings = it.effectSettings.copy(
lockDarkenPercentage = event.lockDarkenPercentage ?: it.lockDarkenPercentage homeDarkenPercentage = event.homeDarkenPercentage ?: it.effectSettings.homeDarkenPercentage,
lockDarkenPercentage = event.lockDarkenPercentage ?: it.effectSettings.lockDarkenPercentage
)
) )
} }
} }
@@ -474,8 +459,10 @@ class SettingsViewModel @Inject constructor (
} }
_state.update { _state.update {
it.copy( it.copy(
homeBlurPercentage = event.homeBlurPercentage ?: it.homeBlurPercentage, effectSettings = it.effectSettings.copy(
lockBlurPercentage = event.lockBlurPercentage ?: it.lockBlurPercentage 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) settingsDataStoreImpl.putBoolean(SettingsConstants.VIGNETTE, event.vignette)
_state.update { _state.update {
it.copy( it.copy(
vignette = event.vignette effectSettings = it.effectSettings.copy(
vignette = event.vignette
)
) )
} }
} }
@@ -502,8 +491,10 @@ class SettingsViewModel @Inject constructor (
} }
_state.update { _state.update {
it.copy( it.copy(
homeVignettePercentage = event.homeVignettePercentage ?: it.homeVignettePercentage, effectSettings = it.effectSettings.copy(
lockVignettePercentage = event.lockVignettePercentage ?: it.lockVignettePercentage 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) settingsDataStoreImpl.putBoolean(SettingsConstants.GRAYSCALE, event.grayscale)
_state.update { _state.update {
it.copy( it.copy(
grayscale = event.grayscale effectSettings = it.effectSettings.copy(
grayscale = event.grayscale
)
) )
} }
} }
@@ -530,8 +523,10 @@ class SettingsViewModel @Inject constructor (
} }
_state.update { _state.update {
it.copy( it.copy(
homeGrayscalePercentage = event.homeGrayscalePercentage ?: it.homeGrayscalePercentage, effectSettings = it.effectSettings.copy(
lockGrayscalePercentage = event.lockGrayscalePercentage ?: it.lockGrayscalePercentage homeGrayscalePercentage = event.homeGrayscalePercentage ?: it.effectSettings.homeGrayscalePercentage,
lockGrayscalePercentage = event.lockGrayscalePercentage ?: it.effectSettings.lockGrayscalePercentage
)
) )
} }
} }
@@ -544,7 +539,9 @@ class SettingsViewModel @Inject constructor (
} }
_state.update { _state.update {
it.copy( it.copy(
currentHomeWallpaper = event.currentHomeWallpaper wallpaperSettings = it.wallpaperSettings.copy(
currentHomeWallpaper = event.currentHomeWallpaper
)
) )
} }
} }
@@ -557,7 +554,9 @@ class SettingsViewModel @Inject constructor (
} }
_state.update { _state.update {
it.copy( it.copy(
currentLockWallpaper = event.currentLockWallpaper wallpaperSettings = it.wallpaperSettings.copy(
currentLockWallpaper = event.currentLockWallpaper
)
) )
} }
} }
@@ -573,8 +572,10 @@ class SettingsViewModel @Inject constructor (
} }
_state.update { _state.update {
it.copy( it.copy(
currentLockWallpaper = event.currentLockWallpaper ?: it.currentLockWallpaper, wallpaperSettings = it.wallpaperSettings.copy(
currentHomeWallpaper = event.currentHomeWallpaper ?: it.currentHomeWallpaper currentLockWallpaper = event.currentLockWallpaper ?: it.wallpaperSettings.currentLockWallpaper,
currentHomeWallpaper = event.currentHomeWallpaper ?: it.wallpaperSettings.currentHomeWallpaper
)
) )
} }
} }
@@ -590,16 +591,18 @@ class SettingsViewModel @Inject constructor (
} }
val enableChanger: Boolean = when { val enableChanger: Boolean = when {
event.homeAlbumName != null && event.lockAlbumName != null -> { true } event.homeAlbumName != null && event.lockAlbumName != null -> { true }
event.homeAlbumName != null && !_state.value.lockAlbumName.isNullOrEmpty() -> { true } event.homeAlbumName != null && !_state.value.wallpaperSettings.lockAlbumName.isNullOrEmpty() -> { true }
event.lockAlbumName != null && !_state.value.homeAlbumName.isNullOrEmpty() -> { true } event.lockAlbumName != null && !_state.value.wallpaperSettings.homeAlbumName.isNullOrEmpty() -> { true }
else -> { false } else -> { false }
} }
settingsDataStoreImpl.putBoolean(SettingsConstants.ENABLE_CHANGER, enableChanger) settingsDataStoreImpl.putBoolean(SettingsConstants.ENABLE_CHANGER, enableChanger)
_state.update { _state.update {
it.copy( it.copy(
homeAlbumName = event.homeAlbumName ?: it.homeAlbumName, wallpaperSettings = it.wallpaperSettings.copy(
lockAlbumName = event.lockAlbumName ?: it.lockAlbumName, homeAlbumName = event.homeAlbumName ?: it.wallpaperSettings.homeAlbumName,
enableChanger = enableChanger lockAlbumName = event.lockAlbumName ?: it.wallpaperSettings.lockAlbumName,
enableChanger = enableChanger
)
) )
} }
} }
@@ -607,7 +610,7 @@ class SettingsViewModel @Inject constructor (
is SettingsEvent.RemoveSelectedAlbumAsType -> { is SettingsEvent.RemoveSelectedAlbumAsType -> {
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
if (_state.value.setLockWallpaper && _state.value.setHomeWallpaper) { if (_state.value.wallpaperSettings.setLockWallpaper && _state.value.wallpaperSettings.setHomeWallpaper) {
if (event.removeLock) { if (event.removeLock) {
settingsDataStoreImpl.deleteString(SettingsConstants.LOCK_ALBUM_NAME) settingsDataStoreImpl.deleteString(SettingsConstants.LOCK_ALBUM_NAME)
} }
@@ -620,15 +623,19 @@ class SettingsViewModel @Inject constructor (
settingsDataStoreImpl.deleteString(SettingsConstants.NEXT_SET_TIME) settingsDataStoreImpl.deleteString(SettingsConstants.NEXT_SET_TIME)
_state.update { _state.update {
it.copy( it.copy(
homeAlbumName = if (event.removeHome) null else it.homeAlbumName, wallpaperSettings = it.wallpaperSettings.copy(
lockAlbumName = if (event.removeLock) null else it.lockAlbumName, homeAlbumName = if (event.removeHome) null else it.wallpaperSettings.homeAlbumName,
currentHomeWallpaper = null, lockAlbumName = if (event.removeLock) null else it.wallpaperSettings.lockAlbumName,
currentLockWallpaper = null, currentHomeWallpaper = null,
nextHomeWallpaper = null, currentLockWallpaper = null,
nextLockWallpaper = null, nextHomeWallpaper = null,
enableChanger = false, nextLockWallpaper = null,
lastSetTime = null, enableChanger = false
nextSetTime = null ),
scheduleSettings = it.scheduleSettings.copy(
lastSetTime = null,
nextSetTime = null
)
) )
} }
} }
@@ -643,11 +650,13 @@ class SettingsViewModel @Inject constructor (
} }
_state.update { _state.update {
it.copy( it.copy(
homeAlbumName = if (event.removeHome) null else it.homeAlbumName, wallpaperSettings = it.wallpaperSettings.copy(
lockAlbumName = if (event.removeLock) null else it.lockAlbumName, homeAlbumName = if (event.removeHome) null else it.wallpaperSettings.homeAlbumName,
currentHomeWallpaper = if (event.removeHome) null else it.currentHomeWallpaper, lockAlbumName = if (event.removeLock) null else it.wallpaperSettings.lockAlbumName,
currentLockWallpaper = if (event.removeLock) null else it.currentLockWallpaper, currentHomeWallpaper = if (event.removeHome) null else it.wallpaperSettings.currentHomeWallpaper,
enableChanger = false currentLockWallpaper = if (event.removeLock) null else it.wallpaperSettings.currentLockWallpaper,
enableChanger = false
)
) )
} }
} }
@@ -656,13 +665,13 @@ class SettingsViewModel @Inject constructor (
is SettingsEvent.RemoveSelectedAlbumAsName -> { is SettingsEvent.RemoveSelectedAlbumAsName -> {
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
var enableChanger = _state.value.enableChanger var enableChanger = _state.value.wallpaperSettings.enableChanger
if (event.albumName == _state.value.lockAlbumName) { if (event.albumName == _state.value.wallpaperSettings.lockAlbumName) {
settingsDataStoreImpl.deleteString(SettingsConstants.LOCK_ALBUM_NAME) settingsDataStoreImpl.deleteString(SettingsConstants.LOCK_ALBUM_NAME)
settingsDataStoreImpl.deleteString(SettingsConstants.CURRENT_LOCK_WALLPAPER) settingsDataStoreImpl.deleteString(SettingsConstants.CURRENT_LOCK_WALLPAPER)
enableChanger = false enableChanger = false
} }
if (event.albumName == _state.value.homeAlbumName) { if (event.albumName == _state.value.wallpaperSettings.homeAlbumName) {
settingsDataStoreImpl.deleteString(SettingsConstants.HOME_ALBUM_NAME) settingsDataStoreImpl.deleteString(SettingsConstants.HOME_ALBUM_NAME)
settingsDataStoreImpl.deleteString(SettingsConstants.CURRENT_HOME_WALLPAPER) settingsDataStoreImpl.deleteString(SettingsConstants.CURRENT_HOME_WALLPAPER)
enableChanger = false enableChanger = false
@@ -670,14 +679,16 @@ class SettingsViewModel @Inject constructor (
settingsDataStoreImpl.putBoolean(SettingsConstants.ENABLE_CHANGER, enableChanger) settingsDataStoreImpl.putBoolean(SettingsConstants.ENABLE_CHANGER, enableChanger)
_state.update { _state.update {
it.copy( it.copy(
homeAlbumName = if (event.albumName == _state.value.homeAlbumName) null else it.homeAlbumName, wallpaperSettings = it.wallpaperSettings.copy(
lockAlbumName = if (event.albumName == _state.value.lockAlbumName) null else it.lockAlbumName, homeAlbumName = if (event.albumName == _state.value.wallpaperSettings.homeAlbumName) null else it.wallpaperSettings.homeAlbumName,
currentHomeWallpaper = if (event.albumName == _state.value.homeAlbumName) null else it.currentHomeWallpaper, lockAlbumName = if (event.albumName == _state.value.wallpaperSettings.lockAlbumName) null else it.wallpaperSettings.lockAlbumName,
currentLockWallpaper = if (event.albumName == _state.value.lockAlbumName) null else it.currentLockWallpaper, currentHomeWallpaper = if (event.albumName == _state.value.wallpaperSettings.homeAlbumName) null else it.wallpaperSettings.currentHomeWallpaper,
enableChanger = enableChanger 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 { _state.update {
it.copy( it.copy(
nextHomeWallpaper = event.nextHomeWallpaper wallpaperSettings = it.wallpaperSettings.copy(
nextHomeWallpaper = event.nextHomeWallpaper
)
) )
} }
} }
@@ -701,7 +714,9 @@ class SettingsViewModel @Inject constructor (
} }
_state.update { _state.update {
it.copy( it.copy(
nextLockWallpaper = event.nextLockWallpaper wallpaperSettings = it.wallpaperSettings.copy(
nextLockWallpaper = event.nextLockWallpaper
)
) )
} }
} }
@@ -717,8 +732,10 @@ class SettingsViewModel @Inject constructor (
} }
_state.update { _state.update {
it.copy( it.copy(
nextHomeWallpaper = event.nextHomeWallpaper ?: it.nextHomeWallpaper, wallpaperSettings = it.wallpaperSettings.copy(
nextLockWallpaper = event.nextLockWallpaper ?: it.nextLockWallpaper 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) } val nextLockWallpaper = async { settingsDataStoreImpl.getString(SettingsConstants.NEXT_LOCK_WALLPAPER) }
_state.update { _state.update {
it.copy( it.copy(
nextHomeWallpaper = nextHomeWallpaper.await(), wallpaperSettings = it.wallpaperSettings.copy(
nextLockWallpaper = nextLockWallpaper.await(), nextHomeWallpaper = nextHomeWallpaper.await(),
currentHomeWallpaper = nextHomeWallpaper.await(), nextLockWallpaper = nextLockWallpaper.await(),
currentLockWallpaper = nextLockWallpaper.await() currentHomeWallpaper = nextHomeWallpaper.await(),
currentLockWallpaper = nextLockWallpaper.await()
)
) )
} }
} }
@@ -743,9 +762,12 @@ class SettingsViewModel @Inject constructor (
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT) val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
val currentTime = if (event.changeStartTime) { val currentTime = if (event.changeStartTime) {
LocalDateTime.now().withHour(_state.value.startTime.first).withMinute(_state.value.startTime.second).let { LocalDateTime.now()
if (it.isBefore(LocalDateTime.now())) it.plusDays(1) else it .withHour(_state.value.scheduleSettings.startTime.first)
} .withMinute(_state.value.scheduleSettings.startTime.second)
.let {
if (it.isBefore(LocalDateTime.now())) it.plusDays(1) else it
}
} else { } else {
LocalDateTime.now() LocalDateTime.now()
} }
@@ -755,16 +777,16 @@ class SettingsViewModel @Inject constructor (
settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, currentTime.toString()) settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, currentTime.toString())
currentTime.format(formatter) currentTime.format(formatter)
} }
_state.value.scheduleSeparately -> { _state.value.scheduleSettings.scheduleSeparately -> {
val nextSetTime1 = currentTime.plusMinutes(_state.value.homeInterval.toLong()) val nextSetTime1 = currentTime.plusMinutes(_state.value.scheduleSettings.homeInterval.toLong())
val nextSetTime2 = currentTime.plusMinutes(_state.value.lockInterval.toLong()) val nextSetTime2 = currentTime.plusMinutes(_state.value.scheduleSettings.lockInterval.toLong())
val nextSetTime = if (nextSetTime1.isBefore(nextSetTime2)) nextSetTime1 else nextSetTime2 val nextSetTime = if (nextSetTime1.isBefore(nextSetTime2)) nextSetTime1 else nextSetTime2
settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, nextSetTime1.toString()) settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, nextSetTime1.toString())
settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, nextSetTime2.toString()) settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, nextSetTime2.toString())
nextSetTime.format(formatter) nextSetTime.format(formatter)
} }
else -> { 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.HOME_NEXT_SET_TIME, nextSetTime.toString())
settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, nextSetTime.toString()) settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, nextSetTime.toString())
nextSetTime.format(formatter) nextSetTime.format(formatter)
@@ -772,8 +794,10 @@ class SettingsViewModel @Inject constructor (
} }
_state.update { _state.update {
it.copy( it.copy(
changeStartTime = event.changeStartTime, scheduleSettings = it.scheduleSettings.copy(
nextSetTime = nextSetTime changeStartTime = event.changeStartTime,
nextSetTime = nextSetTime
)
) )
} }
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, nextSetTime) settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, nextSetTime)
@@ -790,9 +814,11 @@ class SettingsViewModel @Inject constructor (
val nextSetTime = currentTime.format(formatter) val nextSetTime = currentTime.format(formatter)
_state.update { _state.update {
it.copy( it.copy(
startTime = Pair(event.hour, event.minute), scheduleSettings = it.scheduleSettings.copy(
changeStartTime = true, startTime = Pair(event.hour, event.minute),
nextSetTime = nextSetTime changeStartTime = true,
nextSetTime = nextSetTime
)
) )
} }
settingsDataStoreImpl.run { settingsDataStoreImpl.run {
@@ -808,81 +834,54 @@ class SettingsViewModel @Inject constructor (
is SettingsEvent.Reset -> { is SettingsEvent.Reset -> {
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch(Dispatchers.IO) {
settingsDataStoreImpl.deleteBoolean(SettingsConstants.DARK_MODE_TYPE) val keysToDelete = listOf(
settingsDataStoreImpl.deleteBoolean(SettingsConstants.AMOLED_THEME_TYPE) SettingsConstants.DARK_MODE_TYPE,
settingsDataStoreImpl.deleteBoolean(SettingsConstants.DYNAMIC_THEME_TYPE) SettingsConstants.AMOLED_THEME_TYPE,
settingsDataStoreImpl.deleteBoolean(SettingsConstants.FIRST_LAUNCH) SettingsConstants.DYNAMIC_THEME_TYPE,
settingsDataStoreImpl.deleteString(SettingsConstants.LAST_SET_TIME) SettingsConstants.FIRST_LAUNCH,
settingsDataStoreImpl.deleteString(SettingsConstants.NEXT_SET_TIME) SettingsConstants.LAST_SET_TIME,
settingsDataStoreImpl.deleteBoolean(SettingsConstants.ANIMATE_TYPE) SettingsConstants.NEXT_SET_TIME,
settingsDataStoreImpl.deleteBoolean(SettingsConstants.ENABLE_CHANGER) SettingsConstants.ANIMATE_TYPE,
settingsDataStoreImpl.deleteInt(SettingsConstants.HOME_DARKEN_PERCENTAGE) SettingsConstants.ENABLE_CHANGER,
settingsDataStoreImpl.deleteInt(SettingsConstants.LOCK_DARKEN_PERCENTAGE) SettingsConstants.HOME_DARKEN_PERCENTAGE,
settingsDataStoreImpl.deleteBoolean(SettingsConstants.DARKEN) SettingsConstants.LOCK_DARKEN_PERCENTAGE,
settingsDataStoreImpl.deleteString(SettingsConstants.WALLPAPER_SCALING) SettingsConstants.DARKEN,
settingsDataStoreImpl.deleteBoolean(SettingsConstants.ENABLE_HOME_WALLPAPER) SettingsConstants.WALLPAPER_SCALING,
settingsDataStoreImpl.deleteBoolean(SettingsConstants.ENABLE_LOCK_WALLPAPER) SettingsConstants.ENABLE_HOME_WALLPAPER,
settingsDataStoreImpl.deleteString(SettingsConstants.CURRENT_HOME_WALLPAPER) SettingsConstants.ENABLE_LOCK_WALLPAPER,
settingsDataStoreImpl.deleteString(SettingsConstants.CURRENT_LOCK_WALLPAPER) SettingsConstants.CURRENT_HOME_WALLPAPER,
settingsDataStoreImpl.deleteString(SettingsConstants.HOME_ALBUM_NAME) SettingsConstants.CURRENT_LOCK_WALLPAPER,
settingsDataStoreImpl.deleteString(SettingsConstants.LOCK_ALBUM_NAME) SettingsConstants.HOME_ALBUM_NAME,
settingsDataStoreImpl.deleteInt(SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL) SettingsConstants.LOCK_ALBUM_NAME,
settingsDataStoreImpl.deleteInt(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL) SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL,
settingsDataStoreImpl.deleteBoolean(SettingsConstants.SCHEDULE_SEPARATELY) SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL,
settingsDataStoreImpl.deleteBoolean(SettingsConstants.BLUR) SettingsConstants.SCHEDULE_SEPARATELY,
settingsDataStoreImpl.deleteInt(SettingsConstants.HOME_BLUR_PERCENTAGE) SettingsConstants.BLUR,
settingsDataStoreImpl.deleteInt(SettingsConstants.LOCK_BLUR_PERCENTAGE) SettingsConstants.HOME_BLUR_PERCENTAGE,
settingsDataStoreImpl.deleteBoolean(SettingsConstants.FIRST_SET) SettingsConstants.LOCK_BLUR_PERCENTAGE,
settingsDataStoreImpl.deleteString(SettingsConstants.HOME_NEXT_SET_TIME) SettingsConstants.FIRST_SET,
settingsDataStoreImpl.deleteString(SettingsConstants.LOCK_NEXT_SET_TIME) SettingsConstants.HOME_NEXT_SET_TIME,
settingsDataStoreImpl.deleteString(SettingsConstants.NEXT_HOME_WALLPAPER) SettingsConstants.LOCK_NEXT_SET_TIME,
settingsDataStoreImpl.deleteString(SettingsConstants.NEXT_LOCK_WALLPAPER) SettingsConstants.NEXT_HOME_WALLPAPER,
settingsDataStoreImpl.deleteBoolean(SettingsConstants.VIGNETTE) SettingsConstants.NEXT_LOCK_WALLPAPER,
settingsDataStoreImpl.deleteInt(SettingsConstants.HOME_VIGNETTE_PERCENTAGE) SettingsConstants.VIGNETTE,
settingsDataStoreImpl.deleteInt(SettingsConstants.LOCK_VIGNETTE_PERCENTAGE) SettingsConstants.HOME_VIGNETTE_PERCENTAGE,
settingsDataStoreImpl.deleteBoolean(SettingsConstants.GRAYSCALE) SettingsConstants.LOCK_VIGNETTE_PERCENTAGE,
settingsDataStoreImpl.deleteInt(SettingsConstants.HOME_GRAYSCALE_PERCENTAGE) SettingsConstants.GRAYSCALE,
settingsDataStoreImpl.deleteInt(SettingsConstants.LOCK_GRAYSCALE_PERCENTAGE) SettingsConstants.HOME_GRAYSCALE_PERCENTAGE,
settingsDataStoreImpl.deleteBoolean(SettingsConstants.CHANGE_START_TIME) SettingsConstants.LOCK_GRAYSCALE_PERCENTAGE,
settingsDataStoreImpl.deleteInt(SettingsConstants.START_HOUR) SettingsConstants.CHANGE_START_TIME,
settingsDataStoreImpl.deleteInt(SettingsConstants.START_MINUTE) SettingsConstants.START_HOUR,
SettingsConstants.START_MINUTE
)
settingsDataStoreImpl.clear(keysToDelete)
_state.update { _state.update {
it.copy( it.copy(
darkMode = null,
amoledTheme = false,
dynamicTheming = false,
firstLaunch = true, firstLaunch = true,
lastSetTime = null, themeSettings = ThemeSettings(),
nextSetTime = null, scheduleSettings = ScheduleSettings(),
animate = true, wallpaperSettings = WallpaperSettings(),
enableChanger = false, effectSettings = EffectSettings()
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)
) )
} }
} }
@@ -37,11 +37,9 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.contentDescription import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.testTagsAsResourceId
import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import com.airbnb.lottie.compose.LottieAnimation import com.airbnb.lottie.compose.LottieAnimation
@@ -75,20 +73,13 @@ fun StartupScreen(
} }
Scaffold( Scaffold(
modifier = Modifier.semantics {
testTagsAsResourceId = true
},
snackbarHost = { snackbarHost = {
SnackbarHost( SnackbarHost(
hostState = snackbarHostState, hostState = snackbarHostState,
snackbar = { data -> snackbar = { data ->
Snackbar( Snackbar(
snackbarData = data, snackbarData = data,
modifier = Modifier modifier = Modifier.padding(PaddingValues(horizontal = 8.dp)),
.padding(PaddingValues(horizontal = 8.dp))
.semantics {
testTagsAsResourceId = true
},
shape = RoundedCornerShape(24.dp) shape = RoundedCornerShape(24.dp)
) )
} }
@@ -129,9 +120,7 @@ fun StartupScreen(
snackbarHostState.currentSnackbarData?.dismiss() snackbarHostState.currentSnackbarData?.dismiss()
showToS = true showToS = true
} }, } },
modifier = Modifier modifier = Modifier.padding(PaddingValues(vertical = 16.dp))
.padding(PaddingValues(vertical = 16.dp))
.testTag("paperize:privacy_notice_button"),
) { ) {
Text(text = stringResource(R.string.privacy_notice), textAlign = TextAlign.Start) Text(text = stringResource(R.string.privacy_notice), textAlign = TextAlign.Start)
} }
@@ -140,9 +129,7 @@ fun StartupScreen(
}, },
floatingActionButton = { floatingActionButton = {
ExtendedFloatingActionButton( ExtendedFloatingActionButton(
modifier = Modifier modifier = Modifier.padding(8.dp),
.padding(8.dp)
.testTag("paperize:floating_agree_button"),
onClick = { onClick = {
if (seenToS) { if (seenToS) {
onAgree() onAgree()
@@ -176,11 +163,7 @@ fun StartupScreen(
if (showToS) { if (showToS) {
seenToS = true seenToS = true
AlertDialog( AlertDialog(
modifier = Modifier modifier = Modifier.fillMaxHeight(0.7f),
.fillMaxHeight(0.7f)
.semantics {
testTagsAsResourceId = true
},
onDismissRequest = { showToS = false }, onDismissRequest = { showToS = false },
title = { title = {
Box(modifier = Modifier.fillMaxWidth()) { Box(modifier = Modifier.fillMaxWidth()) {
@@ -194,8 +177,7 @@ fun StartupScreen(
text = { PrivacyNoticeText() }, text = { PrivacyNoticeText() },
confirmButton = { confirmButton = {
Button( Button(
onClick = { showToS = false }, onClick = { showToS = false }
modifier = Modifier.testTag("paperize:dismiss_button"),
) { ) {
Text(stringResource(R.string.dismiss)) Text(stringResource(R.string.dismiss))
} }
@@ -29,14 +29,16 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext 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.compose.ui.unit.dp
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import com.anthonyla.paperize.R import com.anthonyla.paperize.R
import com.anthonyla.paperize.core.ScalingConstants import com.anthonyla.paperize.core.ScalingConstants
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
import com.anthonyla.paperize.feature.wallpaper.domain.model.SelectedAlbum 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.AlbumBottomSheet
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.BlurSwitchAndSlider import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.BlurSwitchAndSlider
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.ChangerSelectionRow import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.ChangerSelectionRow
@@ -54,56 +56,34 @@ import kotlinx.coroutines.launch
@Composable @Composable
fun WallpaperScreen( fun WallpaperScreen(
albums: List<AlbumWithWallpaperAndFolder>, albums: List<AlbumWithWallpaperAndFolder>,
animate: Boolean, homeSelectedAlbum: SelectedAlbum?,
darken: Boolean, lockSelectedAlbum: SelectedAlbum?,
homeDarkenPercentage: Int, wallpaperSettings: WallpaperSettings,
lockDarkenPercentage: Int, scheduleSettings: ScheduleSettings,
enableChanger: Boolean, themeSettings: ThemeSettings,
homeEnabled: Boolean, effectSettings: EffectSettings,
homeInterval: Int,
lockInterval: Int,
lastSetTime: String?,
lockEnabled: Boolean,
nextSetTime: String?,
currentHomeWallpaper: String?,
currentLockWallpaper: String?,
onDarkCheck: (Boolean) -> Unit, onDarkCheck: (Boolean) -> Unit,
onDarkenPercentage: (Int, Int) -> Unit, onDarkenPercentage: (Int, Int) -> Unit,
onHomeCheckedChange: (Boolean) -> Unit, onHomeCheckedChange: (Boolean) -> Unit,
onLockCheckedChange: (Boolean) -> Unit, onLockCheckedChange: (Boolean) -> Unit,
scheduleSeparately: Boolean, onScalingChange: (ScalingConstants) -> Unit,
onScheduleSeparatelyChange: (Boolean) -> Unit, onScheduleSeparatelyChange: (Boolean) -> Unit,
onScheduleWallpaperChanger: () -> Unit, onScheduleWallpaperChanger: () -> Unit,
onScalingChange: (ScalingConstants) -> Unit,
onSelectAlbum: (AlbumWithWallpaperAndFolder, Boolean, Boolean) -> Unit, onSelectAlbum: (AlbumWithWallpaperAndFolder, Boolean, Boolean) -> Unit,
onHomeTimeChange: (Int) -> Unit, onHomeTimeChange: (Int) -> Unit,
onLockTimeChange: (Int) -> Unit, onLockTimeChange: (Int) -> Unit,
onStop: (Boolean, Boolean) -> Unit, onStop: (Boolean, Boolean) -> Unit,
onToggleChanger: (Boolean) -> Unit, onToggleChanger: (Boolean) -> Unit,
scaling: ScalingConstants,
homeSelectedAlbum: SelectedAlbum?,
lockSelectedAlbum: SelectedAlbum?,
blur: Boolean,
onBlurPercentageChange: (Int, Int) -> Unit, onBlurPercentageChange: (Int, Int) -> Unit,
onBlurChange: (Boolean) -> Unit, onBlurChange: (Boolean) -> Unit,
homeBlurPercentage: Int,
lockBlurPercentage: Int,
homeVignettePercentage: Int,
lockVignettePercentage: Int,
onVignettePercentageChange: (Int, Int) -> Unit, onVignettePercentageChange: (Int, Int) -> Unit,
onVignetteChange: (Boolean) -> Unit, onVignetteChange: (Boolean) -> Unit,
vignette: Boolean,
homeGrayscalePercentage: Int,
lockGrayscalePercentage: Int,
onGrayscalePercentageChange: (Int, Int) -> Unit, onGrayscalePercentageChange: (Int, Int) -> Unit,
onGrayscaleChange: (Boolean) -> Unit, onGrayscaleChange: (Boolean) -> Unit,
grayscale: Boolean,
changeStartTime: Boolean,
onChangeStartTimeToggle: (Boolean) -> Unit, onChangeStartTimeToggle: (Boolean) -> Unit,
onStartTimeChange: (TimePickerState) -> Unit, onStartTimeChange: (TimePickerState) -> Unit
startingTime: Pair<Int, Int>
) { ) {
val shouldShowScreen = homeEnabled || lockEnabled val shouldShowScreen = wallpaperSettings.setHomeWallpaper || wallpaperSettings.setLockWallpaper
val shouldShowSettings = shouldShowScreen && homeSelectedAlbum != null && lockSelectedAlbum != null val shouldShowSettings = shouldShowScreen && homeSelectedAlbum != null && lockSelectedAlbum != null
val scrollState = rememberScrollState() val scrollState = rememberScrollState()
val context = LocalContext.current val context = LocalContext.current
@@ -111,8 +91,8 @@ fun WallpaperScreen(
val scope = rememberCoroutineScope() val scope = rememberCoroutineScope()
val snackbarHostState = remember { SnackbarHostState() } val snackbarHostState = remember { SnackbarHostState() }
val showInterval = rememberSaveable { mutableStateOf(false) } val showInterval = rememberSaveable { mutableStateOf(false) }
val lock = rememberSaveable { mutableStateOf(false) } val lockEnabled = rememberSaveable { mutableStateOf(false) }
val home = rememberSaveable { mutableStateOf(false) } val homeEnabled = rememberSaveable { mutableStateOf(false) }
Scaffold( Scaffold(
snackbarHost = { snackbarHost = {
@@ -126,9 +106,7 @@ fun WallpaperScreen(
) )
} }
) }, ) },
modifier = Modifier modifier = Modifier.fillMaxSize(),
.fillMaxSize()
.semantics { testTagsAsResourceId = true },
content = { padding -> content = { padding ->
Column( Column(
modifier = Modifier modifier = Modifier
@@ -138,27 +116,24 @@ fun WallpaperScreen(
horizontalAlignment = Alignment.CenterHorizontally horizontalAlignment = Alignment.CenterHorizontally
) { ) {
ChangerSelectionRow( ChangerSelectionRow(
homeEnabled = homeEnabled,
lockEnabled = lockEnabled,
onHomeCheckedChange = onHomeCheckedChange, onHomeCheckedChange = onHomeCheckedChange,
onLockCheckedChange = onLockCheckedChange onLockCheckedChange = onLockCheckedChange,
homeEnabled = wallpaperSettings.setHomeWallpaper,
lockEnabled = wallpaperSettings.setLockWallpaper
) )
if (homeEnabled && lockEnabled) { if (wallpaperSettings.setHomeWallpaper && wallpaperSettings.setLockWallpaper) {
IndividualSchedulingAndToggleRow( IndividualSchedulingAndToggleRow(
animate = animate,
scheduleSeparately = scheduleSeparately,
enableChanger = enableChanger,
onToggleChanger = onToggleChanger, onToggleChanger = onToggleChanger,
onScheduleSeparatelyChange = onScheduleSeparatelyChange onScheduleSeparatelyChange = onScheduleSeparatelyChange,
scheduleSeparately = scheduleSettings.scheduleSeparately,
enableChanger = wallpaperSettings.enableChanger,
animate = themeSettings.animate
) )
} }
if (homeEnabled || lockEnabled) { if (wallpaperSettings.setHomeWallpaper || wallpaperSettings.setLockWallpaper) {
CurrentSelectedAlbum( CurrentSelectedAlbum(
homeSelectedAlbum = homeSelectedAlbum, homeSelectedAlbum = homeSelectedAlbum,
lockSelectedAlbum = lockSelectedAlbum, lockSelectedAlbum = lockSelectedAlbum,
scheduleSeparately = scheduleSeparately,
animate = animate,
enableChanger = enableChanger,
onToggleChanger = { onToggleChanger = {
scope.launch { scope.launch {
snackbarHostState.currentSnackbarData?.dismiss() snackbarHostState.currentSnackbarData?.dismiss()
@@ -175,8 +150,8 @@ fun WallpaperScreen(
onOpenBottomSheet = { changeLock, changeHome -> onOpenBottomSheet = { changeLock, changeHome ->
if (albums.firstOrNull() != null) { if (albums.firstOrNull() != null) {
openBottomSheet = true openBottomSheet = true
lock.value = changeLock lockEnabled.value = changeLock
home.value = changeHome homeEnabled.value = changeHome
} else { } else {
scope.launch { scope.launch {
snackbarHostState.currentSnackbarData?.dismiss() snackbarHostState.currentSnackbarData?.dismiss()
@@ -208,33 +183,37 @@ fun WallpaperScreen(
} }
onStop(lock, home) onStop(lock, home)
} }
} },
scheduleSeparately = scheduleSettings.scheduleSeparately,
enableChanger = wallpaperSettings.enableChanger,
animate = themeSettings.animate
) )
if (shouldShowSettings) { if (shouldShowSettings) {
WallpaperPreviewAndScale( WallpaperPreviewAndScale(
currentHomeWallpaper = currentHomeWallpaper, currentHomeWallpaper = wallpaperSettings.currentHomeWallpaper,
currentLockWallpaper = currentLockWallpaper, currentLockWallpaper = wallpaperSettings.currentLockWallpaper,
darken = darken, scaling = wallpaperSettings.wallpaperScaling,
homeDarkenPercentage = homeDarkenPercentage,
lockDarkenPercentage = lockDarkenPercentage,
scaling = scaling,
onScalingChange = onScalingChange, onScalingChange = onScalingChange,
homeEnabled = homeEnabled, homeBlurPercentage = effectSettings.homeBlurPercentage,
lockEnabled = lockEnabled, lockBlurPercentage = effectSettings.lockBlurPercentage,
blur = blur, homeDarkenPercentage = effectSettings.homeDarkenPercentage,
homeBlurPercentage = homeBlurPercentage, lockDarkenPercentage = effectSettings.lockDarkenPercentage,
lockBlurPercentage = lockBlurPercentage, homeVignettePercentage = effectSettings.homeVignettePercentage,
vignette = vignette, lockVignettePercentage = effectSettings.lockVignettePercentage,
homeVignettePercentage = homeVignettePercentage, homeGrayscalePercentage = effectSettings.homeGrayscalePercentage,
lockVignettePercentage = lockVignettePercentage, lockGrayscalePercentage = effectSettings.lockGrayscalePercentage,
grayscale = grayscale, homeEnabled = wallpaperSettings.setHomeWallpaper,
homeGrayscalePercentage = homeGrayscalePercentage, lockEnabled = wallpaperSettings.setLockWallpaper,
lockGrayscalePercentage = lockGrayscalePercentage darken = effectSettings.darken,
blur = effectSettings.blur,
vignette = effectSettings.vignette,
grayscale = effectSettings.grayscale
) )
CurrentAndNextChange(lastSetTime, nextSetTime) CurrentAndNextChange(scheduleSettings.lastSetTime, scheduleSettings.nextSetTime)
TimeSliders( TimeSliders(
homeInterval = homeInterval, homeInterval = scheduleSettings.homeInterval,
lockInterval = lockInterval, lockInterval = scheduleSettings.lockInterval,
startingTime = scheduleSettings.startTime,
onHomeIntervalChange = { days, hours, minutes -> onHomeIntervalChange = { days, hours, minutes ->
val totalMinutes = 24 * days * 60 + hours * 60 + minutes val totalMinutes = 24 * days * 60 + hours * 60 + minutes
onHomeTimeChange(totalMinutes) onHomeTimeChange(totalMinutes)
@@ -243,52 +222,51 @@ fun WallpaperScreen(
val totalMinutes = 24 * days * 60 + hours * 60 + minutes val totalMinutes = 24 * days * 60 + hours * 60 + minutes
onLockTimeChange(totalMinutes) onLockTimeChange(totalMinutes)
}, },
showInterval = showInterval.value,
animate = animate,
onShowIntervalChange = { showInterval.value = it },
scheduleSeparately = scheduleSeparately,
lockEnabled = lockEnabled,
homeEnabled = homeEnabled,
onStartTimeChange = onStartTimeChange, onStartTimeChange = onStartTimeChange,
changeStartTime = changeStartTime, onShowIntervalChange = { showInterval.value = it },
startingTime = startingTime, onChangeStartTimeToggle = onChangeStartTimeToggle,
onChangeStartTimeToggle = onChangeStartTimeToggle homeEnabled = wallpaperSettings.setHomeWallpaper,
lockEnabled = wallpaperSettings.setLockWallpaper,
showInterval = showInterval.value,
scheduleSeparately = scheduleSettings.scheduleSeparately,
changeStartTime = scheduleSettings.changeStartTime,
animate = themeSettings.animate
) )
DarkenSwitchAndSlider( DarkenSwitchAndSlider(
homeDarkenPercentage = effectSettings.homeDarkenPercentage,
lockDarkenPercentage = effectSettings.lockDarkenPercentage,
onDarkCheck = onDarkCheck, onDarkCheck = onDarkCheck,
darken = darken,
onDarkenChange = onDarkenPercentage, onDarkenChange = onDarkenPercentage,
homeDarkenPercentage = homeDarkenPercentage, darken = effectSettings.darken,
lockDarkenPercentage = lockDarkenPercentage, animate = themeSettings.animate,
animate = animate, bothEnabled = wallpaperSettings.setHomeWallpaper && wallpaperSettings.setLockWallpaper
bothEnabled = homeEnabled && lockEnabled
) )
BlurSwitchAndSlider( BlurSwitchAndSlider(
homeBlurPercentage = effectSettings.homeBlurPercentage,
lockBlurPercentage = effectSettings.lockBlurPercentage,
onBlurPercentageChange = onBlurPercentageChange, onBlurPercentageChange = onBlurPercentageChange,
onBlurChange = onBlurChange, onBlurChange = onBlurChange,
blur = blur, blur = effectSettings.blur,
homeBlurPercentage = homeBlurPercentage, animate = themeSettings.animate,
lockBlurPercentage = lockBlurPercentage, bothEnabled = wallpaperSettings.setHomeWallpaper && wallpaperSettings.setLockWallpaper
animate = animate,
bothEnabled = homeEnabled && lockEnabled
) )
VignetteSwitchAndSlider( VignetteSwitchAndSlider(
homeVignettePercentage = effectSettings.homeVignettePercentage,
lockVignettePercentage = effectSettings.lockVignettePercentage,
onVignettePercentageChange = onVignettePercentageChange, onVignettePercentageChange = onVignettePercentageChange,
onVignetteChange = onVignetteChange, onVignetteChange = onVignetteChange,
vignette = vignette, vignette = effectSettings.vignette,
homeVignettePercentage = homeVignettePercentage, animate = themeSettings.animate,
lockVignettePercentage = lockVignettePercentage, bothEnabled = wallpaperSettings.setHomeWallpaper && wallpaperSettings.setLockWallpaper
animate = animate,
bothEnabled = homeEnabled && lockEnabled
) )
GrayscaleSwitchAndSlider( GrayscaleSwitchAndSlider(
homeGrayscalePercentage = effectSettings.homeGrayscalePercentage,
lockGrayscalePercentage = effectSettings.lockGrayscalePercentage,
onGrayscalePercentageChange = onGrayscalePercentageChange, onGrayscalePercentageChange = onGrayscalePercentageChange,
onGrayscaleChange = onGrayscaleChange, onGrayscaleChange = onGrayscaleChange,
grayscale = grayscale, grayscale = effectSettings.grayscale,
homeGrayscalePercentage = homeGrayscalePercentage, animate = themeSettings.animate,
lockGrayscalePercentage = lockGrayscalePercentage, bothEnabled = wallpaperSettings.setHomeWallpaper && wallpaperSettings.setLockWallpaper
animate = animate,
bothEnabled = homeEnabled && lockEnabled
) )
} }
} }
@@ -298,7 +276,6 @@ fun WallpaperScreen(
albums = albums, albums = albums,
homeSelectedAlbum = homeSelectedAlbum, homeSelectedAlbum = homeSelectedAlbum,
lockSelectedAlbum = lockSelectedAlbum, lockSelectedAlbum = lockSelectedAlbum,
onDismiss = { openBottomSheet = false },
onSelect = { album -> onSelect = { album ->
openBottomSheet = false openBottomSheet = false
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
@@ -310,16 +287,17 @@ fun WallpaperScreen(
} }
} }
else { else {
onSelectAlbum(album, lock.value, home.value) onSelectAlbum(album, lockEnabled.value, homeEnabled.value)
onScheduleWallpaperChanger() onScheduleWallpaperChanger()
} }
} }
else { else {
onSelectAlbum(album, lock.value, home.value) onSelectAlbum(album, lockEnabled.value, homeEnabled.value)
onScheduleWallpaperChanger() onScheduleWallpaperChanger()
} }
}, },
animate = animate onDismiss = { openBottomSheet = false },
animate = themeSettings.animate
) )
} }
}, },
@@ -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 <reified T : Any> NavGraphBuilder.animatedScreen(
typeMap: Map<KType, NavType<*>> = emptyMap(),
animate: Boolean = true,
deepLinks: List<NavDeepLink> = emptyList(),
noinline content: @Composable AnimatedContentScope.(NavBackStackEntry) -> Unit
) = composable<T>(
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
)
@@ -49,7 +49,7 @@ data class AlbumView(val initialAlbumName: String)
* Data class for AddEdit screen * Data class for AddEdit screen
*/ */
@Serializable @Serializable
data class AddEdit(val wallpaper: String) data class AddAlbum(val wallpaper: String)
/** /**
* Data class for WallpaperView screen * Data class for WallpaperView screen