Skip to content

Commit 6a19855

Browse files
committed
Show/hide deck related menu items based on collection status
If the collection is empty(no cards and no user added decks) then deck related menu items will be hidden.
1 parent a19cb96 commit 6a19855

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,7 @@ open class DeckPicker :
952952
launchCatchingTask {
953953
updateMenuState()
954954
updateSearchVisibilityFromState(menu)
955+
updateDeckRelatedMenuItems(menu)
955956
if (!fragmented) {
956957
updateMenuFromState(menu)
957958
}
@@ -1048,6 +1049,7 @@ open class DeckPicker :
10481049
updateUndoLabelFromState(menu.findItem(R.id.action_undo), undoLabel, undoAvailable)
10491050
updateSyncIconFromState(menu.findItem(R.id.action_sync), this)
10501051
}
1052+
updateDeckRelatedMenuItems(menu)
10511053
}
10521054

10531055
private suspend fun updateUndoMenuState() {
@@ -1060,6 +1062,18 @@ open class DeckPicker :
10601062
}
10611063
}
10621064

1065+
/**
1066+
* Shows/hides deck related menu items based on the collection being empty or not.
1067+
*/
1068+
private fun updateDeckRelatedMenuItems(menu: Menu) {
1069+
optionsMenuState?.run {
1070+
menu.findItem(R.id.action_deck_rename)?.isVisible = !isColEmpty
1071+
menu.findItem(R.id.action_deck_delete)?.isVisible = !isColEmpty
1072+
// added to the menu by StudyOptionsFragment
1073+
menu.findItem(R.id.action_deck_or_study_options)?.isVisible = !isColEmpty
1074+
}
1075+
}
1076+
10631077
private fun updateSearchVisibilityFromState(menu: Menu) {
10641078
optionsMenuState?.run {
10651079
menu.findItem(R.id.deck_picker_action_filter).isVisible = searchIcon
@@ -1120,10 +1134,14 @@ open class DeckPicker :
11201134
val searchIcon = decks.count() >= 10
11211135
val undoLabel = undoLabel()
11221136
val undoAvailable = undoAvailable()
1123-
Triple(searchIcon, undoLabel, undoAvailable)
1124-
}?.let { (searchIcon, undoLabel, undoAvailable) ->
1137+
// besides checking for cards being available also consider if we have empty decks
1138+
val isColEmpty = isEmpty && decks.count() == 1
1139+
// the correct sync status is fetched in the next call so "Normal" is used as a placeholder
1140+
// the sync status is calculated in the next call so "Normal" is used as a placeholder
1141+
OptionsMenuState(searchIcon, undoLabel, SyncIconState.Normal, undoAvailable, isColEmpty)
1142+
}?.let { (searchIcon, undoLabel, _, undoAvailable, isColEmpty) ->
11251143
val syncIcon = fetchSyncStatus()
1126-
OptionsMenuState(searchIcon, undoLabel, syncIcon, undoAvailable)
1144+
OptionsMenuState(searchIcon, undoLabel, syncIcon, undoAvailable, isColEmpty)
11271145
}
11281146
}
11291147

@@ -2659,6 +2677,7 @@ data class OptionsMenuState(
26592677
val undoLabel: String?,
26602678
val syncIcon: SyncIconState,
26612679
val undoAvailable: Boolean,
2680+
val isColEmpty: Boolean,
26622681
)
26632682

26642683
enum class SyncIconState {

0 commit comments

Comments
 (0)