-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Enable deck option target selection in study screen #19963
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
Merged
david-allison
merged 1 commit into
ankidroid:main
from
lukstbit:feat_pickDeckOptionsTarget
Mar 9, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
AnkiDroid/src/main/java/com/ichi2/anki/dialogs/DeckOptionsSelectionDialog.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| /* | ||
| * Copyright (c) 2025 lukstbit <52494258+lukstbit@users.noreply.github.com> | ||
| * | ||
| * This program is free software; you can redistribute it and/or modify it under | ||
| * the terms of the GNU General Public License as published by the Free Software | ||
| * Foundation; either version 3 of the License, or (at your option) any later | ||
| * version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, but WITHOUT ANY | ||
| * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||
| * PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License along with | ||
| * this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package com.ichi2.anki.dialogs | ||
|
|
||
| import android.content.Context | ||
| import android.view.LayoutInflater | ||
| import android.view.View | ||
| import android.view.ViewGroup | ||
| import android.widget.ArrayAdapter | ||
| import android.widget.TextView | ||
| import com.google.android.material.dialog.MaterialAlertDialogBuilder | ||
| import com.ichi2.anki.CollectionManager.TR | ||
| import com.ichi2.anki.R | ||
| import com.ichi2.anki.common.annotations.NeedsTest | ||
| import com.ichi2.anki.databinding.DialogDeckOptionsSelectionBinding | ||
| import com.ichi2.anki.pages.DeckOptionsEntry | ||
| import com.ichi2.anki.ui.windows.reviewer.ReviewerFragment | ||
| import com.ichi2.anki.ui.windows.reviewer.ReviewerViewModel | ||
| import com.ichi2.anki.utils.ext.usingStyledAttributes | ||
| import com.ichi2.utils.create | ||
| import com.ichi2.utils.customView | ||
| import com.ichi2.utils.title | ||
| import timber.log.Timber | ||
|
|
||
| /** | ||
| * Shows a list of decks from which the user can select one to display its deck options. | ||
| * @see ReviewerFragment | ||
| * @see ReviewerViewModel.emitDeckOptionsDestination | ||
| */ | ||
| @NeedsTest("verify null deck names => null entry") | ||
| fun Context.showDeckOptionsSelectionDialog( | ||
| options: List<DeckOptionsEntry>, | ||
| onDeckSelected: (DeckOptionsEntry) -> Unit, | ||
| ) { | ||
| Timber.i("Showing deck options selection dialog") | ||
| val binding = DialogDeckOptionsSelectionBinding.inflate(LayoutInflater.from(this)) | ||
| val normalDeckNameColor: Int = | ||
| usingStyledAttributes(null, intArrayOf(android.R.attr.textColor)) { | ||
| getColor(0, 0) | ||
| } | ||
| val dynamicDeckNameColor: Int = | ||
| usingStyledAttributes(null, intArrayOf(R.attr.dynDeckColor)) { | ||
| getColor(0, 0) | ||
| } | ||
| val dialog = | ||
| MaterialAlertDialogBuilder(this).create { | ||
| title(text = TR.deckConfigWhichDeck()) | ||
| customView(binding.root) | ||
| } | ||
| binding.deckOptionsList.adapter = | ||
| object : ArrayAdapter<String>( | ||
| this, | ||
| R.layout.item_deck_option_selection, | ||
| options.map { it.name.toString() }, | ||
| ) { | ||
| override fun getView( | ||
| position: Int, | ||
| convertView: View?, | ||
| parent: ViewGroup, | ||
| ): View { | ||
| val rowView = super.getView(position, convertView, parent) as TextView | ||
| rowView.setTextColor(if (options[position].isFiltered) dynamicDeckNameColor else normalDeckNameColor) | ||
| rowView.setOnClickListener { | ||
| dialog.dismiss() | ||
| onDeckSelected(options[position]) | ||
| } | ||
| return rowView | ||
| } | ||
| } | ||
| dialog.show() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,10 +29,12 @@ import com.ichi2.anki.Reviewer | |
| import com.ichi2.anki.asyncIO | ||
| import com.ichi2.anki.browser.BrowserDestination | ||
| import com.ichi2.anki.cardviewer.SingleCardSide | ||
| import com.ichi2.anki.common.annotations.NeedsTest | ||
| import com.ichi2.anki.launchCatchingIO | ||
| import com.ichi2.anki.libanki.Card | ||
| import com.ichi2.anki.libanki.CardId | ||
| import com.ichi2.anki.libanki.Collection | ||
| import com.ichi2.anki.libanki.DeckId | ||
| import com.ichi2.anki.libanki.NoteId | ||
| import com.ichi2.anki.libanki.redoLabel | ||
| import com.ichi2.anki.libanki.sched.CurrentQueueState | ||
|
|
@@ -43,6 +45,7 @@ import com.ichi2.anki.observability.undoableOp | |
| import com.ichi2.anki.pages.AnkiServer | ||
| import com.ichi2.anki.pages.CardInfoDestination | ||
| import com.ichi2.anki.pages.DeckOptionsDestination | ||
| import com.ichi2.anki.pages.DeckOptionsEntry | ||
| import com.ichi2.anki.pages.PostRequestUri | ||
| import com.ichi2.anki.pages.StatisticsDestination | ||
| import com.ichi2.anki.preferences.reviewer.ViewerAction | ||
|
|
@@ -278,14 +281,49 @@ class ReviewerViewModel( | |
| destinationFlow.emit(destination) | ||
| } | ||
|
|
||
| @NeedsTest("verify that we show the proper deck option targets for the current card") | ||
| private suspend fun emitDeckOptionsDestination() { | ||
| val deckId = withCol { decks.getCurrentId() } | ||
| val isFiltered = withCol { decks.isFiltered(deckId) } | ||
| val destination = DeckOptionsDestination(deckId, isFiltered) | ||
| val card = currentCard.await() | ||
| val options = getDeckOptionsTargets(deckId, card) | ||
| val isFiltered = options.first { it.deckId == deckId }.isFiltered | ||
| val destination = DeckOptionsDestination(deckId, isFiltered, options) | ||
|
Member
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. nit: this logic could be inside either: This feels like a general utility, rather than a responsibility of the study screen |
||
| Timber.i("Launching 'deck options' for deck %d", deckId) | ||
| destinationFlow.emit(destination) | ||
| } | ||
|
|
||
| /** | ||
| * Builds the valid(all [DeckOptionsEntry] that have a proper deck name) list of | ||
| * [DeckOptionsEntry] from which the user can select one to see its deck options. | ||
| * @param currentDeckId the [DeckId] of the currently selected deck | ||
| * @param card current card shown in the study screen | ||
| * See https://github.com/ankitects/anki/blob/b8884bac72aa50fa1189fe0a5079a71574bc5043/qt/aqt/deckoptions.py#L83-L100 | ||
| * for backend implementation and ordering of the entries. | ||
| */ | ||
| private suspend fun getDeckOptionsTargets( | ||
| currentDeckId: DeckId, | ||
| card: Card, | ||
| ): List<DeckOptionsEntry> { | ||
| val extraDeckIds = mutableListOf(currentDeckId) | ||
| if (card.oDid != 0L && card.oDid != currentDeckId) { | ||
| extraDeckIds.add(card.oDid) | ||
| } | ||
| if (card.did != currentDeckId) { | ||
| extraDeckIds.add(card.did) | ||
| } | ||
| return withCol { | ||
| extraDeckIds | ||
| .map { deckId -> | ||
| DeckOptionsEntry( | ||
| deckId = deckId, | ||
| name = decks.nameIfExists(deckId), | ||
| isFiltered = decks.isFiltered(deckId), | ||
| ) | ||
| }.filter { it.name != null } | ||
| .sortedBy { it.isFiltered } | ||
| } | ||
| } | ||
|
|
||
| private suspend fun emitBrowseDestination() { | ||
| val deckId = withCol { decks.getCurrentId() } | ||
| val cardId = currentCard.await().id | ||
|
|
||
10 changes: 10 additions & 0 deletions
10
AnkiDroid/src/main/res/layout/dialog_deck_options_selection.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <ListView xmlns:android="http://schemas.android.com/apk/res/android" | ||
| xmlns:tools="http://schemas.android.com/tools" | ||
| android:id="@+id/deck_options_list" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent" | ||
| android:paddingHorizontal="24dp" | ||
| android:paddingVertical="16dp" | ||
| tools:listitem="@layout/item_deck_option_selection" | ||
| /> |
13 changes: 13 additions & 0 deletions
13
AnkiDroid/src/main/res/layout/item_deck_option_selection.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <com.ichi2.ui.FixedTextView xmlns:android="http://schemas.android.com/apk/res/android" | ||
| xmlns:tools="http://schemas.android.com/tools" | ||
| android:id="@+id/deck_option" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:minHeight="?attr/listPreferredItemHeight" | ||
| android:paddingVertical="8dp" | ||
| android:textAppearance="?attr/textAppearanceListItemSecondary" | ||
| android:gravity="center_vertical|start" | ||
| android:background="?attr/selectableItemBackground" | ||
| tools:text="Deck option target" | ||
| /> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is there a need for this return?