mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-21 17:29:32 +01:00
Fix bugs with notification schedules caused by 24xx end times.
This commit is contained in:
committed by
Greyson Parrelli
parent
5cd0062688
commit
30ad854381
@@ -60,8 +60,7 @@ class EditNotificationProfileScheduleViewModel(
|
||||
}
|
||||
|
||||
fun setEndTime(hour: Int, minute: Int) {
|
||||
val adjustedEndHour = if (hour == 0) 24 else hour
|
||||
scheduleSubject.onNext(schedule.copy(end = adjustedEndHour * 100 + minute))
|
||||
scheduleSubject.onNext(schedule.copy(end = hour * 100 + minute))
|
||||
}
|
||||
|
||||
fun setEnabled(enabled: Boolean) {
|
||||
|
||||
@@ -115,6 +115,7 @@ import org.thoughtcrime.securesms.database.helpers.migration.V255_AddCallTableLo
|
||||
import org.thoughtcrime.securesms.database.helpers.migration.V256_FixIncrementalDigestColumns
|
||||
import org.thoughtcrime.securesms.database.helpers.migration.V257_CreateBackupMediaSyncTable
|
||||
import org.thoughtcrime.securesms.database.helpers.migration.V258_FixGroupRevokedInviteeUpdate
|
||||
import org.thoughtcrime.securesms.database.helpers.migration.V259_AdjustNotificationProfileMidnightEndTimes
|
||||
|
||||
/**
|
||||
* Contains all of the database migrations for [SignalDatabase]. Broken into a separate file for cleanliness.
|
||||
@@ -232,10 +233,11 @@ object SignalDatabaseMigrations {
|
||||
255 to V255_AddCallTableLogIndex,
|
||||
256 to V256_FixIncrementalDigestColumns,
|
||||
257 to V257_CreateBackupMediaSyncTable,
|
||||
258 to V258_FixGroupRevokedInviteeUpdate
|
||||
258 to V258_FixGroupRevokedInviteeUpdate,
|
||||
259 to V259_AdjustNotificationProfileMidnightEndTimes
|
||||
)
|
||||
|
||||
const val DATABASE_VERSION = 258
|
||||
const val DATABASE_VERSION = 259
|
||||
|
||||
@JvmStatic
|
||||
fun migrate(context: Application, db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package org.thoughtcrime.securesms.database.helpers.migration
|
||||
|
||||
import android.app.Application
|
||||
import net.zetetic.database.sqlcipher.SQLiteDatabase
|
||||
|
||||
/**
|
||||
* Adjust notification profile schedules with end times between midnight at 1am. These were originally
|
||||
* stored as 24xx and will now use the same as start with 00xx.
|
||||
*/
|
||||
@Suppress("ClassName")
|
||||
object V259_AdjustNotificationProfileMidnightEndTimes : SignalDatabaseMigration {
|
||||
override fun migrate(context: Application, db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
|
||||
db.execSQL(
|
||||
"""
|
||||
UPDATE
|
||||
notification_profile_schedule
|
||||
SET 'end' = end - 2400
|
||||
WHERE
|
||||
end >= 2400
|
||||
"""
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -39,9 +39,8 @@ data class NotificationProfileSchedule(
|
||||
val localStart: LocalDateTime = start.toLocalDateTime(localNow)
|
||||
val localEnd: LocalDateTime = end.toLocalDateTime(localNow)
|
||||
|
||||
return if (end < start) {
|
||||
(daysEnabled.contains(localStart.dayOfWeek.minus(1)) && localNow.isBetween(localStart.minusDays(1), localEnd)) ||
|
||||
(daysEnabled.contains(localStart.dayOfWeek) && localNow.isBetween(localStart, localEnd.plusDays(1)))
|
||||
return if (end <= start) {
|
||||
(daysEnabled.contains(localStart.dayOfWeek.minus(1)) && localNow.isBetween(localStart.minusDays(1), localEnd)) || (daysEnabled.contains(localStart.dayOfWeek) && localNow.isBetween(localStart, localEnd.plusDays(1)))
|
||||
} else {
|
||||
daysEnabled.contains(localStart.dayOfWeek) && localNow.isBetween(localStart, localEnd)
|
||||
}
|
||||
@@ -55,7 +54,7 @@ data class NotificationProfileSchedule(
|
||||
val localStart: LocalDateTime = start.toLocalDateTime(localNow)
|
||||
val localEnd: LocalDateTime = end.toLocalDateTime(localNow)
|
||||
|
||||
return if (end < start && (daysEnabled.contains(localStart.dayOfWeek.minus(1)) && localNow.isBetween(localStart.minusDays(1), localEnd))) {
|
||||
return if (end <= start && (daysEnabled.contains(localStart.dayOfWeek.minus(1)) && localNow.isBetween(localStart.minusDays(1), localEnd))) {
|
||||
localStart.minusDays(1)
|
||||
} else {
|
||||
localStart
|
||||
@@ -63,15 +62,14 @@ data class NotificationProfileSchedule(
|
||||
}
|
||||
|
||||
fun endTime(): LocalTime {
|
||||
val adjustedEnd = if (end == 2400) 0 else end
|
||||
return LocalTime.of(adjustedEnd / 100, adjustedEnd % 100)
|
||||
return LocalTime.of(end / 100, end % 100)
|
||||
}
|
||||
|
||||
fun endDateTime(localNow: LocalDateTime): LocalDateTime {
|
||||
val localStart: LocalDateTime = start.toLocalDateTime(localNow)
|
||||
val localEnd: LocalDateTime = end.toLocalDateTime(localNow)
|
||||
|
||||
return if (end < start && (daysEnabled.contains(localStart.dayOfWeek) && localNow.isBetween(localStart, localEnd.plusDays(1)))) {
|
||||
return if (end <= start && (daysEnabled.contains(localStart.dayOfWeek) && localNow.isBetween(localStart, localEnd.plusDays(1)))) {
|
||||
localEnd.plusDays(1)
|
||||
} else {
|
||||
localEnd
|
||||
@@ -80,9 +78,5 @@ data class NotificationProfileSchedule(
|
||||
}
|
||||
|
||||
fun Int.toLocalDateTime(now: LocalDateTime): LocalDateTime {
|
||||
if (this == 2400) {
|
||||
return now.plusDays(1).withHour(0).withMinute(0).withSecond(0)
|
||||
}
|
||||
|
||||
return now.withHour(this / 100).withMinute(this % 100).withSecond(0)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user