adding some initial Room database related code

This commit is contained in:
tibbi 2022-09-17 23:43:30 +02:00
parent 0791197d66
commit ab3922be22
3 changed files with 46 additions and 1 deletions

View File

@ -44,4 +44,8 @@ android {
dependencies {
implementation 'com.github.SimpleMobileTools:Simple-Commons:a0121a8d50'
kapt "androidx.room:room-compiler:2.4.3"
implementation "androidx.room:room-runtime:2.4.3"
annotationProcessor "androidx.room:room-compiler:2.4.3"
}

View File

@ -0,0 +1,27 @@
package com.simplemobiletools.launcher.databases
import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.simplemobiletools.launcher.models.AppLauncher
@Database(entities = [AppLauncher::class], version = 1)
abstract class AppsDatabase : RoomDatabase() {
companion object {
private var db: AppsDatabase? = null
fun getInstance(context: Context): AppsDatabase {
if (db == null) {
synchronized(AppsDatabase::class) {
if (db == null) {
db = Room.databaseBuilder(context.applicationContext, AppsDatabase::class.java, "apps.db")
.build()
}
}
}
return db!!
}
}
}

View File

@ -1,16 +1,30 @@
package com.simplemobiletools.launcher.models
import android.graphics.drawable.Drawable
import androidx.room.*
import com.simplemobiletools.commons.helpers.SORT_BY_TITLE
import com.simplemobiletools.commons.helpers.SORT_DESCENDING
data class AppLauncher(val id: Int, var title: String, val packageName: String, var order: Int, val drawable: Drawable? = null) : Comparable<AppLauncher> {
@Entity(tableName = "apps", indices = [(Index(value = ["package_name"], unique = true))])
data class AppLauncher(
@PrimaryKey(autoGenerate = true) var id: Long?,
@ColumnInfo(name = "title") var title: String,
@ColumnInfo(name = "package_name") var packageName: String,
@ColumnInfo(name = "order") var order: Int,
@Ignore var drawable: Drawable?
) : Comparable<AppLauncher> {
constructor() : this(null, "", "", 0, null)
companion object {
var sorting = 0
}
override fun equals(other: Any?) = packageName.equals((other as AppLauncher).packageName, true)
override fun hashCode() = super.hashCode()
fun getBubbleText() = title
override fun compareTo(other: AppLauncher): Int {