Skip to content

Commit

Permalink
Fix: Retain previous selection for Reset Progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya13s committed Dec 17, 2024
1 parent 3751f14 commit 4bdf08f
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package com.ichi2.anki.scheduling
import android.app.Dialog
import android.net.Uri
import android.os.Bundle
import androidx.core.content.edit
import androidx.core.os.bundleOf
import androidx.fragment.app.DialogFragment
import com.google.android.material.checkbox.MaterialCheckBox
Expand Down Expand Up @@ -80,9 +81,14 @@ class ForgetCardsDialog : DialogFragment() {
}

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)
}
val contentView =
layoutInflater.inflate(R.layout.dialog_forget_cards, null).apply {
Expand All @@ -109,6 +115,10 @@ class ForgetCardsDialog : DialogFragment() {
requireActivity().openUrl(Uri.parse(getString(R.string.link_help_forget_cards)))
}
positiveButton(R.string.dialog_ok) {
sharedPrefs.edit {
putBoolean(ARG_RESTORE_ORIGINAL, restoreOriginalPositionIfPossible)
putBoolean(ARG_RESET_REPETITION, resetRepetitionAndLapseCounts)
}
parentFragmentManager.setFragmentResult(
REQUEST_KEY_FORGET,
bundleOf(
Expand Down

0 comments on commit 4bdf08f

Please sign in to comment.