|
18 | 18 | package com.ichi2.libanki
|
19 | 19 |
|
20 | 20 | import androidx.annotation.VisibleForTesting
|
21 |
| -import com.ichi2.libanki.exception.WrongId |
22 | 21 | import com.ichi2.utils.KotlinCleanup
|
23 | 22 | import com.ichi2.utils.emptyStringArray
|
24 | 23 | import com.ichi2.utils.emptyStringMutableList
|
@@ -71,23 +70,21 @@ class Note : Cloneable {
|
71 | 70 | }
|
72 | 71 |
|
73 | 72 | 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) |
91 | 88 | }
|
92 | 89 |
|
93 | 90 | fun reloadModel() {
|
|
0 commit comments