Skip to content

Commit a365309

Browse files
committed
Add 'Create backup' menu option to DeckPicker
To replicate desktop. Adds a SHIFT + CTRL + B shortcut for it which isn't quite what desktop uses.
1 parent 8e22f48 commit a365309

5 files changed

Lines changed: 34 additions & 3 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ import kotlinx.coroutines.Dispatchers
2121
import kotlinx.coroutines.delay
2222
import kotlinx.coroutines.withContext
2323

24-
suspend fun performBackupInBackground() {
24+
suspend fun performBackupInBackground(force: Boolean = false) {
2525
// Wait a second to allow the deck list to finish loading first, or it
2626
// will hang until the first stage of the backup completes.
2727
delay(1000)
28-
createBackup(force = false)
28+
createBackup(force = force)
2929
}
3030

3131
fun <Activity> Activity.importColpkg(colpkgPath: String) where Activity : AnkiActivity, Activity : ImportColpkgListener {

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1392,10 +1392,24 @@ open class DeckPicker :
13921392
ExportDialogFragment.newInstance().show(supportFragmentManager, "exportDialog")
13931393
return true
13941394
}
1395+
R.id.action_create_backup -> {
1396+
Timber.i("DeckPicker::Create backup")
1397+
createBackup()
1398+
return true
1399+
}
13951400
else -> return super.onOptionsItemSelected(item)
13961401
}
13971402
}
13981403

1404+
private fun createBackup() {
1405+
launchCatchingTask {
1406+
withProgress(message = TR.profilesCreatingBackup()) {
1407+
performBackupInBackground(true)
1408+
}
1409+
showThemedToast(this@DeckPicker, TR.profilesBackupCreated(), false)
1410+
}
1411+
}
1412+
13991413
private fun showMediaCheckDialog() {
14001414
Timber.i("showing media check dialog")
14011415
AlertDialog.Builder(this).show {
@@ -1564,7 +1578,11 @@ open class DeckPicker :
15641578
return true
15651579
}
15661580
KeyEvent.KEYCODE_B -> {
1567-
if (event.isCtrlPressed) {
1581+
if (event.isShiftPressed && event.isCtrlPressed) {
1582+
// shortcut SHIFT + CTRL + B
1583+
Timber.i("Create backup from keypress")
1584+
createBackup()
1585+
} else if (event.isCtrlPressed) {
15681586
// Shortcut: CTRL + B
15691587
Timber.i("show restore backup dialog from keypress")
15701588
showDatabaseErrorDialog(DatabaseErrorDialogType.DIALOG_CONFIRM_RESTORE_BACKUP)

AnkiDroid/src/main/res/menu-xlarge/deck_picker.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@
4949
android:title="@string/empty_cards"/>
5050
</menu>
5151
</item>
52+
<!-- Backend string TR.qtAccelCreateBackup() has an & in it -->
53+
<item
54+
android:id="@+id/action_create_backup"
55+
android:menuCategory="secondary"
56+
android:title="@string/menu_create_backup"
57+
/>
5258
<item
5359
android:id="@+id/action_restore_backup"
5460
android:menuCategory="secondary"

AnkiDroid/src/main/res/menu/deck_picker.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@
3939
android:title="@string/empty_cards"/>
4040
</menu>
4141
</item>
42+
<!-- Backend string TR.qtAccelCreateBackup() has an & in it -->
43+
<item
44+
android:id="@+id/action_create_backup"
45+
android:menuCategory="secondary"
46+
android:title="@string/menu_create_backup"
47+
/>
4248
<item
4349
android:id="@+id/action_restore_backup"
4450
android:menuCategory="secondary"

AnkiDroid/src/main/res/values/01-core.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
<string name="menu_unmark_note">Unmark note</string>
100100
<string name="menu_enable_voice_playback" maxLength="28">Enable voice playback</string>
101101
<string name="menu_disable_voice_playback">Disable voice playback</string>
102+
<string name="menu_create_backup" maxLength="28">Create backup</string>
102103
<string name="new_deck">Create deck</string>
103104
<string name="new_dynamic_deck">Create filtered deck</string>
104105
<string name="directory_inaccessible">AnkiDroid directory is inaccessible</string>

0 commit comments

Comments
 (0)