Fixed selected album not showing up in bottom sheet as selected

This commit is contained in:
Anthonyy232 committed 2024-08-08 12:03:46 -07:00
1 parent 7cf4f85b0d
commit 98e0b4ae2f
7 files changed
+75 -87

No files matched your search

@@ -30,6 +30,6 @@ object SettingsConstants {
const val SCHEDULE_SEPARATELY = "schedule_separately"
const val BLUR = "blur"
const val BLUR_PERCENTAGE = "blur_percentage"
const val NEXT_SET_TIME_1 = "next_set_time_1"
const val NEXT_SET_TIME_2 = "next_set_time_2"
const val HOME_NEXT_SET_TIME = "next_set_time_1"
const val LOCK_NEXT_SET_TIME = "next_set_time_2"
}
@@ -227,18 +227,18 @@ class SettingsViewModel @Inject constructor (
val nextSetTime: String?
settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, currentTime.format(formatter))
if (_state.value.scheduleSeparately) {
val nextSetTime1 = currentTime.plusMinutes(event.interval.toLong())
val nextSetTime2 = currentTime.plusMinutes(_state.value.lockInterval.toLong())
nextSetTime = (if (nextSetTime1!!.isBefore(nextSetTime2)) nextSetTime1 else nextSetTime2)!!.format(formatter)
val homeNextSetTime = currentTime.plusMinutes(event.interval.toLong())
val lockNextSetTime = currentTime.plusMinutes(_state.value.lockInterval.toLong())
nextSetTime = (if (homeNextSetTime!!.isBefore(lockNextSetTime)) homeNextSetTime else lockNextSetTime)!!.format(formatter)
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, nextSetTime)
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME_1, nextSetTime1.toString())
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME_2, nextSetTime2.toString())
settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, homeNextSetTime.toString())
settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, lockNextSetTime.toString())
}
else {
nextSetTime = currentTime.plusMinutes(event.interval.toLong()).format(formatter)
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, nextSetTime)
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME_1, currentTime.plusMinutes(event.interval.toLong()).toString())
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME_2, currentTime.plusMinutes(event.interval.toLong()).toString())
settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, currentTime.plusMinutes(event.interval.toLong()).toString())
settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, currentTime.plusMinutes(event.interval.toLong()).toString())
}
_state.update {
it.copy(
@@ -262,14 +262,14 @@ class SettingsViewModel @Inject constructor (
val nextSetTime2 = currentTime.plusMinutes(event.interval.toLong())
nextSetTime = (if (nextSetTime1!!.isBefore(nextSetTime2)) nextSetTime1 else nextSetTime2)!!.format(formatter)
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, nextSetTime)
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME_1, nextSetTime1.toString())
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME_2, nextSetTime2.toString())
settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, nextSetTime1.toString())
settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, nextSetTime2.toString())
}
else {
nextSetTime = currentTime.plusMinutes(event.interval.toLong()).format(formatter)
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, nextSetTime)
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME_1, currentTime.plusMinutes(event.interval.toLong()).toString())
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME_2, currentTime.plusMinutes(event.interval.toLong()).toString())
settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, currentTime.plusMinutes(event.interval.toLong()).toString())
settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, currentTime.plusMinutes(event.interval.toLong()).toString())
}
_state.update {
it.copy(
@@ -292,14 +292,14 @@ class SettingsViewModel @Inject constructor (
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.NEXT_SET_TIME_1, nextSetTime1.toString())
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME_2, nextSetTime2.toString())
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.NEXT_SET_TIME_1, currentTime.plusMinutes(_state.value.homeInterval.toLong()).toString())
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME_2, currentTime.plusMinutes(_state.value.lockInterval.toLong()).toString())
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())
}
_state.update {
it.copy(
@@ -564,8 +564,8 @@ class SettingsViewModel @Inject constructor (
settingsDataStoreImpl.deleteBoolean(SettingsConstants.BLUR)
settingsDataStoreImpl.deleteInt(SettingsConstants.BLUR_PERCENTAGE)
settingsDataStoreImpl.deleteBoolean(SettingsConstants.FIRST_SET)
settingsDataStoreImpl.deleteString(SettingsConstants.NEXT_SET_TIME_1)
settingsDataStoreImpl.deleteString(SettingsConstants.NEXT_SET_TIME_2)
settingsDataStoreImpl.deleteString(SettingsConstants.HOME_NEXT_SET_TIME)
settingsDataStoreImpl.deleteString(SettingsConstants.LOCK_NEXT_SET_TIME)
_state.update {
it.copy(
@@ -237,7 +237,8 @@ fun WallpaperScreen(
if (shouldShowScreen && openBottomSheet) {
AlbumBottomSheet(
albums = albums,
currentSelectedAlbum = null,
homeSelectedAlbum = homeSelectedAlbum,
lockSelectedAlbum = lockSelectedAlbum,
onDismiss = { openBottomSheet = false },
onSelect = { album ->
openBottomSheet = false
@@ -49,7 +49,8 @@ import kotlinx.coroutines.launch
@Composable
fun AlbumBottomSheet(
onDismiss: () -> Unit,
currentSelectedAlbum: SelectedAlbum?,
homeSelectedAlbum: SelectedAlbum?,
lockSelectedAlbum: SelectedAlbum?,
albums: List<AlbumWithWallpaperAndFolder>,
onSelect: (AlbumWithWallpaperAndFolder) -> Unit,
animate: Boolean
@@ -63,7 +64,13 @@ fun AlbumBottomSheet(
containerColor = MaterialTheme.colorScheme.background,
tonalElevation = 5.dp,
modifier = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
Modifier.fillMaxSize().padding(bottom = WindowInsets.navigationBars.asPaddingValues().calculateBottomPadding())
Modifier
.fillMaxSize()
.padding(
bottom = WindowInsets.navigationBars
.asPaddingValues()
.calculateBottomPadding()
)
} else {
Modifier.padding(bottom = WindowInsets.navigationBars.asPaddingValues().calculateBottomPadding())
}
@@ -124,20 +131,12 @@ fun AlbumBottomSheet(
}
},
trailingContent = {
if (currentSelectedAlbum != null) {
if (currentSelectedAlbum.album.initialAlbumName == it.album.initialAlbumName) {
Icon(
contentDescription = stringResource(R.string.currently_selected_album),
imageVector = Icons.Filled.RadioButtonChecked,
)
}
else {
Icon(
contentDescription = stringResource(R.string.currently_selected_album),
imageVector = Icons.Filled.RadioButtonUnchecked,
)
}
}
val isSelected = (homeSelectedAlbum?.album?.initialAlbumName == it.album.initialAlbumName) ||
(lockSelectedAlbum?.album?.displayedAlbumName == it.album.displayedAlbumName)
Icon(
contentDescription = if (isSelected) stringResource(R.string.currently_selected_album) else stringResource(R.string.unselected_album),
imageVector = if (isSelected) Icons.Filled.RadioButtonChecked else Icons.Filled.RadioButtonUnchecked,
)
},
)
}
@@ -129,8 +129,8 @@ class HomeWallpaperService: Service() {
private fun workerTaskRequeue() {
workerHandler.post {
CoroutineScope(Dispatchers.IO).launch {
val nextSetTime1 = LocalDateTime.parse(settingsDataStoreImpl.getString(SettingsConstants.NEXT_SET_TIME_1))
val nextSetTime2 = LocalDateTime.parse(settingsDataStoreImpl.getString(SettingsConstants.NEXT_SET_TIME_2))
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(Context.NOTIFICATION_SERVICE) as NotificationManager
@@ -453,34 +453,34 @@ class HomeWallpaperService: Service() {
}
}
// Run notification
var nextSetTime1 = LocalDateTime.parse(settingsDataStoreImpl.getString(SettingsConstants.NEXT_SET_TIME_1))
var nextSetTime2 = LocalDateTime.parse(settingsDataStoreImpl.getString(SettingsConstants.NEXT_SET_TIME_2))
val nextSetTime: LocalDateTime?
val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
val homeNextSetTime: LocalDateTime?
var lockNextSetTime = LocalDateTime.parse(settingsDataStoreImpl.getString(SettingsConstants.LOCK_NEXT_SET_TIME))
val nextSetTime: LocalDateTime?
val currentTime = LocalDateTime.now()
settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, currentTime.format(formatter))
if (setHome && setLock && !scheduleSeparately) {
nextSetTime1 = currentTime.plusMinutes(homeInterval.toLong())
nextSetTime2 = nextSetTime1
nextSetTime = nextSetTime1
nextSetTime?.let { settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, it.format(formatter)) }
if (homeInterval == lockInterval) {
homeNextSetTime = currentTime.plusMinutes(homeInterval.toLong())
lockNextSetTime = homeNextSetTime
nextSetTime = homeNextSetTime
nextSetTime?.let {
settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, currentTime.format(formatter))
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, it.format(formatter))
settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, it.toString())
settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, it.toString())
}
}
else {
if (setHome) { nextSetTime1 = currentTime.plusMinutes(homeInterval.toLong()) }
else { nextSetTime2 = currentTime.plusMinutes(lockInterval.toLong()) }
nextSetTime = if (nextSetTime1 == null && nextSetTime2 != null) {
nextSetTime2
homeNextSetTime = currentTime.plusMinutes(homeInterval.toLong())
nextSetTime = if (homeNextSetTime.isBefore(lockNextSetTime) && homeNextSetTime.isAfter(currentTime)) homeNextSetTime
else if (lockNextSetTime.isAfter(currentTime)) lockNextSetTime
else currentTime.plusMinutes(homeInterval.toLong())
nextSetTime?.let {
settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, currentTime.format(formatter))
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, it.format(formatter))
settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, homeNextSetTime.toString())
settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, lockNextSetTime.toString())
}
else if (nextSetTime1 != null && nextSetTime2 == null) {
nextSetTime1
}
else {
if (nextSetTime1!!.isBefore(nextSetTime2)) nextSetTime1 else nextSetTime2
}
nextSetTime?.let { settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, it.format(formatter)) }
}
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME_1, nextSetTime1.toString())
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME_2, nextSetTime2.toString())
val notification = createNotification(nextSetTime)
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notification?.let { notificationManager.notify(1, it) }
@@ -127,8 +127,8 @@ class LockWallpaperService: Service() {
private fun workerTaskRequeue() {
workerHandler.post {
CoroutineScope(Dispatchers.IO).launch {
val nextSetTime1 = LocalDateTime.parse(settingsDataStoreImpl.getString(SettingsConstants.NEXT_SET_TIME_1))
val nextSetTime2 = LocalDateTime.parse(settingsDataStoreImpl.getString(SettingsConstants.NEXT_SET_TIME_2))
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(Context.NOTIFICATION_SERVICE) as NotificationManager
@@ -397,34 +397,21 @@ class LockWallpaperService: Service() {
}
// Run notification
if (homeInterval != lockInterval) {
var nextSetTime1 = LocalDateTime.parse(settingsDataStoreImpl.getString(SettingsConstants.NEXT_SET_TIME_1))
var nextSetTime2 = LocalDateTime.parse(settingsDataStoreImpl.getString(SettingsConstants.NEXT_SET_TIME_2))
val nextSetTime: LocalDateTime?
val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
val homeNextSetTime = LocalDateTime.parse(settingsDataStoreImpl.getString(SettingsConstants.HOME_NEXT_SET_TIME))
val lockNextSetTime: LocalDateTime?
val nextSetTime: LocalDateTime?
val currentTime = LocalDateTime.now()
settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, currentTime.format(formatter))
if (setHome && setLock && !scheduleSeparately) {
nextSetTime1 = currentTime.plusMinutes(homeInterval.toLong())
nextSetTime2 = nextSetTime1
nextSetTime = nextSetTime1
nextSetTime?.let { settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, it.format(formatter)) }
lockNextSetTime = currentTime.plusMinutes(lockInterval.toLong())
nextSetTime = if (lockNextSetTime.isBefore(homeNextSetTime) && lockNextSetTime.isAfter(currentTime)) lockNextSetTime
else if (homeNextSetTime.isAfter(currentTime)) homeNextSetTime
else currentTime.plusMinutes(lockInterval.toLong())
nextSetTime?.let {
settingsDataStoreImpl.putString(SettingsConstants.LAST_SET_TIME, currentTime.format(formatter))
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, it.format(formatter))
settingsDataStoreImpl.putString(SettingsConstants.HOME_NEXT_SET_TIME, homeNextSetTime.toString())
settingsDataStoreImpl.putString(SettingsConstants.LOCK_NEXT_SET_TIME, lockNextSetTime.toString())
}
else {
if (setHome) { nextSetTime1 = currentTime.plusMinutes(homeInterval.toLong()) }
else { nextSetTime2 = currentTime.plusMinutes(lockInterval.toLong()) }
nextSetTime = if (nextSetTime1 == null && nextSetTime2 != null) {
nextSetTime2
}
else if (nextSetTime1 != null && nextSetTime2 == null) {
nextSetTime1
}
else {
if (nextSetTime1!!.isBefore(nextSetTime2)) nextSetTime1 else nextSetTime2
}
nextSetTime?.let { settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME, it.format(formatter)) }
}
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME_1, nextSetTime1.toString())
settingsDataStoreImpl.putString(SettingsConstants.NEXT_SET_TIME_2, nextSetTime2.toString())
val notification = createNotification(nextSetTime)
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notification?.let { notificationManager.notify(1, it) }
+1
View File
@@ -160,4 +160,5 @@
<string name="change_next_long">Change to the next wallpaper in the album</string>
<string name="cannot_change_wallpaper">Cannot change wallpaper</string>
<string name="enable_wallpaper_changer">Enable Wallpaper Changer</string>
<string name="unselected_album">Unselected album</string>
</resources>