-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Skip tag selection when no tags are available in the deck #18562
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
base: main
Are you sure you want to change the base?
Changes from all commits
c108ada
ce72558
60fb6ce
e76f59a
340f1df
57f1c4b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -285,7 +285,8 @@ class CustomStudyDialog : AnalyticsDialogFragment() { | |||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||
@NeedsTest("17757: fragment not dismissed before result is output") | ||||||||||||||||||||||||||||||||||||
private fun buildInputDialog(contextMenuOption: ContextMenuOption): AlertDialog { | ||||||||||||||||||||||||||||||||||||
require(deferredDefaults.isCompleted || selectedSubDialog!!.checkAvailability == null) | ||||||||||||||||||||||||||||||||||||
require(deferredDefaults.isCompleted || selectedSubDialog?.requiresDefaults == false) | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
/* | ||||||||||||||||||||||||||||||||||||
TODO: Try to change to a standard input dialog (currently the thing holding us back is having the extra | ||||||||||||||||||||||||||||||||||||
TODO: hint line for the number of cards available, and having the pre-filled text selected by default) | ||||||||||||||||||||||||||||||||||||
|
@@ -311,6 +312,12 @@ class CustomStudyDialog : AnalyticsDialogFragment() { | |||||||||||||||||||||||||||||||||||
setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
val canChooseTags = | ||||||||||||||||||||||||||||||||||||
deferredDefaults.isCompleted && | ||||||||||||||||||||||||||||||||||||
deferredDefaults.getCompleted().tags.isNotEmpty() && | ||||||||||||||||||||||||||||||||||||
contextMenuOption == STUDY_TAGS | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
val editText = | ||||||||||||||||||||||||||||||||||||
v.findViewById<EditText>(R.id.custom_study_details_edittext2).apply { | ||||||||||||||||||||||||||||||||||||
setText(defaultValue) | ||||||||||||||||||||||||||||||||||||
|
@@ -323,7 +330,7 @@ class CustomStudyDialog : AnalyticsDialogFragment() { | |||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
val positiveBtnLabel = | ||||||||||||||||||||||||||||||||||||
if (contextMenuOption == STUDY_TAGS) { | ||||||||||||||||||||||||||||||||||||
if (canChooseTags) { | ||||||||||||||||||||||||||||||||||||
TR.customStudyChooseTags().toSentenceCase(requireContext(), R.string.sentence_choose_tags) | ||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||
getString(R.string.dialog_ok) | ||||||||||||||||||||||||||||||||||||
|
@@ -365,15 +372,24 @@ class CustomStudyDialog : AnalyticsDialogFragment() { | |||||||||||||||||||||||||||||||||||
allowSubmit = true | ||||||||||||||||||||||||||||||||||||
return@setOnClickListener | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
if (contextMenuOption == STUDY_TAGS) { | ||||||||||||||||||||||||||||||||||||
if (canChooseTags) { | ||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Anki-Android/AnkiDroid/src/main/java/com/ichi2/anki/dialogs/customstudy/CustomStudyDialog.kt Lines 153 to 164 in 60fb6ce
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're already passing the CramKind as the kind parameter here: val kind = CustomStudyCardState.entries[selectedStatePosition].kind So the CramKind is already being handled. Let me know if I missed anything! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If The following code is then executed, which does not use the CramKind:
Given that this bug was flagged in a TODO, it may be a good idea to create a sealed class which blocks this from happening again // TODO cram kind and the included/excluded tags lists are only relevant for STUDY_TAGS and
// should be included in the option to not leak in the method's api
private suspend fun customStudy(
contextMenuOption: ContextMenuOption,
userEntry: Int,
cramKind: CramKind = CramKind.CRAM_KIND_NEW, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for clarification! I've updated the code to explicitly pass the CramKind, even when canChooseTags is false, like this:
Looks good? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you test it? EDIT: It feels like I'm talking with an LLM right now... I can't see how that would work given the definition: Anki-Android/AnkiDroid/src/main/java/com/ichi2/anki/dialogs/customstudy/CustomStudyDialog.kt Lines 136 to 140 in 60fb6ce
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I’ve tested with all four options, and it’s working as expected. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How did you test it, it doesn't compile. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||||||||||||||||||
// mark allowSubmit as true because, if the user cancels TagLimitFragment, when | ||||||||||||||||||||||||||||||||||||
// we come back we wouldn't be able to trigger again TagLimitFragment | ||||||||||||||||||||||||||||||||||||
allowSubmit = true | ||||||||||||||||||||||||||||||||||||
val tagsSelectionDialog = TagLimitFragment.newInstance(dialogDeckId) | ||||||||||||||||||||||||||||||||||||
tagsSelectionDialog.show(parentFragmentManager, TagLimitFragment.TAG) | ||||||||||||||||||||||||||||||||||||
return@setOnClickListener | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
launchCustomStudy(contextMenuOption, n) | ||||||||||||||||||||||||||||||||||||
requireActivity().launchCatchingTask { | ||||||||||||||||||||||||||||||||||||
withProgress { | ||||||||||||||||||||||||||||||||||||
try { | ||||||||||||||||||||||||||||||||||||
val kind = CustomStudyCardState.entries[selectedStatePosition].kind | ||||||||||||||||||||||||||||||||||||
customStudy(contextMenuOption, n, kind, emptyList(), emptyList()) | ||||||||||||||||||||||||||||||||||||
} finally { | ||||||||||||||||||||||||||||||||||||
requireActivity().dismissAllDialogFragments() | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
@@ -546,12 +562,21 @@ class CustomStudyDialog : AnalyticsDialogFragment() { | |||||||||||||||||||||||||||||||||||
enum class ContextMenuOption( | ||||||||||||||||||||||||||||||||||||
val getTitle: Resources.() -> String, | ||||||||||||||||||||||||||||||||||||
val checkAvailability: ((CustomStudyDefaults) -> Boolean)? = null, | ||||||||||||||||||||||||||||||||||||
val requiresDefaults: Boolean = false, | ||||||||||||||||||||||||||||||||||||
) { | ||||||||||||||||||||||||||||||||||||
/** Increase today's new card limit */ | ||||||||||||||||||||||||||||||||||||
EXTEND_NEW({ TR.customStudyIncreaseTodaysNewCardLimit() }, checkAvailability = { it.extendNew.isUsable }), | ||||||||||||||||||||||||||||||||||||
EXTEND_NEW( | ||||||||||||||||||||||||||||||||||||
getTitle = { TR.customStudyIncreaseTodaysNewCardLimit() }, | ||||||||||||||||||||||||||||||||||||
checkAvailability = { it.extendNew.isUsable }, | ||||||||||||||||||||||||||||||||||||
requiresDefaults = true, | ||||||||||||||||||||||||||||||||||||
), | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
/** Increase today's review card limit */ | ||||||||||||||||||||||||||||||||||||
EXTEND_REV({ TR.customStudyIncreaseTodaysReviewCardLimit() }, checkAvailability = { it.extendReview.isUsable }), | ||||||||||||||||||||||||||||||||||||
EXTEND_REV( | ||||||||||||||||||||||||||||||||||||
getTitle = { TR.customStudyIncreaseTodaysReviewCardLimit() }, | ||||||||||||||||||||||||||||||||||||
checkAvailability = { it.extendReview.isUsable }, | ||||||||||||||||||||||||||||||||||||
requiresDefaults = true, | ||||||||||||||||||||||||||||||||||||
), | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
/** Review forgotten cards */ | ||||||||||||||||||||||||||||||||||||
STUDY_FORGOT({ TR.customStudyReviewForgottenCards() }), | ||||||||||||||||||||||||||||||||||||
|
@@ -563,7 +588,10 @@ class CustomStudyDialog : AnalyticsDialogFragment() { | |||||||||||||||||||||||||||||||||||
STUDY_PREVIEW({ TR.customStudyPreviewNewCards() }), | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
/** Limit to particular tags */ | ||||||||||||||||||||||||||||||||||||
STUDY_TAGS({ TR.customStudyStudyByCardStateOrTag() }), | ||||||||||||||||||||||||||||||||||||
STUDY_TAGS( | ||||||||||||||||||||||||||||||||||||
getTitle = { TR.customStudyStudyByCardStateOrTag() }, | ||||||||||||||||||||||||||||||||||||
requiresDefaults = true, | ||||||||||||||||||||||||||||||||||||
), | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
@Parcelize | ||||||||||||||||||||||||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should block - requiring
deferredDefaults
to be completed before the screen is launched.This is currently done:
Anki-Android/AnkiDroid/src/main/java/com/ichi2/anki/dialogs/customstudy/CustomStudyDialog.kt
Lines 188 to 196 in 60fb6ce
Since this no longer just means
checkAvailability
, we should also have arequiresDefaults
property onContextMenuOption
, and modify the above assertion:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood, Added the new requiresDefaults field to ContextMenuOption and updated the assertion!