-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
Anki-Android/AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt
Lines 2495 to 2518 in 9f845f0
| /** | |
| * [launchCatchingTask], showing a one-way sync dialog: [R.string.full_sync_confirmation] | |
| */ | |
| fun AnkiActivity.launchCatchingRequiringOneWaySync(block: suspend () -> Unit) = | |
| launchCatchingTask { | |
| try { | |
| block() | |
| } catch (e: ConfirmModSchemaException) { | |
| e.log() | |
| // .also is used to ensure the activity is used as context | |
| val confirmModSchemaDialog = | |
| ConfirmationDialog().also { dialog -> | |
| dialog.setArgs(message = getString(R.string.full_sync_confirmation)) | |
| dialog.setConfirm { | |
| launchCatchingTask { | |
| withCol { modSchemaNoCheck() } | |
| block() | |
| } | |
| } | |
| } | |
| showDialogFragment(confirmModSchemaDialog) | |
| } | |
| } |
Anki-Android/libanki/src/main/java/com/ichi2/anki/libanki/Collection.kt
Lines 340 to 377 in 6819258
| /** Mark schema modified to force a full | |
| * sync, but with the confirmation checking function disabled This | |
| * is equivalent to `modSchema(False)` in Anki. A distinct method | |
| * is used so that the type does not states that an exception is | |
| * thrown when in fact it is never thrown. | |
| */ | |
| @NotInPyLib | |
| fun modSchemaNoCheck() { | |
| db.execute( | |
| "update col set scm=?, mod=?", | |
| TimeManager.time.intTimeMS(), | |
| TimeManager.time.intTimeMS(), | |
| ) | |
| } | |
| /** Mark schema modified to cause a one-way sync. | |
| * ConfirmModSchemaException will be thrown if the user needs to be prompted to confirm the action. | |
| * If the user chooses to confirm then modSchemaNoCheck should be called, after which the exception can | |
| * be safely ignored, and the outer code called again. | |
| * | |
| * @throws ConfirmModSchemaException | |
| */ | |
| @LibAnkiAlias("mod_schema") | |
| fun modSchema() { | |
| if (!schemaChanged()) { | |
| /* In Android we can't show a dialog which blocks the main UI thread | |
| Therefore we can't wait for the user to confirm if they want to do | |
| a one-way sync here, and we instead throw an exception asking the outer | |
| code to handle the user's choice */ | |
| throw ConfirmModSchemaException() | |
| } | |
| modSchemaNoCheck() | |
| } | |
| /** `true` if schema changed since last sync. */ | |
| @LibAnkiAlias("schema_changed") | |
| @RustCleanup("doesn't match upstream") | |
| fun schemaChanged(): Boolean = scm > lastSync |
Anki-Android/libanki/src/main/java/com/ichi2/anki/libanki/exception/ConfirmModSchemaException.kt
Lines 22 to 29 in 22c565c
| class ConfirmModSchemaException : Exception() { | |
| /** | |
| * Add the current exception to log. | |
| */ | |
| fun log() { | |
| Timber.v(this) | |
| } | |
| } |
Metadata
Metadata
Assignees
Labels
No labels