Plugins: bringup
This commit is contained in:
@@ -8,12 +8,14 @@ import androidx.room.Room
|
||||
import androidx.room.RoomDatabase
|
||||
import androidx.room.TypeConverters
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
import de.mm20.launcher2.database.daos.PluginDao
|
||||
import de.mm20.launcher2.database.daos.ThemeDao
|
||||
import de.mm20.launcher2.database.entities.CurrencyEntity
|
||||
import de.mm20.launcher2.database.entities.CustomAttributeEntity
|
||||
import de.mm20.launcher2.database.entities.ForecastEntity
|
||||
import de.mm20.launcher2.database.entities.IconEntity
|
||||
import de.mm20.launcher2.database.entities.IconPackEntity
|
||||
import de.mm20.launcher2.database.entities.PluginEntity
|
||||
import de.mm20.launcher2.database.entities.SavedSearchableEntity
|
||||
import de.mm20.launcher2.database.entities.SearchActionEntity
|
||||
import de.mm20.launcher2.database.entities.ThemeEntity
|
||||
@@ -33,6 +35,7 @@ import de.mm20.launcher2.database.migrations.Migration_21_22
|
||||
import de.mm20.launcher2.database.migrations.Migration_22_23
|
||||
import de.mm20.launcher2.database.migrations.Migration_23_24
|
||||
import de.mm20.launcher2.database.migrations.Migration_24_25
|
||||
import de.mm20.launcher2.database.migrations.Migration_25_26
|
||||
import de.mm20.launcher2.database.migrations.Migration_6_7
|
||||
import de.mm20.launcher2.database.migrations.Migration_7_8
|
||||
import de.mm20.launcher2.database.migrations.Migration_8_9
|
||||
@@ -51,7 +54,8 @@ import java.util.UUID
|
||||
CustomAttributeEntity::class,
|
||||
SearchActionEntity::class,
|
||||
ThemeEntity::class,
|
||||
], version = 25, exportSchema = true
|
||||
PluginEntity::class,
|
||||
], version = 26, exportSchema = true
|
||||
)
|
||||
@TypeConverters(ComponentNameConverter::class)
|
||||
abstract class AppDatabase : RoomDatabase() {
|
||||
@@ -69,6 +73,8 @@ abstract class AppDatabase : RoomDatabase() {
|
||||
|
||||
abstract fun themeDao(): ThemeDao
|
||||
|
||||
abstract fun pluginDao(): PluginDao
|
||||
|
||||
companion object {
|
||||
private var _instance: AppDatabase? = null
|
||||
fun getInstance(context: Context): AppDatabase {
|
||||
@@ -147,6 +153,7 @@ abstract class AppDatabase : RoomDatabase() {
|
||||
Migration_22_23(),
|
||||
Migration_23_24(),
|
||||
Migration_24_25(context),
|
||||
Migration_25_26(),
|
||||
).build()
|
||||
if (_instance == null) _instance = instance
|
||||
return instance
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package de.mm20.launcher2.database.daos
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Delete
|
||||
import androidx.room.Insert
|
||||
import androidx.room.Query
|
||||
import androidx.room.Update
|
||||
import de.mm20.launcher2.database.entities.PluginEntity
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@Dao
|
||||
interface PluginDao {
|
||||
|
||||
@Query("""
|
||||
SELECT * FROM Plugins WHERE
|
||||
(type = :type OR :type IS NULL) AND
|
||||
(enabled = :enabled OR :enabled IS NULL) AND
|
||||
(packageName = :packageName OR :packageName IS NULL)
|
||||
""")
|
||||
fun findMany(
|
||||
type: String? = null,
|
||||
enabled: Boolean? = null,
|
||||
packageName: String? = null,
|
||||
): Flow<List<PluginEntity>>
|
||||
|
||||
@Query("SELECT * FROM Plugins WHERE authority = :authority")
|
||||
fun get(authority: String): Flow<PluginEntity>
|
||||
|
||||
@Insert
|
||||
fun insertMany(plugins: List<PluginEntity>)
|
||||
|
||||
@Insert
|
||||
fun insert(plugin: PluginEntity)
|
||||
|
||||
@Update
|
||||
fun update(plugin: PluginEntity)
|
||||
|
||||
@Query("DELETE FROM Plugins")
|
||||
fun deleteMany()
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package de.mm20.launcher2.database.entities
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "Plugins")
|
||||
data class PluginEntity(
|
||||
@PrimaryKey val authority: String,
|
||||
val label: String,
|
||||
val description: String?,
|
||||
val packageName: String,
|
||||
val className: String,
|
||||
val type: String,
|
||||
val settingsActivity: String?,
|
||||
val enabled: Boolean,
|
||||
)
|
||||
@@ -0,0 +1,24 @@
|
||||
package de.mm20.launcher2.database.migrations
|
||||
|
||||
import androidx.room.migration.Migration
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
internal class Migration_25_26 : Migration(25, 26) {
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("""
|
||||
CREATE TABLE Plugins
|
||||
(
|
||||
authority TEXT NOT NULL,
|
||||
label TEXT NOT NULL,
|
||||
description TEXT,
|
||||
packageName TEXT NOT NULL,
|
||||
className TEXT NOT NULL,
|
||||
type TEXT NOT NULL,
|
||||
settingsActivity TEXT,
|
||||
enabled INTEGER NOT NULL,
|
||||
PRIMARY KEY(`authority`)
|
||||
)
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user