Implement custom legacy to adaptive icon transformations

This commit is contained in:
MM20
2022-07-24 20:47:10 +02:00
parent 5bd86e6f95
commit bb211d4d6a
12 changed files with 85 additions and 28 deletions
@@ -10,7 +10,8 @@ sealed interface CustomAttribute {
fun toDatabaseEntity(key: String): CustomAttributeEntity
companion object {
internal fun fromDatabaseEntity(entity: CustomAttributeEntity): CustomAttribute? {
internal fun fromDatabaseEntity(entity: CustomAttributeEntity?): CustomAttribute? {
if (entity == null) return null
return when (entity.type) {
CustomAttributeType.Label.value -> CustomLabel(
label = entity.value
@@ -1,8 +1,22 @@
package de.mm20.launcher2.customattrs
import de.mm20.launcher2.database.AppDatabase
import de.mm20.launcher2.search.data.Searchable
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
interface CustomAttributesRepository {
fun getCustomAttributes(searchable: Searchable, type: CustomAttributeType? = null): Flow<List<CustomAttribute>>
fun getCustomIcon(searchable: Searchable): Flow<CustomIcon?>
}
internal class CustomAttributesRepositoryImpl(
private val appDatabase: AppDatabase,
) : CustomAttributesRepository {
override fun getCustomIcon(searchable: Searchable): Flow<CustomIcon?> {
val dao = appDatabase.customAttrsDao()
return dao.getCustomIcon(searchable.key)
.map {
CustomAttribute.fromDatabaseEntity(it) as? CustomIcon
}
}
}
@@ -3,5 +3,5 @@ package de.mm20.launcher2.customattrs
import org.koin.dsl.module
val customAttrsModule = module {
single<CustomAttributesRepository> { CustomAttributesRepositoryImpl(get()) }
}