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 18, 2024
1 parent 3751f14 commit dd66729
Showing 1 changed file with 13 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 All @@ -28,6 +29,7 @@ import com.ichi2.anki.AnkiActivity
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
Expand Down Expand Up @@ -80,9 +82,16 @@ class ForgetCardsDialog : DialogFragment() {
}

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val sharedPrefs = requireContext().sharedPrefs()
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.
with(sharedPrefs) {
restoreOriginalPositionIfPossible = getBoolean(ARG_RESTORE_ORIGINAL, true)
resetRepetitionAndLapseCounts = getBoolean(ARG_RESET_REPETITION, false)
}
}
val contentView =
layoutInflater.inflate(R.layout.dialog_forget_cards, null).apply {
Expand All @@ -109,6 +118,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 dd66729

Please sign in to comment.