mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
@@ -24,7 +24,7 @@ import android.content.Context
|
|||||||
import org.isoron.uhabits.core.database.UnsupportedDatabaseVersionException
|
import org.isoron.uhabits.core.database.UnsupportedDatabaseVersionException
|
||||||
import org.isoron.uhabits.core.reminders.ReminderScheduler
|
import org.isoron.uhabits.core.reminders.ReminderScheduler
|
||||||
import org.isoron.uhabits.core.ui.NotificationTray
|
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.AppContextModule
|
||||||
import org.isoron.uhabits.inject.DaggerHabitsApplicationComponent
|
import org.isoron.uhabits.inject.DaggerHabitsApplicationComponent
|
||||||
import org.isoron.uhabits.inject.HabitsApplicationComponent
|
import org.isoron.uhabits.inject.HabitsApplicationComponent
|
||||||
@@ -67,14 +67,22 @@ class HabitsApplication : Application() {
|
|||||||
.habitsModule(HabitsModule(db))
|
.habitsModule(HabitsModule(db))
|
||||||
.build()
|
.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
|
val habitList = component.habitList
|
||||||
for (h in habitList) h.recompute()
|
for (h in habitList) h.recompute()
|
||||||
|
|
||||||
widgetUpdater = component.widgetUpdater
|
widgetUpdater = component.widgetUpdater.apply {
|
||||||
widgetUpdater.startListening()
|
startListening()
|
||||||
widgetUpdater.scheduleStartDayWidgetUpdate()
|
scheduleStartDayWidgetUpdate()
|
||||||
|
}
|
||||||
|
|
||||||
reminderScheduler = component.reminderScheduler
|
reminderScheduler = component.reminderScheduler
|
||||||
reminderScheduler.startListening()
|
reminderScheduler.startListening()
|
||||||
@@ -82,9 +90,6 @@ class HabitsApplication : Application() {
|
|||||||
notificationTray = component.notificationTray
|
notificationTray = component.notificationTray
|
||||||
notificationTray.startListening()
|
notificationTray.startListening()
|
||||||
|
|
||||||
val prefs = component.preferences
|
|
||||||
prefs.lastAppVersion = BuildConfig.VERSION_CODE
|
|
||||||
|
|
||||||
val taskRunner = component.taskRunner
|
val taskRunner = component.taskRunner
|
||||||
taskRunner.execute {
|
taskRunner.execute {
|
||||||
reminderScheduler.scheduleAll()
|
reminderScheduler.scheduleAll()
|
||||||
|
|||||||
@@ -86,6 +86,8 @@ class SharedPreferencesStorage
|
|||||||
when (key) {
|
when (key) {
|
||||||
"pref_checkmark_reverse_order" ->
|
"pref_checkmark_reverse_order" ->
|
||||||
preferences.isCheckmarkSequenceReversed = getBoolean(key, false)
|
preferences.isCheckmarkSequenceReversed = getBoolean(key, false)
|
||||||
|
"pref_midnight_delay" ->
|
||||||
|
preferences.isMidnightDelayEnabled = getBoolean(key, false)
|
||||||
"pref_sticky_notifications" ->
|
"pref_sticky_notifications" ->
|
||||||
preferences.setNotificationsSticky(getBoolean(key, false))
|
preferences.setNotificationsSticky(getBoolean(key, false))
|
||||||
"pref_led_notifications" ->
|
"pref_led_notifications" ->
|
||||||
|
|||||||
@@ -240,4 +240,6 @@
|
|||||||
<string name="pref_unknown_description">Differentiate days without data from actual lapses. To enter a lapse, toggle twice.</string>
|
<string name="pref_unknown_description">Differentiate days without data from actual lapses. To enter a lapse, toggle twice.</string>
|
||||||
<string name="you_are_now_a_developer">You are now a developer</string>
|
<string name="you_are_now_a_developer">You are now a developer</string>
|
||||||
<string name="activity_not_found">No app was found to support this action</string>
|
<string name="activity_not_found">No app was found to support this action</string>
|
||||||
</resources>
|
<string name="pref_midnight_delay_title">Extend day a few hours past midnight</string>
|
||||||
|
<string name="pref_midnight_delay_description">Wait until 3:00 AM to show a new day. Useful if you typically go to sleep after midnight. N.B.: this setting will not take effect until you restart the app.</string>
|
||||||
|
</resources>
|
||||||
|
|||||||
@@ -31,6 +31,13 @@
|
|||||||
android:title="@string/pref_toggle_title"
|
android:title="@string/pref_toggle_title"
|
||||||
app:iconSpaceReserved="false" />
|
app:iconSpaceReserved="false" />
|
||||||
|
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:defaultValue="false"
|
||||||
|
android:key="pref_midnight_delay"
|
||||||
|
android:summary="@string/pref_midnight_delay_description"
|
||||||
|
android:title="@string/pref_midnight_delay_title"
|
||||||
|
app:iconSpaceReserved="false" />
|
||||||
|
|
||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:key="pref_skip_enabled"
|
android:key="pref_skip_enabled"
|
||||||
@@ -245,4 +252,4 @@
|
|||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
|||||||
@@ -183,6 +183,13 @@ open class Preferences(private val storage: Storage) {
|
|||||||
for (l in listeners) l.onCheckmarkSequenceChanged()
|
for (l in listeners) l.onCheckmarkSequenceChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open var isMidnightDelayEnabled: Boolean
|
||||||
|
get() = storage.getBoolean("pref_midnight_delay", false)
|
||||||
|
set(enabled) {
|
||||||
|
storage.putBoolean("pref_midnight_delay", enabled)
|
||||||
|
for (l in listeners) l.onCheckmarkSequenceChanged()
|
||||||
|
}
|
||||||
|
|
||||||
fun updateLastHint(number: Int, timestamp: Timestamp) {
|
fun updateLastHint(number: Int, timestamp: Timestamp) {
|
||||||
storage.putInt("last_hint_number", number)
|
storage.putInt("last_hint_number", number)
|
||||||
storage.putLong("last_hint_timestamp", timestamp.unixTime)
|
storage.putLong("last_hint_timestamp", timestamp.unixTime)
|
||||||
|
|||||||
@@ -167,4 +167,12 @@ class PreferencesTest : BaseUnitTest() {
|
|||||||
assertTrue(prefs.showArchived)
|
assertTrue(prefs.showArchived)
|
||||||
assertFalse(prefs.showCompleted)
|
assertFalse(prefs.showCompleted)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Throws(Exception::class)
|
||||||
|
fun testMidnightDelay() {
|
||||||
|
assertFalse(prefs.isMidnightDelayEnabled)
|
||||||
|
prefs.isMidnightDelayEnabled = true
|
||||||
|
assertTrue(prefs.isMidnightDelayEnabled)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user