Plugins: bringup
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
</manifest>
|
||||
@@ -0,0 +1,9 @@
|
||||
package de.mm20.launcher2.data.plugins
|
||||
|
||||
import de.mm20.launcher2.database.AppDatabase
|
||||
import de.mm20.launcher2.plugin.PluginRepository
|
||||
import org.koin.dsl.module
|
||||
|
||||
val dataPluginsModule = module {
|
||||
factory<PluginRepository> { PluginRepositoryImpl(get<AppDatabase>().pluginDao()) }
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package de.mm20.launcher2.data.plugins
|
||||
|
||||
import de.mm20.launcher2.database.entities.PluginEntity
|
||||
import de.mm20.launcher2.plugin.Plugin
|
||||
import de.mm20.launcher2.plugin.PluginType
|
||||
|
||||
internal fun Plugin(entity: PluginEntity): Plugin? {
|
||||
return Plugin(
|
||||
enabled = entity.enabled,
|
||||
label = entity.label,
|
||||
description = entity.description,
|
||||
settingsActivity = entity.settingsActivity,
|
||||
packageName = entity.packageName,
|
||||
className = entity.className,
|
||||
type = try {
|
||||
PluginType.valueOf(entity.type)
|
||||
} catch (e: IllegalArgumentException) {
|
||||
return null
|
||||
},
|
||||
authority = entity.authority,
|
||||
)
|
||||
}
|
||||
|
||||
internal fun PluginEntity(plugin: Plugin): PluginEntity {
|
||||
return PluginEntity(
|
||||
enabled = plugin.enabled,
|
||||
label = plugin.label,
|
||||
description = plugin.description,
|
||||
settingsActivity = plugin.settingsActivity,
|
||||
packageName = plugin.packageName,
|
||||
className = plugin.className,
|
||||
type = plugin.type.name,
|
||||
authority = plugin.authority,
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package de.mm20.launcher2.data.plugins
|
||||
|
||||
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.flow.Flow
|
||||
import kotlinx.coroutines.flow.map
|
||||
|
||||
internal class PluginRepositoryImpl(
|
||||
private val dao: PluginDao,
|
||||
): PluginRepository {
|
||||
override fun findMany(
|
||||
type: PluginType?,
|
||||
enabled: Boolean?,
|
||||
packageName: String?
|
||||
): Flow<List<Plugin>> {
|
||||
return dao.findMany(
|
||||
type = type?.name,
|
||||
enabled = enabled,
|
||||
packageName = packageName,
|
||||
).map {
|
||||
it.mapNotNull { Plugin(it) }
|
||||
}
|
||||
}
|
||||
|
||||
override fun get(authority: String): Flow<Plugin?> {
|
||||
return dao.get(authority).map { Plugin(it) }
|
||||
}
|
||||
|
||||
override fun insertMany(plugins: List<Plugin>) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun insert(plugin: Plugin) {
|
||||
dao.insert(PluginEntity(plugin))
|
||||
}
|
||||
|
||||
override fun update(plugin: Plugin) {
|
||||
dao.update(PluginEntity(plugin))
|
||||
}
|
||||
|
||||
override fun deleteMany() {
|
||||
dao.deleteMany()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user