Implement the midnight delay option

Closes #694.
This commit is contained in:
Quentin Hibon
2021-01-27 09:52:28 +01:00
parent 64069a6e7f
commit bb8d4abb9e
6 changed files with 41 additions and 10 deletions

View File

@@ -24,7 +24,7 @@ import android.content.Context
import org.isoron.uhabits.core.database.UnsupportedDatabaseVersionException
import org.isoron.uhabits.core.reminders.ReminderScheduler
import org.isoron.uhabits.core.ui.NotificationTray
import org.isoron.uhabits.core.utils.DateUtils
import org.isoron.uhabits.core.utils.DateUtils.Companion.setStartDayOffset
import org.isoron.uhabits.inject.AppContextModule
import org.isoron.uhabits.inject.DaggerHabitsApplicationComponent
import org.isoron.uhabits.inject.HabitsApplicationComponent
@@ -67,14 +67,22 @@ class HabitsApplication : Application() {
.habitsModule(HabitsModule(db))
.build()
DateUtils.setStartDayOffset(3, 0)
val prefs = component.preferences
prefs.lastAppVersion = BuildConfig.VERSION_CODE
if (prefs.isMidnightDelayEnabled) {
setStartDayOffset(3, 0)
} else {
setStartDayOffset(0, 0)
}
val habitList = component.habitList
for (h in habitList) h.recompute()
widgetUpdater = component.widgetUpdater
widgetUpdater.startListening()
widgetUpdater.scheduleStartDayWidgetUpdate()
widgetUpdater = component.widgetUpdater.apply {
startListening()
scheduleStartDayWidgetUpdate()
}
reminderScheduler = component.reminderScheduler
reminderScheduler.startListening()
@@ -82,9 +90,6 @@ class HabitsApplication : Application() {
notificationTray = component.notificationTray
notificationTray.startListening()
val prefs = component.preferences
prefs.lastAppVersion = BuildConfig.VERSION_CODE
val taskRunner = component.taskRunner
taskRunner.execute {
reminderScheduler.scheduleAll()

View File

@@ -86,6 +86,8 @@ class SharedPreferencesStorage
when (key) {
"pref_checkmark_reverse_order" ->
preferences.isCheckmarkSequenceReversed = getBoolean(key, false)
"pref_midnight_delay" ->
preferences.isMidnightDelayEnabled = getBoolean(key, false)
"pref_sticky_notifications" ->
preferences.setNotificationsSticky(getBoolean(key, false))
"pref_led_notifications" ->