Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ import com.ichi2.anki.libanki.NoteTypeId
import com.ichi2.anki.requireAnkiActivity
import com.ichi2.anki.showError
import com.ichi2.anki.snackbar.showSnackbar
import com.ichi2.anki.sync.launchCatchingRequiringOneWaySyncDiscardUndo
import com.ichi2.anki.sync.launchCatchingRequiringOneWaySync
import com.ichi2.anki.ui.BasicItemSelectedListener
import com.ichi2.anki.ui.internationalization.toSentenceCase
import com.ichi2.anki.utils.InitStatus
Expand Down Expand Up @@ -637,7 +637,7 @@ class ChangeNoteTypeDialog : AnalyticsDialogFragment() {
* Changes note type of multiple notes, displaying a message on success
*/
private fun AnkiActivity.changeNoteType(viewModel: ChangeNoteTypeViewModel) =
this.launchCatchingRequiringOneWaySyncDiscardUndo {
this.launchCatchingRequiringOneWaySync {
try {
val notesUpdated =
withProgress {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,6 @@ class ChangeNoteTypeViewModel(
Timber.d("Field map: %s", fieldChangeMap)
Timber.d("Card map: %s", templateChangeMap)

withCol { modSchema(check = true) }

val changes =
changeNoteTypeOfNotes(
noteIds = noteIds,
Expand Down
27 changes: 27 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/anki/sync/SchemaChanges.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import com.ichi2.anki.CollectionManager.withCol
import com.ichi2.anki.R
import com.ichi2.anki.dialogs.ConfirmationDialog
import com.ichi2.anki.launchCatchingTask
import com.ichi2.anki.libanki.Collection
import com.ichi2.anki.libanki.exception.ConfirmModSchemaException
import com.ichi2.anki.utils.ext.showDialogFragment
import com.ichi2.utils.message
Expand All @@ -32,6 +33,32 @@ import com.ichi2.utils.show
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine

/**
* [launchCatchingTask], showing a one-way sync dialog: [R.string.full_sync_confirmation]
*
* @param block calls a backend method which unconditionally performs a schema change,
* such as [Collection.changeNotetypeRaw]
*/
fun AnkiActivity.launchCatchingRequiringOneWaySync(block: suspend () -> Unit) =
launchCatchingTask {
if (withCol { !schemaChanged() }) {
// .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 {
block()
}
}
}
showDialogFragment(confirmModSchemaDialog)
return@launchCatchingTask
}
// TODO: use context(SchemaChangedConfirmed) after bug #20247 is fixed (upstream-issue)
block()
}

/**
* [launchCatchingTask], showing a one-way sync dialog: [R.string.full_sync_confirmation]
*
Expand Down
4 changes: 3 additions & 1 deletion libanki/src/main/java/com/ichi2/anki/libanki/Notetypes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -561,10 +561,12 @@ class Notetypes(
*
* Each value represents the index in the previous notetype.
* -1 indicates the original value will be discarded.
*
* **This method updates the schema without confirmation**
*/
@LibAnkiAlias("change_notetype_of_notes")
fun changeNotetypeOfNotes(input: ChangeNotetypeRequest): OpChanges {
val opBytes = this.col.backend.changeNotetypeRaw(input.toByteArray())
val opBytes = col.backend.changeNotetypeRaw(input.toByteArray())
return OpChanges.parseFrom(opBytes)
}

Expand Down
Loading