Skip to content
Merged
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 @@ -149,7 +149,7 @@ class CustomStudyDialog : AnalyticsDialogFragment() {
val option = selectedSubDialog ?: return@setFragmentResultListener
val selectedCardStateIndex = viewModel.selectedCardStateIndex
if (selectedCardStateIndex == AdapterView.INVALID_POSITION) return@setFragmentResultListener
val kind = CustomStudyCardState.entries[selectedCardStateIndex].kind
val kind = viewModel.selectedKind
val cardsAmount = userInputValue ?: 100 // the default value
launchCustomStudy(option, cardsAmount, kind, tagsToInclude, emptyList())
}
Expand Down Expand Up @@ -404,7 +404,7 @@ class CustomStudyDialog : AnalyticsDialogFragment() {
}
// skip tag selection if there's no tags to select
if (nids.isEmpty()) {
launchCustomStudy(contextMenuOption, n)
launchCustomStudy(contextMenuOption, n, viewModel.selectedKind)
return@launchCatchingTask
}
if (isAdded) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ package com.ichi2.anki.dialogs.customstudy
import android.widget.AdapterView
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import anki.scheduler.CustomStudyRequest.Cram.CramKind
import com.ichi2.anki.common.annotations.NeedsTest
import com.ichi2.anki.dialogs.customstudy.CustomStudyDialog.CustomStudyCardState
import com.ichi2.anki.libanki.Deck
import com.ichi2.anki.libanki.DeckId

Expand All @@ -42,6 +45,20 @@ class CustomStudyViewModel(
val deckId: DeckId
get() = savedStateHandle.get<DeckId>(KEY_DID) ?: error("Deck id was not provided!")

/*
* Translates the user's selection into a specific study type.
* This prevents the app from "forgetting" user's choice (e.g., Due Cards)
* even if the tag selection screen is skipped.
*/
@NeedsTest("Verify that selectedCardStateIndex correctly maps to the corresponding CramKind")
val selectedKind: CramKind
get() =
if (selectedCardStateIndex != AdapterView.INVALID_POSITION) {
CustomStudyCardState.entries[selectedCardStateIndex].kind
} else {
CramKind.CRAM_KIND_NEW
}

companion object {
/**
* Required key for a [DeckId] which [CustomStudyDialog] expects to receive as an argument.
Expand Down
Loading