QuickTiles.kt (770B) - raw


      1 package me.rhunk.snapenhance.storage
      2 
      3 import me.rhunk.snapenhance.common.util.ktx.getStringOrNull
      4 
      5 
      6 fun AppDatabase.getQuickTiles(): List<String> {
      7     return database.rawQuery("SELECT `key` FROM quick_tiles ORDER BY position ASC", null).use { cursor ->
      8         val keys = mutableListOf<String>()
      9         while (cursor.moveToNext()) {
     10             keys.add(cursor.getStringOrNull("key") ?: continue)
     11         }
     12         keys
     13     }
     14 }
     15 
     16 fun AppDatabase.setQuickTiles(keys: List<String>) {
     17     executeAsync {
     18         database.execSQL("DELETE FROM quick_tiles")
     19         keys.forEachIndexed { index, key ->
     20             database.execSQL("INSERT INTO quick_tiles (`key`, position) VALUES (?, ?)", arrayOf(
     21                 key,
     22                 index
     23             ))
     24         }
     25     }
     26 }