Unify switch components into two generic implementations

This commit is contained in:
Gian authored and Anthony La committed 2025-11-13 17:38:18 -08:00
1 parent 66c3a4bb2e
commit c6c841f7c0
9 files changed
+130 -1039

No files matched your search

@@ -37,19 +37,13 @@ import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.Set
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
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.CurrentAndNextChange
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.CurrentSelectedAlbum
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.DarkenSwitchAndSlider
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.GrayscaleSwitchAndSlider
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.IndividualSchedulingAndToggleRow
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.RefreshSwitch
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.ShuffleSwitch
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.SkipLandscapeSwitch
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.SkipNonInteractiveSwitch
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.SettingSwitch
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.SettingSwitchWithSlider
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.TimeSliders
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.VignetteSwitchAndSlider
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.WallpaperPreviewAndScale
import kotlinx.coroutines.launch
@@ -234,57 +228,73 @@ fun WallpaperScreen(
changeStartTime = scheduleSettings.changeStartTime,
animate = themeSettings.animate
)
ShuffleSwitch(
shuffle = scheduleSettings.shuffle,
onShuffleCheck = { onShuffleCheck(it) },
SettingSwitch(
title = R.string.shuffle,
description = R.string.shuffle_the_wallpapers,
checked = scheduleSettings.shuffle,
onCheckedChange = onShuffleCheck
)
DarkenSwitchAndSlider(
homeDarkenPercentage = effectSettings.homeDarkenPercentage,
lockDarkenPercentage = effectSettings.lockDarkenPercentage,
onDarkCheck = onDarkCheck,
onDarkenChange = onDarkenPercentage,
darken = effectSettings.darken,
animate = themeSettings.animate,
bothEnabled = wallpaperSettings.setHomeWallpaper && wallpaperSettings.setLockWallpaper
SettingSwitchWithSlider(
title = R.string.change_brightness,
description = R.string.change_the_image_brightness,
checked = effectSettings.darken,
onCheckedChange = onDarkCheck,
bothEnabled = wallpaperSettings.setHomeWallpaper && wallpaperSettings.setLockWallpaper,
homePercentage = effectSettings.homeDarkenPercentage,
lockPercentage = effectSettings.lockDarkenPercentage,
onPercentageChange = onDarkenPercentage,
animate = themeSettings.animate
)
BlurSwitchAndSlider(
homeBlurPercentage = effectSettings.homeBlurPercentage,
lockBlurPercentage = effectSettings.lockBlurPercentage,
onBlurPercentageChange = onBlurPercentageChange,
onBlurChange = onBlurChange,
blur = effectSettings.blur,
animate = themeSettings.animate,
bothEnabled = wallpaperSettings.setHomeWallpaper && wallpaperSettings.setLockWallpaper
SettingSwitchWithSlider(
title = R.string.change_blur,
description = R.string.add_blur_to_the_image,
checked = effectSettings.blur,
onCheckedChange = onBlurChange,
bothEnabled = wallpaperSettings.setHomeWallpaper && wallpaperSettings.setLockWallpaper,
homePercentage = effectSettings.homeBlurPercentage,
lockPercentage = effectSettings.lockBlurPercentage,
onPercentageChange = onBlurPercentageChange,
animate = themeSettings.animate
)
VignetteSwitchAndSlider(
homeVignettePercentage = effectSettings.homeVignettePercentage,
lockVignettePercentage = effectSettings.lockVignettePercentage,
onVignettePercentageChange = onVignettePercentageChange,
onVignetteChange = onVignetteChange,
vignette = effectSettings.vignette,
animate = themeSettings.animate,
bothEnabled = wallpaperSettings.setHomeWallpaper && wallpaperSettings.setLockWallpaper
SettingSwitchWithSlider(
title = R.string.change_vignette,
description = R.string.darken_the_edges_of_the_image,
checked = effectSettings.vignette,
onCheckedChange = onVignetteChange,
bothEnabled = wallpaperSettings.setHomeWallpaper && wallpaperSettings.setLockWallpaper,
homePercentage = effectSettings.homeVignettePercentage,
lockPercentage = effectSettings.lockVignettePercentage,
onPercentageChange = onVignettePercentageChange,
animate = themeSettings.animate
)
GrayscaleSwitchAndSlider(
homeGrayscalePercentage = effectSettings.homeGrayscalePercentage,
lockGrayscalePercentage = effectSettings.lockGrayscalePercentage,
onGrayscalePercentageChange = onGrayscalePercentageChange,
onGrayscaleChange = onGrayscaleChange,
grayscale = effectSettings.grayscale,
animate = themeSettings.animate,
bothEnabled = wallpaperSettings.setHomeWallpaper && wallpaperSettings.setLockWallpaper
SettingSwitchWithSlider(
title = R.string.gray_filter,
description = R.string.make_the_colors_grayscale,
checked = effectSettings.grayscale,
onCheckedChange = onGrayscaleChange,
bothEnabled = wallpaperSettings.setHomeWallpaper && wallpaperSettings.setLockWallpaper,
homePercentage = effectSettings.homeGrayscalePercentage,
lockPercentage = effectSettings.lockGrayscalePercentage,
onPercentageChange = onGrayscalePercentageChange,
animate = themeSettings.animate
)
RefreshSwitch(
refresh = scheduleSettings.refresh,
onRefreshChange = onRefreshChange
SettingSwitch(
title = R.string.periodic_refresh,
description = R.string.check_folders_for_new_wallpapers,
checked = scheduleSettings.refresh,
onCheckedChange = onRefreshChange
)
SkipLandscapeSwitch(
skipLandscape = scheduleSettings.skipLandscape,
onSkipLandscapeChange = onSkipLandscapeChange
SettingSwitch(
title = R.string.skip_landscape_mode,
description = R.string.prevent_changing_during_landscape_mode,
checked = scheduleSettings.skipLandscape,
onCheckedChange = onSkipLandscapeChange
)
SkipNonInteractiveSwitch(
skipNonInteractive = scheduleSettings.skipNonInteractive,
onSkipNonInteractiveChange = onSkipNonInteractiveChange
SettingSwitch(
title = R.string.skip_non_interactive_state,
description = R.string.prevent_changing_during_non_interactive_state,
checked = scheduleSettings.skipNonInteractive,
onCheckedChange = onSkipNonInteractiveChange
)
}
}
@@ -1,253 +0,0 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components
import android.os.Build
import android.view.HapticFeedbackConstants
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.animateContentSize
import androidx.compose.animation.core.LinearOutSlowInEasing
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.spring
import androidx.compose.animation.core.tween
import androidx.compose.animation.expandVertically
import androidx.compose.animation.fadeOut
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Slider
import androidx.compose.material3.SliderDefaults
import androidx.compose.material3.Surface
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.anthonyla.paperize.R
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlin.math.roundToInt
/**
* Composable that displays a switch and slider to adjust the brightness of the wallpaper
*/
@Composable
fun DarkenSwitchAndSlider(
onDarkCheck: (Boolean) -> Unit,
onDarkenChange: (Int, Int) -> Unit,
darken: Boolean,
bothEnabled: Boolean,
homeDarkenPercentage: Int,
lockDarkenPercentage: Int,
animate: Boolean
) {
val view = LocalView.current
val scope = rememberCoroutineScope()
var job by remember { mutableStateOf<Job?>(null) }
var homePercentage by rememberSaveable { mutableFloatStateOf(homeDarkenPercentage.toFloat()) }
var lockPercentage by rememberSaveable { mutableFloatStateOf(lockDarkenPercentage.toFloat()) }
Surface(
tonalElevation = 10.dp,
shape = RoundedCornerShape(16.dp),
modifier = Modifier
.fillMaxWidth()
.padding(PaddingValues(horizontal = 16.dp, vertical = 8.dp))
) {
val columnModifier = if (animate) {
Modifier.animateContentSize(animationSpec = tween(durationMillis = 300, easing = LinearOutSlowInEasing))
} else { Modifier }
Column(
modifier = columnModifier.padding(16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Column(
verticalArrangement = Arrangement.spacedBy(4.dp)
) {
Text(
text = stringResource(R.string.change_brightness),
style = MaterialTheme.typography.titleMedium,
fontWeight = FontWeight.W500
)
if (!darken) {
Text(
text = stringResource(R.string.change_the_image_brightness),
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
}
}
Switch(
checked = darken,
onCheckedChange = onDarkCheck
)
}
if (animate) {
AnimatedVisibility(
visible = darken,
enter = expandVertically(animationSpec = spring(dampingRatio = Spring.DampingRatioMediumBouncy, stiffness = Spring.StiffnessLow)),
exit = fadeOut(
animationSpec = tween(
durationMillis = 300,
easing = LinearOutSlowInEasing
)
)
) {
Column(
modifier = Modifier.padding(horizontal = 16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
if (bothEnabled) {
Text(
text = stringResource(R.string.home_screen),
style = MaterialTheme.typography.titleSmall,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.End,
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = "${homePercentage.roundToInt()}%",
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.primary
)
}
Slider(
value = homePercentage,
onValueChange = { value ->
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
homePercentage = value
job?.cancel()
job = scope.launch {
delay(100)
onDarkenChange(value.roundToInt(), lockPercentage.roundToInt())
}
},
valueRange = 0f..100f,
steps = 100,
colors = SliderDefaults.colors(
thumbColor = MaterialTheme.colorScheme.primary,
activeTrackColor = MaterialTheme.colorScheme.primary,
inactiveTrackColor = MaterialTheme.colorScheme.primaryContainer
),
onValueChangeFinished = {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
view.performHapticFeedback(HapticFeedbackConstants.CONFIRM)
} else {
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
}
}
)
Spacer(modifier = Modifier.height(8.dp))
Text(
text = stringResource(R.string.lock_screen),
style = MaterialTheme.typography.titleSmall,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.End,
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = "${lockPercentage.roundToInt()}%",
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.primary
)
}
Slider(
value = lockPercentage,
onValueChange = { value ->
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
lockPercentage = value
job?.cancel()
job = scope.launch {
delay(100)
onDarkenChange(homePercentage.roundToInt(), value.roundToInt())
}
},
valueRange = 0f..100f,
steps = 100,
colors = SliderDefaults.colors(
thumbColor = MaterialTheme.colorScheme.primary,
activeTrackColor = MaterialTheme.colorScheme.primary,
inactiveTrackColor = MaterialTheme.colorScheme.primaryContainer
),
onValueChangeFinished = {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
view.performHapticFeedback(HapticFeedbackConstants.CONFIRM)
} else {
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
}
}
)
} else {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.End,
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = "${homePercentage.roundToInt()}%",
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.primary
)
}
Slider(
value = homePercentage,
onValueChange = { value ->
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
homePercentage = value
job?.cancel()
job = scope.launch {
delay(100)
onDarkenChange(value.roundToInt(), lockPercentage.roundToInt())
}
},
valueRange = 0f..100f,
steps = 100,
colors = SliderDefaults.colors(
thumbColor = MaterialTheme.colorScheme.primary,
activeTrackColor = MaterialTheme.colorScheme.primary,
inactiveTrackColor = MaterialTheme.colorScheme.primaryContainer
),
onValueChangeFinished = {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
view.performHapticFeedback(HapticFeedbackConstants.CONFIRM)
} else {
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
}
}
)
}
}
}
}
}
}
}
@@ -1,252 +0,0 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components
import android.os.Build
import android.view.HapticFeedbackConstants
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.animateContentSize
import androidx.compose.animation.core.LinearOutSlowInEasing
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.spring
import androidx.compose.animation.core.tween
import androidx.compose.animation.expandVertically
import androidx.compose.animation.fadeOut
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Slider
import androidx.compose.material3.SliderDefaults
import androidx.compose.material3.Surface
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.anthonyla.paperize.R
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlin.math.roundToInt
/**
* Composable that displays a switch and slider for the grayscale effect
*/
@Composable
fun GrayscaleSwitchAndSlider(
onGrayscalePercentageChange: (Int, Int) -> Unit,
onGrayscaleChange: (Boolean) -> Unit,
grayscale: Boolean,
bothEnabled: Boolean,
homeGrayscalePercentage: Int,
lockGrayscalePercentage: Int,
animate: Boolean
) {
val view = LocalView.current
val scope = rememberCoroutineScope()
var job by remember { mutableStateOf<Job?>(null) }
var homePercentage by rememberSaveable { mutableFloatStateOf(homeGrayscalePercentage.toFloat()) }
var lockPercentage by rememberSaveable { mutableFloatStateOf(lockGrayscalePercentage.toFloat()) }
Surface(
tonalElevation = 10.dp,
shape = RoundedCornerShape(16.dp),
modifier = Modifier
.fillMaxWidth()
.padding(PaddingValues(horizontal = 16.dp, vertical = 8.dp))
) {
val columnModifier = if (animate) {
Modifier.animateContentSize(animationSpec = tween(durationMillis = 300, easing = LinearOutSlowInEasing))
} else { Modifier }
Column(
modifier = columnModifier.padding(16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Column(
verticalArrangement = Arrangement.spacedBy(4.dp)
) {
Text(
text = stringResource(R.string.gray_filter),
style = MaterialTheme.typography.titleMedium,
fontWeight = FontWeight.W500
)
if (!grayscale) {
Text(
text = stringResource(R.string.make_the_colors_grayscale),
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
}
}
Switch(
checked = grayscale,
onCheckedChange = onGrayscaleChange
)
}
if (animate) {
AnimatedVisibility(
visible = grayscale,
enter = expandVertically(animationSpec = spring(dampingRatio = Spring.DampingRatioMediumBouncy, stiffness = Spring.StiffnessLow)),
exit = fadeOut(
animationSpec = tween(
durationMillis = 300,
easing = LinearOutSlowInEasing
)
)
) {
Column(
modifier = Modifier.padding(horizontal = 16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
if (bothEnabled) {
Text(
text = stringResource(R.string.home_screen),
style = MaterialTheme.typography.titleSmall,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.End,
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = "${homePercentage.roundToInt()}%",
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.primary
)
}
Slider(
value = homePercentage,
onValueChange = { value ->
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
homePercentage = value
job?.cancel()
job = scope.launch {
delay(100)
onGrayscalePercentageChange(value.roundToInt(), lockPercentage.roundToInt())
}
},
valueRange = 0f..100f,
steps = 100,
colors = SliderDefaults.colors(
thumbColor = MaterialTheme.colorScheme.primary,
activeTrackColor = MaterialTheme.colorScheme.primary,
inactiveTrackColor = MaterialTheme.colorScheme.primaryContainer
),
onValueChangeFinished = {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
view.performHapticFeedback(HapticFeedbackConstants.CONFIRM)
} else {
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
}
}
)
Spacer(modifier = Modifier.height(8.dp))
Text(
text = stringResource(R.string.lock_screen),
style = MaterialTheme.typography.titleSmall,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.End,
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = "${lockPercentage.roundToInt()}%",
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.primary
)
}
Slider(
value = lockPercentage,
onValueChange = { value ->
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
lockPercentage = value
job?.cancel()
job = scope.launch {
delay(100)
onGrayscalePercentageChange(homePercentage.roundToInt(), value.roundToInt())
}
},
valueRange = 0f..100f,
steps = 100,
colors = SliderDefaults.colors(
thumbColor = MaterialTheme.colorScheme.primary,
activeTrackColor = MaterialTheme.colorScheme.primary,
inactiveTrackColor = MaterialTheme.colorScheme.primaryContainer
),
onValueChangeFinished = {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
view.performHapticFeedback(HapticFeedbackConstants.CONFIRM)
} else {
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
}
}
)
} else {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.End,
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = "${homePercentage.roundToInt()}%",
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.primary
)
}
Slider(
value = homePercentage,
onValueChange = { value ->
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
homePercentage = value
job?.cancel()
job = scope.launch {
delay(100)
onGrayscalePercentageChange(value.roundToInt(), lockPercentage.roundToInt())
}
},
valueRange = 0f..100f,
steps = 100,
colors = SliderDefaults.colors(
thumbColor = MaterialTheme.colorScheme.primary,
activeTrackColor = MaterialTheme.colorScheme.primary,
inactiveTrackColor = MaterialTheme.colorScheme.primaryContainer
),
onValueChangeFinished = {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
view.performHapticFeedback(HapticFeedbackConstants.CONFIRM)
} else {
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
}
}
)
}
}
}
}
}
}
}
@@ -1,5 +1,6 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components
import androidx.annotation.StringRes
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
@@ -17,15 +18,16 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.anthonyla.paperize.R
/**
* Composable that toggles whether to allow album refresh (24 hrs)
* Generic setting switch component with title and description
*/
@Composable
fun RefreshSwitch(
refresh: Boolean,
onRefreshChange: (Boolean) -> Unit,
fun SettingSwitch(
@StringRes title: Int,
@StringRes description: Int,
checked: Boolean,
onCheckedChange: (Boolean) -> Unit
) {
Surface(
tonalElevation = 10.dp,
@@ -45,20 +47,20 @@ fun RefreshSwitch(
verticalArrangement = Arrangement.spacedBy(4.dp)
) {
Text(
text = stringResource(R.string.periodic_refresh),
text = stringResource(title),
style = MaterialTheme.typography.titleMedium,
fontWeight = FontWeight.W500
)
Text(
text = stringResource(R.string.check_folders_for_new_wallpapers),
text = stringResource(description),
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
}
Switch(
checked = refresh,
onCheckedChange = onRefreshChange
checked = checked,
onCheckedChange = onCheckedChange
)
}
}
}
}
@@ -2,6 +2,7 @@ package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.c
import android.os.Build
import android.view.HapticFeedbackConstants
import androidx.annotation.StringRes
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.animateContentSize
import androidx.compose.animation.core.LinearOutSlowInEasing
@@ -40,29 +41,31 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.anthonyla.paperize.R
import kotlin.math.roundToInt
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlin.math.roundToInt
/**
* Composable that displays a switch and slider for the user to adjust the blur effect of the wallpaper
* Generic setting switch component with title, description, and adjustable sliders
*/
@Composable
fun BlurSwitchAndSlider(
onBlurPercentageChange: (Int, Int) -> Unit,
onBlurChange: (Boolean) -> Unit,
blur: Boolean,
fun SettingSwitchWithSlider(
@StringRes title: Int,
@StringRes description: Int,
checked: Boolean,
onCheckedChange: (Boolean) -> Unit,
bothEnabled: Boolean,
homeBlurPercentage: Int,
lockBlurPercentage: Int,
homePercentage: Int,
lockPercentage: Int,
onPercentageChange: (Int, Int) -> Unit,
animate: Boolean
) {
val view = LocalView.current
val scope = rememberCoroutineScope()
var job by remember { mutableStateOf<Job?>(null) }
var homePercentage by rememberSaveable { mutableFloatStateOf(homeBlurPercentage.toFloat()) }
var lockPercentage by rememberSaveable { mutableFloatStateOf(lockBlurPercentage.toFloat()) }
var homeValue by rememberSaveable { mutableFloatStateOf(homePercentage.toFloat()) }
var lockValue by rememberSaveable { mutableFloatStateOf(lockPercentage.toFloat()) }
Surface(
tonalElevation = 10.dp,
@@ -72,8 +75,15 @@ fun BlurSwitchAndSlider(
.padding(PaddingValues(horizontal = 16.dp, vertical = 8.dp))
) {
val columnModifier = if (animate) {
Modifier.animateContentSize(animationSpec = tween(durationMillis = 300, easing = LinearOutSlowInEasing))
} else { Modifier }
Modifier.animateContentSize(
animationSpec = tween(
durationMillis = 300,
easing = LinearOutSlowInEasing
)
)
} else {
Modifier
}
Column(
modifier = columnModifier.padding(16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp)
@@ -87,25 +97,24 @@ fun BlurSwitchAndSlider(
verticalArrangement = Arrangement.spacedBy(4.dp)
) {
Text(
text = stringResource(R.string.change_blur),
text = stringResource(title),
style = MaterialTheme.typography.titleMedium,
fontWeight = FontWeight.W500
)
if (!blur) {
if (!checked) {
Text(
text = stringResource(R.string.add_blur_to_the_image),
text = stringResource(description),
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
}
}
Switch(
checked = blur,
onCheckedChange = onBlurChange
checked = checked,
onCheckedChange = onCheckedChange
)
}
// Show sliders when blur is enabled, regardless of animation setting
if (blur) {
if (checked) {
val sliderContent = @Composable {
Column(
modifier = Modifier.padding(horizontal = 16.dp),
@@ -123,20 +132,23 @@ fun BlurSwitchAndSlider(
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = "${homePercentage.roundToInt()}%",
text = "${homeValue.roundToInt()}%",
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.primary
)
}
Slider(
value = homePercentage,
value = homeValue,
onValueChange = { value ->
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
homePercentage = value
homeValue = value
job?.cancel()
job = scope.launch {
delay(100)
onBlurPercentageChange(value.roundToInt(), lockPercentage.roundToInt())
onPercentageChange(
value.roundToInt(),
lockValue.roundToInt()
)
}
},
valueRange = 0f..100f,
@@ -166,20 +178,23 @@ fun BlurSwitchAndSlider(
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = "${lockPercentage.roundToInt()}%",
text = "${lockValue.roundToInt()}%",
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.primary
)
}
Slider(
value = lockPercentage,
value = lockValue,
onValueChange = { value ->
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
lockPercentage = value
lockValue = value
job?.cancel()
job = scope.launch {
delay(100)
onBlurPercentageChange(homePercentage.roundToInt(), value.roundToInt())
onPercentageChange(
homeValue.roundToInt(),
value.roundToInt()
)
}
},
valueRange = 0f..100f,
@@ -204,20 +219,23 @@ fun BlurSwitchAndSlider(
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = "${homePercentage.roundToInt()}%",
text = "${homeValue.roundToInt()}%",
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.primary
)
}
Slider(
value = homePercentage,
value = homeValue,
onValueChange = { value ->
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
homePercentage = value
homeValue = value
job?.cancel()
job = scope.launch {
delay(100)
onBlurPercentageChange(value.roundToInt(), lockPercentage.roundToInt())
onPercentageChange(
value.roundToInt(),
lockValue.roundToInt()
)
}
},
valueRange = 0f..100f,
@@ -241,8 +259,13 @@ fun BlurSwitchAndSlider(
if (animate) {
AnimatedVisibility(
visible = blur,
enter = expandVertically(animationSpec = spring(dampingRatio = Spring.DampingRatioMediumBouncy, stiffness = Spring.StiffnessLow)),
visible = checked,
enter = expandVertically(
animationSpec = spring(
dampingRatio = Spring.DampingRatioMediumBouncy,
stiffness = Spring.StiffnessLow
)
),
exit = fadeOut(
animationSpec = tween(
durationMillis = 300,
@@ -258,7 +281,4 @@ fun BlurSwitchAndSlider(
}
}
}
}
@@ -1,61 +0,0 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.anthonyla.paperize.R
@Composable
fun ShuffleSwitch(
shuffle: Boolean,
onShuffleCheck: (Boolean) -> Unit
) {
Surface(
tonalElevation = 10.dp,
shape = RoundedCornerShape(16.dp),
modifier = Modifier
.fillMaxWidth()
.padding(PaddingValues(horizontal = 16.dp, vertical = 8.dp))
) {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Column(
verticalArrangement = Arrangement.spacedBy(4.dp)
) {
Text(
text = stringResource(R.string.shuffle),
style = MaterialTheme.typography.titleMedium,
fontWeight = FontWeight.W500
)
Text(
text = stringResource(R.string.shuffle_the_wallpapers),
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
}
Switch(
checked = shuffle,
onCheckedChange = onShuffleCheck
)
}
}
}
@@ -1,61 +0,0 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.anthonyla.paperize.R
@Composable
fun SkipLandscapeSwitch(
skipLandscape: Boolean,
onSkipLandscapeChange: (Boolean) -> Unit
) {
Surface(
tonalElevation = 10.dp,
shape = RoundedCornerShape(16.dp),
modifier = Modifier
.fillMaxWidth()
.padding(PaddingValues(horizontal = 16.dp, vertical = 8.dp))
) {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Column(
verticalArrangement = Arrangement.spacedBy(4.dp)
) {
Text(
text = stringResource(R.string.skip_landscape_mode),
style = MaterialTheme.typography.titleMedium,
fontWeight = FontWeight.W500
)
Text(
text = stringResource(R.string.prevent_changing_during_landscape_mode),
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
}
Switch(
checked = skipLandscape,
onCheckedChange = onSkipLandscapeChange
)
}
}
}
@@ -1,61 +0,0 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.anthonyla.paperize.R
@Composable
fun SkipNonInteractiveSwitch(
skipNonInteractive: Boolean,
onSkipNonInteractiveChange: (Boolean) -> Unit
) {
Surface(
tonalElevation = 10.dp,
shape = RoundedCornerShape(16.dp),
modifier = Modifier
.fillMaxWidth()
.padding(PaddingValues(horizontal = 16.dp, vertical = 8.dp))
) {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Column(
verticalArrangement = Arrangement.spacedBy(4.dp)
) {
Text(
text = stringResource(R.string.skip_non_interactive_state),
style = MaterialTheme.typography.titleMedium,
fontWeight = FontWeight.W500
)
Text(
text = stringResource(R.string.prevent_changing_during_non_interactive_state),
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
}
Switch(
checked = skipNonInteractive,
onCheckedChange = onSkipNonInteractiveChange
)
}
}
}
@@ -1,253 +0,0 @@
package com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components
import android.os.Build
import android.view.HapticFeedbackConstants
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.animateContentSize
import androidx.compose.animation.core.LinearOutSlowInEasing
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.spring
import androidx.compose.animation.core.tween
import androidx.compose.animation.expandVertically
import androidx.compose.animation.fadeOut
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Slider
import androidx.compose.material3.SliderDefaults
import androidx.compose.material3.Surface
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.anthonyla.paperize.R
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlin.math.roundToInt
/**
* Composable that displays a switch and slider for the vignette effect
*/
@Composable
fun VignetteSwitchAndSlider(
onVignettePercentageChange: (Int, Int) -> Unit,
onVignetteChange: (Boolean) -> Unit,
vignette: Boolean,
bothEnabled: Boolean,
homeVignettePercentage: Int,
lockVignettePercentage: Int,
animate: Boolean
) {
val view = LocalView.current
val scope = rememberCoroutineScope()
var job by remember { mutableStateOf<Job?>(null) }
var homePercentage by rememberSaveable { mutableFloatStateOf(homeVignettePercentage.toFloat()) }
var lockPercentage by rememberSaveable { mutableFloatStateOf(lockVignettePercentage.toFloat()) }
Surface(
tonalElevation = 10.dp,
shape = RoundedCornerShape(16.dp),
modifier = Modifier
.fillMaxWidth()
.padding(PaddingValues(horizontal = 16.dp, vertical = 8.dp))
) {
val columnModifier = if (animate) {
Modifier.animateContentSize(animationSpec = tween(durationMillis = 300, easing = LinearOutSlowInEasing))
} else { Modifier }
Column(
modifier = columnModifier.padding(16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Column(
verticalArrangement = Arrangement.spacedBy(4.dp)
) {
Text(
text = stringResource(R.string.change_vignette),
style = MaterialTheme.typography.titleMedium,
fontWeight = FontWeight.W500
)
if (!vignette) {
Text(
text = stringResource(R.string.darken_the_edges_of_the_image),
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
}
}
Switch(
checked = vignette,
onCheckedChange = onVignetteChange
)
}
if (animate) {
AnimatedVisibility(
visible = vignette,
enter = expandVertically(animationSpec = spring(dampingRatio = Spring.DampingRatioMediumBouncy, stiffness = Spring.StiffnessLow)),
exit = fadeOut(
animationSpec = tween(
durationMillis = 300,
easing = LinearOutSlowInEasing
)
)
) {
Column(
modifier = Modifier.padding(horizontal = 16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
if (bothEnabled) {
Text(
text = stringResource(R.string.home_screen),
style = MaterialTheme.typography.titleSmall,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.End,
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = "${homePercentage.roundToInt()}%",
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.primary
)
}
Slider(
value = homePercentage,
onValueChange = { value ->
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
homePercentage = value
job?.cancel()
job = scope.launch {
delay(100)
onVignettePercentageChange(value.roundToInt(), lockPercentage.roundToInt())
}
},
valueRange = 0f..100f,
steps = 100,
colors = SliderDefaults.colors(
thumbColor = MaterialTheme.colorScheme.primary,
activeTrackColor = MaterialTheme.colorScheme.primary,
inactiveTrackColor = MaterialTheme.colorScheme.primaryContainer
),
onValueChangeFinished = {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
view.performHapticFeedback(HapticFeedbackConstants.CONFIRM)
} else {
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
}
}
)
Spacer(modifier = Modifier.height(8.dp))
Text(
text = stringResource(R.string.lock_screen),
style = MaterialTheme.typography.titleSmall,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.End,
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = "${lockPercentage.roundToInt()}%",
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.primary
)
}
Slider(
value = lockPercentage,
onValueChange = { value ->
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
lockPercentage = value
job?.cancel()
job = scope.launch {
delay(100)
onVignettePercentageChange(homePercentage.roundToInt(), value.roundToInt())
}
},
valueRange = 0f..100f,
steps = 100,
colors = SliderDefaults.colors(
thumbColor = MaterialTheme.colorScheme.primary,
activeTrackColor = MaterialTheme.colorScheme.primary,
inactiveTrackColor = MaterialTheme.colorScheme.primaryContainer
),
onValueChangeFinished = {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
view.performHapticFeedback(HapticFeedbackConstants.CONFIRM)
} else {
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
}
}
)
} else {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.End,
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = "${homePercentage.roundToInt()}%",
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.primary
)
}
Slider(
value = homePercentage,
onValueChange = { value ->
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
homePercentage = value
job?.cancel()
job = scope.launch {
delay(100)
onVignettePercentageChange(value.roundToInt(), lockPercentage.roundToInt())
}
},
valueRange = 0f..100f,
steps = 100,
colors = SliderDefaults.colors(
thumbColor = MaterialTheme.colorScheme.primary,
activeTrackColor = MaterialTheme.colorScheme.primary,
inactiveTrackColor = MaterialTheme.colorScheme.primaryContainer
),
onValueChangeFinished = {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
view.performHapticFeedback(HapticFeedbackConstants.CONFIRM)
} else {
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
}
}
)
}
}
}
}
}
}
}