diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/dialogs/customstudy/CustomStudyDialog.kt b/AnkiDroid/src/main/java/com/ichi2/anki/dialogs/customstudy/CustomStudyDialog.kt index d39eec06db32..af5b572c5f1a 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/dialogs/customstudy/CustomStudyDialog.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/dialogs/customstudy/CustomStudyDialog.kt @@ -107,55 +107,54 @@ class CustomStudyDialog(private val collection: Collection, private val customSt val jumpToReviewer = requireArguments().getBoolean("jumpToReviewer") val items = getValuesFromKeys(keyValueMap, listIds).toList().map { it as CharSequence } - return AlertDialog.Builder(requireActivity()).apply { - title(R.string.custom_study) - .cancelable(true) - .listItems(items = items) { _, index -> - when (ContextMenuOption.fromString(resources, items[index].toString())) { - DECK_OPTIONS -> { - // User asked to permanently change the deck options - val deckId = requireArguments().getLong("did") - val i = com.ichi2.anki.pages.DeckOptions.getIntent(requireContext(), deckId) - requireActivity().startActivity(i) - } - MORE_OPTIONS -> { - // User asked to see all custom study options - val d = CustomStudyDialog(collection, customStudyListener) - .withArguments( - STANDARD, - requireArguments().getLong("did"), - jumpToReviewer - ) - customStudyListener?.showDialogFragment(d) - } - STUDY_TAGS -> { + return AlertDialog.Builder(requireActivity()) + .title(R.string.custom_study) + .cancelable(true) + .listItems(items = items) { _, index -> + when (ContextMenuOption.fromString(resources, items[index].toString())) { + DECK_OPTIONS -> { + // User asked to permanently change the deck options + val deckId = requireArguments().getLong("did") + val i = com.ichi2.anki.pages.DeckOptions.getIntent(requireContext(), deckId) + requireActivity().startActivity(i) + } + MORE_OPTIONS -> { + // User asked to see all custom study options + val d = CustomStudyDialog(collection, customStudyListener) + .withArguments( + STANDARD, + requireArguments().getLong("did"), + jumpToReviewer + ) + customStudyListener?.showDialogFragment(d) + } + STUDY_TAGS -> { /* * This is a special Dialog for CUSTOM STUDY, where instead of only collecting a * number, it is necessary to collect a list of tags. This case handles the creation * of that Dialog. */ - val currentDeck = requireArguments().getLong("did") + val currentDeck = requireArguments().getLong("did") - val dialogFragment = TagsDialog().withArguments( - TagsDialog.DialogType.CUSTOM_STUDY_TAGS, - ArrayList(), - ArrayList(collection.tags.byDeck(currentDeck)) + val dialogFragment = TagsDialog().withArguments( + TagsDialog.DialogType.CUSTOM_STUDY_TAGS, + ArrayList(), + ArrayList(collection.tags.byDeck(currentDeck)) + ) + customStudyListener?.showDialogFragment(dialogFragment) + } + else -> { + // User asked for a standard custom study option + val d = CustomStudyDialog(collection, customStudyListener) + .withArguments( + ContextMenuOption.fromString(resources, items[index].toString()), + requireArguments().getLong("did"), + jumpToReviewer ) - customStudyListener?.showDialogFragment(dialogFragment) - } - else -> { - // User asked for a standard custom study option - val d = CustomStudyDialog(collection, customStudyListener) - .withArguments( - ContextMenuOption.fromString(resources, items[index].toString()), - requireArguments().getLong("did"), - jumpToReviewer - ) - customStudyListener?.showDialogFragment(d) - } + customStudyListener?.showDialogFragment(d) } } - }.show() + }.show() } @KotlinCleanup("make this use enum instead of Int") @@ -198,90 +197,90 @@ class CustomStudyDialog(private val collection: Collection, private val customSt // Whether or not to jump straight to the reviewer val jumpToReviewer = requireArguments().getBoolean("jumpToReviewer") // Set material dialog parameters - val dialog = AlertDialog.Builder(requireActivity()).apply { - customView(view = v, paddingLeft = 64, paddingRight = 64, paddingTop = 32, paddingBottom = 32) - .positiveButton(R.string.dialog_ok) { - // Get the value selected by user - val n: Int = try { - editText.text.toString().toInt() - } catch (e: Exception) { - Timber.w(e) - // This should never happen because we disable positive button for non-parsable inputs - return@positiveButton + val dialog = AlertDialog.Builder(requireActivity()) + .customView(view = v, paddingLeft = 64, paddingRight = 64, paddingTop = 32, paddingBottom = 32) + .positiveButton(R.string.dialog_ok) { + // Get the value selected by user + val n: Int = try { + editText.text.toString().toInt() + } catch (e: Exception) { + Timber.w(e) + // This should never happen because we disable positive button for non-parsable inputs + return@positiveButton + } + when (contextMenuOption) { + STUDY_NEW -> { + requireActivity().sharedPrefs().edit { putInt("extendNew", n) } + val deck = collection.decks.get(did)!! + deck.put("extendNew", n) + collection.decks.save(deck) + collection.sched.extendLimits(n, 0) + onLimitsExtended(jumpToReviewer) } - when (contextMenuOption) { - STUDY_NEW -> { - requireActivity().sharedPrefs().edit { putInt("extendNew", n) } - val deck = collection.decks.get(did)!! - deck.put("extendNew", n) - collection.decks.save(deck) - collection.sched.extendLimits(n, 0) - onLimitsExtended(jumpToReviewer) - } - STUDY_REV -> { - requireActivity().sharedPrefs().edit { putInt("extendRev", n) } - val deck = collection.decks.get(did)!! - deck.put("extendRev", n) - collection.decks.save(deck) - collection.sched.extendLimits(0, n) - onLimitsExtended(jumpToReviewer) - } - STUDY_FORGOT -> { - val ar = JSONArray() - ar.put(0, 1) - createCustomStudySession( - ar, - arrayOf( - String.format( - Locale.US, - "rated:%d:1", - n - ), - Consts.DYN_MAX_SIZE, - Consts.DYN_RANDOM - ), - false - ) - } - STUDY_AHEAD -> { - createCustomStudySession( - JSONArray(), - arrayOf( - String.format( - Locale.US, - "prop:due<=%d", - n - ), - Consts.DYN_MAX_SIZE, - Consts.DYN_DUE + STUDY_REV -> { + requireActivity().sharedPrefs().edit { putInt("extendRev", n) } + val deck = collection.decks.get(did)!! + deck.put("extendRev", n) + collection.decks.save(deck) + collection.sched.extendLimits(0, n) + onLimitsExtended(jumpToReviewer) + } + STUDY_FORGOT -> { + val ar = JSONArray() + ar.put(0, 1) + createCustomStudySession( + ar, + arrayOf( + String.format( + Locale.US, + "rated:%d:1", + n ), - true - ) - } - STUDY_RANDOM -> { - createCustomStudySession(JSONArray(), arrayOf("", n, Consts.DYN_RANDOM), true) - } - STUDY_PREVIEW -> { - createCustomStudySession( - JSONArray(), - arrayOf( - "is:new added:" + - n, - Consts.DYN_MAX_SIZE, - Consts.DYN_OLDEST + Consts.DYN_MAX_SIZE, + Consts.DYN_RANDOM + ), + false + ) + } + STUDY_AHEAD -> { + createCustomStudySession( + JSONArray(), + arrayOf( + String.format( + Locale.US, + "prop:due<=%d", + n ), - false - ) - } - STUDY_TAGS, - DECK_OPTIONS, - MORE_OPTIONS -> TODO("This branch has not been covered before") + Consts.DYN_MAX_SIZE, + Consts.DYN_DUE + ), + true + ) } + STUDY_RANDOM -> { + createCustomStudySession(JSONArray(), arrayOf("", n, Consts.DYN_RANDOM), true) + } + STUDY_PREVIEW -> { + createCustomStudySession( + JSONArray(), + arrayOf( + "is:new added:" + + n, + Consts.DYN_MAX_SIZE, + Consts.DYN_OLDEST + ), + false + ) + } + STUDY_TAGS, + DECK_OPTIONS, + MORE_OPTIONS -> TODO("This branch has not been covered before") } - .negativeButton(R.string.dialog_cancel) { - customStudyListener?.dismissAllDialogFragments() - } - }.create() + } + .negativeButton(R.string.dialog_cancel) { + customStudyListener?.dismissAllDialogFragments() + } + .create() editText.addTextChangedListener(object : TextWatcher { override fun beforeTextChanged(charSequence: CharSequence, i: Int, i1: Int, i2: Int) {} override fun onTextChanged(charSequence: CharSequence, i: Int, i1: Int, i2: Int) {}