0
0
mirror of https://github.com/ankidroid/Anki-Android.git synced 2024-09-20 03:52:15 +02:00

Undo was showing even if it is unavailable (fixed)

This commit is contained in:
Aditya kumar 2024-05-25 15:01:07 +05:30 committed by Mike Hardy
parent 3b6288a913
commit 8e0b537b1d

View File

@ -953,16 +953,20 @@ open class DeckPicker :
menu.setGroupVisible(R.id.allItems, optionsMenuState != null) menu.setGroupVisible(R.id.allItems, optionsMenuState != null)
optionsMenuState?.run { optionsMenuState?.run {
menu.findItem(R.id.deck_picker_action_filter).isVisible = searchIcon menu.findItem(R.id.deck_picker_action_filter).isVisible = searchIcon
updateUndoLabelFromState(menu.findItem(R.id.action_undo), undoLabel) updateUndoLabelFromState(menu.findItem(R.id.action_undo), undoLabel, undoAvailable)
updateSyncIconFromState(menu.findItem(R.id.action_sync), this) updateSyncIconFromState(menu.findItem(R.id.action_sync), this)
menu.findItem(R.id.action_scoped_storage_migrate).isVisible = shouldShowStartMigrationButton menu.findItem(R.id.action_scoped_storage_migrate).isVisible = shouldShowStartMigrationButton
setupMigrationProgressMenuItem(menu, mediaMigrationState) setupMigrationProgressMenuItem(menu, mediaMigrationState)
} }
} }
private fun updateUndoLabelFromState(menuItem: MenuItem, undoLabel: String?) { private fun updateUndoLabelFromState(
menuItem: MenuItem,
undoLabel: String?,
undoAvailable: Boolean
) {
menuItem.run { menuItem.run {
if (undoLabel != null) { if (undoLabel != null && undoAvailable) {
isVisible = true isVisible = true
title = undoLabel title = undoLabel
} else { } else {
@ -1011,13 +1015,14 @@ open class DeckPicker :
optionsMenuState = withOpenColOrNull { optionsMenuState = withOpenColOrNull {
val searchIcon = decks.count() >= 10 val searchIcon = decks.count() >= 10
val undoLabel = undoLabel() val undoLabel = undoLabel()
Pair(searchIcon, undoLabel) val undoAvailable = undoAvailable()
}?.let { (searchIcon, undoLabel) -> Triple(searchIcon, undoLabel, undoAvailable)
}?.let { (searchIcon, undoLabel, undoAvailable) ->
val syncIcon = fetchSyncStatus() val syncIcon = fetchSyncStatus()
val mediaMigrationState = getMediaMigrationState() val mediaMigrationState = getMediaMigrationState()
val shouldShowStartMigrationButton = shouldOfferToMigrate() || val shouldShowStartMigrationButton = shouldOfferToMigrate() ||
mediaMigrationState is MediaMigrationState.Ongoing.PausedDueToError mediaMigrationState is MediaMigrationState.Ongoing.PausedDueToError
OptionsMenuState(searchIcon, undoLabel, syncIcon, shouldShowStartMigrationButton, mediaMigrationState) OptionsMenuState(searchIcon, undoLabel, syncIcon, shouldShowStartMigrationButton, mediaMigrationState, undoAvailable)
} }
} }
@ -2043,6 +2048,8 @@ open class DeckPicker :
Pair(sched.deckDueTree(), this.isEmpty) Pair(sched.deckDueTree(), this.isEmpty)
} }
onDecksLoaded(deckData.first, deckData.second) onDecksLoaded(deckData.first, deckData.second)
updateMenuState()
} }
} }
} }
@ -2704,7 +2711,8 @@ data class OptionsMenuState(
val undoLabel: String?, val undoLabel: String?,
val syncIcon: SyncIconState, val syncIcon: SyncIconState,
val shouldShowStartMigrationButton: Boolean, val shouldShowStartMigrationButton: Boolean,
val mediaMigrationState: MediaMigrationState val mediaMigrationState: MediaMigrationState,
val undoAvailable: Boolean
) )
enum class SyncIconState { enum class SyncIconState {