瀏覽代碼

added keys for lazy list items

sirekanian 3 年之前
父節點
當前提交
a005b9b6ea

+ 6 - 4
app/schemas/com.sirekanian.acf.data.local.Database/1.json

@@ -2,7 +2,7 @@
   "formatVersion": 1,
   "database": {
     "version": 1,
-    "identityHash": "71fabb860e0ba05f19f248efc40ff07d",
+    "identityHash": "b8bb5e1f5cbce85118a62d7a7ce20bb4",
     "entities": [
       {
         "ftsVersion": "FTS4",
@@ -46,8 +46,10 @@
           }
         ],
         "primaryKey": {
-          "columnNames": [],
-          "autoGenerate": false
+          "columnNames": [
+            "rowid"
+          ],
+          "autoGenerate": true
         },
         "indices": [],
         "foreignKeys": []
@@ -140,7 +142,7 @@
     "views": [],
     "setupQueries": [
       "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
-      "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '71fabb860e0ba05f19f248efc40ff07d')"
+      "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'b8bb5e1f5cbce85118a62d7a7ce20bb4')"
     ]
   }
 }

+ 1 - 1
app/schemas/init.sql

@@ -1,5 +1,5 @@
 CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT);
-INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '71fabb860e0ba05f19f248efc40ff07d');
+INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'b8bb5e1f5cbce85118a62d7a7ce20bb4');
 CREATE TABLE IF NOT EXISTS `MetaEntity` (`key` TEXT NOT NULL, `value` TEXT NOT NULL, PRIMARY KEY(`key`));
 .import --csv app/schemas/MetaEntity.csv MetaEntity
 CREATE VIRTUAL TABLE IF NOT EXISTS `WarmongerEntity` USING FTS4(`cyrillicName` TEXT NOT NULL, `name` TEXT NOT NULL, `notes` TEXT NOT NULL, `tags` TEXT NOT NULL, tokenize=unicode61);

二進制
app/src/main/assets/warmongers.db


+ 1 - 1
app/src/main/java/com/sirekanian/acf/WarmongerModel.kt

@@ -1,5 +1,5 @@
 package com.sirekanian.acf
 
-class WarmongerModel(val title: String, val description: String) {
+class WarmongerModel(val id: Int, val title: String, val description: String) {
     val content get() = "$title\n\n$description"
 }

+ 5 - 0
app/src/main/java/com/sirekanian/acf/data/Warmonger.kt

@@ -5,6 +5,7 @@ import com.sirekanian.acf.data.local.WarmongerEntity
 import com.sirekanian.acf.data.remote.WarmongerDto
 
 class Warmonger(
+    val id: Int,
     val cyrillicName: String,
     val name: String,
     val notes: String,
@@ -14,6 +15,7 @@ class Warmonger(
 
         fun fromDto(dto: WarmongerDto): Warmonger =
             Warmonger(
+                id = 0, // TODO: 1202468796234411
                 cyrillicName = dto.`0`,
                 name = dto.`1`.ifEmpty { dto.`0` },
                 notes = dto.`4`,
@@ -21,6 +23,7 @@ class Warmonger(
 
         fun fromEntity(entity: WarmongerEntity): Warmonger =
             Warmonger(
+                id = entity.rowid,
                 cyrillicName = entity.cyrillicName,
                 name = entity.name,
                 notes = entity.notes,
@@ -28,6 +31,7 @@ class Warmonger(
 
         fun toEntity(warmonger: Warmonger): WarmongerEntity =
             WarmongerEntity(
+                rowid = warmonger.id,
                 cyrillicName = warmonger.cyrillicName,
                 name = warmonger.name,
                 notes = warmonger.notes,
@@ -36,6 +40,7 @@ class Warmonger(
 
         fun toModel(warmonger: Warmonger, isCyrillic: Boolean): WarmongerModel =
             WarmongerModel(
+                id = warmonger.id,
                 title = if (isCyrillic) warmonger.cyrillicName else warmonger.name,
                 description = warmonger.notes,
             )

+ 2 - 2
app/src/main/java/com/sirekanian/acf/data/local/WarmongerDao.kt

@@ -11,10 +11,10 @@ private const val LIMIT = 200
 @Dao
 interface WarmongerDao {
 
-    @Query("SELECT * FROM WarmongerEntity ORDER BY cyrillicName LIMIT $LIMIT")
+    @Query("SELECT rowid, * FROM WarmongerEntity ORDER BY cyrillicName LIMIT $LIMIT")
     fun observeAll(): Flow<List<WarmongerEntity>>
 
-    @Query("SELECT * FROM WarmongerEntity WHERE WarmongerEntity MATCH :query LIMIT $LIMIT")
+    @Query("SELECT rowid, * FROM WarmongerEntity WHERE WarmongerEntity MATCH :query LIMIT $LIMIT")
     fun observeByQuery(query: String): Flow<List<WarmongerEntity>>
 
     @Query("DELETE FROM WarmongerEntity")

+ 3 - 0
app/src/main/java/com/sirekanian/acf/data/local/WarmongerEntity.kt

@@ -3,10 +3,13 @@ package com.sirekanian.acf.data.local
 import androidx.room.Entity
 import androidx.room.Fts4
 import androidx.room.FtsOptions
+import androidx.room.PrimaryKey
 
 @Fts4(tokenizer = FtsOptions.TOKENIZER_UNICODE61)
 @Entity
 class WarmongerEntity(
+    @PrimaryKey
+    val rowid: Int,
     val cyrillicName: String,
     val name: String,
     val notes: String,

+ 1 - 1
app/src/main/java/com/sirekanian/acf/ui/MainContent.kt

@@ -28,7 +28,7 @@ fun MainContent(insets: PaddingValues, state: MainState, data: List<WarmongerMod
         contentPadding = insets + paddings + D.listPaddings,
         verticalArrangement = Arrangement.spacedBy(D.cardsSpacing)
     ) {
-        items(data) { item ->
+        items(data, key = { it.id }) { item ->
             WarmongerCard(state.dialog, item)
         }
     }