Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ class ReviewerFragment :
}

override fun onMenuItemClick(item: MenuItem): Boolean {
Timber.v("ReviewerFragment::onMenuItemClick %s", item)
if (item.hasSubMenu()) return false
val action = ViewerAction.fromId(item.itemId)
viewModel.executeAction(action)
Expand Down Expand Up @@ -586,6 +585,27 @@ class ReviewerFragment :
}
}
}
viewModel.chooseDeckOptionsFlow
.flowWithLifecycle(lifecycle)
.collectIn(lifecycleScope) { (currentDeckId, cardDeckId) ->
AlertDialog
.Builder(requireContext())
.setTitle(R.string.choose_deck_options_title)
.setItems(
arrayOf(
currentDeckId.toString(),
cardDeckId.toString(),
),
) { _, which ->
val targetDeckId =
if (which == 0) currentDeckId else cardDeckId

lifecycleScope.launch {
viewModel.openDeckOptionsForDeck(targetDeckId)
}
}.setNegativeButton(android.R.string.cancel, null)
.show()
}
}

override fun onSelectedTags(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,23 @@ class ReviewerViewModel(
destinationFlow.emit(destination)
}

val chooseDeckOptionsFlow = MutableSharedFlow<Pair<Long, Long>>()

private suspend fun emitDeckOptionsDestination() {
val deckId = withCol { decks.getCurrentId() }
val currentDeckId = withCol { decks.getCurrentId() }
val cardDeckId = currentCard.await().currentDeckId()

if (currentDeckId == cardDeckId) {
val isFiltered = withCol { decks.isFiltered(currentDeckId) }
destinationFlow.emit(DeckOptionsDestination(currentDeckId, isFiltered))
} else {
chooseDeckOptionsFlow.emit(currentDeckId to cardDeckId)
}
}

suspend fun openDeckOptionsForDeck(deckId: Long) {
val isFiltered = withCol { decks.isFiltered(deckId) }
val destination = DeckOptionsDestination(deckId, isFiltered)
Timber.i("Launching 'deck options' for deck %d", deckId)
destinationFlow.emit(destination)
destinationFlow.emit(DeckOptionsDestination(deckId, isFiltered))
}

private suspend fun emitBrowseDestination() {
Expand Down
1 change: 1 addition & 0 deletions AnkiDroid/src/main/res/values/02-strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
~ this program. If not, see <http://www.gnu.org/licenses/>.
-->
<resources>
<string name="choose_deck_options_title">Which deck would you like to display options for?</string>
<!-- Navigation drawer strings -->
<string name="drawer_open">Open drawer</string>
<string name="drawer_close">Close drawer</string>
Expand Down