Added ability to change starting time
Added settings item for notification permission access Fixed UI elements being out of frame in certain languages
This commit is contained in:
1 parent
18ca6283ee
commit
618e896393
19 files changed
+551
-170
No files matched your search
@@ -2,6 +2,8 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" android:maxSdkVersion="32" />
|
||||
<uses-permission android:name="android.permission.USE_EXACT_ALARM"/>
|
||||
<uses-permission android:name="android.permission.USE_EXACT_ALARM" />
|
||||
<uses-permission android:name="android.permission.SET_WALLPAPER"/>
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||
|
||||
@@ -42,4 +42,7 @@ object SettingsConstants {
|
||||
const val GRAYSCALE = "grayscale"
|
||||
const val HOME_GRAYSCALE_PERCENTAGE = "home_grayscale_percentage"
|
||||
const val LOCK_GRAYSCALE_PERCENTAGE = "lock_grayscale_percentage"
|
||||
const val CHANGE_START_TIME = "change_start_time"
|
||||
const val START_HOUR = "start_hour"
|
||||
const val START_MINUTE = "start_minute"
|
||||
}
|
||||
+81
-18
@@ -4,6 +4,7 @@ import android.Manifest
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import androidx.compose.foundation.layout.navigationBarsPadding
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
@@ -61,6 +62,7 @@ import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun PaperizeApp(
|
||||
firstLaunch: Boolean,
|
||||
@@ -230,6 +232,8 @@ fun PaperizeApp(
|
||||
grayscale = settingsState.value.grayscale,
|
||||
homeGrayscalePercentage = settingsState.value.homeGrayscalePercentage,
|
||||
lockGrayscalePercentage = settingsState.value.lockGrayscalePercentage,
|
||||
changeStartTime = settingsState.value.changeStartTime,
|
||||
startingTime = settingsState.value.startTime,
|
||||
onSettingsClick = { navController.navigate(Settings) },
|
||||
navigateToAddWallpaperScreen = {
|
||||
navController.navigate(AddEdit(it))
|
||||
@@ -248,13 +252,16 @@ fun PaperizeApp(
|
||||
lockInterval = settingsState.value.lockInterval,
|
||||
scheduleSeparately = settingsState.value.scheduleSeparately,
|
||||
setHome = settingsState.value.setHomeWallpaper,
|
||||
setLock = settingsState.value.setLockWallpaper
|
||||
setLock = settingsState.value.setLockWallpaper,
|
||||
changeStartTime = settingsState.value.changeStartTime,
|
||||
startTime = settingsState.value.startTime
|
||||
)
|
||||
alarmItem.let{scheduler.scheduleWallpaperAlarm(
|
||||
wallpaperAlarmItem = it,
|
||||
origin = null,
|
||||
changeImmediate = true,
|
||||
cancelImmediate = true
|
||||
cancelImmediate = true,
|
||||
firstLaunch = true
|
||||
) }
|
||||
scheduler.scheduleRefresh()
|
||||
}
|
||||
@@ -271,13 +278,14 @@ fun PaperizeApp(
|
||||
lockInterval = settingsState.value.lockInterval,
|
||||
scheduleSeparately = settingsState.value.scheduleSeparately,
|
||||
setHome = settingsState.value.setHomeWallpaper,
|
||||
setLock = settingsState.value.setLockWallpaper
|
||||
setLock = settingsState.value.setLockWallpaper,
|
||||
changeStartTime = settingsState.value.changeStartTime,
|
||||
startTime = settingsState.value.startTime
|
||||
)
|
||||
alarmItem.let{scheduler.updateWallpaperAlarm(it)}
|
||||
scheduler.scheduleRefresh()
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
onLockTimeChange = { timeInMinutes ->
|
||||
settingsViewModel.onEvent(SettingsEvent.SetLockWallpaperInterval(timeInMinutes))
|
||||
@@ -290,7 +298,9 @@ fun PaperizeApp(
|
||||
lockInterval = timeInMinutes,
|
||||
scheduleSeparately = settingsState.value.scheduleSeparately,
|
||||
setHome = settingsState.value.setHomeWallpaper,
|
||||
setLock = settingsState.value.setLockWallpaper
|
||||
setLock = settingsState.value.setLockWallpaper,
|
||||
changeStartTime = settingsState.value.changeStartTime,
|
||||
startTime = settingsState.value.startTime
|
||||
)
|
||||
alarmItem.let{scheduler.updateWallpaperAlarm(it)}
|
||||
scheduler.scheduleRefresh()
|
||||
@@ -330,13 +340,16 @@ fun PaperizeApp(
|
||||
lockInterval = settingsState.value.lockInterval,
|
||||
scheduleSeparately = settingsState.value.scheduleSeparately,
|
||||
setHome = settingsState.value.setHomeWallpaper,
|
||||
setLock = settingsState.value.setLockWallpaper
|
||||
setLock = settingsState.value.setLockWallpaper,
|
||||
changeStartTime = settingsState.value.changeStartTime,
|
||||
startTime = settingsState.value.startTime
|
||||
)
|
||||
alarmItem.let{scheduler.scheduleWallpaperAlarm(
|
||||
wallpaperAlarmItem = it,
|
||||
origin = null,
|
||||
changeImmediate = true,
|
||||
cancelImmediate = true
|
||||
cancelImmediate = true,
|
||||
firstLaunch = true
|
||||
) }
|
||||
scheduler.scheduleRefresh()
|
||||
}
|
||||
@@ -458,14 +471,17 @@ fun PaperizeApp(
|
||||
lockInterval = settingsState.value.lockInterval,
|
||||
scheduleSeparately = settingsState.value.scheduleSeparately,
|
||||
setHome = settingsState.value.setHomeWallpaper,
|
||||
setLock = settingsState.value.setLockWallpaper
|
||||
setLock = settingsState.value.setLockWallpaper,
|
||||
changeStartTime = settingsState.value.changeStartTime,
|
||||
startTime = settingsState.value.startTime
|
||||
)
|
||||
alarmItem.let {
|
||||
scheduler.scheduleWallpaperAlarm(
|
||||
wallpaperAlarmItem = it,
|
||||
origin = null,
|
||||
changeImmediate = true,
|
||||
cancelImmediate = true
|
||||
cancelImmediate = true,
|
||||
firstLaunch = true
|
||||
)
|
||||
}
|
||||
scheduler.scheduleRefresh()
|
||||
@@ -508,7 +524,6 @@ fun PaperizeApp(
|
||||
onHomeCheckedChange = { setHome -> settingsViewModel.onEvent(SettingsEvent.SetHome(setHome))
|
||||
if (!selectedState.value.selectedAlbum.isNullOrEmpty() && !setHome && !settingsState.value.setLockWallpaper) {
|
||||
settingsViewModel.onEvent(SettingsEvent.SetChangerToggle(false))
|
||||
settingsViewModel.onEvent(SettingsEvent.SetCurrentWallpaper("", ""))
|
||||
selectedState.value.selectedAlbum?.let { wallpaperScreenViewModel.onEvent(WallpaperEvent.Reset()) }
|
||||
scheduler.cancelWallpaperAlarm()
|
||||
}
|
||||
@@ -536,13 +551,16 @@ fun PaperizeApp(
|
||||
lockInterval = settingsState.value.lockInterval,
|
||||
scheduleSeparately = false,
|
||||
setHome = setHome,
|
||||
setLock = settingsState.value.setLockWallpaper
|
||||
setLock = settingsState.value.setLockWallpaper,
|
||||
changeStartTime = settingsState.value.changeStartTime,
|
||||
startTime = settingsState.value.startTime
|
||||
)
|
||||
alarmItem.let{scheduler.scheduleWallpaperAlarm(
|
||||
wallpaperAlarmItem = it,
|
||||
origin = null,
|
||||
changeImmediate = false,
|
||||
cancelImmediate = true,
|
||||
firstLaunch = true
|
||||
) }
|
||||
scheduler.scheduleRefresh()
|
||||
}
|
||||
@@ -567,7 +585,6 @@ fun PaperizeApp(
|
||||
onLockCheckedChange = { setLock -> settingsViewModel.onEvent(SettingsEvent.SetLock(setLock))
|
||||
if (selectedState.value.selectedAlbum!= null && !setLock && !settingsState.value.setHomeWallpaper) {
|
||||
settingsViewModel.onEvent(SettingsEvent.SetChangerToggle(false))
|
||||
settingsViewModel.onEvent(SettingsEvent.SetCurrentWallpaper("", ""))
|
||||
selectedState.value.selectedAlbum?.let {
|
||||
wallpaperScreenViewModel.onEvent(WallpaperEvent.Reset())
|
||||
}
|
||||
@@ -584,13 +601,16 @@ fun PaperizeApp(
|
||||
lockInterval = settingsState.value.lockInterval,
|
||||
scheduleSeparately = false,
|
||||
setHome = settingsState.value.setHomeWallpaper,
|
||||
setLock = setLock
|
||||
setLock = setLock,
|
||||
changeStartTime = settingsState.value.changeStartTime,
|
||||
startTime = settingsState.value.startTime
|
||||
)
|
||||
alarmItem.let{scheduler.scheduleWallpaperAlarm(
|
||||
alarmItem.let{ scheduler.scheduleWallpaperAlarm(
|
||||
wallpaperAlarmItem = it,
|
||||
origin = null,
|
||||
changeImmediate = false,
|
||||
cancelImmediate = true
|
||||
cancelImmediate = true,
|
||||
firstLaunch = true
|
||||
) }
|
||||
scheduler.scheduleRefresh()
|
||||
}
|
||||
@@ -659,14 +679,17 @@ fun PaperizeApp(
|
||||
lockInterval = settingsState.value.lockInterval,
|
||||
scheduleSeparately = changeSeparately,
|
||||
setHome = settingsState.value.setHomeWallpaper,
|
||||
setLock = settingsState.value.setLockWallpaper
|
||||
setLock = settingsState.value.setLockWallpaper,
|
||||
changeStartTime = settingsState.value.changeStartTime,
|
||||
startTime = settingsState.value.startTime
|
||||
)
|
||||
alarmItem.let{scheduler.scheduleWallpaperAlarm(
|
||||
wallpaperAlarmItem = it,
|
||||
origin = null,
|
||||
changeImmediate = true,
|
||||
cancelImmediate = true)
|
||||
}
|
||||
cancelImmediate = true,
|
||||
firstLaunch = true
|
||||
) }
|
||||
scheduler.scheduleRefresh()
|
||||
}
|
||||
}
|
||||
@@ -731,6 +754,46 @@ fun PaperizeApp(
|
||||
}
|
||||
}
|
||||
},
|
||||
onStartTimeChange = { time ->
|
||||
settingsViewModel.onEvent(SettingsEvent.SetStartTime(time.hour, time.minute))
|
||||
if (settingsState.value.enableChanger) {
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(1000)
|
||||
val alarmItem = WallpaperAlarmItem(
|
||||
homeInterval = settingsState.value.homeInterval,
|
||||
lockInterval = settingsState.value.lockInterval,
|
||||
scheduleSeparately = settingsState.value.scheduleSeparately,
|
||||
setHome = settingsState.value.setHomeWallpaper,
|
||||
setLock = settingsState.value.setLockWallpaper,
|
||||
changeStartTime = true,
|
||||
startTime = Pair(time.hour, time.minute)
|
||||
)
|
||||
alarmItem.let{scheduler.updateWallpaperAlarm(it, true)}
|
||||
scheduler.scheduleRefresh()
|
||||
}
|
||||
}
|
||||
},
|
||||
onChangeStartTimeToggle = { changeStartTime ->
|
||||
settingsViewModel.onEvent(SettingsEvent.SetChangeStartTime(changeStartTime))
|
||||
if (settingsState.value.enableChanger) {
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(1000)
|
||||
val alarmItem = WallpaperAlarmItem(
|
||||
homeInterval = settingsState.value.homeInterval,
|
||||
lockInterval = settingsState.value.lockInterval,
|
||||
scheduleSeparately = settingsState.value.scheduleSeparately,
|
||||
setHome = settingsState.value.setHomeWallpaper,
|
||||
setLock = settingsState.value.setLockWallpaper,
|
||||
changeStartTime = changeStartTime,
|
||||
startTime = settingsState.value.startTime
|
||||
)
|
||||
alarmItem.let{scheduler.updateWallpaperAlarm(it, true)}
|
||||
scheduler.scheduleRefresh()
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
// Navigate to the add album screen to create a new album and add wallpapers to it
|
||||
|
||||
+13
-2
@@ -5,6 +5,7 @@ import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.pager.HorizontalPager
|
||||
import androidx.compose.foundation.pager.rememberPagerState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Tab
|
||||
@@ -12,6 +13,7 @@ import androidx.compose.material3.TabRow
|
||||
import androidx.compose.material3.TabRowDefaults
|
||||
import androidx.compose.material3.TabRowDefaults.tabIndicatorOffset
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TimePickerState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
@@ -30,6 +32,7 @@ import com.anthonyla.paperize.feature.wallpaper.presentation.home_screen.compone
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.library_screen.LibraryScreen
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.WallpaperScreen
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun HomeScreen(
|
||||
albums: List<AlbumWithWallpaperAndFolder>,
|
||||
@@ -79,7 +82,11 @@ fun HomeScreen(
|
||||
lockGrayscalePercentage: Int,
|
||||
onGrayscalePercentageChange: (Int, Int) -> Unit,
|
||||
onGrayscaleChange: (Boolean) -> Unit,
|
||||
grayscale: Boolean
|
||||
grayscale: Boolean,
|
||||
changeStartTime: Boolean,
|
||||
onChangeStartTimeToggle: (Boolean) -> Unit,
|
||||
onStartTimeChange: (TimePickerState) -> Unit,
|
||||
startingTime: Pair<Int, Int>
|
||||
) {
|
||||
val tabItems = getTabItems()
|
||||
val pagerState = rememberPagerState(0) { tabItems.size }
|
||||
@@ -188,7 +195,11 @@ fun HomeScreen(
|
||||
lockGrayscalePercentage = lockGrayscalePercentage,
|
||||
onGrayscalePercentageChange = onGrayscalePercentageChange,
|
||||
onGrayscaleChange = onGrayscaleChange,
|
||||
grayscale = grayscale
|
||||
grayscale = grayscale,
|
||||
changeStartTime = changeStartTime,
|
||||
onChangeStartTimeToggle = onChangeStartTimeToggle,
|
||||
onStartTimeChange = onStartTimeChange,
|
||||
startingTime = startingTime
|
||||
)
|
||||
else -> LibraryScreen(
|
||||
albums = albums,
|
||||
|
||||
+2
@@ -18,6 +18,7 @@ sealed class SettingsEvent {
|
||||
data class SetGrayscale(val grayscale: Boolean): SettingsEvent()
|
||||
data class SetLock(val lock: Boolean): SettingsEvent()
|
||||
data class SetHome(val home: Boolean): SettingsEvent()
|
||||
data class SetChangeStartTime(val changeStartTime: Boolean): SettingsEvent()
|
||||
data class SetCurrentHomeWallpaper(val currentHomeWallpaper: String?): SettingsEvent()
|
||||
data class SetCurrentLockWallpaper(val currentLockWallpaper: String?): SettingsEvent()
|
||||
data class SetCurrentWallpaper(val currentHomeWallpaper: String?, val currentLockWallpaper: String?): SettingsEvent()
|
||||
@@ -36,5 +37,6 @@ sealed class SettingsEvent {
|
||||
data class SetNextHomeWallpaper(val nextHomeWallpaper: String?): SettingsEvent()
|
||||
data class SetNextLockWallpaper(val nextLockWallpaper: String?): SettingsEvent()
|
||||
data class SetNextWallpaper(val nextHomeWallpaper: String?, val nextLockWallpaper: String?): SettingsEvent()
|
||||
data class SetStartTime(val hour: Int, val minute: Int): SettingsEvent()
|
||||
data object RefreshNextWallpaper: SettingsEvent()
|
||||
}
|
||||
+12
@@ -2,6 +2,7 @@ package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen
|
||||
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.provider.Settings
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
@@ -41,6 +42,7 @@ import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.com
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.DynamicThemingListItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.LicenseListItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.ListSectionTitle
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.NotificationListItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.PaperizeListItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.PrivacyPolicyListItem
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components.ResetListItem
|
||||
@@ -155,6 +157,16 @@ fun SettingsScreen(
|
||||
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)
|
||||
|
||||
+3
-1
@@ -36,5 +36,7 @@ data class SettingsState(
|
||||
val lockGrayscalePercentage: Int = 0,
|
||||
val wallpaperScaling: ScalingConstants = ScalingConstants.FILL,
|
||||
val nextHomeWallpaper: String? = null,
|
||||
val nextLockWallpaper: String? = null
|
||||
val nextLockWallpaper: String? = null,
|
||||
val changeStartTime: Boolean = false,
|
||||
val startTime: Pair<Int, Int> = Pair(0, 0)
|
||||
)
|
||||
+127
-25
@@ -66,6 +66,8 @@ class SettingsViewModel @Inject constructor (
|
||||
val lockGrayscalePercentage = async { settingsDataStoreImpl.getInt(SettingsConstants.LOCK_GRAYSCALE_PERCENTAGE) ?: 0 }
|
||||
val nextHomeWallpaper = async { settingsDataStoreImpl.getString(SettingsConstants.HOME_NEXT_SET_TIME) }
|
||||
val nextLockWallpaper = async { settingsDataStoreImpl.getString(SettingsConstants.LOCK_NEXT_SET_TIME) }
|
||||
val changeStartTime = async { settingsDataStoreImpl.getBoolean(SettingsConstants.CHANGE_START_TIME) ?: false }
|
||||
val startTime = async { Pair(settingsDataStoreImpl.getInt(SettingsConstants.START_HOUR) ?: 0, settingsDataStoreImpl.getInt(SettingsConstants.START_MINUTE) ?: 0) }
|
||||
|
||||
_state.update {
|
||||
it.copy(
|
||||
@@ -100,7 +102,9 @@ class SettingsViewModel @Inject constructor (
|
||||
lockVignettePercentage = lockVignettePercentage.await(),
|
||||
grayscale = grayscale.await(),
|
||||
homeGrayscalePercentage = homeGrayscalePercentage.await(),
|
||||
lockGrayscalePercentage = lockGrayscalePercentage.await()
|
||||
lockGrayscalePercentage = lockGrayscalePercentage.await(),
|
||||
changeStartTime = changeStartTime.await(),
|
||||
startTime = startTime.await()
|
||||
)
|
||||
}
|
||||
setKeepOnScreenCondition = false
|
||||
@@ -125,8 +129,9 @@ class SettingsViewModel @Inject constructor (
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.ENABLE_CHANGER, event.toggle)
|
||||
_state.update {
|
||||
it.copy(
|
||||
enableChanger = event.toggle
|
||||
|
||||
enableChanger = event.toggle,
|
||||
currentHomeWallpaper = if (!event.toggle) null else it.currentHomeWallpaper,
|
||||
currentLockWallpaper = if (!event.toggle) null else it.currentLockWallpaper
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -165,6 +170,8 @@ class SettingsViewModel @Inject constructor (
|
||||
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(
|
||||
@@ -198,7 +205,9 @@ class SettingsViewModel @Inject constructor (
|
||||
lockVignettePercentage = lockVignettePercentage.await(),
|
||||
grayscale = grayscale.await(),
|
||||
homeGrayscalePercentage = homeGrayscalePercentage.await(),
|
||||
lockGrayscalePercentage = lockGrayscalePercentage.await()
|
||||
lockGrayscalePercentage = lockGrayscalePercentage.await(),
|
||||
changeStartTime = changeStartTime.await(),
|
||||
startTime = startTime.await()
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -264,7 +273,11 @@ 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 = LocalDateTime.now()
|
||||
val currentTime = if (_state.value.changeStartTime) {
|
||||
LocalDateTime.now().withHour(_state.value.startTime.first).withMinute(_state.value.startTime.second)
|
||||
} else {
|
||||
LocalDateTime.now()
|
||||
}
|
||||
val nextSetTime: String?
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, currentTime.format(formatter))
|
||||
if (_state.value.scheduleSeparately) {
|
||||
@@ -295,7 +308,11 @@ 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 = LocalDateTime.now()
|
||||
val currentTime = if (_state.value.changeStartTime) {
|
||||
LocalDateTime.now().withHour(_state.value.startTime.first).withMinute(_state.value.startTime.second)
|
||||
} else {
|
||||
LocalDateTime.now()
|
||||
}
|
||||
val nextSetTime: String?
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, currentTime.format(formatter))
|
||||
if (_state.value.scheduleSeparately) {
|
||||
@@ -325,29 +342,42 @@ class SettingsViewModel @Inject constructor (
|
||||
is SettingsEvent.RefreshNextSetTime -> {
|
||||
viewModelScope.launch {
|
||||
val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
|
||||
val currentTime = 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())
|
||||
val nextSetTime2 = currentTime.plusMinutes(_state.value.lockInterval.toLong())
|
||||
nextSetTime = (if (nextSetTime1!!.isBefore(nextSetTime2)) nextSetTime1 else nextSetTime2)!!.format(formatter)
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, nextSetTime)
|
||||
settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, nextSetTime1.toString())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, nextSetTime2.toString())
|
||||
}
|
||||
else {
|
||||
nextSetTime = currentTime.plusMinutes(_state.value.homeInterval.toLong()).format(formatter)
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, nextSetTime)
|
||||
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 currentTime = if (_state.value.changeStartTime) {
|
||||
var calculatedTime = LocalDateTime.now().withHour(_state.value.startTime.first).withMinute(_state.value.startTime.second)
|
||||
if (calculatedTime.isBefore(LocalDateTime.now())) {
|
||||
calculatedTime = calculatedTime.plusDays(1)
|
||||
}
|
||||
calculatedTime
|
||||
} else {
|
||||
LocalDateTime.now()
|
||||
}
|
||||
val nextSetTime = when {
|
||||
_state.value.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())
|
||||
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())
|
||||
}
|
||||
}.format(formatter)
|
||||
_state.update {
|
||||
it.copy(
|
||||
lastSetTime = currentTime.format(formatter),
|
||||
nextSetTime = nextSetTime
|
||||
lastSetTime = LocalDateTime.now().format(formatter),
|
||||
nextSetTime = nextSetTime,
|
||||
)
|
||||
}
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, LocalDateTime.now().format(formatter))
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, nextSetTime)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -709,6 +739,73 @@ class SettingsViewModel @Inject constructor (
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetChangeStartTime -> {
|
||||
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
|
||||
}
|
||||
} else {
|
||||
LocalDateTime.now()
|
||||
}
|
||||
val nextSetTime = when {
|
||||
event.changeStartTime -> {
|
||||
settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, currentTime.toString())
|
||||
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())
|
||||
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())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, nextSetTime.toString())
|
||||
settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, nextSetTime.toString())
|
||||
nextSetTime.format(formatter)
|
||||
}
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
changeStartTime = event.changeStartTime,
|
||||
nextSetTime = nextSetTime
|
||||
)
|
||||
}
|
||||
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, nextSetTime)
|
||||
settingsDataStoreImpl.putBoolean(SettingsConstants.CHANGE_START_TIME, event.changeStartTime)
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.SetStartTime -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
|
||||
val currentTime = LocalDateTime.now().withHour(event.hour).withMinute(event.minute).let {
|
||||
if (it.isBefore(LocalDateTime.now())) it.plusDays(1) else it
|
||||
}
|
||||
val nextSetTime = currentTime.format(formatter)
|
||||
_state.update {
|
||||
it.copy(
|
||||
startTime = Pair(event.hour, event.minute),
|
||||
changeStartTime = true,
|
||||
nextSetTime = nextSetTime
|
||||
)
|
||||
}
|
||||
settingsDataStoreImpl.run {
|
||||
putString(SettingsConstants.HOME_NEXT_SET_TIME, currentTime.toString())
|
||||
putString(SettingsConstants.LOCK_NEXT_SET_TIME, currentTime.toString())
|
||||
putString(SettingsConstants.NEXT_SET_TIME, nextSetTime)
|
||||
putInt(SettingsConstants.START_HOUR, event.hour)
|
||||
putInt(SettingsConstants.START_MINUTE, event.minute)
|
||||
putBoolean(SettingsConstants.CHANGE_START_TIME, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is SettingsEvent.Reset -> {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsDataStoreImpl.deleteBoolean(SettingsConstants.DARK_MODE_TYPE)
|
||||
@@ -746,6 +843,9 @@ class SettingsViewModel @Inject constructor (
|
||||
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)
|
||||
|
||||
_state.update {
|
||||
it.copy(
|
||||
@@ -780,7 +880,9 @@ class SettingsViewModel @Inject constructor (
|
||||
lockVignettePercentage = 0,
|
||||
grayscale = false,
|
||||
homeGrayscalePercentage = 0,
|
||||
lockGrayscalePercentage = 0
|
||||
lockGrayscalePercentage = 0,
|
||||
changeStartTime = false,
|
||||
startTime = Pair(0, 0)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.settings_screen.components
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.Notifications
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.ListItem
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
/**
|
||||
* Notification list item to send to the notification permission page
|
||||
*/
|
||||
@Composable
|
||||
fun NotificationListItem(onClick: () -> Unit) {
|
||||
Row {
|
||||
ListItem(
|
||||
modifier = Modifier
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
.clickable { onClick() },
|
||||
headlineContent = {
|
||||
Text(
|
||||
text = stringResource(R.string.notifications),
|
||||
style = MaterialTheme.typography.titleMedium
|
||||
) },
|
||||
supportingContent = {
|
||||
Text(
|
||||
text = stringResource(R.string.change_notification_settings),
|
||||
style = MaterialTheme.typography.bodySmall
|
||||
) },
|
||||
trailingContent = {},
|
||||
leadingContent = {
|
||||
Icon(
|
||||
Icons.Outlined.Notifications,
|
||||
contentDescription = stringResource(R.string.notifications),
|
||||
tint = MaterialTheme.colorScheme.primary
|
||||
) },
|
||||
tonalElevation = 5.dp
|
||||
)
|
||||
}
|
||||
}
|
||||
+12
-1
@@ -11,11 +11,13 @@ import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Snackbar
|
||||
import androidx.compose.material3.SnackbarDuration
|
||||
import androidx.compose.material3.SnackbarHost
|
||||
import androidx.compose.material3.SnackbarHostState
|
||||
import androidx.compose.material3.TimePickerState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
@@ -45,6 +47,7 @@ import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.co
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.wallpaper_screen.components.WallpaperPreviewAndScale
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun WallpaperScreen(
|
||||
albums: List<AlbumWithWallpaperAndFolder>,
|
||||
@@ -92,6 +95,10 @@ fun WallpaperScreen(
|
||||
onGrayscalePercentageChange: (Int, Int) -> Unit,
|
||||
onGrayscaleChange: (Boolean) -> Unit,
|
||||
grayscale: Boolean,
|
||||
changeStartTime: Boolean,
|
||||
onChangeStartTimeToggle: (Boolean) -> Unit,
|
||||
onStartTimeChange: (TimePickerState) -> Unit,
|
||||
startingTime: Pair<Int, Int>
|
||||
) {
|
||||
val shouldShowScreen = homeEnabled || lockEnabled
|
||||
val shouldShowSettings = shouldShowScreen && homeSelectedAlbum != null && lockSelectedAlbum != null
|
||||
@@ -236,7 +243,11 @@ fun WallpaperScreen(
|
||||
onShowIntervalChange = { showInterval.value = it },
|
||||
scheduleSeparately = scheduleSeparately,
|
||||
lockEnabled = lockEnabled,
|
||||
homeEnabled = homeEnabled
|
||||
homeEnabled = homeEnabled,
|
||||
onStartTimeChange = onStartTimeChange,
|
||||
changeStartTime = changeStartTime,
|
||||
startingTime = startingTime,
|
||||
onChangeStartTimeToggle = onChangeStartTimeToggle
|
||||
)
|
||||
DarkenSwitchAndSlider(
|
||||
onDarkCheck = onDarkCheck,
|
||||
|
||||
+16
-6
@@ -12,6 +12,7 @@ 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.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
@@ -26,6 +27,7 @@ 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.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
|
||||
@@ -62,18 +64,22 @@ fun IndividualSchedulingAndToggleRow(
|
||||
modifier = columnModifier
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(start = 32.dp, end = 32.dp, top = 8.dp, bottom = 8.dp),
|
||||
horizontalArrangement = Arrangement.Center,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.individual_scheduling),
|
||||
modifier = Modifier.padding(16.dp),
|
||||
fontWeight = FontWeight.W500
|
||||
fontWeight = FontWeight.W500,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
maxLines = 1
|
||||
)
|
||||
Spacer(modifier = Modifier.padding(8.dp))
|
||||
Switch(
|
||||
checked = scheduleSeparately,
|
||||
onCheckedChange = onScheduleSeparatelyChange
|
||||
onCheckedChange = onScheduleSeparatelyChange,
|
||||
)
|
||||
}
|
||||
if (animate) {
|
||||
@@ -88,14 +94,18 @@ fun IndividualSchedulingAndToggleRow(
|
||||
HorizontalDivider(color = MaterialTheme.colorScheme.outline, thickness = 2.dp)
|
||||
}
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(start = 32.dp, end = 32.dp, top = 8.dp, bottom = 8.dp),
|
||||
horizontalArrangement = Arrangement.Center,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.enable_wallpaper_changer),
|
||||
modifier = Modifier.padding(16.dp),
|
||||
fontWeight = FontWeight.W500
|
||||
fontWeight = FontWeight.W500,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
maxLines = 1
|
||||
)
|
||||
Switch(
|
||||
checked = enableChanger,
|
||||
|
||||
+189
-42
@@ -12,6 +12,7 @@ import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.animation.shrinkVertically
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.IntrinsicSize
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
@@ -22,6 +23,8 @@ import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.ArrowDropDown
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
@@ -29,6 +32,9 @@ import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Slider
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TimePicker
|
||||
import androidx.compose.material3.TimePickerState
|
||||
import androidx.compose.material3.rememberTimePickerState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableFloatStateOf
|
||||
@@ -43,15 +49,19 @@ 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 androidx.compose.ui.window.Dialog
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.core.SettingsConstants.WALLPAPER_CHANGE_INTERVAL_MIN
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import java.util.Calendar
|
||||
import java.util.Locale
|
||||
|
||||
/**
|
||||
* TimeSliders is a composable that displays sliders for the user to select the time interval for changing wallpaper
|
||||
*/
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun TimeSliders(
|
||||
homeInterval: Int,
|
||||
@@ -64,6 +74,10 @@ fun TimeSliders(
|
||||
onLockIntervalChange: (Int, Int, Int) -> Unit,
|
||||
lockEnabled: Boolean,
|
||||
homeEnabled: Boolean,
|
||||
startingTime: Pair<Int, Int>,
|
||||
changeStartTime: Boolean,
|
||||
onChangeStartTimeToggle: (Boolean) -> Unit,
|
||||
onStartTimeChange: (TimePickerState) -> Unit
|
||||
) {
|
||||
val view = LocalView.current
|
||||
var days1 by rememberSaveable { mutableFloatStateOf((homeInterval / (24 * 60)).toFloat()) }
|
||||
@@ -75,13 +89,70 @@ fun TimeSliders(
|
||||
val scope = rememberCoroutineScope()
|
||||
val context = LocalView.current
|
||||
var job by remember { mutableStateOf<Job?>(null) }
|
||||
val shouldShowDialog = remember { mutableStateOf(false) }
|
||||
val timePickerState = rememberTimePickerState(
|
||||
initialHour = startingTime.first,
|
||||
initialMinute = startingTime.second,
|
||||
is24Hour = false,
|
||||
)
|
||||
|
||||
if (shouldShowDialog.value) {
|
||||
val initialHour = startingTime.first
|
||||
val initialMinute = startingTime.second
|
||||
Dialog(
|
||||
onDismissRequest = {
|
||||
timePickerState.hour = initialHour
|
||||
timePickerState.minute = initialMinute
|
||||
shouldShowDialog.value = false
|
||||
}
|
||||
) {
|
||||
Surface(
|
||||
shape = MaterialTheme.shapes.large,
|
||||
tonalElevation = 5.dp,
|
||||
modifier = Modifier
|
||||
.width(IntrinsicSize.Min)
|
||||
.height(IntrinsicSize.Min)
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.padding(24.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Text(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(bottom = 24.dp),
|
||||
text = stringResource(R.string.select_starting_time),
|
||||
style = MaterialTheme.typography.labelMedium
|
||||
)
|
||||
TimePicker(state = timePickerState)
|
||||
Spacer(modifier = Modifier.height(24.dp))
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.SpaceEvenly
|
||||
) {
|
||||
Button(
|
||||
onClick = { shouldShowDialog.value = false }
|
||||
) { Text(stringResource(R.string.dismiss)) }
|
||||
Button(
|
||||
onClick = { onStartTimeChange(timePickerState); shouldShowDialog.value = false }
|
||||
) { Text(stringResource(R.string.confirm)) }
|
||||
}
|
||||
Button(
|
||||
onClick = { onChangeStartTimeToggle(false); shouldShowDialog.value = false }
|
||||
) { Text(stringResource(R.string.reset_to_default)) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val columnModifier = remember {
|
||||
if (animate) {
|
||||
Modifier.animateContentSize(
|
||||
animationSpec = tween(durationMillis = 300, easing = LinearOutSlowInEasing)
|
||||
)
|
||||
} else { Modifier }
|
||||
} else {
|
||||
Modifier
|
||||
}
|
||||
}
|
||||
|
||||
Surface(
|
||||
@@ -91,7 +162,7 @@ fun TimeSliders(
|
||||
.fillMaxWidth()
|
||||
.padding(PaddingValues(horizontal = 16.dp, vertical = 8.dp))
|
||||
) {
|
||||
Column (
|
||||
Column(
|
||||
modifier = columnModifier
|
||||
) {
|
||||
val totalMinutes1 = (days1.toInt() * 24 * 60) + (hours1.toInt() * 60) + minutes1.toInt()
|
||||
@@ -101,22 +172,30 @@ fun TimeSliders(
|
||||
|
||||
val formattedDays1 = if (displayDays1 > 0) {
|
||||
context.resources.getQuantityString(R.plurals.days, displayDays1, displayDays1)
|
||||
} else {""}
|
||||
} else { "" }
|
||||
|
||||
val formattedHours1 = if (displayHours1 > 0) {
|
||||
context.resources.getQuantityString(R.plurals.hours, displayHours1, displayHours1)
|
||||
} else {""}
|
||||
} else { "" }
|
||||
|
||||
val formattedMinutes1 = if (displayMinutes1 > 0) {
|
||||
context.resources.getQuantityString(R.plurals.minutes, displayMinutes1, displayMinutes1)
|
||||
} else {""}
|
||||
context.resources.getQuantityString(
|
||||
R.plurals.minutes,
|
||||
displayMinutes1,
|
||||
displayMinutes1
|
||||
)
|
||||
} else { "" }
|
||||
|
||||
val formattedTime1 = stringResource(
|
||||
if (scheduleSeparately)
|
||||
R.string.interval_home
|
||||
else
|
||||
R.string.interval,
|
||||
listOf(formattedDays1, formattedHours1, formattedMinutes1).filter { it.isNotEmpty() }.joinToString(", ")
|
||||
listOf(
|
||||
formattedDays1,
|
||||
formattedHours1,
|
||||
formattedMinutes1
|
||||
).filter { it.isNotEmpty() }.joinToString(", ")
|
||||
)
|
||||
|
||||
val totalMinutes2 = (days2.toInt() * 24 * 60) + (hours2.toInt() * 60) + minutes2.toInt()
|
||||
@@ -126,25 +205,35 @@ fun TimeSliders(
|
||||
|
||||
val formattedDays2 = if (displayDays2 > 0) {
|
||||
context.resources.getQuantityString(R.plurals.days, displayDays2, displayDays2)
|
||||
} else {""}
|
||||
} else {
|
||||
""
|
||||
}
|
||||
|
||||
val formattedHours2 = if (displayHours2 > 0) {
|
||||
context.resources.getQuantityString(R.plurals.hours, displayHours2, displayHours2)
|
||||
} else {""}
|
||||
} else { "" }
|
||||
|
||||
val formattedMinutes2 = if (displayMinutes2 > 0) {
|
||||
context.resources.getQuantityString(R.plurals.minutes, displayMinutes2, displayMinutes2)
|
||||
} else {""}
|
||||
context.resources.getQuantityString(
|
||||
R.plurals.minutes,
|
||||
displayMinutes2,
|
||||
displayMinutes2
|
||||
)
|
||||
} else { "" }
|
||||
|
||||
val formattedTime2 = stringResource(
|
||||
if (scheduleSeparately)
|
||||
R.string.interval_lock
|
||||
else
|
||||
R.string.interval,
|
||||
listOf(formattedDays2, formattedHours2, formattedMinutes2).filter { it.isNotEmpty() }.joinToString(", ")
|
||||
listOf(
|
||||
formattedDays2,
|
||||
formattedHours2,
|
||||
formattedMinutes2
|
||||
).filter { it.isNotEmpty() }.joinToString(", ")
|
||||
)
|
||||
|
||||
Row (
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.Center
|
||||
@@ -165,7 +254,10 @@ fun TimeSliders(
|
||||
IconButton(
|
||||
onClick = { onShowIntervalChange(!showInterval) },
|
||||
) {
|
||||
Icon(imageVector = Icons.Filled.ArrowDropDown, contentDescription = stringResource(R.string.show_interval_sliders))
|
||||
Icon(
|
||||
imageVector = Icons.Filled.ArrowDropDown,
|
||||
contentDescription = stringResource(R.string.show_interval_sliders)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,19 +286,24 @@ fun TimeSliders(
|
||||
val totalMinute =
|
||||
(newDays.toInt() * 24 * 60) + (hours1.toInt() * 60) + minutes1.toInt()
|
||||
if (totalMinute < WALLPAPER_CHANGE_INTERVAL_MIN) {
|
||||
minutes1 = WALLPAPER_CHANGE_INTERVAL_MIN.toFloat() - (hours1.toInt() * 60)
|
||||
minutes1 =
|
||||
WALLPAPER_CHANGE_INTERVAL_MIN.toFloat() - (hours1.toInt() * 60)
|
||||
}
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onHomeIntervalChange(newDays.toInt(), hours1.toInt(), minutes1.toInt())
|
||||
onHomeIntervalChange(
|
||||
newDays.toInt(),
|
||||
hours1.toInt(),
|
||||
minutes1.toInt()
|
||||
)
|
||||
}
|
||||
},
|
||||
valueRange = 0f..30f,
|
||||
steps = 30,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
Slider(
|
||||
value = hours1,
|
||||
onValueChange = { newHours ->
|
||||
@@ -215,19 +312,24 @@ fun TimeSliders(
|
||||
val totalMinute =
|
||||
(days1.toInt() * 24 * 60) + (newHours.toInt() * 60) + minutes1.toInt()
|
||||
if (totalMinute < WALLPAPER_CHANGE_INTERVAL_MIN) {
|
||||
minutes1 = WALLPAPER_CHANGE_INTERVAL_MIN.toFloat() - (newHours.toInt() * 60)
|
||||
minutes1 =
|
||||
WALLPAPER_CHANGE_INTERVAL_MIN.toFloat() - (newHours.toInt() * 60)
|
||||
}
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onHomeIntervalChange(days1.toInt(), newHours.toInt(), minutes1.toInt())
|
||||
onHomeIntervalChange(
|
||||
days1.toInt(),
|
||||
newHours.toInt(),
|
||||
minutes1.toInt()
|
||||
)
|
||||
}
|
||||
},
|
||||
valueRange = 0f..24f,
|
||||
steps = 24,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
Slider(
|
||||
value = minutes1,
|
||||
onValueChange = { newMinutes ->
|
||||
@@ -241,7 +343,11 @@ fun TimeSliders(
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onHomeIntervalChange(days1.toInt(), hours1.toInt(), minutes1.toInt())
|
||||
onHomeIntervalChange(
|
||||
days1.toInt(),
|
||||
hours1.toInt(),
|
||||
minutes1.toInt()
|
||||
)
|
||||
}
|
||||
},
|
||||
valueRange = 0f..60f,
|
||||
@@ -269,7 +375,11 @@ fun TimeSliders(
|
||||
verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
HorizontalDivider(color = MaterialTheme.colorScheme.outline)
|
||||
HorizontalDivider(
|
||||
color = MaterialTheme.colorScheme.outline,
|
||||
modifier = Modifier.padding(horizontal = 32.dp),
|
||||
thickness = 2.dp
|
||||
)
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
Text(
|
||||
text = formattedTime2,
|
||||
@@ -283,7 +393,8 @@ fun TimeSliders(
|
||||
val totalMinute =
|
||||
(newDays.toInt() * 24 * 60) + (hours2.toInt() * 60) + minutes2.toInt()
|
||||
if (totalMinute < WALLPAPER_CHANGE_INTERVAL_MIN) {
|
||||
minutes2 = WALLPAPER_CHANGE_INTERVAL_MIN.toFloat() - (hours2.toInt() * 60)
|
||||
minutes2 =
|
||||
WALLPAPER_CHANGE_INTERVAL_MIN.toFloat() - (hours2.toInt() * 60)
|
||||
}
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
@@ -299,7 +410,7 @@ fun TimeSliders(
|
||||
steps = 30,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
Slider(
|
||||
value = hours2,
|
||||
onValueChange = { newHours ->
|
||||
@@ -308,7 +419,8 @@ fun TimeSliders(
|
||||
val totalMinute =
|
||||
(days2.toInt() * 24 * 60) + (newHours.toInt() * 60) + minutes2.toInt()
|
||||
if (totalMinute < WALLPAPER_CHANGE_INTERVAL_MIN) {
|
||||
minutes2 = WALLPAPER_CHANGE_INTERVAL_MIN.toFloat() - (newHours.toInt() * 60)
|
||||
minutes2 =
|
||||
WALLPAPER_CHANGE_INTERVAL_MIN.toFloat() - (newHours.toInt() * 60)
|
||||
}
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
@@ -324,7 +436,7 @@ fun TimeSliders(
|
||||
steps = 24,
|
||||
modifier = Modifier.padding(PaddingValues(horizontal = 30.dp))
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
Slider(
|
||||
value = minutes2,
|
||||
onValueChange = { newMinutes ->
|
||||
@@ -352,25 +464,50 @@ fun TimeSliders(
|
||||
}
|
||||
}
|
||||
}
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
Button(
|
||||
onClick = {
|
||||
shouldShowDialog.value = true
|
||||
},
|
||||
modifier = Modifier
|
||||
.padding(16.dp)
|
||||
.align(Alignment.CenterHorizontally)
|
||||
) {
|
||||
val (hour, minute, period) = if (changeStartTime) {
|
||||
val hour = if (timePickerState.hour == 0) 12 else timePickerState.hour % 12
|
||||
val period = if (timePickerState.hour < 12) "AM" else "PM"
|
||||
Triple(hour, timePickerState.minute, period)
|
||||
} else {
|
||||
val currentTime = Calendar.getInstance()
|
||||
val hour = if (currentTime.get(Calendar.HOUR) == 0) 12 else currentTime.get(Calendar.HOUR) % 12
|
||||
val period = if (currentTime.get(Calendar.AM_PM) == 0) "AM" else "PM"
|
||||
Triple(hour, currentTime.get(Calendar.MINUTE), period)
|
||||
}
|
||||
val formattedMinutes = String.format(Locale.getDefault(), "%02d", minute)
|
||||
Text(text = "$hour:$formattedMinutes $period")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (showInterval) {
|
||||
Slider(
|
||||
value = days1,
|
||||
onValueChange = { newDays ->
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
days1 = newDays
|
||||
val totalMinute = (newDays.toInt() * 24 * 60) + (hours1.toInt() * 60) + minutes1.toInt()
|
||||
val totalMinute =
|
||||
(newDays.toInt() * 24 * 60) + (hours1.toInt() * 60) + minutes1.toInt()
|
||||
if (totalMinute < WALLPAPER_CHANGE_INTERVAL_MIN) {
|
||||
minutes1 = WALLPAPER_CHANGE_INTERVAL_MIN.toFloat() - (hours1.toInt() * 60)
|
||||
minutes1 =
|
||||
WALLPAPER_CHANGE_INTERVAL_MIN.toFloat() - (hours1.toInt() * 60)
|
||||
}
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onHomeIntervalChange(newDays.toInt(), hours1.toInt(), minutes1.toInt())
|
||||
onHomeIntervalChange(
|
||||
newDays.toInt(),
|
||||
hours1.toInt(),
|
||||
minutes1.toInt()
|
||||
)
|
||||
}
|
||||
},
|
||||
valueRange = 0f..30f,
|
||||
@@ -383,14 +520,20 @@ fun TimeSliders(
|
||||
onValueChange = { newHours ->
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
hours1 = newHours
|
||||
val totalMinute = (days1.toInt() * 24 * 60) + (newHours.toInt() * 60) + minutes1.toInt()
|
||||
val totalMinute =
|
||||
(days1.toInt() * 24 * 60) + (newHours.toInt() * 60) + minutes1.toInt()
|
||||
if (totalMinute < WALLPAPER_CHANGE_INTERVAL_MIN) {
|
||||
minutes1 = WALLPAPER_CHANGE_INTERVAL_MIN.toFloat() - (newHours.toInt() * 60)
|
||||
minutes1 =
|
||||
WALLPAPER_CHANGE_INTERVAL_MIN.toFloat() - (newHours.toInt() * 60)
|
||||
}
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onHomeIntervalChange(days1.toInt(), newHours.toInt(), minutes1.toInt())
|
||||
onHomeIntervalChange(
|
||||
days1.toInt(),
|
||||
newHours.toInt(),
|
||||
minutes1.toInt()
|
||||
)
|
||||
}
|
||||
},
|
||||
valueRange = 0f..24f,
|
||||
@@ -402,15 +545,20 @@ fun TimeSliders(
|
||||
value = minutes1,
|
||||
onValueChange = { newMinutes ->
|
||||
view.performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
|
||||
minutes1 = if (days1.toInt() == 0 && hours1.toInt() == 0 && newMinutes < WALLPAPER_CHANGE_INTERVAL_MIN) {
|
||||
WALLPAPER_CHANGE_INTERVAL_MIN.toFloat()
|
||||
} else {
|
||||
newMinutes
|
||||
}
|
||||
minutes1 =
|
||||
if (days1.toInt() == 0 && hours1.toInt() == 0 && newMinutes < WALLPAPER_CHANGE_INTERVAL_MIN) {
|
||||
WALLPAPER_CHANGE_INTERVAL_MIN.toFloat()
|
||||
} else {
|
||||
newMinutes
|
||||
}
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(500)
|
||||
onHomeIntervalChange(days1.toInt(), hours1.toInt(), minutes1.toInt())
|
||||
onHomeIntervalChange(
|
||||
days1.toInt(),
|
||||
hours1.toInt(),
|
||||
minutes1.toInt()
|
||||
)
|
||||
}
|
||||
},
|
||||
valueRange = 0f..60f,
|
||||
@@ -421,5 +569,4 @@ fun TimeSliders(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+2
@@ -16,4 +16,6 @@ data class WallpaperAlarmItem(
|
||||
val scheduleSeparately: Boolean = false,
|
||||
val setHome : Boolean = false,
|
||||
val setLock : Boolean = false,
|
||||
val changeStartTime: Boolean = false,
|
||||
val startTime: Pair<Int, Int> = Pair(0, 0),
|
||||
)
|
||||
+4
-2
@@ -7,13 +7,15 @@ interface WallpaperAlarmScheduler {
|
||||
* @param origin where the request came from (null if not from a specific origin, 0 if home screen, 1 if lock screen, 2 if both)
|
||||
* @param changeImmediate whether to change the wallpaper immediately or just schedule the alarm
|
||||
* @param cancelImmediate whether to cancel all alarms before scheduling the new one
|
||||
* @param setAlarm whether to set the alarm or not
|
||||
* @param firstLaunch whether this is the first launch of the wallpaper changer
|
||||
*/
|
||||
fun scheduleWallpaperAlarm(wallpaperAlarmItem: WallpaperAlarmItem, origin: Int? = null, changeImmediate: Boolean = false, cancelImmediate: Boolean = false, setAlarm: Boolean = true)
|
||||
fun scheduleWallpaperAlarm(wallpaperAlarmItem: WallpaperAlarmItem, origin: Int? = null, changeImmediate: Boolean = false, cancelImmediate: Boolean = false, setAlarm: Boolean = true, firstLaunch: Boolean = false)
|
||||
|
||||
/**
|
||||
* Update the wallpaper alarm with new times without changing the wallpaper
|
||||
*/
|
||||
fun updateWallpaperAlarm(wallpaperAlarmItem: WallpaperAlarmItem)
|
||||
fun updateWallpaperAlarm(wallpaperAlarmItem: WallpaperAlarmItem, firstLaunch: Boolean = false)
|
||||
|
||||
/**
|
||||
* Update the wallpaper without changing the alarm
|
||||
|
||||
+29
-30
@@ -30,6 +30,7 @@ class WallpaperAlarmSchedulerImpl (
|
||||
changeImmediate: Boolean,
|
||||
cancelImmediate: Boolean,
|
||||
setAlarm: Boolean,
|
||||
firstLaunch: Boolean
|
||||
) {
|
||||
// Cancel previous alarms before setting new ones to prevent stale alarms
|
||||
if (cancelImmediate) cancelWallpaperAlarm()
|
||||
@@ -50,11 +51,11 @@ class WallpaperAlarmSchedulerImpl (
|
||||
when (origin) {
|
||||
Type.LOCK.ordinal -> {
|
||||
if (changeImmediate) changeWallpaperImmediate(wallpaperAlarmItem, Type.LOCK)
|
||||
if (setAlarm) scheduleWallpaper(wallpaperAlarmItem, Type.LOCK, origin)
|
||||
if (setAlarm) scheduleWallpaper(wallpaperAlarmItem, Type.LOCK, origin, firstLaunch)
|
||||
}
|
||||
Type.HOME.ordinal -> {
|
||||
if (changeImmediate) changeWallpaperImmediate(wallpaperAlarmItem, Type.HOME)
|
||||
if (setAlarm) scheduleWallpaper(wallpaperAlarmItem, Type.HOME, origin)
|
||||
if (setAlarm) scheduleWallpaper(wallpaperAlarmItem, Type.HOME, origin, firstLaunch)
|
||||
}
|
||||
null -> {
|
||||
if (changeImmediate) {
|
||||
@@ -62,29 +63,29 @@ class WallpaperAlarmSchedulerImpl (
|
||||
changeWallpaperImmediate(wallpaperAlarmItem, Type.HOME)
|
||||
}
|
||||
if (setAlarm) {
|
||||
scheduleWallpaper(wallpaperAlarmItem, Type.LOCK, Type.LOCK.ordinal)
|
||||
scheduleWallpaper(wallpaperAlarmItem, Type.HOME, Type.HOME.ordinal)
|
||||
scheduleWallpaper(wallpaperAlarmItem, Type.LOCK, Type.LOCK.ordinal, firstLaunch)
|
||||
scheduleWallpaper(wallpaperAlarmItem, Type.HOME, Type.HOME.ordinal, firstLaunch)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (changeImmediate) changeWallpaperImmediate(wallpaperAlarmItem, Type.SINGLE)
|
||||
if (setAlarm) scheduleWallpaper(wallpaperAlarmItem, Type.SINGLE)
|
||||
if (setAlarm) scheduleWallpaper(wallpaperAlarmItem, Type.SINGLE, null, firstLaunch)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the alarms
|
||||
*/
|
||||
override fun updateWallpaperAlarm(wallpaperAlarmItem: WallpaperAlarmItem) {
|
||||
override fun updateWallpaperAlarm(wallpaperAlarmItem: WallpaperAlarmItem, firstLaunch: Boolean) {
|
||||
cancelWallpaperAlarm()
|
||||
if (wallpaperAlarmItem.scheduleSeparately) {
|
||||
scheduleWallpaper(wallpaperAlarmItem, Type.LOCK, null, true)
|
||||
scheduleWallpaper(wallpaperAlarmItem, Type.HOME, null, true)
|
||||
scheduleWallpaper(wallpaperAlarmItem, Type.LOCK, null, firstLaunch)
|
||||
scheduleWallpaper(wallpaperAlarmItem, Type.HOME, null, firstLaunch)
|
||||
}
|
||||
else {
|
||||
scheduleWallpaper(wallpaperAlarmItem, Type.SINGLE, null, true)
|
||||
scheduleWallpaper(wallpaperAlarmItem, Type.SINGLE, null, firstLaunch)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,11 +117,21 @@ class WallpaperAlarmSchedulerImpl (
|
||||
/**
|
||||
* Schedules the wallpaper alarm based on type and time
|
||||
*/
|
||||
private fun scheduleWallpaper(wallpaperAlarmItem: WallpaperAlarmItem, type: Type, origin: Int? = null, update: Boolean = false) {
|
||||
val nextTime = when (type) {
|
||||
Type.LOCK -> LocalDateTime.now().plusMinutes(wallpaperAlarmItem.lockInterval.toLong())
|
||||
Type.HOME -> if (wallpaperAlarmItem.scheduleSeparately) LocalDateTime.now().plusMinutes(wallpaperAlarmItem.homeInterval.toLong()).plusSeconds(10) else LocalDateTime.now().plusMinutes(wallpaperAlarmItem.homeInterval.toLong())
|
||||
else -> LocalDateTime.now().plusMinutes(wallpaperAlarmItem.homeInterval.toLong())
|
||||
private fun scheduleWallpaper(wallpaperAlarmItem: WallpaperAlarmItem, type: Type, origin: Int? = null, firstLaunch: Boolean = false) {
|
||||
val startTime = if (wallpaperAlarmItem.changeStartTime && firstLaunch) {
|
||||
var calculatedStartTime = LocalDateTime.now().withHour(wallpaperAlarmItem.startTime.first).withMinute(wallpaperAlarmItem.startTime.second)
|
||||
if (calculatedStartTime.isBefore(LocalDateTime.now())) {
|
||||
calculatedStartTime = calculatedStartTime.plusDays(1)
|
||||
}
|
||||
calculatedStartTime
|
||||
} else {
|
||||
LocalDateTime.now()
|
||||
}
|
||||
val nextTime = when {
|
||||
wallpaperAlarmItem.changeStartTime && firstLaunch -> startTime
|
||||
type == Type.LOCK -> startTime.plusMinutes(wallpaperAlarmItem.lockInterval.toLong())
|
||||
type == Type.HOME && wallpaperAlarmItem.scheduleSeparately -> startTime.plusMinutes(wallpaperAlarmItem.homeInterval.toLong()).plusSeconds(10)
|
||||
else -> startTime.plusMinutes(wallpaperAlarmItem.homeInterval.toLong())
|
||||
}
|
||||
val intent = Intent(context, WallpaperReceiver::class.java).apply {
|
||||
putExtra("homeInterval", wallpaperAlarmItem.homeInterval)
|
||||
@@ -129,6 +140,8 @@ class WallpaperAlarmSchedulerImpl (
|
||||
putExtra("type", type.ordinal)
|
||||
putExtra("setHome", wallpaperAlarmItem.setHome)
|
||||
putExtra("setLock", wallpaperAlarmItem.setLock)
|
||||
putExtra("changeStartTime", wallpaperAlarmItem.changeStartTime)
|
||||
putExtra("startTime", wallpaperAlarmItem.startTime)
|
||||
putExtra("origin", origin)
|
||||
}
|
||||
|
||||
@@ -161,20 +174,6 @@ class WallpaperAlarmSchedulerImpl (
|
||||
)
|
||||
)
|
||||
}
|
||||
if (update) {
|
||||
when (type.ordinal) {
|
||||
Type.SINGLE.ordinal -> {
|
||||
if (wallpaperAlarmItem.setLock) startService(context, LockWallpaperService::class.java, LockWallpaperService.Actions.REQUEUE.toString(), wallpaperAlarmItem.homeInterval, wallpaperAlarmItem.lockInterval, wallpaperAlarmItem.scheduleSeparately, Type.SINGLE.ordinal)
|
||||
if (wallpaperAlarmItem.setHome) startService(context, HomeWallpaperService::class.java, HomeWallpaperService.Actions.REQUEUE.toString(), wallpaperAlarmItem.homeInterval, wallpaperAlarmItem.lockInterval, wallpaperAlarmItem.scheduleSeparately, Type.SINGLE.ordinal)
|
||||
}
|
||||
Type.HOME.ordinal -> {
|
||||
startService(context, HomeWallpaperService::class.java, HomeWallpaperService.Actions.REQUEUE.toString(), wallpaperAlarmItem.homeInterval, wallpaperAlarmItem.lockInterval, wallpaperAlarmItem.scheduleSeparately, Type.HOME.ordinal)
|
||||
}
|
||||
Type.LOCK.ordinal -> {
|
||||
startService(context, LockWallpaperService::class.java, LockWallpaperService.Actions.REQUEUE.toString(), wallpaperAlarmItem.homeInterval, wallpaperAlarmItem.lockInterval, wallpaperAlarmItem.scheduleSeparately, Type.LOCK.ordinal)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -191,7 +190,7 @@ class WallpaperAlarmSchedulerImpl (
|
||||
cancelWallpaperAlarm()
|
||||
}
|
||||
else {
|
||||
alarmManager.setExact(
|
||||
alarmManager.setExactAndAllowWhileIdle(
|
||||
AlarmManager.RTC_WAKEUP,
|
||||
nextMidnight.atZone(ZoneId.systemDefault()).toEpochSecond() * 1000,
|
||||
PendingIntent.getBroadcast(
|
||||
@@ -204,7 +203,7 @@ class WallpaperAlarmSchedulerImpl (
|
||||
}
|
||||
}
|
||||
else {
|
||||
alarmManager.setExact(
|
||||
alarmManager.setExactAndAllowWhileIdle(
|
||||
AlarmManager.RTC_WAKEUP,
|
||||
nextMidnight.atZone(ZoneId.systemDefault()).toEpochSecond() * 1000,
|
||||
PendingIntent.getBroadcast(
|
||||
|
||||
+5
-1
@@ -30,6 +30,8 @@ class WallpaperReceiver: BroadcastReceiver() {
|
||||
val type = intent?.getIntExtra("type", Type.SINGLE.ordinal) ?: Type.SINGLE.ordinal
|
||||
val setHome = intent?.getBooleanExtra("setHome", false) ?: false
|
||||
val setLock = intent?.getBooleanExtra("setLock", false) ?: false
|
||||
val changeStartTime = intent?.getBooleanExtra("changeStartTime", false) ?: false
|
||||
val startTime = intent?.getIntArrayExtra("startTime") ?: intArrayOf(0, 0)
|
||||
|
||||
when (type) {
|
||||
Type.SINGLE.ordinal -> {
|
||||
@@ -52,7 +54,9 @@ class WallpaperReceiver: BroadcastReceiver() {
|
||||
lockInterval = lockInterval,
|
||||
scheduleSeparately = scheduleSeparately,
|
||||
setHome = setHome,
|
||||
setLock = setLock
|
||||
setLock = setLock,
|
||||
changeStartTime = changeStartTime,
|
||||
startTime = Pair(startTime[0], startTime[1]),
|
||||
),
|
||||
origin
|
||||
)
|
||||
|
||||
-21
@@ -61,7 +61,6 @@ class HomeWallpaperService: Service() {
|
||||
|
||||
enum class Actions {
|
||||
START,
|
||||
REQUEUE,
|
||||
UPDATE,
|
||||
REFRESH
|
||||
}
|
||||
@@ -86,12 +85,6 @@ class HomeWallpaperService: Service() {
|
||||
type = intent.getIntExtra("type", Type.SINGLE.ordinal)
|
||||
workerTaskStart()
|
||||
}
|
||||
Actions.REQUEUE.toString() -> {
|
||||
homeInterval = intent.getIntExtra("homeInterval", SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT)
|
||||
lockInterval = intent.getIntExtra("lockInterval", SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT)
|
||||
scheduleSeparately = intent.getBooleanExtra("scheduleSeparately", false)
|
||||
workerTaskRequeue()
|
||||
}
|
||||
Actions.UPDATE.toString() -> {
|
||||
workerTaskUpdate()
|
||||
}
|
||||
@@ -119,20 +112,6 @@ class HomeWallpaperService: Service() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun workerTaskRequeue() {
|
||||
workerHandler.post {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
val nextSetTime1 = LocalDateTime.parse(settingsDataStoreImpl.getString(SettingsConstants.HOME_NEXT_SET_TIME))
|
||||
val nextSetTime2 = LocalDateTime.parse(settingsDataStoreImpl.getString(SettingsConstants.LOCK_NEXT_SET_TIME))
|
||||
val nextSetTime = (if (nextSetTime1!!.isBefore(nextSetTime2)) nextSetTime1 else nextSetTime2)
|
||||
val notification = createNotification(nextSetTime)
|
||||
val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
|
||||
notification?.let { notificationManager.notify(1, it) }
|
||||
}
|
||||
stopSelf()
|
||||
}
|
||||
}
|
||||
|
||||
private fun workerTaskUpdate() {
|
||||
workerHandler.post {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
|
||||
-21
@@ -60,7 +60,6 @@ class LockWallpaperService: Service() {
|
||||
|
||||
enum class Actions {
|
||||
START,
|
||||
REQUEUE,
|
||||
UPDATE,
|
||||
REFRESH
|
||||
}
|
||||
@@ -85,12 +84,6 @@ class LockWallpaperService: Service() {
|
||||
type = intent.getIntExtra("type", Type.SINGLE.ordinal)
|
||||
workerTaskStart()
|
||||
}
|
||||
Actions.REQUEUE.toString() -> {
|
||||
homeInterval = intent.getIntExtra("homeInterval", SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT)
|
||||
lockInterval = intent.getIntExtra("lockInterval", SettingsConstants.WALLPAPER_CHANGE_INTERVAL_DEFAULT)
|
||||
scheduleSeparately = intent.getBooleanExtra("scheduleSeparately", false)
|
||||
workerTaskRequeue()
|
||||
}
|
||||
Actions.UPDATE.toString() -> {
|
||||
workerTaskUpdate()
|
||||
}
|
||||
@@ -117,20 +110,6 @@ class LockWallpaperService: Service() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun workerTaskRequeue() {
|
||||
workerHandler.post {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
val nextSetTime1 = LocalDateTime.parse(settingsDataStoreImpl.getString(SettingsConstants.HOME_NEXT_SET_TIME))
|
||||
val nextSetTime2 = LocalDateTime.parse(settingsDataStoreImpl.getString(SettingsConstants.LOCK_NEXT_SET_TIME))
|
||||
val nextSetTime = (if (nextSetTime1!!.isBefore(nextSetTime2)) nextSetTime1 else nextSetTime2)
|
||||
val notification = createNotification(nextSetTime)
|
||||
val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
|
||||
notification?.let { notificationManager.notify(1, it) }
|
||||
}
|
||||
stopSelf()
|
||||
}
|
||||
}
|
||||
|
||||
private fun workerTaskUpdate() {
|
||||
workerHandler.post {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
|
||||
@@ -165,4 +165,6 @@
|
||||
<string name="change_vignette">Vignette Effect</string>
|
||||
<string name="none">None</string>
|
||||
<string name="gray_filter">Gray Filter</string>
|
||||
<string name="select_starting_time">Select starting time</string>
|
||||
<string name="change_notification_settings">Change notification settings</string>
|
||||
</resources>
|
||||
Reference in new issue
Block a user