Make search action order customizable

This commit is contained in:
MM20
2022-11-05 17:59:24 +01:00
parent 960c3b70f5
commit 3463b3b800
29 changed files with 526 additions and 253 deletions
@@ -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)