Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Retain previous selection for Reset Progress #17615

Merged
merged 1 commit into from
Dec 18, 2024

Conversation

Aditya13s
Copy link
Contributor

@Aditya13s Aditya13s commented Dec 17, 2024

Purpose / Description

The issue was that the settings for "Reset Progress" were not retaining the user's previous selection. This change addresses that by saving the selected options in shared preferences.

Fixes

Approach

The solution involves saving the user’s selection (whether to reset repetition and lapse counts) in shared preferences. When the dialog is reopened, the saved preferences are loaded to restore the previous settings.

How Has This Been Tested?

Tested by opening the "Reset Progress" dialog, selecting various options, and verifying that the settings are retained even after reopening the dialog. Tested on a physical device running Android 12.

Checklist

Please, go through these checks before submitting the PR.

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

@Aditya13s
Copy link
Contributor Author

@Arthur-Milchior Please Review this.

Copy link
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! One last change

Index: AnkiDroid/src/main/java/com/ichi2/anki/scheduling/ForgetCardsDialog.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/scheduling/ForgetCardsDialog.kt b/AnkiDroid/src/main/java/com/ichi2/anki/scheduling/ForgetCardsDialog.kt
--- a/AnkiDroid/src/main/java/com/ichi2/anki/scheduling/ForgetCardsDialog.kt	(revision 4bdf08fcb784c14749fe5bf0ce0fd41c78120839)
+++ b/AnkiDroid/src/main/java/com/ichi2/anki/scheduling/ForgetCardsDialog.kt	(date 1734493627020)
@@ -29,6 +29,7 @@
 import com.ichi2.anki.CollectionManager.TR
 import com.ichi2.anki.R
 import com.ichi2.anki.launchCatchingTask
+import com.ichi2.anki.preferences.sharedPrefs
 import com.ichi2.anki.snackbar.showSnackbar
 import com.ichi2.anki.utils.openUrl
 import com.ichi2.anki.withProgress
@@ -81,14 +82,15 @@
         }
 
     override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
-        val sharedPrefs = requireContext().getSharedPreferences("dialog_prefs", 0)
         if (savedInstanceState != null) {
             restoreOriginalPositionIfPossible = savedInstanceState.getBoolean(ARG_RESTORE_ORIGINAL, true)
             resetRepetitionAndLapseCounts = savedInstanceState.getBoolean(ARG_RESET_REPETITION, false)
         } else {
             // If no saved instance state, load the last saved preferences for restore position and reset counts.
-            restoreOriginalPositionIfPossible = sharedPrefs.getBoolean(ARG_RESTORE_ORIGINAL, true)
-            resetRepetitionAndLapseCounts = sharedPrefs.getBoolean(ARG_RESET_REPETITION, false)
+            with (requireContext().sharedPrefs()) {
+                restoreOriginalPositionIfPossible = getBoolean(ARG_RESTORE_ORIGINAL, true)
+                resetRepetitionAndLapseCounts = getBoolean(ARG_RESET_REPETITION, false)
+            }
         }
         val contentView =
             layoutInflater.inflate(R.layout.dialog_forget_cards, null).apply {

Copy link
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cheers!

Optional request for a @NeedsTest here

@david-allison david-allison added the Needs Second Approval Has one approval, one more approval to merge label Dec 18, 2024
@BrayanDSO BrayanDSO added Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) and removed Needs Second Approval Has one approval, one more approval to merge labels Dec 18, 2024
@BrayanDSO BrayanDSO added this pull request to the merge queue Dec 18, 2024
Merged via the queue into ankidroid:main with commit b46565e Dec 18, 2024
9 checks passed
@github-actions github-actions bot removed the Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) label Dec 18, 2024
@github-actions github-actions bot added this to the 2.21 release milestone Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG]: Reset progress don’t retain previous selection
3 participants