Tags editor
This commit is contained in:
+20
-1
@@ -1,6 +1,5 @@
|
||||
package de.mm20.launcher2.customattrs
|
||||
|
||||
import android.util.Log
|
||||
import de.mm20.launcher2.crashreporter.CrashReporter
|
||||
import de.mm20.launcher2.database.AppDatabase
|
||||
import de.mm20.launcher2.database.entities.CustomAttributeEntity
|
||||
@@ -11,6 +10,7 @@ import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.flow
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.mapNotNull
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONException
|
||||
import java.io.File
|
||||
@@ -23,6 +23,9 @@ interface CustomAttributesRepository {
|
||||
fun setCustomLabel(searchable: Searchable, label: String)
|
||||
fun clearCustomLabel(searchable: Searchable)
|
||||
|
||||
fun setTags(searchable: Searchable, tags: List<String>)
|
||||
fun getTags(searchable: Searchable): Flow<List<String>>
|
||||
|
||||
suspend fun search(query: String): Flow<List<Searchable>>
|
||||
|
||||
suspend fun export(toDir: File)
|
||||
@@ -84,6 +87,22 @@ internal class CustomAttributesRepositoryImpl(
|
||||
}
|
||||
}
|
||||
|
||||
override fun setTags(searchable: Searchable, tags: List<String>) {
|
||||
val dao = appDatabase.customAttrsDao()
|
||||
scope.launch {
|
||||
dao.setTags(searchable.key, tags.map {
|
||||
CustomTag(it).toDatabaseEntity(searchable.key)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
override fun getTags(searchable: Searchable): Flow<List<String>> {
|
||||
val dao = appDatabase.customAttrsDao()
|
||||
return dao.getCustomAttributes(listOf(searchable.key), CustomAttributeType.Tag.value).map {
|
||||
it.map { it.value }
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun search(query: String): Flow<List<Searchable>> {
|
||||
if (query.isBlank()) {
|
||||
return flow {
|
||||
|
||||
Reference in New Issue
Block a user