Add plugin settings screen
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package de.mm20.launcher2.sdk.base
|
||||
|
||||
import android.content.ContentProvider
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Bundle
|
||||
import de.mm20.launcher2.plugin.PluginState
|
||||
import de.mm20.launcher2.plugin.PluginType
|
||||
@@ -43,4 +45,11 @@ abstract class BasePluginProvider : ContentProvider() {
|
||||
return PluginState.Ready
|
||||
}
|
||||
|
||||
internal fun checkPermissionOrThrow(context: Context) {
|
||||
if (context.checkCallingPermission(PluginContract.Permission) == PackageManager.PERMISSION_GRANTED) {
|
||||
return
|
||||
}
|
||||
throw SecurityException("Caller does not have permission to use plugins")
|
||||
}
|
||||
|
||||
}
|
||||
@@ -45,7 +45,7 @@ abstract class SearchPluginProvider<T> : BasePluginProvider() {
|
||||
val context = context ?: return null
|
||||
checkPermissionOrThrow(context)
|
||||
when {
|
||||
uri.path == SearchPluginContract.Paths.Search -> {
|
||||
uri.pathSegments.size == 1 && uri.pathSegments.first() == SearchPluginContract.Paths.Search -> {
|
||||
val query =
|
||||
uri.getQueryParameter(SearchPluginContract.Paths.QueryParam) ?: return null
|
||||
val results = search(query, cancellationSignal)
|
||||
@@ -53,7 +53,7 @@ abstract class SearchPluginProvider<T> : BasePluginProvider() {
|
||||
for (result in results) {
|
||||
writeToCursor(cursor, result)
|
||||
}
|
||||
return null
|
||||
return cursor
|
||||
}
|
||||
uri.pathSegments.size == 2 && uri.pathSegments.first() == SearchPluginContract.Paths.Root -> {
|
||||
val id = uri.pathSegments[1]
|
||||
@@ -110,12 +110,4 @@ abstract class SearchPluginProvider<T> : BasePluginProvider() {
|
||||
|
||||
internal abstract fun createCursor(capacity: Int): MatrixCursor
|
||||
internal abstract fun writeToCursor(cursor: MatrixCursor, item: T)
|
||||
|
||||
|
||||
private fun checkPermissionOrThrow(context: Context) {
|
||||
if (context.checkCallingPermission(PluginContract.Permission) == PackageManager.PERMISSION_GRANTED) {
|
||||
return
|
||||
}
|
||||
throw SecurityException("Caller does not have permission to use plugins")
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,15 @@
|
||||
package de.mm20.launcher2.sdk.files
|
||||
|
||||
import android.database.Cursor
|
||||
import android.database.MatrixCursor
|
||||
import android.net.Uri
|
||||
import de.mm20.launcher2.plugin.PluginType
|
||||
import de.mm20.launcher2.plugin.contracts.FilePluginContract
|
||||
import de.mm20.launcher2.sdk.base.SearchPluginProvider
|
||||
|
||||
abstract class FileProvider : SearchPluginProvider<File>() {
|
||||
abstract override suspend fun search(query: String): List<File>
|
||||
|
||||
final override fun getPluginType(): de.mm20.launcher2.plugin.PluginType {
|
||||
return de.mm20.launcher2.plugin.PluginType.FileSearch
|
||||
final override fun getPluginType(): PluginType {
|
||||
return PluginType.FileSearch
|
||||
}
|
||||
|
||||
override fun createCursor(capacity: Int): MatrixCursor {
|
||||
|
||||
Reference in New Issue
Block a user