diff --git a/AnkiDroid/src/main/java/com/ichi2/libanki/Note.kt b/AnkiDroid/src/main/java/com/ichi2/libanki/Note.kt index 8155da1cfda1..322a9cef9961 100644 --- a/AnkiDroid/src/main/java/com/ichi2/libanki/Note.kt +++ b/AnkiDroid/src/main/java/com/ichi2/libanki/Note.kt @@ -18,7 +18,6 @@ package com.ichi2.libanki import androidx.annotation.VisibleForTesting -import com.ichi2.libanki.exception.WrongId import com.ichi2.utils.KotlinCleanup import com.ichi2.utils.emptyStringArray import com.ichi2.utils.emptyStringMutableList @@ -71,23 +70,21 @@ class Note : Cloneable { } fun load() { - col.db - .query( - "SELECT guid, mid, mod, usn, tags, flds FROM notes WHERE id = ?", - this.id - ).use { cursor -> - if (!cursor.moveToFirst()) { - throw WrongId(this.id, "note") - } - guId = cursor.getString(0) - mid = cursor.getLong(1) - mod = cursor.getLong(2).toInt() - usn = cursor.getInt(3) - tags = col.tags.split(cursor.getString(4)) - fields = Utils.splitFields(cursor.getString(5)) - notetype = col.notetypes.get(mid)!! - mFMap = Notetypes.fieldMap(notetype) - } + val note = col.backend.getNote(this.id) + loadFromBackendNote(note) + } + + private fun loadFromBackendNote(note: anki.notes.Note) { + this.id = note.id + this.guId = note.guid + this.mid = note.notetypeId + this.notetype = col.notetypes.get(mid)!! // not in libAnki + this.mod = note.mtimeSecs + this.usn = note.usn + // the lists in the protobuf are NOT mutable, even though they cast to MutableList + this.tags = note.tagsList.toMutableList() + this.fields = note.fieldsList.toMutableList() + this.mFMap = Notetypes.fieldMap(notetype) } fun reloadModel() { diff --git a/AnkiDroid/src/main/java/com/ichi2/libanki/exception/WrongId.kt b/AnkiDroid/src/main/java/com/ichi2/libanki/exception/WrongId.kt deleted file mode 100644 index 70a991ab2e52..000000000000 --- a/AnkiDroid/src/main/java/com/ichi2/libanki/exception/WrongId.kt +++ /dev/null @@ -1,20 +0,0 @@ -/**************************************************************************************** - * Copyright (c) 2020 Arthur Milchior * - * * - * This program is free software; you can redistribute it and/or modify it under * - * the terms of the GNU General Public License as published by the Free Software * - * Foundation; either version 3 of the License, or (at your option) any later * - * version. * - * * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY * - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * - * PARTICULAR PURPOSE. See the GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License along with * - * this program. If not, see . * - ****************************************************************************************/ -package com.ichi2.libanki.exception - -import java.lang.RuntimeException - -class WrongId(id: Long, kind: String) : RuntimeException(" No $kind with id $id")