chore/Refactor code
This commit is contained in:
1 parent
a26f7e30a4
commit
68e6544da8
15 files changed
+996
-1174
No files matched your search
@@ -13,5 +13,6 @@ interface SettingsDataStore {
|
||||
suspend fun deleteBoolean(key: String)
|
||||
suspend fun deleteString(key: String)
|
||||
suspend fun deleteInt(key: String)
|
||||
suspend fun clear(keys: List<String>)
|
||||
suspend fun clearPreferences()
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import androidx.datastore.preferences.core.stringPreferencesKey
|
||||
import androidx.datastore.preferences.preferencesDataStore
|
||||
import com.anthonyla.paperize.core.SettingsConstants.SETTINGS_DATASTORE
|
||||
import kotlinx.coroutines.flow.first
|
||||
import javax.inject.Inject
|
||||
|
||||
private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = SETTINGS_DATASTORE)
|
||||
|
||||
@@ -95,4 +94,17 @@ class SettingsDataStoreImpl(private val context: Context) : SettingsDataStore {
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+127
-84
@@ -35,6 +35,7 @@ import com.anthonyla.paperize.data.settings.SettingsDataStore
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album.AlbumsEvent
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.album.AlbumsViewModel
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsEvent
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsState
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsViewModel
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.themes.PaperizeTheme
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.WallpaperEvent
|
||||
@@ -79,99 +80,24 @@ class MainActivity : ComponentActivity() {
|
||||
splashScreen.setKeepOnScreenCondition { settingsViewModel.setKeepOnScreenCondition }
|
||||
|
||||
setContent {
|
||||
val scheduler = WallpaperAlarmSchedulerImpl(context)
|
||||
val settingsState = settingsViewModel.state.collectAsStateWithLifecycle()
|
||||
val isFirstLaunch = runBlocking { settingsDataStoreImpl.getBoolean(SettingsConstants.FIRST_LAUNCH) } ?: true
|
||||
val scheduler = WallpaperAlarmSchedulerImpl(context)
|
||||
if (isFirstLaunch) {
|
||||
scheduler.cancelWallpaperAlarm()
|
||||
wallpaperScreenViewModel.onEvent(WallpaperEvent.Reset())
|
||||
settingsViewModel.onEvent(SettingsEvent.Reset)
|
||||
albumsViewModel.onEvent(AlbumsEvent.Reset)
|
||||
val contentResolver = context.contentResolver
|
||||
val persistedUris = contentResolver.persistedUriPermissions
|
||||
for (permission in persistedUris) {
|
||||
contentResolver.releasePersistableUriPermission(permission.uri, Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
|
||||
}
|
||||
handleFirstLaunch(scheduler)
|
||||
}
|
||||
|
||||
LifecycleEventEffect(Lifecycle.Event.ON_CREATE) {
|
||||
lifecycleScope.launch {
|
||||
if (settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_CHANGER) == true) {
|
||||
val homeAlbumName = settingsDataStoreImpl.getString(SettingsConstants.HOME_ALBUM_NAME)
|
||||
val lockAlbumName = settingsDataStoreImpl.getString(SettingsConstants.LOCK_ALBUM_NAME)
|
||||
if (homeAlbumName.isNullOrEmpty() || lockAlbumName.isNullOrEmpty()) {
|
||||
settingsViewModel.onEvent(SettingsEvent.SetChangerToggle(false))
|
||||
}
|
||||
else {
|
||||
val shouldScheduleSeparately = settingsDataStoreImpl.getBoolean(SettingsConstants.SCHEDULE_SEPARATELY) ?: false
|
||||
val shouldScheduleAlarm = if (shouldScheduleSeparately) {
|
||||
!(isPendingIntentSet(Type.HOME.ordinal) && isPendingIntentSet(Type.LOCK.ordinal))
|
||||
} else {
|
||||
!isPendingIntentSet(Type.SINGLE.ordinal)
|
||||
}
|
||||
if (shouldScheduleAlarm) {
|
||||
scheduler.scheduleWallpaperAlarm(
|
||||
WallpaperAlarmItem(
|
||||
homeInterval = settingsDataStoreImpl.getInt(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT,
|
||||
lockInterval = settingsDataStoreImpl.getInt(SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT,
|
||||
setLock = settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_LOCK_WALLPAPER) ?: false,
|
||||
setHome = settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_HOME_WALLPAPER) ?: false,
|
||||
scheduleSeparately = shouldScheduleSeparately,
|
||||
changeStartTime = settingsDataStoreImpl.getBoolean(SettingsConstants.CHANGE_START_TIME) ?: false,
|
||||
startTime = Pair(
|
||||
settingsDataStoreImpl.getInt(SettingsConstants.START_HOUR) ?: 0,
|
||||
settingsDataStoreImpl.getInt(SettingsConstants.START_MINUTE) ?: 0
|
||||
),
|
||||
),
|
||||
origin = null,
|
||||
changeImmediate = true,
|
||||
cancelImmediate = true,
|
||||
firstLaunch = true
|
||||
)
|
||||
settingsViewModel.onEvent(SettingsEvent.RefreshNextSetTime)
|
||||
val selectedState = wallpaperScreenViewModel.state.value
|
||||
val currentHomeAlbum = selectedState.selectedAlbum?.find { it.album.initialAlbumName == settingsState.value.homeAlbumName }
|
||||
val currentLockAlbum = selectedState.selectedAlbum?.find { it.album.initialAlbumName == settingsState.value.lockAlbumName }
|
||||
when {
|
||||
settingsState.value.scheduleSeparately && settingsState.value.setHomeWallpaper && settingsState.value.setLockWallpaper -> {
|
||||
if (currentHomeAlbum != null && currentLockAlbum != null) {
|
||||
settingsViewModel.onEvent(SettingsEvent.SetCurrentWallpaper(
|
||||
currentHomeWallpaper = currentHomeAlbum.album.homeWallpapersInQueue.firstOrNull() ?: currentHomeAlbum.wallpapers.firstOrNull()?.wallpaperUri,
|
||||
currentLockWallpaper = currentLockAlbum.album.lockWallpapersInQueue.firstOrNull() ?: currentLockAlbum.wallpapers.firstOrNull()?.wallpaperUri
|
||||
))
|
||||
}
|
||||
}
|
||||
!settingsState.value.scheduleSeparately && settingsState.value.setHomeWallpaper && settingsState.value.setLockWallpaper -> {
|
||||
if (currentHomeAlbum != null && currentLockAlbum != null) {
|
||||
settingsViewModel.onEvent(SettingsEvent.SetCurrentWallpaper(
|
||||
currentHomeWallpaper = currentHomeAlbum.album.homeWallpapersInQueue.firstOrNull() ?: currentHomeAlbum.wallpapers.firstOrNull()?.wallpaperUri,
|
||||
currentLockWallpaper = currentHomeAlbum.album.homeWallpapersInQueue.firstOrNull() ?: currentHomeAlbum.wallpapers.firstOrNull()?.wallpaperUri
|
||||
))
|
||||
}
|
||||
}
|
||||
settingsState.value.setHomeWallpaper -> {
|
||||
if (currentHomeAlbum != null) {
|
||||
settingsViewModel.onEvent(SettingsEvent.SetCurrentWallpaper(
|
||||
currentHomeWallpaper = currentHomeAlbum.album.homeWallpapersInQueue.firstOrNull() ?: currentHomeAlbum.wallpapers.firstOrNull()?.wallpaperUri,
|
||||
currentLockWallpaper = if (settingsState.value.scheduleSeparately) null else currentHomeAlbum.album.homeWallpapersInQueue.firstOrNull() ?: currentHomeAlbum.wallpapers.firstOrNull()?.wallpaperUri
|
||||
))
|
||||
}
|
||||
}
|
||||
settingsState.value.setLockWallpaper -> {
|
||||
if (currentLockAlbum != null) {
|
||||
settingsViewModel.onEvent(SettingsEvent.SetCurrentWallpaper(
|
||||
currentHomeWallpaper = if (settingsState.value.scheduleSeparately) null else currentLockAlbum.album.lockWallpapersInQueue.firstOrNull() ?: currentLockAlbum.wallpapers.firstOrNull()?.wallpaperUri,
|
||||
currentLockWallpaper = currentLockAlbum.album.lockWallpapersInQueue.firstOrNull() ?: currentLockAlbum.wallpapers.firstOrNull()?.wallpaperUri
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
handleWallpaperScheduling(settingsState.value, scheduler)
|
||||
}
|
||||
}
|
||||
|
||||
PaperizeTheme(settingsState.value.darkMode, settingsState.value.amoledTheme, settingsState.value.dynamicTheming) {
|
||||
PaperizeTheme(
|
||||
darkMode = settingsState.value.themeSettings.darkMode,
|
||||
amoledMode = settingsState.value.themeSettings.amoledTheme,
|
||||
dynamicTheming = settingsState.value.themeSettings.dynamicTheming
|
||||
) {
|
||||
Surface(tonalElevation = 5.dp) {
|
||||
PaperizeApp(isFirstLaunch, scheduler)
|
||||
}
|
||||
@@ -179,6 +105,123 @@ class MainActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleFirstLaunch(scheduler: WallpaperAlarmSchedulerImpl) {
|
||||
scheduler.cancelWallpaperAlarm()
|
||||
wallpaperScreenViewModel.onEvent(WallpaperEvent.Reset())
|
||||
settingsViewModel.onEvent(SettingsEvent.Reset)
|
||||
albumsViewModel.onEvent(AlbumsEvent.Reset)
|
||||
clearPersistedUriPermissions()
|
||||
}
|
||||
|
||||
private fun clearPersistedUriPermissions() {
|
||||
val contentResolver = context.contentResolver
|
||||
val persistedUris = contentResolver.persistedUriPermissions
|
||||
for (permission in persistedUris) {
|
||||
contentResolver.releasePersistableUriPermission(
|
||||
permission.uri,
|
||||
Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleWallpaperScheduling(
|
||||
settings: SettingsState,
|
||||
scheduler: WallpaperAlarmSchedulerImpl
|
||||
) {
|
||||
val wallpaperSettings = settings.wallpaperSettings
|
||||
val scheduleSettings = settings.scheduleSettings
|
||||
|
||||
if (!wallpaperSettings.enableChanger) return
|
||||
if (wallpaperSettings.homeAlbumName.isNullOrEmpty() || wallpaperSettings.lockAlbumName.isNullOrEmpty()) {
|
||||
settingsViewModel.onEvent(SettingsEvent.SetChangerToggle(false))
|
||||
return
|
||||
}
|
||||
|
||||
val shouldScheduleAlarm = if (scheduleSettings.scheduleSeparately) {
|
||||
!(isPendingIntentSet(Type.HOME.ordinal) && isPendingIntentSet(Type.LOCK.ordinal))
|
||||
} else {
|
||||
!isPendingIntentSet(Type.SINGLE.ordinal)
|
||||
}
|
||||
|
||||
if (shouldScheduleAlarm) {
|
||||
scheduleWallpaperAlarm(settings, scheduler)
|
||||
updateCurrentWallpapers(settings)
|
||||
}
|
||||
}
|
||||
|
||||
private fun scheduleWallpaperAlarm(
|
||||
settings: SettingsState,
|
||||
scheduler: WallpaperAlarmSchedulerImpl
|
||||
) {
|
||||
val scheduleSettings = settings.scheduleSettings
|
||||
val wallpaperSettings = settings.wallpaperSettings
|
||||
|
||||
scheduler.scheduleWallpaperAlarm(
|
||||
WallpaperAlarmItem(
|
||||
homeInterval = scheduleSettings.homeInterval,
|
||||
lockInterval = scheduleSettings.lockInterval,
|
||||
setLock = wallpaperSettings.setLockWallpaper,
|
||||
setHome = wallpaperSettings.setHomeWallpaper,
|
||||
scheduleSeparately = scheduleSettings.scheduleSeparately,
|
||||
changeStartTime = scheduleSettings.changeStartTime,
|
||||
startTime = scheduleSettings.startTime
|
||||
),
|
||||
origin = null,
|
||||
changeImmediate = true,
|
||||
cancelImmediate = true,
|
||||
firstLaunch = true
|
||||
)
|
||||
settingsViewModel.onEvent(SettingsEvent.RefreshNextSetTime)
|
||||
}
|
||||
|
||||
private fun updateCurrentWallpapers(settings: SettingsState) {
|
||||
val selectedState = wallpaperScreenViewModel.state.value
|
||||
val currentHomeAlbum = selectedState.selectedAlbum?.find {
|
||||
it.album.initialAlbumName == settings.wallpaperSettings.homeAlbumName
|
||||
}
|
||||
val currentLockAlbum = selectedState.selectedAlbum?.find {
|
||||
it.album.initialAlbumName == settings.wallpaperSettings.lockAlbumName
|
||||
}
|
||||
|
||||
val wallpaperSettings = settings.wallpaperSettings
|
||||
val scheduleSettings = settings.scheduleSettings
|
||||
|
||||
when {
|
||||
scheduleSettings.scheduleSeparately && wallpaperSettings.setHomeWallpaper && wallpaperSettings.setLockWallpaper -> {
|
||||
if (currentHomeAlbum != null && currentLockAlbum != null) {
|
||||
settingsViewModel.onEvent(SettingsEvent.SetCurrentWallpaper(
|
||||
currentHomeWallpaper = currentHomeAlbum.album.homeWallpapersInQueue.firstOrNull() ?: currentHomeAlbum.wallpapers.firstOrNull()?.wallpaperUri,
|
||||
currentLockWallpaper = currentLockAlbum.album.lockWallpapersInQueue.firstOrNull() ?: currentLockAlbum.wallpapers.firstOrNull()?.wallpaperUri
|
||||
))
|
||||
}
|
||||
}
|
||||
!scheduleSettings.scheduleSeparately && wallpaperSettings.setHomeWallpaper && wallpaperSettings.setLockWallpaper -> {
|
||||
if (currentHomeAlbum != null && currentLockAlbum != null) {
|
||||
settingsViewModel.onEvent(SettingsEvent.SetCurrentWallpaper(
|
||||
currentHomeWallpaper = currentHomeAlbum.album.homeWallpapersInQueue.firstOrNull() ?: currentHomeAlbum.wallpapers.firstOrNull()?.wallpaperUri,
|
||||
currentLockWallpaper = currentHomeAlbum.album.homeWallpapersInQueue.firstOrNull() ?: currentHomeAlbum.wallpapers.firstOrNull()?.wallpaperUri
|
||||
))
|
||||
}
|
||||
}
|
||||
wallpaperSettings.setHomeWallpaper -> {
|
||||
if (currentHomeAlbum != null) {
|
||||
settingsViewModel.onEvent(SettingsEvent.SetCurrentWallpaper(
|
||||
currentHomeWallpaper = currentHomeAlbum.album.homeWallpapersInQueue.firstOrNull() ?: currentHomeAlbum.wallpapers.firstOrNull()?.wallpaperUri,
|
||||
currentLockWallpaper = if (scheduleSettings.scheduleSeparately) null else currentHomeAlbum.album.homeWallpapersInQueue.firstOrNull() ?: currentHomeAlbum.wallpapers.firstOrNull()?.wallpaperUri
|
||||
))
|
||||
}
|
||||
}
|
||||
wallpaperSettings.setLockWallpaper -> {
|
||||
if (currentLockAlbum != null) {
|
||||
settingsViewModel.onEvent(SettingsEvent.SetCurrentWallpaper(
|
||||
currentHomeWallpaper = if (scheduleSettings.scheduleSeparately) null else currentLockAlbum.album.lockWallpapersInQueue.firstOrNull() ?: currentLockAlbum.wallpapers.firstOrNull()?.wallpaperUri,
|
||||
currentLockWallpaper = currentLockAlbum.album.lockWallpapersInQueue.firstOrNull() ?: currentLockAlbum.wallpapers.firstOrNull()?.wallpaperUri
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
|
||||
+192
-411
File diff suppressed because it is too large.
Load diff
+22
-69
@@ -23,9 +23,6 @@ import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.ExperimentalComposeUiApi
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.semantics.testTagsAsResourceId
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.core.ScalingConstants
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
|
||||
@@ -34,24 +31,23 @@ import com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.co
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.home_screen.components.HomeTopBar
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.home_screen.components.getTabItems
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.library_screen.LibraryScreen
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsState.EffectSettings
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsState.ScheduleSettings
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsState.ThemeSettings
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsState.WallpaperSettings
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.WallpaperScreen
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class, ExperimentalComposeUiApi::class)
|
||||
@Composable
|
||||
fun HomeScreen(
|
||||
albums: List<AlbumWithWallpaperAndFolder>,
|
||||
animate : Boolean,
|
||||
darken: Boolean,
|
||||
homeDarkenPercentage: Int,
|
||||
lockDarkenPercentage: Int,
|
||||
enableChanger: Boolean,
|
||||
homeEnabled : Boolean,
|
||||
homeInterval: Int,
|
||||
lockInterval: Int,
|
||||
lastSetTime: String?,
|
||||
lockEnabled : Boolean,
|
||||
navigateToAddWallpaperScreen: (String) -> Unit,
|
||||
nextSetTime: String?,
|
||||
homeSelectedAlbum: SelectedAlbum?,
|
||||
lockSelectedAlbum: SelectedAlbum?,
|
||||
themeSettings: ThemeSettings,
|
||||
wallpaperSettings: WallpaperSettings,
|
||||
scheduleSettings: ScheduleSettings,
|
||||
effectSettings: EffectSettings,
|
||||
onNavigateAddWallpaper: (String) -> Unit,
|
||||
onViewAlbum: (String) -> Unit,
|
||||
onDarkCheck: (Boolean) -> Unit,
|
||||
onDarkenPercentage: (Int, Int) -> Unit,
|
||||
@@ -66,31 +62,14 @@ fun HomeScreen(
|
||||
onSettingsClick: () -> Unit,
|
||||
onStop: (Boolean, Boolean) -> Unit,
|
||||
onToggleChanger: (Boolean) -> Unit,
|
||||
scaling: ScalingConstants,
|
||||
scheduleSeparately: Boolean,
|
||||
blur: Boolean,
|
||||
onBlurPercentageChange: (Int, Int) -> Unit,
|
||||
onBlurChange: (Boolean) -> Unit,
|
||||
homeBlurPercentage: Int,
|
||||
lockBlurPercentage: Int,
|
||||
currentHomeWallpaper: String?,
|
||||
currentLockWallpaper: String?,
|
||||
homeSelectedAlbum: SelectedAlbum?,
|
||||
lockSelectedAlbum: SelectedAlbum?,
|
||||
homeVignettePercentage: Int,
|
||||
lockVignettePercentage: Int,
|
||||
onVignettePercentageChange: (Int, Int) -> Unit,
|
||||
onVignetteChange: (Boolean) -> Unit,
|
||||
vignette: Boolean,
|
||||
homeGrayscalePercentage: Int,
|
||||
lockGrayscalePercentage: Int,
|
||||
onGrayscalePercentageChange: (Int, Int) -> Unit,
|
||||
onGrayscaleChange: (Boolean) -> Unit,
|
||||
grayscale: Boolean,
|
||||
changeStartTime: Boolean,
|
||||
onChangeStartTimeToggle: (Boolean) -> Unit,
|
||||
onStartTimeChange: (TimePickerState) -> Unit,
|
||||
startingTime: Pair<Int, Int>
|
||||
onStartTimeChange: (TimePickerState) -> Unit
|
||||
) {
|
||||
val tabItems = getTabItems()
|
||||
val pagerState = rememberPagerState(0) { tabItems.size }
|
||||
@@ -98,7 +77,7 @@ fun HomeScreen(
|
||||
var addAlbumDialog by rememberSaveable { mutableStateOf(false) }
|
||||
if (addAlbumDialog) AddAlbumDialog(
|
||||
onDismissRequest = { addAlbumDialog = false },
|
||||
onConfirmation = { navigateToAddWallpaperScreen(it) }
|
||||
onConfirmation = { onNavigateAddWallpaper(it) }
|
||||
)
|
||||
|
||||
LaunchedEffect(tabIndex) {
|
||||
@@ -109,9 +88,6 @@ fun HomeScreen(
|
||||
}
|
||||
|
||||
Scaffold (
|
||||
modifier = Modifier.semantics {
|
||||
testTagsAsResourceId = true
|
||||
},
|
||||
topBar = {
|
||||
HomeTopBar(
|
||||
showSelectionModeAppBar = false,
|
||||
@@ -148,8 +124,7 @@ fun HomeScreen(
|
||||
imageVector = if (index == tabIndex) item.filledIcon else item.unfilledIcon,
|
||||
contentDescription = item.title
|
||||
)
|
||||
},
|
||||
modifier = Modifier.testTag("paperize:${item.title}_button"),
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -160,54 +135,32 @@ fun HomeScreen(
|
||||
when (index.coerceIn(tabItems.indices)) {
|
||||
0 -> WallpaperScreen(
|
||||
albums = albums,
|
||||
animate = animate,
|
||||
darken = darken,
|
||||
homeDarkenPercentage = homeDarkenPercentage,
|
||||
lockDarkenPercentage = lockDarkenPercentage,
|
||||
enableChanger = enableChanger,
|
||||
homeEnabled = homeEnabled,
|
||||
homeInterval = homeInterval,
|
||||
lockInterval = lockInterval,
|
||||
lastSetTime = lastSetTime,
|
||||
lockEnabled = lockEnabled,
|
||||
nextSetTime = nextSetTime,
|
||||
homeSelectedAlbum = homeSelectedAlbum,
|
||||
lockSelectedAlbum = lockSelectedAlbum,
|
||||
themeSettings = themeSettings,
|
||||
wallpaperSettings = wallpaperSettings,
|
||||
scheduleSettings = scheduleSettings,
|
||||
effectSettings = effectSettings,
|
||||
onDarkCheck = onDarkCheck,
|
||||
onDarkenPercentage = onDarkenPercentage,
|
||||
onHomeCheckedChange = onHomeCheckedChange,
|
||||
onLockCheckedChange = onLockCheckedChange,
|
||||
scheduleSeparately = scheduleSeparately,
|
||||
onScalingChange = onScalingChange,
|
||||
onScheduleSeparatelyChange = onScheduleSeparatelyChange,
|
||||
onScheduleWallpaperChanger = onScheduleWallpaperChanger,
|
||||
onScalingChange = onScalingChange,
|
||||
onSelectAlbum = onSelectAlbum,
|
||||
onHomeTimeChange = onHomeTimeChange,
|
||||
onLockTimeChange = onLockTimeChange,
|
||||
onStop = onStop,
|
||||
onToggleChanger = onToggleChanger,
|
||||
scaling = scaling,
|
||||
homeSelectedAlbum = homeSelectedAlbum,
|
||||
lockSelectedAlbum = lockSelectedAlbum,
|
||||
blur = blur,
|
||||
onBlurPercentageChange = onBlurPercentageChange,
|
||||
onBlurChange = onBlurChange,
|
||||
homeBlurPercentage = homeBlurPercentage,
|
||||
lockBlurPercentage = lockBlurPercentage,
|
||||
currentHomeWallpaper = currentHomeWallpaper,
|
||||
currentLockWallpaper = currentLockWallpaper,
|
||||
homeVignettePercentage = homeVignettePercentage,
|
||||
lockVignettePercentage = lockVignettePercentage,
|
||||
onVignettePercentageChange = onVignettePercentageChange,
|
||||
onVignetteChange = onVignetteChange,
|
||||
vignette = vignette,
|
||||
homeGrayscalePercentage = homeGrayscalePercentage,
|
||||
lockGrayscalePercentage = lockGrayscalePercentage,
|
||||
onGrayscalePercentageChange = onGrayscalePercentageChange,
|
||||
onGrayscaleChange = onGrayscaleChange,
|
||||
grayscale = grayscale,
|
||||
changeStartTime = changeStartTime,
|
||||
onChangeStartTimeToggle = onChangeStartTimeToggle,
|
||||
onStartTimeChange = onStartTimeChange,
|
||||
startingTime = startingTime
|
||||
onStartTimeChange = onStartTimeChange
|
||||
)
|
||||
else -> LibraryScreen(
|
||||
albums = albums,
|
||||
|
||||
+1
-9
@@ -17,10 +17,7 @@ import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.ExperimentalComposeUiApi
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.semantics.testTagsAsResourceId
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
|
||||
@@ -35,17 +32,12 @@ fun LibraryScreen(
|
||||
) {
|
||||
val lazyListState = rememberLazyGridState()
|
||||
Scaffold(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.semantics {
|
||||
testTagsAsResourceId = true
|
||||
},
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
floatingActionButton = {
|
||||
LargeFloatingActionButton(
|
||||
containerColor = MaterialTheme.colorScheme.primaryContainer,
|
||||
contentColor = MaterialTheme.colorScheme.onPrimaryContainer,
|
||||
onClick = onAddNewAlbumClick,
|
||||
modifier = Modifier.testTag("paperize:library_floating_button")
|
||||
) {
|
||||
Icon(
|
||||
Icons.Filled.Add,
|
||||
|
||||
+1
-8
@@ -28,11 +28,9 @@ import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.ExperimentalComposeUiApi
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.contentDescription
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.semantics.testTagsAsResourceId
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.airbnb.lottie.compose.LottieAnimation
|
||||
@@ -78,9 +76,6 @@ fun NotificationScreen(
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
modifier = Modifier.semantics {
|
||||
testTagsAsResourceId = true
|
||||
},
|
||||
content = { it
|
||||
Column (modifier = Modifier.padding(32.dp)) {
|
||||
Spacer(modifier = Modifier.height(120.dp))
|
||||
@@ -109,9 +104,7 @@ fun NotificationScreen(
|
||||
},
|
||||
floatingActionButton = {
|
||||
ExtendedFloatingActionButton(
|
||||
modifier = Modifier
|
||||
.padding(8.dp)
|
||||
.testTag("paperize:floating_notification_button"),
|
||||
modifier = Modifier.padding(8.dp),
|
||||
onClick = { askPermission.value = true },
|
||||
icon = {
|
||||
Icon(
|
||||
|
||||
+142
-111
@@ -30,15 +30,12 @@ import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.ExperimentalComposeUiApi
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.semantics.testTagsAsResourceId
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.lerp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsState.ThemeSettings
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.AmoledListItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.AnimationListItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.ContactListItem
|
||||
@@ -51,15 +48,40 @@ import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.com
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.PrivacyPolicyListItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.ResetListItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.TranslateListItem
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import me.onebone.toolbar.CollapsingToolbarScaffold
|
||||
import me.onebone.toolbar.ScrollStrategy
|
||||
import me.onebone.toolbar.rememberCollapsingToolbarScaffoldState
|
||||
|
||||
private object Links {
|
||||
const val TRANSLATE = "https://crowdin.com/project/paperize/invite?h=d8d7a7513d2beb0c96ba9b2a5f85473e2084922"
|
||||
const val GITHUB = "https://github.com/Anthonyy232/Paperize"
|
||||
const val FDROID = "https://f-droid.org/en/packages/com.anthonyla.paperize/"
|
||||
const val IZZY = "https://apt.izzysoft.de/fdroid/index/apk/com.anthonyla.paperize"
|
||||
}
|
||||
|
||||
private object ToolbarConfig {
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
val LargeTopAppBarHeight = TopAppBarDefaults.LargeAppBarExpandedHeight
|
||||
val StartPadding = 64.dp
|
||||
val EndPadding = 16.dp
|
||||
const val START = 30
|
||||
const val END = 21
|
||||
val TitleExtraStartPadding = 32.dp
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun calculateToolbarValues(collapseFraction: Float) = with(ToolbarConfig) {
|
||||
val firstPaddingInterpolation = lerp((EndPadding * 5 / 4), EndPadding, collapseFraction) + TitleExtraStartPadding
|
||||
val secondPaddingInterpolation = lerp(StartPadding, (EndPadding * 5 / 4), collapseFraction)
|
||||
val dynamicPaddingStart = lerp(firstPaddingInterpolation, secondPaddingInterpolation, collapseFraction)
|
||||
val textSize = (END + (START - END) * collapseFraction).sp
|
||||
Pair(dynamicPaddingStart, textSize)
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class, ExperimentalComposeUiApi::class)
|
||||
@Composable
|
||||
fun SettingsScreen(
|
||||
settingsState: StateFlow<SettingsState>,
|
||||
themeSettings: ThemeSettings,
|
||||
onBackClick: () -> Unit,
|
||||
onDarkModeClick: (Boolean?) -> Unit,
|
||||
onAmoledClick: (Boolean) -> Unit,
|
||||
@@ -70,31 +92,11 @@ fun SettingsScreen(
|
||||
onResetClick: () -> Unit,
|
||||
onContactClick: () -> Unit
|
||||
) {
|
||||
val topBarState = rememberCollapsingToolbarScaffoldState()
|
||||
val state = settingsState.collectAsStateWithLifecycle()
|
||||
val context = LocalContext.current
|
||||
val topBarState = rememberCollapsingToolbarScaffoldState()
|
||||
val (dynamicPaddingStart, textSize) = calculateToolbarValues(topBarState.toolbarState.progress)
|
||||
|
||||
val translateLink = "https://crowdin.com/project/paperize/invite?h=d8d7a7513d2beb0c96ba9b2a5f85473e2084922"
|
||||
val githubLink = "https://github.com/Anthonyy232/Paperize"
|
||||
val fdroidLink = "https://f-droid.org/en/packages/com.anthonyla.paperize/"
|
||||
val izzyOnDroidLink = "https://apt.izzysoft.de/fdroid/index/apk/com.anthonyla.paperize"
|
||||
|
||||
// Collapsing top bar
|
||||
val largeTopAppBarHeight = TopAppBarDefaults.LargeAppBarExpandedHeight
|
||||
val startPadding = 64.dp
|
||||
val endPadding = 16.dp
|
||||
val titleFontScaleStart = 30
|
||||
val titleFontScaleEnd = 21
|
||||
val titleExtraStartPadding = 32.dp
|
||||
val collapseFraction = topBarState.toolbarState.progress
|
||||
val firstPaddingInterpolation = lerp((endPadding * 5 / 4), endPadding, collapseFraction) + titleExtraStartPadding
|
||||
val secondPaddingInterpolation = lerp(startPadding, (endPadding * 5 / 4), collapseFraction)
|
||||
val dynamicPaddingStart = lerp(firstPaddingInterpolation, secondPaddingInterpolation, collapseFraction)
|
||||
val textSize = (titleFontScaleEnd + (titleFontScaleStart - titleFontScaleEnd) * collapseFraction).sp
|
||||
|
||||
Scaffold(
|
||||
modifier = Modifier.semantics { testTagsAsResourceId = true },
|
||||
) {
|
||||
Scaffold {
|
||||
CollapsingToolbarScaffold(
|
||||
state = topBarState,
|
||||
modifier = Modifier.fillMaxSize().padding(it),
|
||||
@@ -103,7 +105,7 @@ fun SettingsScreen(
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(largeTopAppBarHeight)
|
||||
.height(ToolbarConfig.LargeTopAppBarHeight)
|
||||
.background(MaterialTheme.colorScheme.surfaceColorAtElevation(5.dp))
|
||||
.pin()
|
||||
)
|
||||
@@ -112,7 +114,6 @@ fun SettingsScreen(
|
||||
modifier = Modifier
|
||||
.padding(16.dp)
|
||||
.size(24.dp)
|
||||
.testTag("paperize:settings_to_home_button"),
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
|
||||
@@ -130,86 +131,116 @@ fun SettingsScreen(
|
||||
)
|
||||
}
|
||||
) {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.Start,
|
||||
verticalArrangement = Arrangement.Top,
|
||||
modifier = Modifier
|
||||
.verticalScroll(rememberScrollState())
|
||||
.fillMaxSize()
|
||||
.padding(horizontal = 24.dp)
|
||||
.testTag("paperize:settings_column"),
|
||||
) {
|
||||
ListSectionTitle(stringResource(R.string.appearance))
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
DarkModeListItem(
|
||||
darkMode = state.value.darkMode,
|
||||
onDarkModeClick = { onDarkModeClick(it) }
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
if (state.value.darkMode == null || state.value.darkMode == true) {
|
||||
AmoledListItem(
|
||||
amoledMode = state.value.amoledTheme,
|
||||
onAmoledClick = { onAmoledClick(it) }
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
}
|
||||
DynamicThemingListItem(
|
||||
dynamicTheming = state.value.dynamicTheming,
|
||||
onDynamicThemingClick = { onDynamicThemingClick(it) }
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
AnimationListItem(
|
||||
animate = state.value.animate,
|
||||
onAnimateClick = { onAnimateClick(it) }
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
ListSectionTitle(stringResource(R.string.about))
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
NotificationListItem(
|
||||
onClick = {
|
||||
val intent = Intent().apply {
|
||||
action = Settings.ACTION_APP_NOTIFICATION_SETTINGS
|
||||
putExtra(Settings.EXTRA_APP_PACKAGE, context.packageName)
|
||||
}
|
||||
context.startActivity(intent)
|
||||
}
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
TranslateListItem(
|
||||
onClick = {
|
||||
val openURL = Intent(Intent.ACTION_VIEW)
|
||||
openURL.data = Uri.parse(translateLink)
|
||||
context.startActivity(openURL)
|
||||
}
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
PrivacyPolicyListItem (onPrivacyPolicyClick = onPrivacyClick)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
LicenseListItem(onLicenseClick = onLicenseClick)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
ContactListItem(onContactClick = onContactClick)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
PaperizeListItem(
|
||||
onGitHubClick = {
|
||||
val openURL = Intent(Intent.ACTION_VIEW)
|
||||
openURL.data = Uri.parse(githubLink)
|
||||
context.startActivity(openURL)
|
||||
},
|
||||
onFdroidClick = {
|
||||
val openURL = Intent(Intent.ACTION_VIEW)
|
||||
openURL.data = Uri.parse(fdroidLink)
|
||||
context.startActivity(openURL)
|
||||
},
|
||||
onIzzyOnDroidClick = {
|
||||
val openURL = Intent(Intent.ACTION_VIEW)
|
||||
openURL.data = Uri.parse(izzyOnDroidLink)
|
||||
context.startActivity(openURL)
|
||||
},
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
ResetListItem(onResetClick = onResetClick)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
}
|
||||
SettingsContent(
|
||||
themeSettings = themeSettings,
|
||||
onDarkModeClick = onDarkModeClick,
|
||||
onAmoledClick = onAmoledClick,
|
||||
onDynamicThemingClick = onDynamicThemingClick,
|
||||
onAnimateClick = onAnimateClick,
|
||||
onPrivacyClick = onPrivacyClick,
|
||||
onLicenseClick = onLicenseClick,
|
||||
onResetClick = onResetClick,
|
||||
onContactClick = onContactClick,
|
||||
context = context
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SettingsContent(
|
||||
themeSettings: ThemeSettings,
|
||||
onDarkModeClick: (Boolean?) -> Unit,
|
||||
onAmoledClick: (Boolean) -> Unit,
|
||||
onDynamicThemingClick: (Boolean) -> Unit,
|
||||
onAnimateClick: (Boolean) -> Unit,
|
||||
onPrivacyClick: () -> Unit,
|
||||
onLicenseClick: () -> Unit,
|
||||
onResetClick: () -> Unit,
|
||||
onContactClick: () -> Unit,
|
||||
context: android.content.Context
|
||||
) {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.Start,
|
||||
verticalArrangement = Arrangement.Top,
|
||||
modifier = Modifier
|
||||
.verticalScroll(rememberScrollState())
|
||||
.fillMaxSize()
|
||||
.padding(horizontal = 24.dp)
|
||||
) {
|
||||
AppearanceSection(themeSettings, onDarkModeClick, onAmoledClick, onDynamicThemingClick, onAnimateClick)
|
||||
AboutSection(context, onPrivacyClick, onLicenseClick, onContactClick, onResetClick)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun AppearanceSection(
|
||||
themeSettings: ThemeSettings,
|
||||
onDarkModeClick: (Boolean?) -> Unit,
|
||||
onAmoledClick: (Boolean) -> Unit,
|
||||
onDynamicThemingClick: (Boolean) -> Unit,
|
||||
onAnimateClick: (Boolean) -> Unit
|
||||
) {
|
||||
ListSectionTitle(stringResource(R.string.appearance))
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
DarkModeListItem(
|
||||
darkMode = themeSettings.darkMode,
|
||||
onDarkModeClick = onDarkModeClick
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
if (themeSettings.darkMode == null || themeSettings.darkMode == true) {
|
||||
AmoledListItem(
|
||||
amoledMode = themeSettings.amoledTheme,
|
||||
onAmoledClick = onAmoledClick
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
}
|
||||
DynamicThemingListItem(
|
||||
dynamicTheming = themeSettings.dynamicTheming,
|
||||
onDynamicThemingClick = onDynamicThemingClick
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
AnimationListItem(
|
||||
animate = themeSettings.animate,
|
||||
onAnimateClick = onAnimateClick
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun AboutSection(
|
||||
context: android.content.Context,
|
||||
onPrivacyClick: () -> Unit,
|
||||
onLicenseClick: () -> Unit,
|
||||
onContactClick: () -> Unit,
|
||||
onResetClick: () -> Unit
|
||||
) {
|
||||
ListSectionTitle(stringResource(R.string.about))
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
NotificationListItem {
|
||||
val intent = Intent().apply {
|
||||
action = Settings.ACTION_APP_NOTIFICATION_SETTINGS
|
||||
putExtra(Settings.EXTRA_APP_PACKAGE, context.packageName)
|
||||
}
|
||||
context.startActivity(intent)
|
||||
}
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
TranslateListItem {
|
||||
context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(Links.TRANSLATE)))
|
||||
}
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
PrivacyPolicyListItem(onPrivacyClick)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
LicenseListItem(onLicenseClick)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
ContactListItem(onContactClick)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
PaperizeListItem(
|
||||
onGitHubClick = { context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(Links.GITHUB))) },
|
||||
onFdroidClick = { context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(Links.FDROID))) },
|
||||
onIzzyOnDroidClick = { context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(Links.IZZY))) }
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
ResetListItem(onResetClick)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
}
|
||||
+51
-36
@@ -1,42 +1,57 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen
|
||||
|
||||
import com.anthonyla.paperize.core.ScalingConstants
|
||||
import com.anthonyla.paperize.core.SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
|
||||
data class SettingsState(
|
||||
val firstLaunch: Boolean = true,
|
||||
// App settings
|
||||
val darkMode: Boolean? = null,
|
||||
val amoledTheme: Boolean = false,
|
||||
val dynamicTheming: Boolean = false,
|
||||
val animate: Boolean = true,
|
||||
// Wallpaper settings
|
||||
val enableChanger: Boolean = false,
|
||||
val setHomeWallpaper: Boolean = false,
|
||||
val setLockWallpaper: Boolean = false,
|
||||
val currentHomeWallpaper: String? = null,
|
||||
val currentLockWallpaper: String? = null,
|
||||
val homeAlbumName: String? = null,
|
||||
val lockAlbumName: String? = null,
|
||||
val scheduleSeparately: Boolean = false,
|
||||
val homeInterval: Int = WALLPAPER_CHANGE_INTERVAL_DEFAULT,
|
||||
val lockInterval: Int = WALLPAPER_CHANGE_INTERVAL_DEFAULT,
|
||||
val lastSetTime: String? = null,
|
||||
val nextSetTime: String? = null,
|
||||
val homeDarkenPercentage: Int = 100,
|
||||
val lockDarkenPercentage: Int = 100,
|
||||
val darken: Boolean = false,
|
||||
val blur: Boolean = false,
|
||||
val homeBlurPercentage: Int = 0,
|
||||
val lockBlurPercentage: Int = 0,
|
||||
val vignette: Boolean = false,
|
||||
val homeVignettePercentage: Int = 0,
|
||||
val lockVignettePercentage: Int = 0,
|
||||
val grayscale: Boolean = false,
|
||||
val homeGrayscalePercentage: Int = 0,
|
||||
val lockGrayscalePercentage: Int = 0,
|
||||
val wallpaperScaling: ScalingConstants = ScalingConstants.FILL,
|
||||
val nextHomeWallpaper: String? = null,
|
||||
val nextLockWallpaper: String? = null,
|
||||
val changeStartTime: Boolean = false,
|
||||
val startTime: Pair<Int, Int> = Pair(0, 0)
|
||||
)
|
||||
val themeSettings: ThemeSettings = ThemeSettings(),
|
||||
val wallpaperSettings: WallpaperSettings = WallpaperSettings(),
|
||||
val scheduleSettings: ScheduleSettings = ScheduleSettings(),
|
||||
val effectSettings: EffectSettings = EffectSettings()
|
||||
) {
|
||||
data class ThemeSettings(
|
||||
val darkMode: Boolean? = null,
|
||||
val amoledTheme: Boolean = false,
|
||||
val dynamicTheming: Boolean = false,
|
||||
val animate: Boolean = true
|
||||
)
|
||||
|
||||
data class WallpaperSettings(
|
||||
val enableChanger: Boolean = false,
|
||||
val setHomeWallpaper: Boolean = false,
|
||||
val setLockWallpaper: Boolean = false,
|
||||
val currentHomeWallpaper: String? = null,
|
||||
val currentLockWallpaper: String? = null,
|
||||
val nextHomeWallpaper: String? = null,
|
||||
val nextLockWallpaper: String? = null,
|
||||
val homeAlbumName: String? = null,
|
||||
val lockAlbumName: String? = null,
|
||||
val wallpaperScaling: ScalingConstants = ScalingConstants.FILL
|
||||
)
|
||||
|
||||
data class ScheduleSettings(
|
||||
val scheduleSeparately: Boolean = false,
|
||||
val homeInterval: Int = WALLPAPER_CHANGE_INTERVAL_DEFAULT,
|
||||
val lockInterval: Int = WALLPAPER_CHANGE_INTERVAL_DEFAULT,
|
||||
val lastSetTime: String? = null,
|
||||
val nextSetTime: String? = null,
|
||||
val changeStartTime: Boolean = false,
|
||||
val startTime: Pair<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
|
||||
)
|
||||
}
|
||||
+312
-313
@@ -4,7 +4,12 @@ import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.anthonyla.paperize.core.ScalingConstants
|
||||
import com.anthonyla.paperize.core.SettingsConstants
|
||||
import com.anthonyla.paperize.core.SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
import com.anthonyla.paperize.data.settings.SettingsDataStore
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsState.EffectSettings
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsState.ScheduleSettings
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsState.ThemeSettings
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsState.WallpaperSettings
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
@@ -35,81 +40,81 @@ class SettingsViewModel @Inject constructor (
|
||||
init {
|
||||
currentGetJob = viewModelScope.launch(Dispatchers.IO) {
|
||||
val firstLaunch = async { settingsDataStoreImpl.getBoolean(SettingsConstants.FIRST_LAUNCH) ?: true }
|
||||
val darkMode = async { settingsDataStoreImpl.getBoolean(SettingsConstants.DARK_MODE_TYPE) }
|
||||
val amoledTheme = async { settingsDataStoreImpl.getBoolean(SettingsConstants.AMOLED_THEME_TYPE) ?: false }
|
||||
val dynamicTheming = async { settingsDataStoreImpl.getBoolean(SettingsConstants.DYNAMIC_THEME_TYPE) ?: false }
|
||||
val enableChanger = async { settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_CHANGER) ?: false }
|
||||
val setHomeWallpaper = async { settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_HOME_WALLPAPER) ?: false }
|
||||
val setLockWallpaper = async { settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_LOCK_WALLPAPER) ?: false }
|
||||
val setCurrentHomeWallpaper = async { settingsDataStoreImpl.getString(SettingsConstants.CURRENT_HOME_WALLPAPER) }
|
||||
val setCurrentLockWallpaper = async { settingsDataStoreImpl.getString(SettingsConstants.CURRENT_LOCK_WALLPAPER) }
|
||||
val homeWallpaperInterval = async { settingsDataStoreImpl.getInt(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT }
|
||||
val lockWallpaperInterval = async { settingsDataStoreImpl.getInt(SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT }
|
||||
val homeAlbumName = async { settingsDataStoreImpl.getString(SettingsConstants.HOME_ALBUM_NAME) }
|
||||
val lockAlbumName = async { settingsDataStoreImpl.getString(SettingsConstants.LOCK_ALBUM_NAME) }
|
||||
val lastSetTime = async { settingsDataStoreImpl.getString(SettingsConstants.LAST_SET_TIME) }
|
||||
val nextSetTime = async { settingsDataStoreImpl.getString(SettingsConstants.NEXT_SET_TIME) }
|
||||
val animate = async { settingsDataStoreImpl.getBoolean(SettingsConstants.ANIMATE_TYPE) ?: true }
|
||||
val homeDarkenPercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.HOME_DARKEN_PERCENTAGE) ?: 100 }
|
||||
val lockDarkenPercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.LOCK_DARKEN_PERCENTAGE) ?: 100 }
|
||||
val darken = async { settingsDataStoreImpl.getBoolean(SettingsConstants.DARKEN) ?: false }
|
||||
val wallpaperScaling = async { ScalingConstants.valueOf(settingsDataStoreImpl.getString(SettingsConstants.WALLPAPER_SCALING) ?: ScalingConstants.FILL.name) }
|
||||
val scheduleSeparately = async { settingsDataStoreImpl.getBoolean(SettingsConstants.SCHEDULE_SEPARATELY) ?: false }
|
||||
val blur = async { settingsDataStoreImpl.getBoolean(SettingsConstants.BLUR) ?: false }
|
||||
val homeBlurPercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.HOME_BLUR_PERCENTAGE) ?: 0 }
|
||||
val lockBlurPercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.LOCK_BLUR_PERCENTAGE) ?: 0 }
|
||||
val vignette = async { settingsDataStoreImpl.getBoolean(SettingsConstants.VIGNETTE) ?: false }
|
||||
val homeVignettePercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.HOME_VIGNETTE_PERCENTAGE) ?: 0 }
|
||||
val lockVignettePercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.LOCK_VIGNETTE_PERCENTAGE) ?: 0 }
|
||||
val grayscale = async { settingsDataStoreImpl.getBoolean(SettingsConstants.GRAYSCALE) ?: false }
|
||||
val homeGrayscalePercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.HOME_GRAYSCALE_PERCENTAGE) ?: 0 }
|
||||
val lockGrayscalePercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.LOCK_GRAYSCALE_PERCENTAGE) ?: 0 }
|
||||
val nextHomeWallpaper = async { settingsDataStoreImpl.getString(SettingsConstants.HOME_NEXT_SET_TIME) }
|
||||
val nextLockWallpaper = async { settingsDataStoreImpl.getString(SettingsConstants.LOCK_NEXT_SET_TIME) }
|
||||
val changeStartTime = async { settingsDataStoreImpl.getBoolean(SettingsConstants.CHANGE_START_TIME) ?: false }
|
||||
val startTime = async { Pair(settingsDataStoreImpl.getInt(SettingsConstants.START_HOUR) ?: 0, settingsDataStoreImpl.getInt(SettingsConstants.START_MINUTE) ?: 0) }
|
||||
|
||||
val themeSettings = async { loadThemeSettings() }
|
||||
val wallpaperSettings = async { loadWallpaperSettings() }
|
||||
val scheduleSettings = async { loadScheduleSettings() }
|
||||
val effectSettings = async { loadEffectSettings() }
|
||||
_state.update {
|
||||
it.copy(
|
||||
darkMode = darkMode.await(),
|
||||
amoledTheme = amoledTheme.await(),
|
||||
dynamicTheming = dynamicTheming.await(),
|
||||
homeInterval = homeWallpaperInterval.await(),
|
||||
lockInterval = lockWallpaperInterval.await(),
|
||||
homeAlbumName = homeAlbumName.await(),
|
||||
lockAlbumName = lockAlbumName.await(),
|
||||
firstLaunch = firstLaunch.await(),
|
||||
lastSetTime = lastSetTime.await(),
|
||||
nextSetTime = nextSetTime.await(),
|
||||
animate = animate.await(),
|
||||
enableChanger = enableChanger.await(),
|
||||
homeDarkenPercentage = homeDarkenPercentage.await(),
|
||||
lockDarkenPercentage = lockDarkenPercentage.await(),
|
||||
darken = darken.await(),
|
||||
wallpaperScaling = wallpaperScaling.await(),
|
||||
setHomeWallpaper = setHomeWallpaper.await(),
|
||||
setLockWallpaper = setLockWallpaper.await(),
|
||||
currentHomeWallpaper = setCurrentHomeWallpaper.await(),
|
||||
currentLockWallpaper = setCurrentLockWallpaper.await(),
|
||||
scheduleSeparately = scheduleSeparately.await(),
|
||||
blur = blur.await(),
|
||||
homeBlurPercentage = homeBlurPercentage.await(),
|
||||
lockBlurPercentage = lockBlurPercentage.await(),
|
||||
nextHomeWallpaper = nextHomeWallpaper.await(),
|
||||
nextLockWallpaper = nextLockWallpaper.await(),
|
||||
vignette = vignette.await(),
|
||||
homeVignettePercentage = homeVignettePercentage.await(),
|
||||
lockVignettePercentage = lockVignettePercentage.await(),
|
||||
grayscale = grayscale.await(),
|
||||
homeGrayscalePercentage = homeGrayscalePercentage.await(),
|
||||
lockGrayscalePercentage = lockGrayscalePercentage.await(),
|
||||
changeStartTime = changeStartTime.await(),
|
||||
startTime = startTime.await()
|
||||
themeSettings = themeSettings.await(),
|
||||
wallpaperSettings = wallpaperSettings.await(),
|
||||
scheduleSettings = scheduleSettings.await(),
|
||||
effectSettings = effectSettings.await()
|
||||
)
|
||||
}
|
||||
setKeepOnScreenCondition = false
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun loadThemeSettings(): ThemeSettings {
|
||||
return ThemeSettings(
|
||||
darkMode = settingsDataStoreImpl.getBoolean(SettingsConstants.DARK_MODE_TYPE),
|
||||
amoledTheme = settingsDataStoreImpl.getBoolean(SettingsConstants.AMOLED_THEME_TYPE) ?: false,
|
||||
dynamicTheming = settingsDataStoreImpl.getBoolean(SettingsConstants.DYNAMIC_THEME_TYPE) ?: false,
|
||||
animate = settingsDataStoreImpl.getBoolean(SettingsConstants.ANIMATE_TYPE) ?: true
|
||||
)
|
||||
}
|
||||
|
||||
private suspend fun loadWallpaperSettings(): WallpaperSettings {
|
||||
return WallpaperSettings(
|
||||
enableChanger = settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_CHANGER) ?: false,
|
||||
setHomeWallpaper = settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_HOME_WALLPAPER) ?: false,
|
||||
setLockWallpaper = settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_LOCK_WALLPAPER) ?: false,
|
||||
currentHomeWallpaper = settingsDataStoreImpl.getString(SettingsConstants.CURRENT_HOME_WALLPAPER),
|
||||
currentLockWallpaper = settingsDataStoreImpl.getString(SettingsConstants.CURRENT_LOCK_WALLPAPER),
|
||||
nextHomeWallpaper = settingsDataStoreImpl.getString(SettingsConstants.HOME_NEXT_SET_TIME),
|
||||
nextLockWallpaper = settingsDataStoreImpl.getString(SettingsConstants.LOCK_NEXT_SET_TIME),
|
||||
homeAlbumName = settingsDataStoreImpl.getString(SettingsConstants.HOME_ALBUM_NAME),
|
||||
lockAlbumName = settingsDataStoreImpl.getString(SettingsConstants.LOCK_ALBUM_NAME),
|
||||
wallpaperScaling = ScalingConstants.valueOf(
|
||||
settingsDataStoreImpl.getString(SettingsConstants.WALLPAPER_SCALING)
|
||||
?: ScalingConstants.FILL.name
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
private suspend fun loadScheduleSettings(): ScheduleSettings {
|
||||
return ScheduleSettings(
|
||||
scheduleSeparately = settingsDataStoreImpl.getBoolean(SettingsConstants.SCHEDULE_SEPARATELY) ?: false,
|
||||
homeInterval = settingsDataStoreImpl.getInt(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL) ?: WALLPAPER_CHANGE_INTERVAL_DEFAULT,
|
||||
lockInterval = settingsDataStoreImpl.getInt(SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL) ?: WALLPAPER_CHANGE_INTERVAL_DEFAULT,
|
||||
lastSetTime = settingsDataStoreImpl.getString(SettingsConstants.LAST_SET_TIME),
|
||||
nextSetTime = settingsDataStoreImpl.getString(SettingsConstants.NEXT_SET_TIME),
|
||||
changeStartTime = settingsDataStoreImpl.getBoolean(SettingsConstants.CHANGE_START_TIME) ?: false,
|
||||
startTime = Pair(
|
||||
settingsDataStoreImpl.getInt(SettingsConstants.START_HOUR) ?: 0,
|
||||
settingsDataStoreImpl.getInt(SettingsConstants.START_MINUTE) ?: 0
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
private suspend fun loadEffectSettings(): EffectSettings {
|
||||
return EffectSettings(
|
||||
darken = settingsDataStoreImpl.getBoolean(SettingsConstants.DARKEN) ?: false,
|
||||
homeDarkenPercentage = settingsDataStoreImpl.getInt(SettingsConstants.HOME_DARKEN_PERCENTAGE) ?: 100,
|
||||
lockDarkenPercentage = settingsDataStoreImpl.getInt(SettingsConstants.LOCK_DARKEN_PERCENTAGE) ?: 100,
|
||||
blur = settingsDataStoreImpl.getBoolean(SettingsConstants.BLUR) ?: false,
|
||||
homeBlurPercentage = settingsDataStoreImpl.getInt(SettingsConstants.HOME_BLUR_PERCENTAGE) ?: 0,
|
||||
lockBlurPercentage = settingsDataStoreImpl.getInt(SettingsConstants.LOCK_BLUR_PERCENTAGE) ?: 0,
|
||||
vignette = settingsDataStoreImpl.getBoolean(SettingsConstants.VIGNETTE) ?: false,
|
||||
homeVignettePercentage = settingsDataStoreImpl.getInt(SettingsConstants.HOME_VIGNETTE_PERCENTAGE) ?: 0,
|
||||
lockVignettePercentage = settingsDataStoreImpl.getInt(SettingsConstants.LOCK_VIGNETTE_PERCENTAGE) ?: 0,
|
||||
grayscale = settingsDataStoreImpl.getBoolean(SettingsConstants.GRAYSCALE) ?: false,
|
||||
homeGrayscalePercentage = settingsDataStoreImpl.getInt(SettingsConstants.HOME_GRAYSCALE_PERCENTAGE) ?: 0,
|
||||
lockGrayscalePercentage = settingsDataStoreImpl.getInt(SettingsConstants.LOCK_GRAYSCALE_PERCENTAGE) ?: 0
|
||||
)
|
||||
}
|
||||
|
||||
fun onEvent(event: SettingsEvent) {
|
||||
when (event) {
|
||||
@@ -117,9 +122,7 @@ class SettingsViewModel @Inject constructor (
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.FIRST_LAUNCH, false)
|
||||
_state.update {
|
||||
it.copy(
|
||||
firstLaunch = false
|
||||
)
|
||||
it.copy(firstLaunch = false)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -127,11 +130,13 @@ class SettingsViewModel @Inject constructor (
|
||||
is SettingsEvent.SetChangerToggle -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.ENABLE_CHANGER, event.toggle)
|
||||
_state.update {
|
||||
it.copy(
|
||||
enableChanger = event.toggle,
|
||||
currentHomeWallpaper = if (!event.toggle) null else it.currentHomeWallpaper,
|
||||
currentLockWallpaper = if (!event.toggle) null else it.currentLockWallpaper
|
||||
_state.update { currentState ->
|
||||
currentState.copy(
|
||||
wallpaperSettings = currentState.wallpaperSettings.copy(
|
||||
enableChanger = event.toggle,
|
||||
currentHomeWallpaper = if (!event.toggle) null else currentState.wallpaperSettings.currentHomeWallpaper,
|
||||
currentLockWallpaper = if (!event.toggle) null else currentState.wallpaperSettings.currentLockWallpaper
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -139,75 +144,19 @@ class SettingsViewModel @Inject constructor (
|
||||
|
||||
is SettingsEvent.Refresh -> {
|
||||
currentGetJob = viewModelScope.launch(Dispatchers.IO) {
|
||||
val darkMode = async { settingsDataStoreImpl.getBoolean(SettingsConstants.DARK_MODE_TYPE) }
|
||||
val amoledTheme = async { settingsDataStoreImpl.getBoolean(SettingsConstants.AMOLED_THEME_TYPE) ?: false }
|
||||
val dynamicTheming = async { settingsDataStoreImpl.getBoolean(SettingsConstants.DYNAMIC_THEME_TYPE) ?: false }
|
||||
val themeSettings = async { loadThemeSettings() }
|
||||
val wallpaperSettings = async { loadWallpaperSettings() }
|
||||
val scheduleSettings = async { loadScheduleSettings() }
|
||||
val effectSettings = async { loadEffectSettings() }
|
||||
val firstLaunch = async { settingsDataStoreImpl.getBoolean(SettingsConstants.FIRST_LAUNCH) ?: true }
|
||||
val lastSetTime = async { settingsDataStoreImpl.getString(SettingsConstants.LAST_SET_TIME) }
|
||||
val nextSetTime = async { settingsDataStoreImpl.getString(SettingsConstants.NEXT_SET_TIME) }
|
||||
val animate = async { settingsDataStoreImpl.getBoolean(SettingsConstants.ANIMATE_TYPE) ?: true }
|
||||
val enableChanger = async { settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_CHANGER) ?: false }
|
||||
val homeDarkenPercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.HOME_DARKEN_PERCENTAGE) ?: 0 }
|
||||
val lockDarkenPercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.LOCK_DARKEN_PERCENTAGE) ?: 0 }
|
||||
val darken = async { settingsDataStoreImpl.getBoolean(SettingsConstants.DARKEN) ?: false }
|
||||
val setHomeWallpaper = async { settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_HOME_WALLPAPER) ?: false }
|
||||
val setLockWallpaper = async { settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_LOCK_WALLPAPER) ?: false }
|
||||
val homeAlbumName = async { settingsDataStoreImpl.getString(SettingsConstants.HOME_ALBUM_NAME) }
|
||||
val lockAlbumName = async { settingsDataStoreImpl.getString(SettingsConstants.LOCK_ALBUM_NAME) }
|
||||
val currentHomeWallpaper = async { settingsDataStoreImpl.getString(SettingsConstants.CURRENT_HOME_WALLPAPER) }
|
||||
val currentLockWallpaper = async { settingsDataStoreImpl.getString(SettingsConstants.CURRENT_LOCK_WALLPAPER) }
|
||||
val homeWallpaperInterval = async { settingsDataStoreImpl.getInt(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT }
|
||||
val lockWallpaperInterval = async { settingsDataStoreImpl.getInt(SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL) ?: SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT }
|
||||
val scheduleSeparately = async { settingsDataStoreImpl.getBoolean(SettingsConstants.SCHEDULE_SEPARATELY) ?: false }
|
||||
val blur = async { settingsDataStoreImpl.getBoolean(SettingsConstants.BLUR) ?: false }
|
||||
val homeBlurPercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.HOME_BLUR_PERCENTAGE) ?: 0 }
|
||||
val lockBlurPercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.LOCK_BLUR_PERCENTAGE) ?: 0 }
|
||||
val nextHomeWallpaper = async { settingsDataStoreImpl.getString(SettingsConstants.HOME_NEXT_SET_TIME) }
|
||||
val nextLockWallpaper = async { settingsDataStoreImpl.getString(SettingsConstants.LOCK_NEXT_SET_TIME) }
|
||||
val vignette = async { settingsDataStoreImpl.getBoolean(SettingsConstants.VIGNETTE) ?: false }
|
||||
val homeVignettePercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.HOME_VIGNETTE_PERCENTAGE) ?: 0 }
|
||||
val lockVignettePercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.LOCK_VIGNETTE_PERCENTAGE) ?: 0 }
|
||||
val grayscale = async { settingsDataStoreImpl.getBoolean(SettingsConstants.GRAYSCALE) ?: false }
|
||||
val homeGrayscalePercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.HOME_GRAYSCALE_PERCENTAGE) ?: 0 }
|
||||
val lockGrayscalePercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.LOCK_GRAYSCALE_PERCENTAGE) ?: 0 }
|
||||
val changeStartTime = async { settingsDataStoreImpl.getBoolean(SettingsConstants.CHANGE_START_TIME) ?: false }
|
||||
val startTime = async { Pair(settingsDataStoreImpl.getInt(SettingsConstants.START_HOUR) ?: 0, settingsDataStoreImpl.getInt(SettingsConstants.START_MINUTE) ?: 0) }
|
||||
|
||||
_state.update {
|
||||
it.copy(
|
||||
darkMode = darkMode.await(),
|
||||
amoledTheme = amoledTheme.await(),
|
||||
dynamicTheming = dynamicTheming.await(),
|
||||
firstLaunch = firstLaunch.await(),
|
||||
lastSetTime = lastSetTime.await(),
|
||||
nextSetTime = nextSetTime.await(),
|
||||
animate = animate.await(),
|
||||
enableChanger = enableChanger.await(),
|
||||
homeDarkenPercentage = homeDarkenPercentage.await(),
|
||||
lockDarkenPercentage = lockDarkenPercentage.await(),
|
||||
darken = darken.await(),
|
||||
setHomeWallpaper = setHomeWallpaper.await(),
|
||||
setLockWallpaper = setLockWallpaper.await(),
|
||||
homeAlbumName = homeAlbumName.await(),
|
||||
lockAlbumName = lockAlbumName.await(),
|
||||
currentHomeWallpaper = currentHomeWallpaper.await(),
|
||||
currentLockWallpaper = currentLockWallpaper.await(),
|
||||
lockInterval = lockWallpaperInterval.await(),
|
||||
homeInterval = homeWallpaperInterval.await(),
|
||||
scheduleSeparately = scheduleSeparately.await(),
|
||||
blur = blur.await(),
|
||||
homeBlurPercentage = homeBlurPercentage.await(),
|
||||
lockBlurPercentage = lockBlurPercentage.await(),
|
||||
nextHomeWallpaper = nextHomeWallpaper.await(),
|
||||
nextLockWallpaper = nextLockWallpaper.await(),
|
||||
vignette = vignette.await(),
|
||||
homeVignettePercentage = homeVignettePercentage.await(),
|
||||
lockVignettePercentage = lockVignettePercentage.await(),
|
||||
grayscale = grayscale.await(),
|
||||
homeGrayscalePercentage = homeGrayscalePercentage.await(),
|
||||
lockGrayscalePercentage = lockGrayscalePercentage.await(),
|
||||
changeStartTime = changeStartTime.await(),
|
||||
startTime = startTime.await()
|
||||
themeSettings = themeSettings.await(),
|
||||
wallpaperSettings = wallpaperSettings.await(),
|
||||
scheduleSettings = scheduleSettings.await(),
|
||||
effectSettings = effectSettings.await()
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -222,7 +171,9 @@ class SettingsViewModel @Inject constructor (
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
darkMode = event.darkMode
|
||||
themeSettings = it.themeSettings.copy(
|
||||
darkMode = event.darkMode
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -236,8 +187,10 @@ class SettingsViewModel @Inject constructor (
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
amoledTheme = event.amoledTheme,
|
||||
dynamicTheming = if (event.amoledTheme) false else it.dynamicTheming
|
||||
themeSettings = it.themeSettings.copy(
|
||||
amoledTheme = event.amoledTheme,
|
||||
dynamicTheming = if (event.amoledTheme) false else it.themeSettings.dynamicTheming
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -251,8 +204,10 @@ class SettingsViewModel @Inject constructor (
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
amoledTheme = if (event.dynamicTheming) false else it.amoledTheme,
|
||||
dynamicTheming = event.dynamicTheming
|
||||
themeSettings = it.themeSettings.copy(
|
||||
amoledTheme = if (event.dynamicTheming) false else it.themeSettings.amoledTheme,
|
||||
dynamicTheming = event.dynamicTheming
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -263,7 +218,9 @@ class SettingsViewModel @Inject constructor (
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.ANIMATE_TYPE, event.animate)
|
||||
_state.update {
|
||||
it.copy(
|
||||
animate = event.animate
|
||||
themeSettings = it.themeSettings.copy(
|
||||
animate = event.animate
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -273,16 +230,17 @@ class SettingsViewModel @Inject constructor (
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putInt(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL, event.interval)
|
||||
val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
|
||||
val currentTime = if (_state.value.changeStartTime) {
|
||||
LocalDateTime.now().withHour(_state.value.startTime.first).withMinute(_state.value.startTime.second)
|
||||
val currentTime = if (_state.value.scheduleSettings.changeStartTime) {
|
||||
LocalDateTime.now().withHour(_state.value.scheduleSettings.startTime.first)
|
||||
.withMinute(_state.value.scheduleSettings.startTime.second)
|
||||
} else {
|
||||
LocalDateTime.now()
|
||||
}
|
||||
val nextSetTime: String?
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, currentTime.format(formatter))
|
||||
if (_state.value.scheduleSeparately) {
|
||||
if (_state.value.scheduleSettings.scheduleSeparately) {
|
||||
val homeNextSetTime = currentTime.plusMinutes(event.interval.toLong())
|
||||
val lockNextSetTime = currentTime.plusMinutes(_state.value.lockInterval.toLong())
|
||||
val lockNextSetTime = currentTime.plusMinutes(_state.value.scheduleSettings.lockInterval.toLong())
|
||||
nextSetTime = (if (homeNextSetTime!!.isBefore(lockNextSetTime)) homeNextSetTime else lockNextSetTime)!!.format(formatter)
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, nextSetTime)
|
||||
settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, homeNextSetTime.toString())
|
||||
@@ -296,9 +254,11 @@ class SettingsViewModel @Inject constructor (
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
homeInterval = event.interval,
|
||||
lastSetTime = currentTime.format(formatter),
|
||||
nextSetTime = nextSetTime
|
||||
scheduleSettings = it.scheduleSettings.copy(
|
||||
homeInterval = event.interval,
|
||||
lastSetTime = currentTime.format(formatter),
|
||||
nextSetTime = nextSetTime
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -308,15 +268,16 @@ class SettingsViewModel @Inject constructor (
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.putInt(SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL, event.interval)
|
||||
val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
|
||||
val currentTime = if (_state.value.changeStartTime) {
|
||||
LocalDateTime.now().withHour(_state.value.startTime.first).withMinute(_state.value.startTime.second)
|
||||
val currentTime = if (_state.value.scheduleSettings.changeStartTime) {
|
||||
LocalDateTime.now().withHour(_state.value.scheduleSettings.startTime.first)
|
||||
.withMinute(_state.value.scheduleSettings.startTime.second)
|
||||
} else {
|
||||
LocalDateTime.now()
|
||||
}
|
||||
val nextSetTime: String?
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, currentTime.format(formatter))
|
||||
if (_state.value.scheduleSeparately) {
|
||||
val nextSetTime1 = currentTime.plusMinutes(_state.value.homeInterval.toLong())
|
||||
if (_state.value.scheduleSettings.scheduleSeparately) {
|
||||
val nextSetTime1 = currentTime.plusMinutes(_state.value.scheduleSettings.homeInterval.toLong())
|
||||
val nextSetTime2 = currentTime.plusMinutes(event.interval.toLong())
|
||||
nextSetTime = (if (nextSetTime1!!.isBefore(nextSetTime2)) nextSetTime1 else nextSetTime2)!!.format(formatter)
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, nextSetTime)
|
||||
@@ -331,9 +292,11 @@ class SettingsViewModel @Inject constructor (
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
lockInterval = event.interval,
|
||||
lastSetTime = currentTime.format(formatter),
|
||||
nextSetTime = nextSetTime
|
||||
scheduleSettings = it.scheduleSettings.copy(
|
||||
lockInterval = event.interval,
|
||||
lastSetTime = currentTime.format(formatter),
|
||||
nextSetTime = nextSetTime
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -342,8 +305,10 @@ class SettingsViewModel @Inject constructor (
|
||||
is SettingsEvent.RefreshNextSetTime -> {
|
||||
viewModelScope.launch {
|
||||
val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
|
||||
val currentTime = if (_state.value.changeStartTime) {
|
||||
var calculatedTime = LocalDateTime.now().withHour(_state.value.startTime.first).withMinute(_state.value.startTime.second)
|
||||
val currentTime = if (_state.value.scheduleSettings.changeStartTime) {
|
||||
var calculatedTime = LocalDateTime.now()
|
||||
.withHour(_state.value.scheduleSettings.startTime.first)
|
||||
.withMinute(_state.value.scheduleSettings.startTime.second)
|
||||
if (calculatedTime.isBefore(LocalDateTime.now())) {
|
||||
calculatedTime = calculatedTime.plusDays(1)
|
||||
}
|
||||
@@ -352,28 +317,34 @@ class SettingsViewModel @Inject constructor (
|
||||
LocalDateTime.now()
|
||||
}
|
||||
val nextSetTime = when {
|
||||
_state.value.changeStartTime -> {
|
||||
_state.value.scheduleSettings.changeStartTime -> {
|
||||
settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, currentTime.toString())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, currentTime.toString())
|
||||
currentTime
|
||||
}
|
||||
_state.value.scheduleSeparately -> {
|
||||
settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, currentTime.plusMinutes(_state.value.homeInterval.toLong()).toString())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, currentTime.plusMinutes(_state.value.lockInterval.toLong()).toString())
|
||||
val nextSetTime1 = currentTime.plusMinutes(_state.value.homeInterval.toLong())
|
||||
val nextSetTime2 = currentTime.plusMinutes(_state.value.lockInterval.toLong())
|
||||
_state.value.scheduleSettings.scheduleSeparately -> {
|
||||
settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME,
|
||||
currentTime.plusMinutes(_state.value.scheduleSettings.homeInterval.toLong()).toString())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME,
|
||||
currentTime.plusMinutes(_state.value.scheduleSettings.lockInterval.toLong()).toString())
|
||||
val nextSetTime1 = currentTime.plusMinutes(_state.value.scheduleSettings.homeInterval.toLong())
|
||||
val nextSetTime2 = currentTime.plusMinutes(_state.value.scheduleSettings.lockInterval.toLong())
|
||||
if (nextSetTime1.isBefore(nextSetTime2)) nextSetTime1 else nextSetTime2
|
||||
}
|
||||
else -> {
|
||||
settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, currentTime.plusMinutes(_state.value.homeInterval.toLong()).toString())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, currentTime.plusMinutes(_state.value.lockInterval.toLong()).toString())
|
||||
currentTime.plusMinutes(_state.value.homeInterval.toLong())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME,
|
||||
currentTime.plusMinutes(_state.value.scheduleSettings.homeInterval.toLong()).toString())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME,
|
||||
currentTime.plusMinutes(_state.value.scheduleSettings.lockInterval.toLong()).toString())
|
||||
currentTime.plusMinutes(_state.value.scheduleSettings.homeInterval.toLong())
|
||||
}
|
||||
}.format(formatter)
|
||||
_state.update {
|
||||
it.copy(
|
||||
lastSetTime = LocalDateTime.now().format(formatter),
|
||||
nextSetTime = nextSetTime,
|
||||
scheduleSettings = it.scheduleSettings.copy(
|
||||
lastSetTime = LocalDateTime.now().format(formatter),
|
||||
nextSetTime = nextSetTime
|
||||
)
|
||||
)
|
||||
}
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, LocalDateTime.now().format(formatter))
|
||||
@@ -386,7 +357,9 @@ class SettingsViewModel @Inject constructor (
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.ENABLE_HOME_WALLPAPER, event.home)
|
||||
_state.update {
|
||||
it.copy(
|
||||
setHomeWallpaper = event.home
|
||||
wallpaperSettings = it.wallpaperSettings.copy(
|
||||
setHomeWallpaper = event.home
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -397,7 +370,9 @@ class SettingsViewModel @Inject constructor (
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.ENABLE_LOCK_WALLPAPER, event.lock)
|
||||
_state.update {
|
||||
it.copy(
|
||||
setLockWallpaper = event.lock
|
||||
wallpaperSettings = it.wallpaperSettings.copy(
|
||||
setLockWallpaper = event.lock
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -408,7 +383,9 @@ class SettingsViewModel @Inject constructor (
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.DARKEN, event.darken)
|
||||
_state.update {
|
||||
it.copy(
|
||||
darken = event.darken
|
||||
effectSettings = it.effectSettings.copy(
|
||||
darken = event.darken
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -419,7 +396,9 @@ class SettingsViewModel @Inject constructor (
|
||||
settingsDataStoreImpl.putString(SettingsConstants.WALLPAPER_SCALING, event.scaling.name)
|
||||
_state.update {
|
||||
it.copy(
|
||||
wallpaperScaling = event.scaling
|
||||
wallpaperSettings = it.wallpaperSettings.copy(
|
||||
wallpaperScaling = event.scaling
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -430,7 +409,9 @@ class SettingsViewModel @Inject constructor (
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.SCHEDULE_SEPARATELY, event.scheduleSeparately)
|
||||
_state.update {
|
||||
it.copy(
|
||||
scheduleSeparately = event.scheduleSeparately
|
||||
scheduleSettings = it.scheduleSettings.copy(
|
||||
scheduleSeparately = event.scheduleSeparately
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -441,7 +422,9 @@ class SettingsViewModel @Inject constructor (
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.BLUR, event.blur)
|
||||
_state.update {
|
||||
it.copy(
|
||||
blur = event.blur
|
||||
effectSettings = it.effectSettings.copy(
|
||||
blur = event.blur
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -457,8 +440,10 @@ class SettingsViewModel @Inject constructor (
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
homeDarkenPercentage = event.homeDarkenPercentage ?: it.homeDarkenPercentage,
|
||||
lockDarkenPercentage = event.lockDarkenPercentage ?: it.lockDarkenPercentage
|
||||
effectSettings = it.effectSettings.copy(
|
||||
homeDarkenPercentage = event.homeDarkenPercentage ?: it.effectSettings.homeDarkenPercentage,
|
||||
lockDarkenPercentage = event.lockDarkenPercentage ?: it.effectSettings.lockDarkenPercentage
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -474,8 +459,10 @@ class SettingsViewModel @Inject constructor (
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
homeBlurPercentage = event.homeBlurPercentage ?: it.homeBlurPercentage,
|
||||
lockBlurPercentage = event.lockBlurPercentage ?: it.lockBlurPercentage
|
||||
effectSettings = it.effectSettings.copy(
|
||||
homeBlurPercentage = event.homeBlurPercentage ?: it.effectSettings.homeBlurPercentage,
|
||||
lockBlurPercentage = event.lockBlurPercentage ?: it.effectSettings.lockBlurPercentage
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -486,7 +473,9 @@ class SettingsViewModel @Inject constructor (
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.VIGNETTE, event.vignette)
|
||||
_state.update {
|
||||
it.copy(
|
||||
vignette = event.vignette
|
||||
effectSettings = it.effectSettings.copy(
|
||||
vignette = event.vignette
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -502,8 +491,10 @@ class SettingsViewModel @Inject constructor (
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
homeVignettePercentage = event.homeVignettePercentage ?: it.homeVignettePercentage,
|
||||
lockVignettePercentage = event.lockVignettePercentage ?: it.lockVignettePercentage
|
||||
effectSettings = it.effectSettings.copy(
|
||||
homeVignettePercentage = event.homeVignettePercentage ?: it.effectSettings.homeVignettePercentage,
|
||||
lockVignettePercentage = event.lockVignettePercentage ?: it.effectSettings.lockVignettePercentage
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -514,7 +505,9 @@ class SettingsViewModel @Inject constructor (
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.GRAYSCALE, event.grayscale)
|
||||
_state.update {
|
||||
it.copy(
|
||||
grayscale = event.grayscale
|
||||
effectSettings = it.effectSettings.copy(
|
||||
grayscale = event.grayscale
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -530,8 +523,10 @@ class SettingsViewModel @Inject constructor (
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
homeGrayscalePercentage = event.homeGrayscalePercentage ?: it.homeGrayscalePercentage,
|
||||
lockGrayscalePercentage = event.lockGrayscalePercentage ?: it.lockGrayscalePercentage
|
||||
effectSettings = it.effectSettings.copy(
|
||||
homeGrayscalePercentage = event.homeGrayscalePercentage ?: it.effectSettings.homeGrayscalePercentage,
|
||||
lockGrayscalePercentage = event.lockGrayscalePercentage ?: it.effectSettings.lockGrayscalePercentage
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -544,7 +539,9 @@ class SettingsViewModel @Inject constructor (
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
currentHomeWallpaper = event.currentHomeWallpaper
|
||||
wallpaperSettings = it.wallpaperSettings.copy(
|
||||
currentHomeWallpaper = event.currentHomeWallpaper
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -557,7 +554,9 @@ class SettingsViewModel @Inject constructor (
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
currentLockWallpaper = event.currentLockWallpaper
|
||||
wallpaperSettings = it.wallpaperSettings.copy(
|
||||
currentLockWallpaper = event.currentLockWallpaper
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -573,8 +572,10 @@ class SettingsViewModel @Inject constructor (
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
currentLockWallpaper = event.currentLockWallpaper ?: it.currentLockWallpaper,
|
||||
currentHomeWallpaper = event.currentHomeWallpaper ?: it.currentHomeWallpaper
|
||||
wallpaperSettings = it.wallpaperSettings.copy(
|
||||
currentLockWallpaper = event.currentLockWallpaper ?: it.wallpaperSettings.currentLockWallpaper,
|
||||
currentHomeWallpaper = event.currentHomeWallpaper ?: it.wallpaperSettings.currentHomeWallpaper
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -590,16 +591,18 @@ class SettingsViewModel @Inject constructor (
|
||||
}
|
||||
val enableChanger: Boolean = when {
|
||||
event.homeAlbumName != null && event.lockAlbumName != null -> { true }
|
||||
event.homeAlbumName != null && !_state.value.lockAlbumName.isNullOrEmpty() -> { true }
|
||||
event.lockAlbumName != null && !_state.value.homeAlbumName.isNullOrEmpty() -> { true }
|
||||
event.homeAlbumName != null && !_state.value.wallpaperSettings.lockAlbumName.isNullOrEmpty() -> { true }
|
||||
event.lockAlbumName != null && !_state.value.wallpaperSettings.homeAlbumName.isNullOrEmpty() -> { true }
|
||||
else -> { false }
|
||||
}
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.ENABLE_CHANGER, enableChanger)
|
||||
_state.update {
|
||||
it.copy(
|
||||
homeAlbumName = event.homeAlbumName ?: it.homeAlbumName,
|
||||
lockAlbumName = event.lockAlbumName ?: it.lockAlbumName,
|
||||
enableChanger = enableChanger
|
||||
wallpaperSettings = it.wallpaperSettings.copy(
|
||||
homeAlbumName = event.homeAlbumName ?: it.wallpaperSettings.homeAlbumName,
|
||||
lockAlbumName = event.lockAlbumName ?: it.wallpaperSettings.lockAlbumName,
|
||||
enableChanger = enableChanger
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -607,7 +610,7 @@ class SettingsViewModel @Inject constructor (
|
||||
|
||||
is SettingsEvent.RemoveSelectedAlbumAsType -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
if (_state.value.setLockWallpaper && _state.value.setHomeWallpaper) {
|
||||
if (_state.value.wallpaperSettings.setLockWallpaper && _state.value.wallpaperSettings.setHomeWallpaper) {
|
||||
if (event.removeLock) {
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.LOCK_ALBUM_NAME)
|
||||
}
|
||||
@@ -620,15 +623,19 @@ class SettingsViewModel @Inject constructor (
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.NEXT_SET_TIME)
|
||||
_state.update {
|
||||
it.copy(
|
||||
homeAlbumName = if (event.removeHome) null else it.homeAlbumName,
|
||||
lockAlbumName = if (event.removeLock) null else it.lockAlbumName,
|
||||
currentHomeWallpaper = null,
|
||||
currentLockWallpaper = null,
|
||||
nextHomeWallpaper = null,
|
||||
nextLockWallpaper = null,
|
||||
enableChanger = false,
|
||||
lastSetTime = null,
|
||||
nextSetTime = null
|
||||
wallpaperSettings = it.wallpaperSettings.copy(
|
||||
homeAlbumName = if (event.removeHome) null else it.wallpaperSettings.homeAlbumName,
|
||||
lockAlbumName = if (event.removeLock) null else it.wallpaperSettings.lockAlbumName,
|
||||
currentHomeWallpaper = null,
|
||||
currentLockWallpaper = null,
|
||||
nextHomeWallpaper = null,
|
||||
nextLockWallpaper = null,
|
||||
enableChanger = false
|
||||
),
|
||||
scheduleSettings = it.scheduleSettings.copy(
|
||||
lastSetTime = null,
|
||||
nextSetTime = null
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -643,11 +650,13 @@ class SettingsViewModel @Inject constructor (
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
homeAlbumName = if (event.removeHome) null else it.homeAlbumName,
|
||||
lockAlbumName = if (event.removeLock) null else it.lockAlbumName,
|
||||
currentHomeWallpaper = if (event.removeHome) null else it.currentHomeWallpaper,
|
||||
currentLockWallpaper = if (event.removeLock) null else it.currentLockWallpaper,
|
||||
enableChanger = false
|
||||
wallpaperSettings = it.wallpaperSettings.copy(
|
||||
homeAlbumName = if (event.removeHome) null else it.wallpaperSettings.homeAlbumName,
|
||||
lockAlbumName = if (event.removeLock) null else it.wallpaperSettings.lockAlbumName,
|
||||
currentHomeWallpaper = if (event.removeHome) null else it.wallpaperSettings.currentHomeWallpaper,
|
||||
currentLockWallpaper = if (event.removeLock) null else it.wallpaperSettings.currentLockWallpaper,
|
||||
enableChanger = false
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -656,13 +665,13 @@ class SettingsViewModel @Inject constructor (
|
||||
|
||||
is SettingsEvent.RemoveSelectedAlbumAsName -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
var enableChanger = _state.value.enableChanger
|
||||
if (event.albumName == _state.value.lockAlbumName) {
|
||||
var enableChanger = _state.value.wallpaperSettings.enableChanger
|
||||
if (event.albumName == _state.value.wallpaperSettings.lockAlbumName) {
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.LOCK_ALBUM_NAME)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.CURRENT_LOCK_WALLPAPER)
|
||||
enableChanger = false
|
||||
}
|
||||
if (event.albumName == _state.value.homeAlbumName) {
|
||||
if (event.albumName == _state.value.wallpaperSettings.homeAlbumName) {
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.HOME_ALBUM_NAME)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.CURRENT_HOME_WALLPAPER)
|
||||
enableChanger = false
|
||||
@@ -670,14 +679,16 @@ class SettingsViewModel @Inject constructor (
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.ENABLE_CHANGER, enableChanger)
|
||||
_state.update {
|
||||
it.copy(
|
||||
homeAlbumName = if (event.albumName == _state.value.homeAlbumName) null else it.homeAlbumName,
|
||||
lockAlbumName = if (event.albumName == _state.value.lockAlbumName) null else it.lockAlbumName,
|
||||
currentHomeWallpaper = if (event.albumName == _state.value.homeAlbumName) null else it.currentHomeWallpaper,
|
||||
currentLockWallpaper = if (event.albumName == _state.value.lockAlbumName) null else it.currentLockWallpaper,
|
||||
enableChanger = enableChanger
|
||||
wallpaperSettings = it.wallpaperSettings.copy(
|
||||
homeAlbumName = if (event.albumName == _state.value.wallpaperSettings.homeAlbumName) null else it.wallpaperSettings.homeAlbumName,
|
||||
lockAlbumName = if (event.albumName == _state.value.wallpaperSettings.lockAlbumName) null else it.wallpaperSettings.lockAlbumName,
|
||||
currentHomeWallpaper = if (event.albumName == _state.value.wallpaperSettings.homeAlbumName) null else it.wallpaperSettings.currentHomeWallpaper,
|
||||
currentLockWallpaper = if (event.albumName == _state.value.wallpaperSettings.lockAlbumName) null else it.wallpaperSettings.currentLockWallpaper,
|
||||
enableChanger = enableChanger
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -688,7 +699,9 @@ class SettingsViewModel @Inject constructor (
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
nextHomeWallpaper = event.nextHomeWallpaper
|
||||
wallpaperSettings = it.wallpaperSettings.copy(
|
||||
nextHomeWallpaper = event.nextHomeWallpaper
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -701,7 +714,9 @@ class SettingsViewModel @Inject constructor (
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
nextLockWallpaper = event.nextLockWallpaper
|
||||
wallpaperSettings = it.wallpaperSettings.copy(
|
||||
nextLockWallpaper = event.nextLockWallpaper
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -717,8 +732,10 @@ class SettingsViewModel @Inject constructor (
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
nextHomeWallpaper = event.nextHomeWallpaper ?: it.nextHomeWallpaper,
|
||||
nextLockWallpaper = event.nextLockWallpaper ?: it.nextLockWallpaper
|
||||
wallpaperSettings = it.wallpaperSettings.copy(
|
||||
nextHomeWallpaper = event.nextHomeWallpaper ?: it.wallpaperSettings.nextHomeWallpaper,
|
||||
nextLockWallpaper = event.nextLockWallpaper ?: it.wallpaperSettings.nextLockWallpaper
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -730,10 +747,12 @@ class SettingsViewModel @Inject constructor (
|
||||
val nextLockWallpaper = async { settingsDataStoreImpl.getString(SettingsConstants.NEXT_LOCK_WALLPAPER) }
|
||||
_state.update {
|
||||
it.copy(
|
||||
nextHomeWallpaper = nextHomeWallpaper.await(),
|
||||
nextLockWallpaper = nextLockWallpaper.await(),
|
||||
currentHomeWallpaper = nextHomeWallpaper.await(),
|
||||
currentLockWallpaper = nextLockWallpaper.await()
|
||||
wallpaperSettings = it.wallpaperSettings.copy(
|
||||
nextHomeWallpaper = nextHomeWallpaper.await(),
|
||||
nextLockWallpaper = nextLockWallpaper.await(),
|
||||
currentHomeWallpaper = nextHomeWallpaper.await(),
|
||||
currentLockWallpaper = nextLockWallpaper.await()
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -743,9 +762,12 @@ class SettingsViewModel @Inject constructor (
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
|
||||
val currentTime = if (event.changeStartTime) {
|
||||
LocalDateTime.now().withHour(_state.value.startTime.first).withMinute(_state.value.startTime.second).let {
|
||||
if (it.isBefore(LocalDateTime.now())) it.plusDays(1) else it
|
||||
}
|
||||
LocalDateTime.now()
|
||||
.withHour(_state.value.scheduleSettings.startTime.first)
|
||||
.withMinute(_state.value.scheduleSettings.startTime.second)
|
||||
.let {
|
||||
if (it.isBefore(LocalDateTime.now())) it.plusDays(1) else it
|
||||
}
|
||||
} else {
|
||||
LocalDateTime.now()
|
||||
}
|
||||
@@ -755,16 +777,16 @@ class SettingsViewModel @Inject constructor (
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, currentTime.toString())
|
||||
currentTime.format(formatter)
|
||||
}
|
||||
_state.value.scheduleSeparately -> {
|
||||
val nextSetTime1 = currentTime.plusMinutes(_state.value.homeInterval.toLong())
|
||||
val nextSetTime2 = currentTime.plusMinutes(_state.value.lockInterval.toLong())
|
||||
_state.value.scheduleSettings.scheduleSeparately -> {
|
||||
val nextSetTime1 = currentTime.plusMinutes(_state.value.scheduleSettings.homeInterval.toLong())
|
||||
val nextSetTime2 = currentTime.plusMinutes(_state.value.scheduleSettings.lockInterval.toLong())
|
||||
val nextSetTime = if (nextSetTime1.isBefore(nextSetTime2)) nextSetTime1 else nextSetTime2
|
||||
settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, nextSetTime1.toString())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, nextSetTime2.toString())
|
||||
nextSetTime.format(formatter)
|
||||
}
|
||||
else -> {
|
||||
val nextSetTime = currentTime.plusMinutes(_state.value.homeInterval.toLong())
|
||||
val nextSetTime = currentTime.plusMinutes(_state.value.scheduleSettings.homeInterval.toLong())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, nextSetTime.toString())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, nextSetTime.toString())
|
||||
nextSetTime.format(formatter)
|
||||
@@ -772,8 +794,10 @@ class SettingsViewModel @Inject constructor (
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
changeStartTime = event.changeStartTime,
|
||||
nextSetTime = nextSetTime
|
||||
scheduleSettings = it.scheduleSettings.copy(
|
||||
changeStartTime = event.changeStartTime,
|
||||
nextSetTime = nextSetTime
|
||||
)
|
||||
)
|
||||
}
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, nextSetTime)
|
||||
@@ -790,9 +814,11 @@ class SettingsViewModel @Inject constructor (
|
||||
val nextSetTime = currentTime.format(formatter)
|
||||
_state.update {
|
||||
it.copy(
|
||||
startTime = Pair(event.hour, event.minute),
|
||||
changeStartTime = true,
|
||||
nextSetTime = nextSetTime
|
||||
scheduleSettings = it.scheduleSettings.copy(
|
||||
startTime = Pair(event.hour, event.minute),
|
||||
changeStartTime = true,
|
||||
nextSetTime = nextSetTime
|
||||
)
|
||||
)
|
||||
}
|
||||
settingsDataStoreImpl.run {
|
||||
@@ -808,81 +834,54 @@ class SettingsViewModel @Inject constructor (
|
||||
|
||||
is SettingsEvent.Reset -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.DARK_MODE_TYPE)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.AMOLED_THEME_TYPE)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.DYNAMIC_THEME_TYPE)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.FIRST_LAUNCH)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.LAST_SET_TIME)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.NEXT_SET_TIME)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.ANIMATE_TYPE)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.ENABLE_CHANGER)
|
||||
settingsDataStoreImpl.deleteInt(SettingsConstants.HOME_DARKEN_PERCENTAGE)
|
||||
settingsDataStoreImpl.deleteInt(SettingsConstants.LOCK_DARKEN_PERCENTAGE)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.DARKEN)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.WALLPAPER_SCALING)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.ENABLE_HOME_WALLPAPER)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.ENABLE_LOCK_WALLPAPER)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.CURRENT_HOME_WALLPAPER)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.CURRENT_LOCK_WALLPAPER)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.HOME_ALBUM_NAME)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.LOCK_ALBUM_NAME)
|
||||
settingsDataStoreImpl.deleteInt(SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL)
|
||||
settingsDataStoreImpl.deleteInt(SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.SCHEDULE_SEPARATELY)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.BLUR)
|
||||
settingsDataStoreImpl.deleteInt(SettingsConstants.HOME_BLUR_PERCENTAGE)
|
||||
settingsDataStoreImpl.deleteInt(SettingsConstants.LOCK_BLUR_PERCENTAGE)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.FIRST_SET)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.HOME_NEXT_SET_TIME)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.LOCK_NEXT_SET_TIME)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.NEXT_HOME_WALLPAPER)
|
||||
settingsDataStoreImpl.deleteString(SettingsConstants.NEXT_LOCK_WALLPAPER)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.VIGNETTE)
|
||||
settingsDataStoreImpl.deleteInt(SettingsConstants.HOME_VIGNETTE_PERCENTAGE)
|
||||
settingsDataStoreImpl.deleteInt(SettingsConstants.LOCK_VIGNETTE_PERCENTAGE)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.GRAYSCALE)
|
||||
settingsDataStoreImpl.deleteInt(SettingsConstants.HOME_GRAYSCALE_PERCENTAGE)
|
||||
settingsDataStoreImpl.deleteInt(SettingsConstants.LOCK_GRAYSCALE_PERCENTAGE)
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.CHANGE_START_TIME)
|
||||
settingsDataStoreImpl.deleteInt(SettingsConstants.START_HOUR)
|
||||
settingsDataStoreImpl.deleteInt(SettingsConstants.START_MINUTE)
|
||||
|
||||
val keysToDelete = listOf(
|
||||
SettingsConstants.DARK_MODE_TYPE,
|
||||
SettingsConstants.AMOLED_THEME_TYPE,
|
||||
SettingsConstants.DYNAMIC_THEME_TYPE,
|
||||
SettingsConstants.FIRST_LAUNCH,
|
||||
SettingsConstants.LAST_SET_TIME,
|
||||
SettingsConstants.NEXT_SET_TIME,
|
||||
SettingsConstants.ANIMATE_TYPE,
|
||||
SettingsConstants.ENABLE_CHANGER,
|
||||
SettingsConstants.HOME_DARKEN_PERCENTAGE,
|
||||
SettingsConstants.LOCK_DARKEN_PERCENTAGE,
|
||||
SettingsConstants.DARKEN,
|
||||
SettingsConstants.WALLPAPER_SCALING,
|
||||
SettingsConstants.ENABLE_HOME_WALLPAPER,
|
||||
SettingsConstants.ENABLE_LOCK_WALLPAPER,
|
||||
SettingsConstants.CURRENT_HOME_WALLPAPER,
|
||||
SettingsConstants.CURRENT_LOCK_WALLPAPER,
|
||||
SettingsConstants.HOME_ALBUM_NAME,
|
||||
SettingsConstants.LOCK_ALBUM_NAME,
|
||||
SettingsConstants.LOCK_WALLPAPER_CHANGE_INTERVAL,
|
||||
SettingsConstants.HOME_WALLPAPER_CHANGE_INTERVAL,
|
||||
SettingsConstants.SCHEDULE_SEPARATELY,
|
||||
SettingsConstants.BLUR,
|
||||
SettingsConstants.HOME_BLUR_PERCENTAGE,
|
||||
SettingsConstants.LOCK_BLUR_PERCENTAGE,
|
||||
SettingsConstants.FIRST_SET,
|
||||
SettingsConstants.HOME_NEXT_SET_TIME,
|
||||
SettingsConstants.LOCK_NEXT_SET_TIME,
|
||||
SettingsConstants.NEXT_HOME_WALLPAPER,
|
||||
SettingsConstants.NEXT_LOCK_WALLPAPER,
|
||||
SettingsConstants.VIGNETTE,
|
||||
SettingsConstants.HOME_VIGNETTE_PERCENTAGE,
|
||||
SettingsConstants.LOCK_VIGNETTE_PERCENTAGE,
|
||||
SettingsConstants.GRAYSCALE,
|
||||
SettingsConstants.HOME_GRAYSCALE_PERCENTAGE,
|
||||
SettingsConstants.LOCK_GRAYSCALE_PERCENTAGE,
|
||||
SettingsConstants.CHANGE_START_TIME,
|
||||
SettingsConstants.START_HOUR,
|
||||
SettingsConstants.START_MINUTE
|
||||
)
|
||||
settingsDataStoreImpl.clear(keysToDelete)
|
||||
_state.update {
|
||||
it.copy(
|
||||
darkMode = null,
|
||||
amoledTheme = false,
|
||||
dynamicTheming = false,
|
||||
firstLaunch = true,
|
||||
lastSetTime = null,
|
||||
nextSetTime = null,
|
||||
animate = true,
|
||||
enableChanger = false,
|
||||
homeDarkenPercentage = 100,
|
||||
lockDarkenPercentage = 100,
|
||||
homeBlurPercentage = 0,
|
||||
lockBlurPercentage = 0,
|
||||
darken = false,
|
||||
wallpaperScaling = ScalingConstants.FILL,
|
||||
setHomeWallpaper = false,
|
||||
setLockWallpaper = false,
|
||||
currentHomeWallpaper = null,
|
||||
currentLockWallpaper = null,
|
||||
lockInterval = SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT,
|
||||
homeInterval = SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT,
|
||||
homeAlbumName = null,
|
||||
lockAlbumName = null,
|
||||
scheduleSeparately = false,
|
||||
blur = false,
|
||||
nextHomeWallpaper = null,
|
||||
nextLockWallpaper = null,
|
||||
vignette = false,
|
||||
homeVignettePercentage = 0,
|
||||
lockVignettePercentage = 0,
|
||||
grayscale = false,
|
||||
homeGrayscalePercentage = 0,
|
||||
lockGrayscalePercentage = 0,
|
||||
changeStartTime = false,
|
||||
startTime = Pair(0, 0)
|
||||
themeSettings = ThemeSettings(),
|
||||
scheduleSettings = ScheduleSettings(),
|
||||
wallpaperSettings = WallpaperSettings(),
|
||||
effectSettings = EffectSettings()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+5
-23
@@ -37,11 +37,9 @@ import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.ExperimentalComposeUiApi
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.contentDescription
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.semantics.testTagsAsResourceId
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.airbnb.lottie.compose.LottieAnimation
|
||||
@@ -75,20 +73,13 @@ fun StartupScreen(
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
modifier = Modifier.semantics {
|
||||
testTagsAsResourceId = true
|
||||
},
|
||||
snackbarHost = {
|
||||
SnackbarHost(
|
||||
hostState = snackbarHostState,
|
||||
snackbar = { data ->
|
||||
Snackbar(
|
||||
snackbarData = data,
|
||||
modifier = Modifier
|
||||
.padding(PaddingValues(horizontal = 8.dp))
|
||||
.semantics {
|
||||
testTagsAsResourceId = true
|
||||
},
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 8.dp)),
|
||||
shape = RoundedCornerShape(24.dp)
|
||||
)
|
||||
}
|
||||
@@ -129,9 +120,7 @@ fun StartupScreen(
|
||||
snackbarHostState.currentSnackbarData?.dismiss()
|
||||
showToS = true
|
||||
} },
|
||||
modifier = Modifier
|
||||
.padding(PaddingValues(vertical = 16.dp))
|
||||
.testTag("paperize:privacy_notice_button"),
|
||||
modifier = Modifier.padding(PaddingValues(vertical = 16.dp))
|
||||
) {
|
||||
Text(text = stringResource(R.string.privacy_notice), textAlign = TextAlign.Start)
|
||||
}
|
||||
@@ -140,9 +129,7 @@ fun StartupScreen(
|
||||
},
|
||||
floatingActionButton = {
|
||||
ExtendedFloatingActionButton(
|
||||
modifier = Modifier
|
||||
.padding(8.dp)
|
||||
.testTag("paperize:floating_agree_button"),
|
||||
modifier = Modifier.padding(8.dp),
|
||||
onClick = {
|
||||
if (seenToS) {
|
||||
onAgree()
|
||||
@@ -176,11 +163,7 @@ fun StartupScreen(
|
||||
if (showToS) {
|
||||
seenToS = true
|
||||
AlertDialog(
|
||||
modifier = Modifier
|
||||
.fillMaxHeight(0.7f)
|
||||
.semantics {
|
||||
testTagsAsResourceId = true
|
||||
},
|
||||
modifier = Modifier.fillMaxHeight(0.7f),
|
||||
onDismissRequest = { showToS = false },
|
||||
title = {
|
||||
Box(modifier = Modifier.fillMaxWidth()) {
|
||||
@@ -194,8 +177,7 @@ fun StartupScreen(
|
||||
text = { PrivacyNoticeText() },
|
||||
confirmButton = {
|
||||
Button(
|
||||
onClick = { showToS = false },
|
||||
modifier = Modifier.testTag("paperize:dismiss_button"),
|
||||
onClick = { showToS = false }
|
||||
) {
|
||||
Text(stringResource(R.string.dismiss))
|
||||
}
|
||||
|
||||
+84
-106
@@ -29,14 +29,16 @@ import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.ExperimentalComposeUiApi
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.semantics.testTagsAsResourceId
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.core.ScalingConstants
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.AlbumWithWallpaperAndFolder
|
||||
import com.anthonyla.paperize.feature.wallpaper.domain.model.SelectedAlbum
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsState.EffectSettings
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsState.ScheduleSettings
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsState.ThemeSettings
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.SettingsState.WallpaperSettings
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.AlbumBottomSheet
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.BlurSwitchAndSlider
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.ChangerSelectionRow
|
||||
@@ -54,56 +56,34 @@ import kotlinx.coroutines.launch
|
||||
@Composable
|
||||
fun WallpaperScreen(
|
||||
albums: List<AlbumWithWallpaperAndFolder>,
|
||||
animate: Boolean,
|
||||
darken: Boolean,
|
||||
homeDarkenPercentage: Int,
|
||||
lockDarkenPercentage: Int,
|
||||
enableChanger: Boolean,
|
||||
homeEnabled: Boolean,
|
||||
homeInterval: Int,
|
||||
lockInterval: Int,
|
||||
lastSetTime: String?,
|
||||
lockEnabled: Boolean,
|
||||
nextSetTime: String?,
|
||||
currentHomeWallpaper: String?,
|
||||
currentLockWallpaper: String?,
|
||||
homeSelectedAlbum: SelectedAlbum?,
|
||||
lockSelectedAlbum: SelectedAlbum?,
|
||||
wallpaperSettings: WallpaperSettings,
|
||||
scheduleSettings: ScheduleSettings,
|
||||
themeSettings: ThemeSettings,
|
||||
effectSettings: EffectSettings,
|
||||
onDarkCheck: (Boolean) -> Unit,
|
||||
onDarkenPercentage: (Int, Int) -> Unit,
|
||||
onHomeCheckedChange: (Boolean) -> Unit,
|
||||
onLockCheckedChange: (Boolean) -> Unit,
|
||||
scheduleSeparately: Boolean,
|
||||
onScalingChange: (ScalingConstants) -> Unit,
|
||||
onScheduleSeparatelyChange: (Boolean) -> Unit,
|
||||
onScheduleWallpaperChanger: () -> Unit,
|
||||
onScalingChange: (ScalingConstants) -> Unit,
|
||||
onSelectAlbum: (AlbumWithWallpaperAndFolder, Boolean, Boolean) -> Unit,
|
||||
onHomeTimeChange: (Int) -> Unit,
|
||||
onLockTimeChange: (Int) -> Unit,
|
||||
onStop: (Boolean, Boolean) -> Unit,
|
||||
onToggleChanger: (Boolean) -> Unit,
|
||||
scaling: ScalingConstants,
|
||||
homeSelectedAlbum: SelectedAlbum?,
|
||||
lockSelectedAlbum: SelectedAlbum?,
|
||||
blur: Boolean,
|
||||
onBlurPercentageChange: (Int, Int) -> Unit,
|
||||
onBlurChange: (Boolean) -> Unit,
|
||||
homeBlurPercentage: Int,
|
||||
lockBlurPercentage: Int,
|
||||
homeVignettePercentage: Int,
|
||||
lockVignettePercentage: Int,
|
||||
onVignettePercentageChange: (Int, Int) -> Unit,
|
||||
onVignetteChange: (Boolean) -> Unit,
|
||||
vignette: Boolean,
|
||||
homeGrayscalePercentage: Int,
|
||||
lockGrayscalePercentage: Int,
|
||||
onGrayscalePercentageChange: (Int, Int) -> Unit,
|
||||
onGrayscaleChange: (Boolean) -> Unit,
|
||||
grayscale: Boolean,
|
||||
changeStartTime: Boolean,
|
||||
onChangeStartTimeToggle: (Boolean) -> Unit,
|
||||
onStartTimeChange: (TimePickerState) -> Unit,
|
||||
startingTime: Pair<Int, Int>
|
||||
onStartTimeChange: (TimePickerState) -> Unit
|
||||
) {
|
||||
val shouldShowScreen = homeEnabled || lockEnabled
|
||||
val shouldShowScreen = wallpaperSettings.setHomeWallpaper || wallpaperSettings.setLockWallpaper
|
||||
val shouldShowSettings = shouldShowScreen && homeSelectedAlbum != null && lockSelectedAlbum != null
|
||||
val scrollState = rememberScrollState()
|
||||
val context = LocalContext.current
|
||||
@@ -111,8 +91,8 @@ fun WallpaperScreen(
|
||||
val scope = rememberCoroutineScope()
|
||||
val snackbarHostState = remember { SnackbarHostState() }
|
||||
val showInterval = rememberSaveable { mutableStateOf(false) }
|
||||
val lock = rememberSaveable { mutableStateOf(false) }
|
||||
val home = rememberSaveable { mutableStateOf(false) }
|
||||
val lockEnabled = rememberSaveable { mutableStateOf(false) }
|
||||
val homeEnabled = rememberSaveable { mutableStateOf(false) }
|
||||
|
||||
Scaffold(
|
||||
snackbarHost = {
|
||||
@@ -126,9 +106,7 @@ fun WallpaperScreen(
|
||||
)
|
||||
}
|
||||
) },
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.semantics { testTagsAsResourceId = true },
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
content = { padding ->
|
||||
Column(
|
||||
modifier = Modifier
|
||||
@@ -138,27 +116,24 @@ fun WallpaperScreen(
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
ChangerSelectionRow(
|
||||
homeEnabled = homeEnabled,
|
||||
lockEnabled = lockEnabled,
|
||||
onHomeCheckedChange = onHomeCheckedChange,
|
||||
onLockCheckedChange = onLockCheckedChange
|
||||
onLockCheckedChange = onLockCheckedChange,
|
||||
homeEnabled = wallpaperSettings.setHomeWallpaper,
|
||||
lockEnabled = wallpaperSettings.setLockWallpaper
|
||||
)
|
||||
if (homeEnabled && lockEnabled) {
|
||||
if (wallpaperSettings.setHomeWallpaper && wallpaperSettings.setLockWallpaper) {
|
||||
IndividualSchedulingAndToggleRow(
|
||||
animate = animate,
|
||||
scheduleSeparately = scheduleSeparately,
|
||||
enableChanger = enableChanger,
|
||||
onToggleChanger = onToggleChanger,
|
||||
onScheduleSeparatelyChange = onScheduleSeparatelyChange
|
||||
onScheduleSeparatelyChange = onScheduleSeparatelyChange,
|
||||
scheduleSeparately = scheduleSettings.scheduleSeparately,
|
||||
enableChanger = wallpaperSettings.enableChanger,
|
||||
animate = themeSettings.animate
|
||||
)
|
||||
}
|
||||
if (homeEnabled || lockEnabled) {
|
||||
if (wallpaperSettings.setHomeWallpaper || wallpaperSettings.setLockWallpaper) {
|
||||
CurrentSelectedAlbum(
|
||||
homeSelectedAlbum = homeSelectedAlbum,
|
||||
lockSelectedAlbum = lockSelectedAlbum,
|
||||
scheduleSeparately = scheduleSeparately,
|
||||
animate = animate,
|
||||
enableChanger = enableChanger,
|
||||
onToggleChanger = {
|
||||
scope.launch {
|
||||
snackbarHostState.currentSnackbarData?.dismiss()
|
||||
@@ -175,8 +150,8 @@ fun WallpaperScreen(
|
||||
onOpenBottomSheet = { changeLock, changeHome ->
|
||||
if (albums.firstOrNull() != null) {
|
||||
openBottomSheet = true
|
||||
lock.value = changeLock
|
||||
home.value = changeHome
|
||||
lockEnabled.value = changeLock
|
||||
homeEnabled.value = changeHome
|
||||
} else {
|
||||
scope.launch {
|
||||
snackbarHostState.currentSnackbarData?.dismiss()
|
||||
@@ -208,33 +183,37 @@ fun WallpaperScreen(
|
||||
}
|
||||
onStop(lock, home)
|
||||
}
|
||||
}
|
||||
},
|
||||
scheduleSeparately = scheduleSettings.scheduleSeparately,
|
||||
enableChanger = wallpaperSettings.enableChanger,
|
||||
animate = themeSettings.animate
|
||||
)
|
||||
if (shouldShowSettings) {
|
||||
WallpaperPreviewAndScale(
|
||||
currentHomeWallpaper = currentHomeWallpaper,
|
||||
currentLockWallpaper = currentLockWallpaper,
|
||||
darken = darken,
|
||||
homeDarkenPercentage = homeDarkenPercentage,
|
||||
lockDarkenPercentage = lockDarkenPercentage,
|
||||
scaling = scaling,
|
||||
currentHomeWallpaper = wallpaperSettings.currentHomeWallpaper,
|
||||
currentLockWallpaper = wallpaperSettings.currentLockWallpaper,
|
||||
scaling = wallpaperSettings.wallpaperScaling,
|
||||
onScalingChange = onScalingChange,
|
||||
homeEnabled = homeEnabled,
|
||||
lockEnabled = lockEnabled,
|
||||
blur = blur,
|
||||
homeBlurPercentage = homeBlurPercentage,
|
||||
lockBlurPercentage = lockBlurPercentage,
|
||||
vignette = vignette,
|
||||
homeVignettePercentage = homeVignettePercentage,
|
||||
lockVignettePercentage = lockVignettePercentage,
|
||||
grayscale = grayscale,
|
||||
homeGrayscalePercentage = homeGrayscalePercentage,
|
||||
lockGrayscalePercentage = lockGrayscalePercentage
|
||||
homeBlurPercentage = effectSettings.homeBlurPercentage,
|
||||
lockBlurPercentage = effectSettings.lockBlurPercentage,
|
||||
homeDarkenPercentage = effectSettings.homeDarkenPercentage,
|
||||
lockDarkenPercentage = effectSettings.lockDarkenPercentage,
|
||||
homeVignettePercentage = effectSettings.homeVignettePercentage,
|
||||
lockVignettePercentage = effectSettings.lockVignettePercentage,
|
||||
homeGrayscalePercentage = effectSettings.homeGrayscalePercentage,
|
||||
lockGrayscalePercentage = effectSettings.lockGrayscalePercentage,
|
||||
homeEnabled = wallpaperSettings.setHomeWallpaper,
|
||||
lockEnabled = wallpaperSettings.setLockWallpaper,
|
||||
darken = effectSettings.darken,
|
||||
blur = effectSettings.blur,
|
||||
vignette = effectSettings.vignette,
|
||||
grayscale = effectSettings.grayscale
|
||||
)
|
||||
CurrentAndNextChange(lastSetTime, nextSetTime)
|
||||
CurrentAndNextChange(scheduleSettings.lastSetTime, scheduleSettings.nextSetTime)
|
||||
TimeSliders(
|
||||
homeInterval = homeInterval,
|
||||
lockInterval = lockInterval,
|
||||
homeInterval = scheduleSettings.homeInterval,
|
||||
lockInterval = scheduleSettings.lockInterval,
|
||||
startingTime = scheduleSettings.startTime,
|
||||
onHomeIntervalChange = { days, hours, minutes ->
|
||||
val totalMinutes = 24 * days * 60 + hours * 60 + minutes
|
||||
onHomeTimeChange(totalMinutes)
|
||||
@@ -243,52 +222,51 @@ fun WallpaperScreen(
|
||||
val totalMinutes = 24 * days * 60 + hours * 60 + minutes
|
||||
onLockTimeChange(totalMinutes)
|
||||
},
|
||||
showInterval = showInterval.value,
|
||||
animate = animate,
|
||||
onShowIntervalChange = { showInterval.value = it },
|
||||
scheduleSeparately = scheduleSeparately,
|
||||
lockEnabled = lockEnabled,
|
||||
homeEnabled = homeEnabled,
|
||||
onStartTimeChange = onStartTimeChange,
|
||||
changeStartTime = changeStartTime,
|
||||
startingTime = startingTime,
|
||||
onChangeStartTimeToggle = onChangeStartTimeToggle
|
||||
onShowIntervalChange = { showInterval.value = it },
|
||||
onChangeStartTimeToggle = onChangeStartTimeToggle,
|
||||
homeEnabled = wallpaperSettings.setHomeWallpaper,
|
||||
lockEnabled = wallpaperSettings.setLockWallpaper,
|
||||
showInterval = showInterval.value,
|
||||
scheduleSeparately = scheduleSettings.scheduleSeparately,
|
||||
changeStartTime = scheduleSettings.changeStartTime,
|
||||
animate = themeSettings.animate
|
||||
)
|
||||
DarkenSwitchAndSlider(
|
||||
homeDarkenPercentage = effectSettings.homeDarkenPercentage,
|
||||
lockDarkenPercentage = effectSettings.lockDarkenPercentage,
|
||||
onDarkCheck = onDarkCheck,
|
||||
darken = darken,
|
||||
onDarkenChange = onDarkenPercentage,
|
||||
homeDarkenPercentage = homeDarkenPercentage,
|
||||
lockDarkenPercentage = lockDarkenPercentage,
|
||||
animate = animate,
|
||||
bothEnabled = homeEnabled && lockEnabled
|
||||
darken = effectSettings.darken,
|
||||
animate = themeSettings.animate,
|
||||
bothEnabled = wallpaperSettings.setHomeWallpaper && wallpaperSettings.setLockWallpaper
|
||||
)
|
||||
BlurSwitchAndSlider(
|
||||
homeBlurPercentage = effectSettings.homeBlurPercentage,
|
||||
lockBlurPercentage = effectSettings.lockBlurPercentage,
|
||||
onBlurPercentageChange = onBlurPercentageChange,
|
||||
onBlurChange = onBlurChange,
|
||||
blur = blur,
|
||||
homeBlurPercentage = homeBlurPercentage,
|
||||
lockBlurPercentage = lockBlurPercentage,
|
||||
animate = animate,
|
||||
bothEnabled = homeEnabled && lockEnabled
|
||||
blur = effectSettings.blur,
|
||||
animate = themeSettings.animate,
|
||||
bothEnabled = wallpaperSettings.setHomeWallpaper && wallpaperSettings.setLockWallpaper
|
||||
)
|
||||
VignetteSwitchAndSlider(
|
||||
homeVignettePercentage = effectSettings.homeVignettePercentage,
|
||||
lockVignettePercentage = effectSettings.lockVignettePercentage,
|
||||
onVignettePercentageChange = onVignettePercentageChange,
|
||||
onVignetteChange = onVignetteChange,
|
||||
vignette = vignette,
|
||||
homeVignettePercentage = homeVignettePercentage,
|
||||
lockVignettePercentage = lockVignettePercentage,
|
||||
animate = animate,
|
||||
bothEnabled = homeEnabled && lockEnabled
|
||||
vignette = effectSettings.vignette,
|
||||
animate = themeSettings.animate,
|
||||
bothEnabled = wallpaperSettings.setHomeWallpaper && wallpaperSettings.setLockWallpaper
|
||||
)
|
||||
GrayscaleSwitchAndSlider(
|
||||
homeGrayscalePercentage = effectSettings.homeGrayscalePercentage,
|
||||
lockGrayscalePercentage = effectSettings.lockGrayscalePercentage,
|
||||
onGrayscalePercentageChange = onGrayscalePercentageChange,
|
||||
onGrayscaleChange = onGrayscaleChange,
|
||||
grayscale = grayscale,
|
||||
homeGrayscalePercentage = homeGrayscalePercentage,
|
||||
lockGrayscalePercentage = lockGrayscalePercentage,
|
||||
animate = animate,
|
||||
bothEnabled = homeEnabled && lockEnabled
|
||||
grayscale = effectSettings.grayscale,
|
||||
animate = themeSettings.animate,
|
||||
bothEnabled = wallpaperSettings.setHomeWallpaper && wallpaperSettings.setLockWallpaper
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -298,7 +276,6 @@ fun WallpaperScreen(
|
||||
albums = albums,
|
||||
homeSelectedAlbum = homeSelectedAlbum,
|
||||
lockSelectedAlbum = lockSelectedAlbum,
|
||||
onDismiss = { openBottomSheet = false },
|
||||
onSelect = { album ->
|
||||
openBottomSheet = false
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
@@ -310,16 +287,17 @@ fun WallpaperScreen(
|
||||
}
|
||||
}
|
||||
else {
|
||||
onSelectAlbum(album, lock.value, home.value)
|
||||
onSelectAlbum(album, lockEnabled.value, homeEnabled.value)
|
||||
onScheduleWallpaperChanger()
|
||||
}
|
||||
}
|
||||
else {
|
||||
onSelectAlbum(album, lock.value, home.value)
|
||||
onSelectAlbum(album, lockEnabled.value, homeEnabled.value)
|
||||
onScheduleWallpaperChanger()
|
||||
}
|
||||
},
|
||||
animate = animate
|
||||
onDismiss = { openBottomSheet = false },
|
||||
animate = themeSettings.animate
|
||||
)
|
||||
}
|
||||
},
|
||||
|
||||
+42
@@ -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
|
||||
)
|
||||
+1
-1
@@ -49,7 +49,7 @@ data class AlbumView(val initialAlbumName: String)
|
||||
* Data class for AddEdit screen
|
||||
*/
|
||||
@Serializable
|
||||
data class AddEdit(val wallpaper: String)
|
||||
data class AddAlbum(val wallpaper: String)
|
||||
|
||||
/**
|
||||
* Data class for WallpaperView screen
|
||||
|
||||
Reference in new issue
Block a user