mirror of
https://github.com/Anthonyy232/Paperize.git
synced 2026-03-13 10:04:27 +08:00
Added setting to prevent changing wallpaper during landscape mode https://github.com/Anthonyy232/Paperize/issues/328
This commit is contained in:
@@ -47,4 +47,5 @@ object SettingsConstants {
|
||||
const val START_HOUR = "start_hour"
|
||||
const val START_MINUTE = "start_minute"
|
||||
const val SHUFFLE = "shuffle"
|
||||
const val SKIP_LANDSCAPE = "skip_landscape"
|
||||
}
|
||||
@@ -510,6 +510,9 @@ fun PaperizeApp(
|
||||
if (settingsState.value.wallpaperSettings.enableChanger) {
|
||||
scheduler.scheduleRefresh(refresh)
|
||||
}
|
||||
},
|
||||
onSkipLandscapeChange = { skipLandscape ->
|
||||
settingsViewModel.onEvent(SettingsEvent.SetSkipLandscape(skipLandscape))
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -64,7 +64,8 @@ fun HomeScreen(
|
||||
onChangeStartTimeToggle: (Boolean) -> Unit,
|
||||
onStartTimeChange: (TimePickerState) -> Unit,
|
||||
onShuffleCheck: (Boolean) -> Unit,
|
||||
onRefreshChange: (Boolean) -> Unit
|
||||
onRefreshChange: (Boolean) -> Unit,
|
||||
onSkipLandscapeChange: (Boolean) -> Unit
|
||||
) {
|
||||
val tabItems = getTabItems()
|
||||
val pagerState = rememberPagerState(0) { tabItems.size }
|
||||
@@ -142,7 +143,8 @@ fun HomeScreen(
|
||||
onChangeStartTimeToggle = onChangeStartTimeToggle,
|
||||
onStartTimeChange = onStartTimeChange,
|
||||
onShuffleCheck = onShuffleCheck,
|
||||
onRefreshChange = onRefreshChange
|
||||
onRefreshChange = onRefreshChange,
|
||||
onSkipLandscapeChange = onSkipLandscapeChange
|
||||
)
|
||||
else -> LibraryScreen(
|
||||
albums = albums,
|
||||
|
||||
@@ -34,4 +34,5 @@ sealed class SettingsEvent {
|
||||
data class SetStartTime(val hour: Int, val minute: Int): SettingsEvent()
|
||||
data class SetShuffle(val shuffle: Boolean): SettingsEvent()
|
||||
data class SetRefresh(val refresh: Boolean): SettingsEvent()
|
||||
data class SetSkipLandscape(val skipLandscape: Boolean): SettingsEvent()
|
||||
}
|
||||
@@ -40,7 +40,8 @@ data class SettingsState(
|
||||
val nextSetTime: String? = null,
|
||||
val changeStartTime: Boolean = false,
|
||||
val startTime: Pair<Int, Int> = Pair(0, 0),
|
||||
val refresh: Boolean = true
|
||||
val refresh: Boolean = true,
|
||||
val skipLandscape: Boolean = false
|
||||
)
|
||||
|
||||
data class EffectSettings(
|
||||
@@ -77,6 +78,7 @@ data class SettingsState(
|
||||
val lockGrayscalePercentage: Int,
|
||||
val lockAlbumName: String,
|
||||
val homeAlbumName: String,
|
||||
val shuffle: Boolean
|
||||
val shuffle: Boolean,
|
||||
val skipLandscape: Boolean
|
||||
)
|
||||
}
|
||||
@@ -108,7 +108,8 @@ class SettingsViewModel @Inject constructor(
|
||||
settingsDataStoreImpl.getIntFlow(SettingsConstants.START_HOUR),
|
||||
settingsDataStoreImpl.getIntFlow(SettingsConstants.START_MINUTE),
|
||||
settingsDataStoreImpl.getBooleanFlow(SettingsConstants.SHUFFLE),
|
||||
settingsDataStoreImpl.getBooleanFlow(SettingsConstants.REFRESH)
|
||||
settingsDataStoreImpl.getBooleanFlow(SettingsConstants.REFRESH),
|
||||
settingsDataStoreImpl.getBooleanFlow(SettingsConstants.SKIP_LANDSCAPE)
|
||||
) { flows ->
|
||||
ScheduleSettings(
|
||||
scheduleSeparately = flows[0] as Boolean? ?: false,
|
||||
@@ -119,7 +120,8 @@ class SettingsViewModel @Inject constructor(
|
||||
changeStartTime = flows[5] as Boolean? ?: false,
|
||||
startTime = Pair(flows[6] as Int? ?: 0, flows[7] as Int? ?: 0),
|
||||
shuffle = flows[8] as Boolean? ?: true,
|
||||
refresh = flows[9] as Boolean? ?: true
|
||||
refresh = flows[9] as Boolean? ?: true,
|
||||
skipLandscape = flows[10] as Boolean? ?: false
|
||||
)
|
||||
}
|
||||
|
||||
@@ -547,6 +549,12 @@ class SettingsViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetSkipLandscape -> {
|
||||
viewModelScope.launch {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.SKIP_LANDSCAPE, event.skipLandscape)
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.Reset -> {
|
||||
viewModelScope.launch {
|
||||
val keysToDelete = listOf(
|
||||
@@ -589,7 +597,8 @@ class SettingsViewModel @Inject constructor(
|
||||
SettingsConstants.START_HOUR,
|
||||
SettingsConstants.START_MINUTE,
|
||||
SettingsConstants.SHUFFLE,
|
||||
SettingsConstants.REFRESH
|
||||
SettingsConstants.REFRESH,
|
||||
SettingsConstants.SKIP_LANDSCAPE
|
||||
)
|
||||
settingsDataStoreImpl.clear(keysToDelete)
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.co
|
||||
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.TimeSliders
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.VignetteSwitchAndSlider
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.WallpaperPreviewAndScale
|
||||
@@ -81,7 +82,8 @@ fun WallpaperScreen(
|
||||
onChangeStartTimeToggle: (Boolean) -> Unit,
|
||||
onStartTimeChange: (TimePickerState) -> Unit,
|
||||
onShuffleCheck: (Boolean) -> Unit,
|
||||
onRefreshChange: (Boolean) -> Unit
|
||||
onRefreshChange: (Boolean) -> Unit,
|
||||
onSkipLandscapeChange: (Boolean) -> Unit
|
||||
) {
|
||||
val shouldShowScreen = wallpaperSettings.setHomeWallpaper || wallpaperSettings.setLockWallpaper
|
||||
val shouldShowSettings = shouldShowScreen && homeSelectedAlbum != null && lockSelectedAlbum != null
|
||||
@@ -274,6 +276,10 @@ fun WallpaperScreen(
|
||||
refresh = scheduleSettings.refresh,
|
||||
onRefreshChange = onRefreshChange
|
||||
)
|
||||
SkipLandscapeSwitch(
|
||||
skipLandscape = scheduleSettings.skipLandscape,
|
||||
onSkipLandscapeChange = onSkipLandscapeChange
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
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
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -204,7 +204,8 @@ class HomeWallpaperService: Service() {
|
||||
lockGrayscalePercentage = settingsDataStoreImpl.getInt(SettingsConstants.LOCK_GRAYSCALE_PERCENTAGE) ?: 0,
|
||||
lockAlbumName = settingsDataStoreImpl.getString(SettingsConstants.LOCK_ALBUM_NAME) ?: "",
|
||||
homeAlbumName = settingsDataStoreImpl.getString(SettingsConstants.HOME_ALBUM_NAME) ?: "",
|
||||
shuffle = settingsDataStoreImpl.getBoolean(SettingsConstants.SHUFFLE) ?: true
|
||||
shuffle = settingsDataStoreImpl.getBoolean(SettingsConstants.SHUFFLE) ?: true,
|
||||
skipLandscape = settingsDataStoreImpl.getBoolean(SettingsConstants.SKIP_LANDSCAPE) ?: false
|
||||
)
|
||||
}
|
||||
|
||||
@@ -224,6 +225,14 @@ class HomeWallpaperService: Service() {
|
||||
onDestroy()
|
||||
return
|
||||
}
|
||||
|
||||
// Check if we should skip wallpaper change due to landscape orientation
|
||||
if (settings.skipLandscape && context.resources.configuration.orientation == android.content.res.Configuration.ORIENTATION_LANDSCAPE) {
|
||||
Log.d("PaperizeWallpaperChanger", "Skipping wallpaper change - device is in landscape mode")
|
||||
onDestroy()
|
||||
return
|
||||
}
|
||||
|
||||
var homeAlbum = selectedAlbum.find { it.album.initialAlbumName == settings.homeAlbumName }
|
||||
if (homeAlbum == null) {
|
||||
onDestroy()
|
||||
@@ -561,7 +570,7 @@ class HomeWallpaperService: Service() {
|
||||
if (bothEnabled) {
|
||||
setWallpaper(
|
||||
context = context,
|
||||
wallpaper = currentHomeWallpaper.decompress("content://com.android.externalstorage.documents/").toUri(),
|
||||
wallpaper = currentHomeWallpaper.decompress("content://com.android/externalstorage/documents/").toUri(),
|
||||
darken = settings.darken,
|
||||
darkenPercent = settings.homeDarkenPercentage,
|
||||
scaling = settings.scaling,
|
||||
@@ -578,7 +587,7 @@ class HomeWallpaperService: Service() {
|
||||
if (settings.setHome) {
|
||||
setWallpaper(
|
||||
context = context,
|
||||
wallpaper = currentHomeWallpaper.decompress("content://com.android.externalstorage.documents/").toUri(),
|
||||
wallpaper = currentHomeWallpaper.decompress("content://com.android/externalstorage/documents/").toUri(),
|
||||
darken = settings.darken,
|
||||
darkenPercent = settings.homeDarkenPercentage,
|
||||
scaling = settings.scaling,
|
||||
|
||||
@@ -186,7 +186,8 @@ class LockWallpaperService: Service() {
|
||||
lockGrayscalePercentage = settingsDataStoreImpl.getInt(SettingsConstants.LOCK_GRAYSCALE_PERCENTAGE) ?: 0,
|
||||
lockAlbumName = settingsDataStoreImpl.getString(SettingsConstants.LOCK_ALBUM_NAME) ?: "",
|
||||
homeAlbumName = settingsDataStoreImpl.getString(SettingsConstants.HOME_ALBUM_NAME) ?: "",
|
||||
shuffle = settingsDataStoreImpl.getBoolean(SettingsConstants.SHUFFLE) ?: true
|
||||
shuffle = settingsDataStoreImpl.getBoolean(SettingsConstants.SHUFFLE) ?: true,
|
||||
skipLandscape = settingsDataStoreImpl.getBoolean(SettingsConstants.SKIP_LANDSCAPE) ?: false
|
||||
)
|
||||
}
|
||||
|
||||
@@ -206,6 +207,14 @@ class LockWallpaperService: Service() {
|
||||
onDestroy()
|
||||
return
|
||||
}
|
||||
|
||||
// Check if we should skip wallpaper change due to landscape orientation
|
||||
if (settings.skipLandscape && context.resources.configuration.orientation == android.content.res.Configuration.ORIENTATION_LANDSCAPE) {
|
||||
Log.d("PaperizeWallpaperChanger", "Skipping wallpaper change - device is in landscape mode")
|
||||
onDestroy()
|
||||
return
|
||||
}
|
||||
|
||||
val lockAlbum = selectedAlbum.find { it.album.initialAlbumName == settings.lockAlbumName }
|
||||
val homeAlbum = selectedAlbum.find { it.album.initialAlbumName == settings.homeAlbumName }
|
||||
if (lockAlbum == null || homeAlbum == null) {
|
||||
|
||||
@@ -148,6 +148,7 @@
|
||||
<string name="show_interval_sliders">Show interval sliders</string>
|
||||
<string name="interval_text">Time Interval</string>
|
||||
<string name="change_blur">Blur Effect</string>
|
||||
<string name="skip_landscape_mode">Skip in landscape mode</string>
|
||||
<string name="paperize_is_running">Paperize is running</string>
|
||||
<string name="next_wallpaper_change">Next wallpaper change: %1$s</string>
|
||||
<string name="delay_notice">Delay Notice</string>
|
||||
@@ -190,4 +191,5 @@
|
||||
<string name="darken_the_edges_of_the_image">Darken the edges of the image</string>
|
||||
<string name="make_the_colors_grayscale">Make the colors grayscale</string>
|
||||
<string name="shuffle_the_wallpapers">Shuffle the wallpapers</string>
|
||||
<string name="prevent_changing_during_landscape_mode">Prevent changing during landscape mode</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user