Implemented toggle for wallpaper refresh
This commit is contained in:
1 parent
bb34c1e02f
commit
1e971d4ec3
13 files changed
+109
-33
No files matched your search
@@ -18,6 +18,7 @@ object SettingsConstants {
|
||||
const val LOCK_ALBUM_NAME = "lock_album_name"
|
||||
const val HOME_WALLPAPER_CHANGE_INTERVAL = "home_wallpaper_change_interval"
|
||||
const val LOCK_WALLPAPER_CHANGE_INTERVAL = "lock_wallpaper_change_interval"
|
||||
const val REFRESH = "refresh"
|
||||
const val WALLPAPER_CHANGE_INTERVAL_DEFAULT = 15
|
||||
const val WALLPAPER_CHANGE_INTERVAL_MIN = 1
|
||||
const val FIRST_LAUNCH = "first_launch"
|
||||
|
||||
+8
-2
@@ -504,6 +504,12 @@ fun PaperizeApp(
|
||||
)
|
||||
}
|
||||
},
|
||||
onRefreshChange = { refresh ->
|
||||
settingsViewModel.onEvent(SettingsEvent.SetRefresh(refresh))
|
||||
if (settingsState.value.wallpaperSettings.enableChanger) {
|
||||
scheduler.scheduleRefresh(refresh)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -712,7 +718,7 @@ private fun CoroutineScope.scheduleWallpaperUpdate(
|
||||
cancelImmediate = cancelImmediate,
|
||||
firstLaunch = firstLaunch
|
||||
)
|
||||
scheduler.scheduleRefresh()
|
||||
scheduler.scheduleRefresh(settingsState.scheduleSettings.refresh)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -739,7 +745,7 @@ private fun CoroutineScope.updateWallpaperAlarm(
|
||||
wallpaperAlarmItem = alarmItem,
|
||||
firstLaunch = firstLaunch
|
||||
)
|
||||
scheduler.scheduleRefresh()
|
||||
scheduler.scheduleRefresh(settingsState.scheduleSettings.refresh)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -68,7 +68,8 @@ fun HomeScreen(
|
||||
onGrayscaleChange: (Boolean) -> Unit,
|
||||
onChangeStartTimeToggle: (Boolean) -> Unit,
|
||||
onStartTimeChange: (TimePickerState) -> Unit,
|
||||
onShuffleCheck: (Boolean) -> Unit
|
||||
onShuffleCheck: (Boolean) -> Unit,
|
||||
onRefreshChange: (Boolean) -> Unit
|
||||
) {
|
||||
val tabItems = getTabItems()
|
||||
val pagerState = rememberPagerState(0) { tabItems.size }
|
||||
@@ -160,6 +161,7 @@ fun HomeScreen(
|
||||
onChangeStartTimeToggle = onChangeStartTimeToggle,
|
||||
onStartTimeChange = onStartTimeChange,
|
||||
onShuffleCheck = onShuffleCheck,
|
||||
onRefreshChange = onRefreshChange
|
||||
)
|
||||
else -> LibraryScreen(
|
||||
albums = albums,
|
||||
|
||||
+1
@@ -33,4 +33,5 @@ sealed class SettingsEvent {
|
||||
data class SetWallpaperScaling(val scaling: ScalingConstants): 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()
|
||||
}
|
||||
+2
-1
@@ -39,7 +39,8 @@ data class SettingsState(
|
||||
val lastSetTime: String? = null,
|
||||
val nextSetTime: String? = null,
|
||||
val changeStartTime: Boolean = false,
|
||||
val startTime: Pair<Int, Int> = Pair(0, 0)
|
||||
val startTime: Pair<Int, Int> = Pair(0, 0),
|
||||
val refresh: Boolean = true
|
||||
)
|
||||
|
||||
data class EffectSettings(
|
||||
|
||||
+12
-3
@@ -107,7 +107,8 @@ class SettingsViewModel @Inject constructor(
|
||||
settingsDataStoreImpl.getBooleanFlow(SettingsConstants.CHANGE_START_TIME),
|
||||
settingsDataStoreImpl.getIntFlow(SettingsConstants.START_HOUR),
|
||||
settingsDataStoreImpl.getIntFlow(SettingsConstants.START_MINUTE),
|
||||
settingsDataStoreImpl.getBooleanFlow(SettingsConstants.SHUFFLE)
|
||||
settingsDataStoreImpl.getBooleanFlow(SettingsConstants.SHUFFLE),
|
||||
settingsDataStoreImpl.getBooleanFlow(SettingsConstants.REFRESH)
|
||||
) { flows ->
|
||||
ScheduleSettings(
|
||||
scheduleSeparately = flows[0] as Boolean? ?: false,
|
||||
@@ -117,7 +118,8 @@ class SettingsViewModel @Inject constructor(
|
||||
nextSetTime = flows[4] as String?,
|
||||
changeStartTime = flows[5] as Boolean? ?: false,
|
||||
startTime = Pair(flows[6] as Int? ?: 0, flows[7] as Int? ?: 0),
|
||||
shuffle = flows[8] as Boolean? ?: true
|
||||
shuffle = flows[8] as Boolean? ?: true,
|
||||
refresh = flows[9] as Boolean? ?: true
|
||||
)
|
||||
}
|
||||
|
||||
@@ -539,6 +541,12 @@ class SettingsViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetRefresh -> {
|
||||
viewModelScope.launch {
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.REFRESH, event.refresh)
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.Reset -> {
|
||||
viewModelScope.launch {
|
||||
val keysToDelete = listOf(
|
||||
@@ -580,7 +588,8 @@ class SettingsViewModel @Inject constructor(
|
||||
SettingsConstants.CHANGE_START_TIME,
|
||||
SettingsConstants.START_HOUR,
|
||||
SettingsConstants.START_MINUTE,
|
||||
SettingsConstants.SHUFFLE
|
||||
SettingsConstants.SHUFFLE,
|
||||
SettingsConstants.REFRESH
|
||||
)
|
||||
settingsDataStoreImpl.clear(keysToDelete)
|
||||
}
|
||||
|
||||
+7
-2
@@ -16,7 +16,6 @@ import androidx.compose.material3.Snackbar
|
||||
import androidx.compose.material3.SnackbarDuration
|
||||
import androidx.compose.material3.SnackbarHost
|
||||
import androidx.compose.material3.SnackbarHostState
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TimePickerState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
@@ -45,6 +44,7 @@ import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.co
|
||||
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.TimeSliders
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.VignetteSwitchAndSlider
|
||||
@@ -80,7 +80,8 @@ fun WallpaperScreen(
|
||||
onGrayscaleChange: (Boolean) -> Unit,
|
||||
onChangeStartTimeToggle: (Boolean) -> Unit,
|
||||
onStartTimeChange: (TimePickerState) -> Unit,
|
||||
onShuffleCheck: (Boolean) -> Unit
|
||||
onShuffleCheck: (Boolean) -> Unit,
|
||||
onRefreshChange: (Boolean) -> Unit
|
||||
) {
|
||||
val shouldShowScreen = wallpaperSettings.setHomeWallpaper || wallpaperSettings.setLockWallpaper
|
||||
val shouldShowSettings = shouldShowScreen && homeSelectedAlbum != null && lockSelectedAlbum != null
|
||||
@@ -269,6 +270,10 @@ fun WallpaperScreen(
|
||||
animate = themeSettings.animate,
|
||||
bothEnabled = wallpaperSettings.setHomeWallpaper && wallpaperSettings.setLockWallpaper
|
||||
)
|
||||
RefreshSwitch(
|
||||
refresh = scheduleSettings.refresh,
|
||||
onRefreshChange = onRefreshChange
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-1
@@ -225,5 +225,4 @@ fun GrayscaleSwitchAndSlider(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
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.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 that toggles whether to allow album refresh (24 hrs)
|
||||
*/
|
||||
@Composable
|
||||
fun RefreshSwitch(
|
||||
refresh: Boolean,
|
||||
onRefreshChange: (Boolean) -> Unit,
|
||||
) {
|
||||
Surface(
|
||||
tonalElevation = 10.dp,
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(PaddingValues(horizontal = 16.dp, vertical = 8.dp))
|
||||
) {
|
||||
Column (
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center,
|
||||
) {
|
||||
Row (horizontalArrangement = Arrangement.Center, verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(
|
||||
text = stringResource(R.string.periodic_refresh),
|
||||
modifier = Modifier.padding(16.dp),
|
||||
fontWeight = FontWeight.W500
|
||||
)
|
||||
Switch(
|
||||
checked = refresh,
|
||||
onCheckedChange = onRefreshChange
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+16
-14
@@ -243,22 +243,24 @@ class WallpaperAlarmSchedulerImpl @Inject constructor(
|
||||
/**
|
||||
* Schedules a refresh alarm every 24hrs
|
||||
*/
|
||||
fun scheduleRefresh() {
|
||||
fun scheduleRefresh(refresh: Boolean = true) {
|
||||
cancelAlarm(Type.REFRESH)
|
||||
val intent = Intent(context, WallpaperReceiver::class.java).apply {
|
||||
putExtra("refresh", true)
|
||||
}
|
||||
val nextMidnight = LocalDateTime.now().plusDays(1).withHour(0).withMinute(0).withSecond(0).withNano(0)
|
||||
alarmManager.setAndAllowWhileIdle(
|
||||
AlarmManager.RTC_WAKEUP,
|
||||
nextMidnight.atZone(ZoneId.systemDefault()).toEpochSecond() * 1000,
|
||||
PendingIntent.getBroadcast(
|
||||
context,
|
||||
Type.REFRESH.ordinal,
|
||||
intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
|
||||
if (refresh) {
|
||||
val intent = Intent(context, WallpaperReceiver::class.java).apply {
|
||||
putExtra("refresh", true)
|
||||
}
|
||||
val nextMidnight = LocalDateTime.now().plusDays(1).withHour(0).withMinute(0).withSecond(0).withNano(0)
|
||||
alarmManager.setAndAllowWhileIdle(
|
||||
AlarmManager.RTC_WAKEUP,
|
||||
nextMidnight.atZone(ZoneId.systemDefault()).toEpochSecond() * 1000,
|
||||
PendingIntent.getBroadcast(
|
||||
context,
|
||||
Type.REFRESH.ordinal,
|
||||
intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+2
@@ -45,6 +45,7 @@ class WallpaperBootAndChangeReceiver : BroadcastReceiver() {
|
||||
val scheduleSeparately = settingsDataStoreImpl.getBoolean(SettingsConstants.SCHEDULE_SEPARATELY) ?: false
|
||||
val setLock = settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_LOCK_WALLPAPER) ?: false
|
||||
val setHome = settingsDataStoreImpl.getBoolean(SettingsConstants.ENABLE_HOME_WALLPAPER) ?: false
|
||||
val refresh = settingsDataStoreImpl.getBoolean(SettingsConstants.REFRESH) ?: true
|
||||
val alarmItem = WallpaperAlarmItem(
|
||||
homeInterval = homeInterval,
|
||||
lockInterval = lockInterval,
|
||||
@@ -63,6 +64,7 @@ class WallpaperBootAndChangeReceiver : BroadcastReceiver() {
|
||||
lockNextTime = settingsDataStoreImpl.getString(SettingsConstants.LOCK_NEXT_SET_TIME),
|
||||
)
|
||||
}
|
||||
scheduler.scheduleRefresh(refresh)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-9
@@ -1,15 +1,8 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.wallpaper_alarmmanager
|
||||
|
||||
import android.app.ActivityOptions
|
||||
import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
import android.app.Service.NOTIFICATION_SERVICE
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.content.ContextCompat.getSystemService
|
||||
import com.anthonyla.paperize.core.SettingsConstants
|
||||
import com.anthonyla.paperize.core.SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
import com.anthonyla.paperize.core.Type
|
||||
@@ -31,12 +24,13 @@ class WallpaperReceiver : BroadcastReceiver() {
|
||||
lateinit var settingsDataStoreImpl: SettingsDataStore
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
if (context != null) {
|
||||
if (intent?.getBooleanExtra("refresh", false) == true) {
|
||||
val refresh = intent?.getBooleanExtra("refresh", true)
|
||||
if (refresh == true) {
|
||||
val serviceIntent = Intent(context, HomeWallpaperService::class.java).apply {
|
||||
action = HomeWallpaperService.Actions.REFRESH.toString()
|
||||
}
|
||||
context.startService(serviceIntent)
|
||||
WallpaperAlarmSchedulerImpl(context).scheduleRefresh()
|
||||
WallpaperAlarmSchedulerImpl(context).scheduleRefresh(refresh)
|
||||
} else {
|
||||
val homeInterval = intent?.getIntExtra("homeInterval", WALLPAPER_CHANGE_INTERVAL_DEFAULT) ?: WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
val lockInterval = intent?.getIntExtra("lockInterval", WALLPAPER_CHANGE_INTERVAL_DEFAULT) ?: WALLPAPER_CHANGE_INTERVAL_DEFAULT
|
||||
|
||||
@@ -180,4 +180,5 @@
|
||||
<string name="sort_by_last_modified_newest">Sort by Last Modified (Newest)</string>
|
||||
<string name="sort_by_last_modified_oldest">Sort by Last Modified (Oldest)</string>
|
||||
<string name="shuffle_wallpaper">Shuffle Wallpapers</string>
|
||||
<string name="periodic_refresh">Periodic Refresh</string>
|
||||
</resources>
|
||||
Reference in new issue
Block a user