-
-
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?
Skip tag selection when no tags are available in the deck #18562
Conversation
First PR! 🚀 We sincerely appreciate that you have taken the time to propose a change to AnkiDroid! Please have patience with us as we are all volunteers - we will get to this as soon as possible. |
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.
I have some asynchronous-data-loading concern about deferredDefaults
as mentioned directly in comments, but, assuming those are handled well, the feature itself looks like exactly what was settled on in the related issue. Nice!
AnkiDroid/src/main/java/com/ichi2/anki/dialogs/customstudy/CustomStudyDialog.kt
Outdated
Show resolved
Hide resolved
…tomStudyDialog.kt Co-authored-by: Mike Hardy <[email protected]>
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.
Thanks! Couple of architectural fixes, then good to go!
@@ -295,6 +295,12 @@ class CustomStudyDialog : AnalyticsDialogFragment() { | |||
setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) | |||
} | |||
} | |||
|
|||
val canChooseTags = |
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
// on a slow phone, 'extend limits' may be clicked before we know there's no new/review cards | |
// show 'no cards due' if this occurs | |
if (item.checkAvailability != null) { | |
val defaults = withProgress { deferredDefaults.await() } | |
if (!item.checkAvailability(defaults)) { | |
showSnackbar(getString((R.string.studyoptions_no_cards_due))) | |
return | |
} | |
} |
Since this no longer just means checkAvailability
, we should also have a requiresDefaults
property on ContextMenuOption
, and modify the above assertion:
require(deferredDefaults.isCompleted || selectedSubDialog!!.checkAvailability == null)
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!
@@ -349,7 +355,7 @@ 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 comment
The reason will be displayed to describe this comment to others. Learn more.
CramKind
selection
Anki-Android/AnkiDroid/src/main/java/com/ichi2/anki/dialogs/customstudy/CustomStudyDialog.kt
Lines 153 to 164 in 60fb6ce
if (selectedStatePosition == AdapterView.INVALID_POSITION) return@setFragmentResultListener | |
val kind = CustomStudyCardState.entries[selectedStatePosition].kind | |
val cardsAmount = userInputValue ?: 100 // the default value | |
requireActivity().launchCatchingTask { | |
withProgress { | |
try { | |
customStudy(option, cardsAmount, kind, tagsToInclude, tagsToExclude) | |
} finally { | |
requireActivity().dismissAllDialogFragments() | |
} | |
} | |
} |
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're already passing the CramKind as the kind parameter here:
val kind = CustomStudyCardState.entries[selectedStatePosition].kind
...
customStudy(option, cardsAmount, kind, tagsToInclude, tagsToExclude)
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 comment
The reason will be displayed to describe this comment to others. Learn more.
If canChooseTags
is false
AND contextMenuOption == STUDY_TAGS
: A user has selected a CramKind
The following code is then executed, which does not use the CramKind: customStudy(contextMenuOption, n)
customStudy
is defined as the following, which uses a default value of cramKind
instead.
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 comment
The 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:
requireActivity().launchCatchingTask {
withProgress {
try {
val kind = CustomStudyCardState.entries[selectedStatePosition].kind
customStudy(contextMenuOption, n, kind)
} finally {
requireActivity().dismissAllDialogFragments()
}
}
}
Looks good?
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.
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
private val selectedStatePosition: Int | |
get() = | |
dialog | |
?.findViewById<Spinner>(R.id.cards_state_selector) | |
?.selectedItemPosition ?: AdapterView.INVALID_POSITION |
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.
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
1137777
to
340f1df
Compare
Purpose / Description
Skip Tag Selection - In Custom Study options, if no tags are available, display 'OK' instead of 'Choose Tags' and start the custom study session directly, skipping the tag selection screen
Fixes
Approach
We check whether the deck's tag list is empty. If it is, we skip the tag selection screen and proceed directly to the custom study session
How Has This Been Tested?
456150775-f7d9c81c-a7ac-4f1e-b7de-9a3073fb7474.mov
Checklist
Please, go through these checks before submitting the PR.