From 415c8501ddfb8c10eb203c8c247731c7d9b3e2d5 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 25 Oct 2022 19:56:54 +0200 Subject: [PATCH] add a new db table for hidden icons --- .../launcher/databases/AppsDatabase.kt | 14 +++++++++++++- .../launcher/interfaces/HiddenIconDao.kt | 16 ++++++++++++++++ .../launcher/models/HiddenIcon.kt | 16 ++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 app/src/main/kotlin/com/simplemobiletools/launcher/interfaces/HiddenIconDao.kt create mode 100644 app/src/main/kotlin/com/simplemobiletools/launcher/models/HiddenIcon.kt diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/databases/AppsDatabase.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/databases/AppsDatabase.kt index b32ea36..95d9d76 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/databases/AppsDatabase.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/databases/AppsDatabase.kt @@ -9,11 +9,13 @@ import androidx.room.migration.Migration import androidx.sqlite.db.SupportSQLiteDatabase import com.simplemobiletools.launcher.helpers.Converters import com.simplemobiletools.launcher.interfaces.AppLaunchersDao +import com.simplemobiletools.launcher.interfaces.HiddenIconDao import com.simplemobiletools.launcher.interfaces.HomeScreenGridItemsDao import com.simplemobiletools.launcher.models.AppLauncher +import com.simplemobiletools.launcher.models.HiddenIcon import com.simplemobiletools.launcher.models.HomeScreenGridItem -@Database(entities = [AppLauncher::class, HomeScreenGridItem::class], version = 3) +@Database(entities = [AppLauncher::class, HomeScreenGridItem::class, HiddenIcon::class], version = 4) @TypeConverters(Converters::class) abstract class AppsDatabase : RoomDatabase() { @@ -21,6 +23,8 @@ abstract class AppsDatabase : RoomDatabase() { abstract fun HomeScreenGridItemsDao(): HomeScreenGridItemsDao + abstract fun HiddenIconsDao(): HiddenIconDao + companion object { private var db: AppsDatabase? = null @@ -31,6 +35,7 @@ abstract class AppsDatabase : RoomDatabase() { db = Room.databaseBuilder(context.applicationContext, AppsDatabase::class.java, "apps.db") .addMigrations(MIGRATION_1_2) .addMigrations(MIGRATION_2_3) + .addMigrations(MIGRATION_3_4) .build() } } @@ -52,5 +57,12 @@ abstract class AppsDatabase : RoomDatabase() { database.execSQL("ALTER TABLE home_screen_grid_items ADD COLUMN activity_name TEXT default '' NOT NULL") } } + + private val MIGRATION_3_4 = object : Migration(3, 4) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("CREATE TABLE IF NOT EXISTS `hidden_icons` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `package_name` TEXT NOT NULL, `activity_name` TEXT NOT NULL, `title` TEXT NOT NULL)") + database.execSQL("CREATE UNIQUE INDEX `index_hidden_icons_id` ON `hidden_icons` (`id`)") + } + } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/interfaces/HiddenIconDao.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/interfaces/HiddenIconDao.kt new file mode 100644 index 0000000..0a695b2 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/interfaces/HiddenIconDao.kt @@ -0,0 +1,16 @@ +package com.simplemobiletools.launcher.interfaces + +import androidx.room.Dao +import androidx.room.Insert +import androidx.room.OnConflictStrategy +import androidx.room.Query +import com.simplemobiletools.launcher.models.HiddenIcon + +@Dao +interface HiddenIconDao { + @Query("SELECT * FROM hidden_icons") + fun getHiddenIcons(): List + + @Insert(onConflict = OnConflictStrategy.REPLACE) + fun insert(hiddenIcon: HiddenIcon): Long +} diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/models/HiddenIcon.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/models/HiddenIcon.kt new file mode 100644 index 0000000..8c3fb7c --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/models/HiddenIcon.kt @@ -0,0 +1,16 @@ +package com.simplemobiletools.launcher.models + +import android.graphics.drawable.Drawable +import androidx.room.* + +@Entity(tableName = "hidden_icons", indices = [(Index(value = ["id"], unique = true))]) +data class HiddenIcon( + @PrimaryKey(autoGenerate = true) var id: Long?, + @ColumnInfo(name = "package_name") var packageName: String, + @ColumnInfo(name = "activity_name") var activityName: String, + @ColumnInfo(name = "title") var title: String, + + @Ignore var drawable: Drawable? = null, +) { + constructor() : this(null, "", "", "", null) +}