From 554f8c582ce4d215acfc3c1dc9c2a3170d4c1da0 Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Mon, 22 Nov 2021 13:28:42 -0600 Subject: [PATCH] Use shifted values for reminder preferences --- .../java/org/tasks/preferences/PreferenceTests.kt | 13 ++++++++----- .../{Upgrade_11_12.kt => Upgrade_11_12_3.kt} | 4 ++-- .../java/com/todoroo/astrid/service/Upgrader.kt | 6 +++--- .../main/java/org/tasks/preferences/Preferences.kt | 2 +- app/src/main/res/values/keys.xml | 6 +++--- 5 files changed, 17 insertions(+), 14 deletions(-) rename app/src/main/java/com/todoroo/astrid/service/{Upgrade_11_12.kt => Upgrade_11_12_3.kt} (91%) diff --git a/app/src/androidTest/java/org/tasks/preferences/PreferenceTests.kt b/app/src/androidTest/java/org/tasks/preferences/PreferenceTests.kt index 20970a321..00988fbaf 100644 --- a/app/src/androidTest/java/org/tasks/preferences/PreferenceTests.kt +++ b/app/src/androidTest/java/org/tasks/preferences/PreferenceTests.kt @@ -3,6 +3,9 @@ package org.tasks.preferences import android.annotation.SuppressLint import androidx.test.core.app.ApplicationProvider import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.todoroo.astrid.data.Task.Companion.NOTIFY_AFTER_DEADLINE +import com.todoroo.astrid.data.Task.Companion.NOTIFY_AT_DEADLINE +import com.todoroo.astrid.data.Task.Companion.NOTIFY_AT_START import org.junit.Assert.assertEquals import org.junit.Before import org.junit.Test @@ -119,11 +122,11 @@ class PreferenceTests { @Test fun testDefaultReminders() { assertEquals(0, defaultReminders()) - assertEquals(2, defaultReminders(1)) - assertEquals(4, defaultReminders(2)) - assertEquals(6, defaultReminders(1, 2)) - assertEquals(32, defaultReminders(5)) - assertEquals(38, defaultReminders(1, 2, 5)) + assertEquals(2, defaultReminders(NOTIFY_AT_DEADLINE)) + assertEquals(4, defaultReminders(NOTIFY_AFTER_DEADLINE)) + assertEquals(6, defaultReminders(NOTIFY_AT_DEADLINE, NOTIFY_AFTER_DEADLINE)) + assertEquals(32, defaultReminders(NOTIFY_AT_START)) + assertEquals(38, defaultReminders(NOTIFY_AT_START, NOTIFY_AT_DEADLINE, NOTIFY_AFTER_DEADLINE)) } private fun setQuietHoursStart(hour: Int) { diff --git a/app/src/main/java/com/todoroo/astrid/service/Upgrade_11_12.kt b/app/src/main/java/com/todoroo/astrid/service/Upgrade_11_12_3.kt similarity index 91% rename from app/src/main/java/com/todoroo/astrid/service/Upgrade_11_12.kt rename to app/src/main/java/com/todoroo/astrid/service/Upgrade_11_12_3.kt index 44184c3d6..7af65aa51 100644 --- a/app/src/main/java/com/todoroo/astrid/service/Upgrade_11_12.kt +++ b/app/src/main/java/com/todoroo/astrid/service/Upgrade_11_12_3.kt @@ -8,7 +8,7 @@ import org.tasks.R import org.tasks.preferences.Preferences import javax.inject.Inject -class Upgrade_11_12 @Inject constructor( +class Upgrade_11_12_3 @Inject constructor( private val preferences: Preferences ) { internal fun migrateDefaultReminderPreference() { @@ -26,7 +26,7 @@ class Upgrade_11_12 @Inject constructor( } companion object { - const val VERSION = 111200 + const val VERSION = 111203 private const val LEGACY_PREFERENCE = "p_def_reminders" } } \ No newline at end of file diff --git a/app/src/main/java/com/todoroo/astrid/service/Upgrader.kt b/app/src/main/java/com/todoroo/astrid/service/Upgrader.kt index ed8f85336..7b345afc2 100644 --- a/app/src/main/java/com/todoroo/astrid/service/Upgrader.kt +++ b/app/src/main/java/com/todoroo/astrid/service/Upgrader.kt @@ -44,7 +44,7 @@ class Upgrader @Inject constructor( private val taskMover: TaskMover, private val upgraderDao: UpgraderDao, private val upgrade_11_3: Lazy, - private val upgrade_11_12: Lazy, + private val upgrade_11_12_3: Lazy, ) { fun upgrade(from: Int, to: Int) { @@ -80,8 +80,8 @@ class Upgrader @Inject constructor( applyOpenTaskStartDates() } } - run(from, Upgrade_11_12.VERSION) { - with(upgrade_11_12.get()) { + run(from, Upgrade_11_12_3.VERSION) { + with(upgrade_11_12_3.get()) { migrateDefaultReminderPreference() } } diff --git a/app/src/main/java/org/tasks/preferences/Preferences.kt b/app/src/main/java/org/tasks/preferences/Preferences.kt index 57ccf4398..f13e6391b 100644 --- a/app/src/main/java/org/tasks/preferences/Preferences.kt +++ b/app/src/main/java/org/tasks/preferences/Preferences.kt @@ -203,7 +203,7 @@ class Preferences @JvmOverloads constructor( val defaultReminders: Int get() = defaultRemindersSet .mapNotNull { it.toIntOrNull() } - .fold(0) { v, e -> v or (1 shl e) } + .sum() val defaultRingMode: Int get() = getIntegerFromString(R.string.p_default_reminders_mode_key, 0) diff --git a/app/src/main/res/values/keys.xml b/app/src/main/res/values/keys.xml index e8877cdf4..075c8b938 100644 --- a/app/src/main/res/values/keys.xml +++ b/app/src/main/res/values/keys.xml @@ -202,9 +202,9 @@ - 5 - 1 - 2 + 32 + 2 + 4