Skip to content

Commit a505a6d

Browse files
committed
note: load from Backend
1 parent 24aa83d commit a505a6d

File tree

2 files changed

+15
-38
lines changed

2 files changed

+15
-38
lines changed

AnkiDroid/src/main/java/com/ichi2/libanki/Note.kt

+15-18
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package com.ichi2.libanki
1919

2020
import androidx.annotation.VisibleForTesting
21-
import com.ichi2.libanki.exception.WrongId
2221
import com.ichi2.utils.KotlinCleanup
2322
import com.ichi2.utils.emptyStringArray
2423
import com.ichi2.utils.emptyStringMutableList
@@ -71,23 +70,21 @@ class Note : Cloneable {
7170
}
7271

7372
fun load() {
74-
col.db
75-
.query(
76-
"SELECT guid, mid, mod, usn, tags, flds FROM notes WHERE id = ?",
77-
this.id
78-
).use { cursor ->
79-
if (!cursor.moveToFirst()) {
80-
throw WrongId(this.id, "note")
81-
}
82-
guId = cursor.getString(0)
83-
mid = cursor.getLong(1)
84-
mod = cursor.getLong(2).toInt()
85-
usn = cursor.getInt(3)
86-
tags = col.tags.split(cursor.getString(4))
87-
fields = Utils.splitFields(cursor.getString(5))
88-
notetype = col.notetypes.get(mid)!!
89-
mFMap = Notetypes.fieldMap(notetype)
90-
}
73+
val note = col.backend.getNote(this.id)
74+
loadFromBackendNote(note)
75+
}
76+
77+
private fun loadFromBackendNote(note: anki.notes.Note) {
78+
this.id = note.id
79+
this.guId = note.guid
80+
this.mid = note.notetypeId
81+
this.notetype = col.notetypes.get(mid)!! // not in libAnki
82+
this.mod = note.mtimeSecs
83+
this.usn = note.usn
84+
// the lists in the protobuf are NOT mutable, even though they cast to MutableList
85+
this.tags = note.tagsList.toMutableList()
86+
this.fields = note.fieldsList.toMutableList()
87+
this.mFMap = Notetypes.fieldMap(notetype)
9188
}
9289

9390
fun reloadModel() {

AnkiDroid/src/main/java/com/ichi2/libanki/exception/WrongId.kt

-20
This file was deleted.

0 commit comments

Comments
 (0)