From e943ac46f3d615c706b5c50304e6ba2f565c94e0 Mon Sep 17 00:00:00 2001 From: mshabiola Date: Sat, 15 Apr 2023 16:00:59 +0100 Subject: [PATCH 1/6] fix: remove image name in Image database --- .../3.json | 322 ++++++++++++++++++ .../com/mshdabiola/database/NoteDatabase.kt | 14 +- .../database/model/NoteImageEntity.kt | 5 +- .../designsystem/component/NoteCard.kt | 2 +- .../component/state/NoteImageUiState.kt | 6 +- .../component/state/NotePadUiState.kt | 7 +- .../java/com/mshdabiola/model/NoteImage.kt | 1 - .../com/mshdabiola/worker/work/SaveWorker.kt | 2 +- .../com/mshdabiola/editscreen/EditScreen.kt | 6 +- .../mshdabiola/editscreen/EditViewModel.kt | 28 +- .../editscreen/component/ShareViewModel.kt | 2 +- .../com/mshdabiola/gallery/GalleryScreen.kt | 12 +- .../mshdabiola/gallery/GalleryViewModel.kt | 5 +- .../mshdabiola/mainscreen/MainViewModel.kt | 8 +- .../searchscreen/SearchViewModel.kt | 6 +- 15 files changed, 381 insertions(+), 45 deletions(-) create mode 100644 core/database/schemas/com.mshdabiola.database.NoteDatabase/3.json diff --git a/core/database/schemas/com.mshdabiola.database.NoteDatabase/3.json b/core/database/schemas/com.mshdabiola.database.NoteDatabase/3.json new file mode 100644 index 00000000..9492f633 --- /dev/null +++ b/core/database/schemas/com.mshdabiola.database.NoteDatabase/3.json @@ -0,0 +1,322 @@ +{ + "formatVersion": 1, + "database": { + "version": 3, + "identityHash": "8a44b7a696de82b667d9efea96f5377f", + "entities": [ + { + "tableName": "note_table", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `title` TEXT NOT NULL, `detail` TEXT NOT NULL, `editDate` INTEGER NOT NULL, `isCheck` INTEGER NOT NULL, `color` INTEGER NOT NULL, `background` INTEGER NOT NULL, `isPin` INTEGER NOT NULL, `reminder` INTEGER NOT NULL, `interval` INTEGER NOT NULL, `noteType` TEXT NOT NULL)", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": false + }, + { + "fieldPath": "title", + "columnName": "title", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "detail", + "columnName": "detail", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "editDate", + "columnName": "editDate", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isCheck", + "columnName": "isCheck", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "color", + "columnName": "color", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "background", + "columnName": "background", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isPin", + "columnName": "isPin", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "reminder", + "columnName": "reminder", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "interval", + "columnName": "interval", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "noteType", + "columnName": "noteType", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "autoGenerate": true, + "columnNames": [ + "id" + ] + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "note_voice_table", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `noteId` INTEGER NOT NULL, `voiceName` TEXT NOT NULL, PRIMARY KEY(`id`, `noteId`))", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "noteId", + "columnName": "noteId", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "voiceName", + "columnName": "voiceName", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "autoGenerate": false, + "columnNames": [ + "id", + "noteId" + ] + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "note_image_table", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `noteId` INTEGER NOT NULL, `isDrawing` INTEGER NOT NULL, `timestamp` INTEGER NOT NULL DEFAULT 0, PRIMARY KEY(`id`, `noteId`))", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "noteId", + "columnName": "noteId", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "isDrawing", + "columnName": "isDrawing", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "timestamp", + "columnName": "timestamp", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + } + ], + "primaryKey": { + "autoGenerate": false, + "columnNames": [ + "id", + "noteId" + ] + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "note_check_table", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `noteId` INTEGER NOT NULL, `content` TEXT NOT NULL, `isCheck` INTEGER NOT NULL, PRIMARY KEY(`id`, `noteId`))", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "noteId", + "columnName": "noteId", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "content", + "columnName": "content", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "isCheck", + "columnName": "isCheck", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "autoGenerate": false, + "columnNames": [ + "id", + "noteId" + ] + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "note_label_table", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`noteId` INTEGER NOT NULL, `labelId` INTEGER NOT NULL, PRIMARY KEY(`noteId`, `labelId`))", + "fields": [ + { + "fieldPath": "noteId", + "columnName": "noteId", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "labelId", + "columnName": "labelId", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "autoGenerate": false, + "columnNames": [ + "noteId", + "labelId" + ] + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "label_table", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `name` TEXT NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "autoGenerate": false, + "columnNames": [ + "id" + ] + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "path_table", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`imageId` INTEGER NOT NULL, `pathId` INTEGER NOT NULL, `color` INTEGER NOT NULL, `width` INTEGER NOT NULL, `join` INTEGER NOT NULL, `alpha` REAL NOT NULL, `cap` INTEGER NOT NULL, `paths` TEXT NOT NULL, PRIMARY KEY(`imageId`, `pathId`))", + "fields": [ + { + "fieldPath": "imageId", + "columnName": "imageId", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "pathId", + "columnName": "pathId", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "color", + "columnName": "color", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "width", + "columnName": "width", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "join", + "columnName": "join", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "alpha", + "columnName": "alpha", + "affinity": "REAL", + "notNull": true + }, + { + "fieldPath": "cap", + "columnName": "cap", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "paths", + "columnName": "paths", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "autoGenerate": false, + "columnNames": [ + "imageId", + "pathId" + ] + }, + "indices": [], + "foreignKeys": [] + } + ], + "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, '8a44b7a696de82b667d9efea96f5377f')" + ] + } +} \ No newline at end of file diff --git a/core/database/src/main/java/com/mshdabiola/database/NoteDatabase.kt b/core/database/src/main/java/com/mshdabiola/database/NoteDatabase.kt index 3da23e25..04bd5370 100644 --- a/core/database/src/main/java/com/mshdabiola/database/NoteDatabase.kt +++ b/core/database/src/main/java/com/mshdabiola/database/NoteDatabase.kt @@ -2,7 +2,10 @@ package com.mshdabiola.database import androidx.room.AutoMigration import androidx.room.Database +import androidx.room.DeleteColumn +import androidx.room.DeleteTable import androidx.room.RoomDatabase +import androidx.room.migration.AutoMigrationSpec import com.mshdabiola.database.dao.LabelDao import com.mshdabiola.database.dao.NoteCheckDao import com.mshdabiola.database.dao.NoteDao @@ -29,10 +32,11 @@ import com.mshdabiola.database.model.NoteVoiceEntity LabelEntity::class, DrawPathEntity::class, ], - version = 2, - autoMigrations = [ AutoMigration(1,2)] - - + version = 3, + autoMigrations = [ + AutoMigration(1,2), + AutoMigration(2 ,3,NoteDatabase.Migrate2to3::class) + ] ) abstract class NoteDatabase : RoomDatabase() { @@ -51,4 +55,6 @@ abstract class NoteDatabase : RoomDatabase() { abstract fun getNotePadDao(): NotepadDao abstract fun getPath(): PathDao + @DeleteColumn(tableName = "note_image_table", columnName = "imageName") + class Migrate2to3 : AutoMigrationSpec } diff --git a/core/database/src/main/java/com/mshdabiola/database/model/NoteImageEntity.kt b/core/database/src/main/java/com/mshdabiola/database/model/NoteImageEntity.kt index af2a9306..cd9133a8 100644 --- a/core/database/src/main/java/com/mshdabiola/database/model/NoteImageEntity.kt +++ b/core/database/src/main/java/com/mshdabiola/database/model/NoteImageEntity.kt @@ -12,11 +12,10 @@ import java.sql.Timestamp data class NoteImageEntity( val id: Long, val noteId: Long, - val imageName: String, val isDrawing: Boolean, @ColumnInfo(defaultValue = "0") val timestamp: Long ) -fun NoteImage.toNoteImageEntity() = NoteImageEntity(id, noteId, imageName, isDrawing,timestamp) -fun NoteImageEntity.toNoteImage() = NoteImage(id, noteId, imageName, isDrawing,timestamp) +fun NoteImage.toNoteImageEntity() = NoteImageEntity(id, noteId, isDrawing,timestamp) +fun NoteImageEntity.toNoteImage() = NoteImage(id, noteId,isDrawing,timestamp) diff --git a/core/designsystem/src/main/java/com/mshdabiola/designsystem/component/NoteCard.kt b/core/designsystem/src/main/java/com/mshdabiola/designsystem/component/NoteCard.kt index ac0c3712..e4df7ff5 100644 --- a/core/designsystem/src/main/java/com/mshdabiola/designsystem/component/NoteCard.kt +++ b/core/designsystem/src/main/java/com/mshdabiola/designsystem/component/NoteCard.kt @@ -134,7 +134,7 @@ fun NoteCard( modifier = Modifier .weight(1f) .height(100.dp), - model = it.imageName, + model = it.path, contentDescription = "", contentScale = ContentScale.Crop, ) diff --git a/core/designsystem/src/main/java/com/mshdabiola/designsystem/component/state/NoteImageUiState.kt b/core/designsystem/src/main/java/com/mshdabiola/designsystem/component/state/NoteImageUiState.kt index 3038d03b..fdc4d711 100644 --- a/core/designsystem/src/main/java/com/mshdabiola/designsystem/component/state/NoteImageUiState.kt +++ b/core/designsystem/src/main/java/com/mshdabiola/designsystem/component/state/NoteImageUiState.kt @@ -5,11 +5,11 @@ import com.mshdabiola.model.NoteImage data class NoteImageUiState( val id: Long, val noteId: Long, - val imageName: String, + val path: String, val isDrawing: Boolean, val timestamp: Long=0 ) -fun NoteImage.toNoteImageUiState() = NoteImageUiState(id, noteId, imageName, isDrawing,timestamp) +fun NoteImage.toNoteImageUiState(toPath:(Long)->String) = NoteImageUiState(id, noteId, toPath(id), isDrawing,timestamp) -fun NoteImageUiState.toNoteImage() = NoteImage(id, noteId, imageName, isDrawing,timestamp) +fun NoteImageUiState.toNoteImage() = NoteImage(id, noteId, isDrawing,timestamp) diff --git a/core/designsystem/src/main/java/com/mshdabiola/designsystem/component/state/NotePadUiState.kt b/core/designsystem/src/main/java/com/mshdabiola/designsystem/component/state/NotePadUiState.kt index 5597a33e..218241f1 100644 --- a/core/designsystem/src/main/java/com/mshdabiola/designsystem/component/state/NotePadUiState.kt +++ b/core/designsystem/src/main/java/com/mshdabiola/designsystem/component/state/NotePadUiState.kt @@ -51,9 +51,12 @@ data class NotePadUiState( } } -fun NotePad.toNotePadUiState(list: List