Skip to content

Commit

Permalink
Support deleting/undoing deck from deck picker
Browse files Browse the repository at this point in the history
+ Delete the cards inside the default deck if user tries to delete it

Closes #11703
  • Loading branch information
dae committed Jun 30, 2022
1 parent 7ba4ab1 commit 2e6d415
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,8 @@ import com.ichi2.async.CollectionTask.*
import com.ichi2.async.Connection.CancellableTaskListener
import com.ichi2.async.Connection.ConflictResolution
import com.ichi2.compat.CompatHelper.Companion.sdkVersion
import com.ichi2.libanki.ChangeManager
import com.ichi2.libanki.*
import com.ichi2.libanki.Collection.CheckDatabaseResult
import com.ichi2.libanki.Consts
import com.ichi2.libanki.Decks
import com.ichi2.libanki.Utils
import com.ichi2.libanki.importer.AnkiPackageImporter
import com.ichi2.libanki.sched.AbstractDeckTreeNode
import com.ichi2.libanki.sched.TreeNode
Expand Down Expand Up @@ -2229,6 +2226,24 @@ open class DeckPicker :
}

fun confirmDeckDeletion(did: Long) {
if (!BackendFactory.defaultLegacySchema) {
dismissAllDialogFragments()
// No confirmation required, as undoable
launchCatchingCollectionTask { col ->
val changes = runInBackgroundWithProgress {
undoableOp {
col.newDecks.removeDecks(listOf(did))
}
}
showSimpleSnackbar(
this@DeckPicker,
col.tr.browsingCardsDeleted(changes.count),
false
)
}
return
}

val res = resources
if (!colIsOpen()) {
return
Expand Down

0 comments on commit 2e6d415

Please sign in to comment.