Skip to content

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Amardurai
Copy link

@Amardurai Amardurai commented Jun 18, 2025

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.

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

Copy link

welcome bot commented Jun 18, 2025

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.

Copy link
Member

@mikehardy mikehardy left a 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!

@Amardurai Amardurai requested a review from mikehardy June 19, 2025 13:42
Copy link
Member

@david-allison david-allison left a 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 =
Copy link
Member

@david-allison david-allison Jun 19, 2025

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:

// 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)

Copy link
Author

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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ This doesn't seem to pass in the CramKind selection

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()
}
}
}

Copy link
Author

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!

Copy link
Member

@david-allison david-allison Jun 19, 2025

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,

Copy link
Author

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?

Copy link
Member

@david-allison david-allison Jun 19, 2025

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:

private val selectedStatePosition: Int
get() =
dialog
?.findViewById<Spinner>(R.id.cards_state_selector)
?.selectedItemPosition ?: AdapterView.INVALID_POSITION

Copy link
Author

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.

Copy link
Member

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2025-06-19 at 11 28 00 PM

@david-allison david-allison added the Needs Author Reply Waiting for a reply from the original author label Jun 19, 2025
@Amardurai Amardurai force-pushed the 18479-fix-custom-study-navigation branch from 1137777 to 340f1df Compare June 21, 2025 06:52
@david-allison david-allison added Needs Review and removed Needs Author Reply Waiting for a reply from the original author labels Jun 23, 2025
@david-allison david-allison dismissed their stale review June 23, 2025 00:59

leaving for someone else

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Onboarding/UX: Handle 'Custom Study by card state or tag' when there are no tags
3 participants