Add plugin settings screen

This commit is contained in:
MM20
2023-11-06 19:30:41 +01:00
parent 7c20d541cd
commit e7ae751340
20 changed files with 398 additions and 85 deletions
@@ -3,6 +3,7 @@ package de.mm20.launcher2.database.daos
import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import de.mm20.launcher2.database.entities.PluginEntity
@@ -26,15 +27,15 @@ interface PluginDao {
@Query("SELECT * FROM Plugins WHERE authority = :authority")
fun get(authority: String): Flow<PluginEntity>
@Insert
fun insertMany(plugins: List<PluginEntity>)
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertMany(plugins: List<PluginEntity>)
@Insert
fun insert(plugin: PluginEntity)
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insert(plugin: PluginEntity)
@Update
fun update(plugin: PluginEntity)
suspend fun update(plugin: PluginEntity)
@Query("DELETE FROM Plugins")
fun deleteMany()
suspend fun deleteMany()
}
+1
View File
@@ -42,6 +42,7 @@ dependencies {
implementation(libs.bundles.androidx.lifecycle)
implementation(libs.koin.android)
implementation(libs.coil.core)
implementation(project(":core:base"))
implementation(project(":core:ktx"))
@@ -2,9 +2,16 @@ package de.mm20.launcher2.files.providers
import android.content.Context
import android.content.Intent
import android.graphics.drawable.Drawable
import android.net.Uri
import android.os.Bundle
import coil.imageLoader
import coil.request.ImageRequest
import de.mm20.launcher2.files.PluginFileSerializer
import de.mm20.launcher2.icons.ColorLayer
import de.mm20.launcher2.icons.LauncherIcon
import de.mm20.launcher2.icons.StaticIconLayer
import de.mm20.launcher2.icons.StaticLauncherIcon
import de.mm20.launcher2.ktx.tryStartActivity
import de.mm20.launcher2.plugin.config.StorageStrategy
import de.mm20.launcher2.search.File
@@ -47,6 +54,21 @@ data class PluginFile(
return PluginFileSerializer()
}
override suspend fun loadIcon(context: Context, size: Int, themed: Boolean): LauncherIcon? {
if (thumbnailUri != null) {
val request = ImageRequest.Builder(context)
.data(thumbnailUri)
.build()
val result = context.imageLoader.execute(request)
val drawable = result.drawable ?: return null
return StaticLauncherIcon(
foregroundLayer = StaticIconLayer(icon = drawable, scale = 1.5f),
backgroundLayer = ColorLayer(),
)
}
return null
}
companion object {
const val Domain = "plugin.file"
}
@@ -4,6 +4,7 @@ import android.content.Context
import android.database.Cursor
import android.net.Uri
import android.os.CancellationSignal
import android.util.Log
import androidx.core.database.getStringOrNull
import de.mm20.launcher2.plugin.Plugin
import de.mm20.launcher2.plugin.config.StorageStrategy
@@ -36,7 +37,13 @@ class PluginFileProvider(
null,
null,
cancellationSignal
) ?: return@suspendCancellableCoroutine it.resume(emptyList<File>())
)
if (cursor == null) {
Log.e("MM20", "Plugin ${plugin.authority} returned null cursor")
it.resume(emptyList())
return@suspendCancellableCoroutine
}
val results = fromCursor(cursor) ?: emptyList()
it.resume(results)
@@ -4,12 +4,18 @@ import de.mm20.launcher2.database.daos.PluginDao
import de.mm20.launcher2.plugin.Plugin
import de.mm20.launcher2.plugin.PluginRepository
import de.mm20.launcher2.plugin.PluginType
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
internal class PluginRepositoryImpl(
private val dao: PluginDao,
): PluginRepository {
) : PluginRepository {
private val scope = CoroutineScope(Job() + Dispatchers.IO)
override fun findMany(
type: PluginType?,
enabled: Boolean?,
@@ -28,19 +34,27 @@ internal class PluginRepositoryImpl(
return dao.get(authority).map { Plugin(it) }
}
override fun insertMany(plugins: List<Plugin>) {
TODO("Not yet implemented")
override fun insertMany(plugins: List<Plugin>): Job {
return scope.launch {
dao.insertMany(plugins.map { PluginEntity(it) })
}
}
override fun insert(plugin: Plugin) {
dao.insert(PluginEntity(plugin))
override fun insert(plugin: Plugin): Job {
return scope.launch {
dao.insert(PluginEntity(plugin))
}
}
override fun update(plugin: Plugin) {
dao.update(PluginEntity(plugin))
override fun update(plugin: Plugin): Job {
return scope.launch {
dao.update(PluginEntity(plugin))
}
}
override fun deleteMany() {
dao.deleteMany()
override fun deleteMany(): Job {
return scope.launch {
dao.deleteMany()
}
}
}