Add settings page to manage tags

This commit is contained in:
MM20
2022-12-21 19:24:32 +01:00
parent 85f7a740e0
commit ddc157741a
16 changed files with 586 additions and 38 deletions
@@ -9,10 +9,10 @@ import kotlinx.coroutines.flow.Flow
@Dao
interface CustomAttrsDao {
@Query("SELECT * FROM CustomAttributes WHERE type = :type AND key = :key LIMIT 1")
@Query("SELECT * FROM CustomAttributes WHERE type = :type AND `key` = :key LIMIT 1")
fun getCustomAttribute(key: String, type: String) : Flow<CustomAttributeEntity?>
@Query("DELETE FROM CustomAttributes WHERE type = :type AND key = :key")
@Query("DELETE FROM CustomAttributes WHERE type = :type AND `key` = :key")
fun clearCustomAttribute(key: String, type: String)
@Insert
@@ -21,10 +21,10 @@ interface CustomAttrsDao {
@Insert
suspend fun insertCustomAttributes(entities: List<CustomAttributeEntity>)
@Query("SELECT * FROM CustomAttributes WHERE type = :type AND key IN (:keys)")
@Query("SELECT * FROM CustomAttributes WHERE type = :type AND `key` IN (:keys)")
fun getCustomAttributes(keys: List<String>, type: String) : Flow<List<CustomAttributeEntity>>
@Query("SELECT DISTINCT key FROM CustomAttributes WHERE (type = 'label' OR type = 'tag') AND value LIKE :query")
@Query("SELECT DISTINCT `key` FROM CustomAttributes WHERE (type = 'label' OR type = 'tag') AND value LIKE :query")
fun search(query: String): Flow<List<String>>
@Transaction
@@ -34,24 +34,30 @@ interface CustomAttrsDao {
}
@Query("SELECT DISTINCT value FROM CustomAttributes WHERE type = 'tag' AND value LIKE :like ORDER BY value")
suspend fun getAllTagsLike(like: String): List<String>
fun getAllTagsLike(like: String): Flow<List<String>>
@Query("SELECT DISTINCT value FROM CustomAttributes WHERE type = 'tag' ORDER BY value")
suspend fun getAllTags(): List<String>
fun getAllTags(): Flow<List<String>>
@Query("SELECT key FROM CustomAttributes WHERE type = 'tag' AND value = :tag")
@Query("SELECT `key` FROM CustomAttributes WHERE type = 'tag' AND value = :tag")
fun getItemsWithTag(tag: String): Flow<List<String>>
@Transaction
suspend fun setItemsWithTag(tag: String, items: List<String>) {
deleteTag(tag)
insertCustomAttributes(items.map { CustomAttributeEntity(it, "tag", tag) })
}
@Transaction
suspend fun addTag(key: String, tag: String) {
removeTag(key, tag)
insertTag(key, tag)
}
@Query("DELETE FROM CustomAttributes WHERE type = 'tag' AND key = :key AND value = :tag")
@Query("DELETE FROM CustomAttributes WHERE type = 'tag' AND `key` = :key AND value = :tag")
suspend fun removeTag(key: String, tag: String)
@Query("INSERT INTO CustomAttributes (key, value, type) VALUES (:key, :tag, 'tag')")
@Query("INSERT INTO CustomAttributes (`key`, value, type) VALUES (:key, :tag, 'tag')")
suspend fun insertTag(key: String, tag: String)
@Query("UPDATE CustomAttributes SET value = :newName WHERE value = :oldName AND type = 'tag'")
+12
View File
@@ -710,4 +710,16 @@
<string name="search_action_websearch_url_hint">The URL template that is used to construct the web search URL. Use ${1} as a placeholder for the actual search term, e.g. https://google.com/search?q=${1}.</string>
<string name="more_information">More information</string>
<string name="experimental_feature">Experimental</string>
<string name="create_tag_title">New tag</string>
<string name="edit_tag_title">Edit tag</string>
<string name="tag_exists_error">A tag with this name already exists.</string>
<string name="tag_exists_message">A tag with this name already exists. If you continue, the two tags will be merged.</string>
<string name="tag_no_items_message">No items are assigned to this tag. If you continue, the tag will be deleted.</string>
<string name="tag_empty_message">Tag name must not be blank.</string>
<string name="tag_select_items">Select items:</string>
<string name="tag_name">Tag name</string>
<plurals name="tag_selected_items">
<item quantity="one">%1$d item selected</item>
<item quantity="other">%1$d items selected</item>
</plurals>
</resources>