Implement custom legacy to adaptive icon transformations
This commit is contained in:
@@ -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
|
||||
|
||||
+15
-1
@@ -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()) }
|
||||
}
|
||||
Reference in New Issue
Block a user