Make search action order customizable
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
"formatVersion": 1,
|
||||
"database": {
|
||||
"version": 19,
|
||||
"identityHash": "c6adf1dca8ade5117d4e8952a67786fa",
|
||||
"identityHash": "968a73b13f39e00505a4adf1bda01394",
|
||||
"entities": [
|
||||
{
|
||||
"tableName": "forecasts",
|
||||
@@ -398,7 +398,7 @@
|
||||
},
|
||||
{
|
||||
"tableName": "SearchAction",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`position` INTEGER NOT NULL, `type` TEXT NOT NULL, `data` TEXT NOT NULL, `label` TEXT, `icon` INTEGER NOT NULL, `color` INTEGER NOT NULL, `customIcon` TEXT, `options` TEXT, PRIMARY KEY(`position`))",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`position` INTEGER NOT NULL, `type` TEXT NOT NULL, `data` TEXT, `label` TEXT, `icon` INTEGER, `color` INTEGER, `customIcon` TEXT, `options` TEXT, PRIMARY KEY(`position`))",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "position",
|
||||
@@ -416,7 +416,7 @@
|
||||
"fieldPath": "data",
|
||||
"columnName": "data",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "label",
|
||||
@@ -428,13 +428,13 @@
|
||||
"fieldPath": "icon",
|
||||
"columnName": "icon",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "color",
|
||||
"columnName": "color",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "customIcon",
|
||||
@@ -462,7 +462,7 @@
|
||||
"views": [],
|
||||
"setupQueries": [
|
||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'c6adf1dca8ade5117d4e8952a67786fa')"
|
||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '968a73b13f39e00505a4adf1bda01394')"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -57,13 +57,23 @@ abstract class AppDatabase : RoomDatabase() {
|
||||
.addCallback(object : Callback() {
|
||||
override fun onCreate(db: SupportSQLiteDatabase) {
|
||||
super.onCreate(db)
|
||||
db.execSQL("INSERT INTO `SearchAction` (`position`, `type`) VALUES" +
|
||||
"(0, 'call')," +
|
||||
"(1, 'message')," +
|
||||
"(2, 'email')," +
|
||||
"(3, 'contact')," +
|
||||
"(4, 'alarm')," +
|
||||
"(5, 'timer')," +
|
||||
"(6, 'calendar')," +
|
||||
"(7, 'website')"
|
||||
)
|
||||
|
||||
db.execSQL("INSERT INTO `SearchAction` (`position`, `type`, `data`, `label`, `color`, `icon`, `customIcon`, `options`) " +
|
||||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
arrayOf(
|
||||
0, "url", context.getString(R.string.default_websearch_1_url), context.getString(R.string.default_websearch_1_name), 0, 0, null, null,
|
||||
0, "url", context.getString(R.string.default_websearch_2_url), context.getString(R.string.default_websearch_2_name), 0, 0, null, null,
|
||||
0, "url", context.getString(R.string.default_websearch_3_url), context.getString(R.string.default_websearch_3_name), 0, 0, null, null,
|
||||
8, "url", context.getString(R.string.default_websearch_1_url), context.getString(R.string.default_websearch_1_name), 0, 0, null, null,
|
||||
9, "url", context.getString(R.string.default_websearch_2_url), context.getString(R.string.default_websearch_2_name), 0, 0, null, null,
|
||||
10, "url", context.getString(R.string.default_websearch_3_url), context.getString(R.string.default_websearch_3_name), 0, 0, null, null,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package de.mm20.launcher2.database
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.Query
|
||||
import androidx.room.Transaction
|
||||
import de.mm20.launcher2.database.entities.SearchActionEntity
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@@ -9,4 +11,16 @@ import kotlinx.coroutines.flow.Flow
|
||||
interface SearchActionDao {
|
||||
@Query("SELECT * FROM SearchAction ORDER BY position ASC")
|
||||
fun getSearchActions(): Flow<List<SearchActionEntity>>
|
||||
|
||||
@Transaction
|
||||
suspend fun replaceAll(actions: List<SearchActionEntity>) {
|
||||
deleteAll()
|
||||
insertAll(actions)
|
||||
}
|
||||
|
||||
@Query("DELETE FROM `SearchAction`")
|
||||
suspend fun deleteAll()
|
||||
|
||||
@Insert
|
||||
suspend fun insertAll(actions: List<SearchActionEntity>)
|
||||
}
|
||||
@@ -7,10 +7,10 @@ import androidx.room.PrimaryKey
|
||||
data class SearchActionEntity(
|
||||
@PrimaryKey val position: Int,
|
||||
val type: String,
|
||||
val data: String,
|
||||
val label: String?,
|
||||
val icon: Int,
|
||||
val color: Int = 0,
|
||||
val data: String? = null,
|
||||
val label: String? = null,
|
||||
val icon: Int? = null,
|
||||
val color: Int? = null,
|
||||
val customIcon: String? = null,
|
||||
val options: String? = null,
|
||||
)
|
||||
@@ -9,9 +9,19 @@ class Migration_18_19 : Migration(18, 19) {
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
val websearches =
|
||||
database.query("SELECT label, urlTemplate, color, icon, encoding FROM `Websearch` ORDER BY label ASC")
|
||||
database.execSQL("CREATE TABLE IF NOT EXISTS `SearchAction` (`position` INTEGER NOT NULL, `type` TEXT NOT NULL, `data` TEXT NOT NULL, `label` TEXT, `icon` INTEGER NOT NULL, `color` INTEGER NOT NULL, `customIcon` TEXT, `options` TEXT, PRIMARY KEY(`position`))"
|
||||
database.execSQL("CREATE TABLE IF NOT EXISTS `SearchAction` (`position` INTEGER NOT NULL, `type` TEXT NOT NULL, `data` TEXT, `label` TEXT, `icon` INTEGER, `color` INTEGER, `customIcon` TEXT, `options` TEXT, PRIMARY KEY(`position`))"
|
||||
)
|
||||
var position = 0
|
||||
database.execSQL("INSERT INTO `SearchAction` (`position`, `type`) VALUES" +
|
||||
"(0, 'call')," +
|
||||
"(1, 'message')," +
|
||||
"(2, 'email')," +
|
||||
"(3, 'contact')," +
|
||||
"(4, 'alarm')," +
|
||||
"(5, 'timer')," +
|
||||
"(6, 'calendar')," +
|
||||
"(7, 'website')"
|
||||
)
|
||||
var position = 8
|
||||
while (websearches.moveToNext()) {
|
||||
val label = websearches.getString(0)
|
||||
val data = websearches.getString(1)
|
||||
|
||||
Reference in New Issue
Block a user