Skip to content

Commit

Permalink
remove new timezone handling
Browse files Browse the repository at this point in the history
fixes 15746
  • Loading branch information
MorenoTropical committed Apr 5, 2024
1 parent 512c2e9 commit 1506d50
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,6 @@ object UsageAnalytics {
"timeLimit", // Timebox time limit
"timeoutAnswer", // Automatic display answer
"keepScreenOn", // Disable screen timeout
"newTimezoneHandling", // New timezone handling
"doubleTapTimeInterval", // Double tap time interval (milliseconds)
// Sync
"syncFetchMedia", // Fetch media on sync
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.ichi2.anki.preferences

import androidx.preference.SwitchPreferenceCompat
import com.ichi2.anki.CollectionManager.withCol
import com.ichi2.anki.R
import com.ichi2.anki.launchCatchingTask
Expand Down Expand Up @@ -60,20 +59,5 @@ class ReviewingSettingsFragment : SettingsFragment() {
launchCatchingTask { setDayOffset(requireContext(), newValue as Int) }
}
}

// New timezone handling
requirePreference<SwitchPreferenceCompat>(R.string.new_timezone_handling_preference).apply {
launchCatchingTask {
isChecked = withCol { sched.newTimezoneEnabled() }
isEnabled = withCol { schedVer() > 1 }
}
setOnPreferenceChangeListener { newValue ->
if (newValue == true) {
launchCatchingTask { withCol { sched.setCreationOffset() } }
} else {
launchCatchingTask { withCol { sched.clearCreationOffset() } }
}
}
}
}
}
20 changes: 18 additions & 2 deletions AnkiDroid/src/main/java/com/ichi2/libanki/Collection.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ import anki.card_rendering.EmptyCardsReport
import anki.collection.OpChanges
import anki.collection.OpChangesWithCount
import anki.config.ConfigKey
import anki.config.Preferences
import anki.config.copy
import anki.config.preferences
import anki.search.SearchNode
import anki.sync.SyncAuth
import anki.sync.SyncStatusResponse
Expand Down Expand Up @@ -167,12 +170,17 @@ open class Collection(
val ver = schedVer()
if (ver == 1) {
sched = DummyScheduler(this)
} else {
} else if (ver == 2) {
if (!backend.getConfigBool(ConfigKey.Bool.SCHED_2021)) {
backend.setConfigBool(ConfigKey.Bool.SCHED_2021, true, undoable = false)
}
sched = Scheduler(this)
config.set("localOffset", sched.currentTimezoneOffset())
if (config.get<Int>("creationOffset") == null) {
val prefs = getPreferences().copy {
scheduling = scheduling.copy { newTimezone = true }
}
setPreferences(prefs)
}
}
}

Expand Down Expand Up @@ -692,4 +700,12 @@ open class Collection(
val homeDeck = currentReviewCard?.currentDeckId()?.did ?: 0L
return backend.defaultsForAdding(homeDeckOfCurrentReviewCard = homeDeck)
}

fun getPreferences(): Preferences {
return backend.getPreferences()
}

fun setPreferences(preferences: Preferences): OpChanges {
return backend.setPreferences(preferences)
}
}
1 change: 0 additions & 1 deletion AnkiDroid/src/main/res/values/10-preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@
<string name="use_current" maxLength="41">Deck for new cards</string>
<string name="learn_cutoff" maxLength="41">Learn ahead limit</string>
<string name="time_limit" maxLength="41">Timebox time limit</string>
<string name="new_timezone" maxLength="41">New timezone handling</string>
<string name="day_offset_with_description" maxLength="41">Start of next day</string>
<plurals name="day_offset_summ" comment="%d is going to be replaced with the number of hours past midnight. It can be replaced if something else suits better the translation">
<item quantity="one">%d hour past midnight</item>
Expand Down
1 change: 0 additions & 1 deletion AnkiDroid/src/main/res/values/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<string name="time_limit_preference">timeLimit</string>
<string name="timeout_answer_preference">timeoutAnswer</string>
<string name="keep_screen_on_preference">keepScreenOn</string>
<string name="new_timezone_handling_preference">newTimezoneHandling</string>
<string name="double_tap_time_interval_preference">doubleTapTimeInterval</string>
<!-- Sync -->
<string name="pref_sync_screen_key">syncScreen</string>
Expand Down
4 changes: 0 additions & 4 deletions AnkiDroid/src/main/res/xml/preferences_reviewing.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@
android:key="@string/keep_screen_on_preference"
android:summary="@string/pref_keep_screen_on_summ"
android:title="@string/pref_keep_screen_on" />
<SwitchPreferenceCompat
android:key="@string/new_timezone_handling_preference"
android:title="@string/new_timezone"
android:defaultValue="false" />
<com.ichi2.preferences.NumberRangePreferenceCompat
android:defaultValue="200"
android:key="@string/double_tap_time_interval_preference"
Expand Down
5 changes: 0 additions & 5 deletions AnkiDroid/src/test/java/com/ichi2/libanki/SchedulerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,6 @@ open class SchedulerTest : JvmTest() {
SYNC_VER,
Matchers.equalTo(10)
)
MatcherAssert.assertThat(
"localOffset should be set if using V2 Scheduler",
col.config.get<Int?>("localOffset") != null,
Matchers.equalTo(true)
)
val sched = col.sched
MatcherAssert.assertThat(
"new timezone should be enabled by default",
Expand Down

0 comments on commit 1506d50

Please sign in to comment.