Skip to content

Commit 415c850

Browse files
committed
add a new db table for hidden icons
1 parent 98139b1 commit 415c850

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

app/src/main/kotlin/com/simplemobiletools/launcher/databases/AppsDatabase.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,22 @@ import androidx.room.migration.Migration
99
import androidx.sqlite.db.SupportSQLiteDatabase
1010
import com.simplemobiletools.launcher.helpers.Converters
1111
import com.simplemobiletools.launcher.interfaces.AppLaunchersDao
12+
import com.simplemobiletools.launcher.interfaces.HiddenIconDao
1213
import com.simplemobiletools.launcher.interfaces.HomeScreenGridItemsDao
1314
import com.simplemobiletools.launcher.models.AppLauncher
15+
import com.simplemobiletools.launcher.models.HiddenIcon
1416
import com.simplemobiletools.launcher.models.HomeScreenGridItem
1517

16-
@Database(entities = [AppLauncher::class, HomeScreenGridItem::class], version = 3)
18+
@Database(entities = [AppLauncher::class, HomeScreenGridItem::class, HiddenIcon::class], version = 4)
1719
@TypeConverters(Converters::class)
1820
abstract class AppsDatabase : RoomDatabase() {
1921

2022
abstract fun AppLaunchersDao(): AppLaunchersDao
2123

2224
abstract fun HomeScreenGridItemsDao(): HomeScreenGridItemsDao
2325

26+
abstract fun HiddenIconsDao(): HiddenIconDao
27+
2428
companion object {
2529
private var db: AppsDatabase? = null
2630

@@ -31,6 +35,7 @@ abstract class AppsDatabase : RoomDatabase() {
3135
db = Room.databaseBuilder(context.applicationContext, AppsDatabase::class.java, "apps.db")
3236
.addMigrations(MIGRATION_1_2)
3337
.addMigrations(MIGRATION_2_3)
38+
.addMigrations(MIGRATION_3_4)
3439
.build()
3540
}
3641
}
@@ -52,5 +57,12 @@ abstract class AppsDatabase : RoomDatabase() {
5257
database.execSQL("ALTER TABLE home_screen_grid_items ADD COLUMN activity_name TEXT default '' NOT NULL")
5358
}
5459
}
60+
61+
private val MIGRATION_3_4 = object : Migration(3, 4) {
62+
override fun migrate(database: SupportSQLiteDatabase) {
63+
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)")
64+
database.execSQL("CREATE UNIQUE INDEX `index_hidden_icons_id` ON `hidden_icons` (`id`)")
65+
}
66+
}
5567
}
5668
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.simplemobiletools.launcher.interfaces
2+
3+
import androidx.room.Dao
4+
import androidx.room.Insert
5+
import androidx.room.OnConflictStrategy
6+
import androidx.room.Query
7+
import com.simplemobiletools.launcher.models.HiddenIcon
8+
9+
@Dao
10+
interface HiddenIconDao {
11+
@Query("SELECT * FROM hidden_icons")
12+
fun getHiddenIcons(): List<HiddenIcon>
13+
14+
@Insert(onConflict = OnConflictStrategy.REPLACE)
15+
fun insert(hiddenIcon: HiddenIcon): Long
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.simplemobiletools.launcher.models
2+
3+
import android.graphics.drawable.Drawable
4+
import androidx.room.*
5+
6+
@Entity(tableName = "hidden_icons", indices = [(Index(value = ["id"], unique = true))])
7+
data class HiddenIcon(
8+
@PrimaryKey(autoGenerate = true) var id: Long?,
9+
@ColumnInfo(name = "package_name") var packageName: String,
10+
@ColumnInfo(name = "activity_name") var activityName: String,
11+
@ColumnInfo(name = "title") var title: String,
12+
13+
@Ignore var drawable: Drawable? = null,
14+
) {
15+
constructor() : this(null, "", "", "", null)
16+
}

0 commit comments

Comments
 (0)