add a new db table for hidden icons

This commit is contained in:
tibbi 2022-10-25 19:56:54 +02:00
parent 98139b1e24
commit 415c8501dd
3 changed files with 45 additions and 1 deletions

View file

@ -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`)")
}
}
}
}

View file

@ -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<HiddenIcon>
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(hiddenIcon: HiddenIcon): Long
}

View file

@ -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)
}