Plugin stuff, idk, i wrote that shit yesterday

This commit is contained in:
MM20
2023-11-08 19:02:53 +01:00
parent c5e524c702
commit b7452f6bce
9 changed files with 113 additions and 31 deletions
@@ -0,0 +1,38 @@
package de.mm20.launcher2.plugin.config
import android.os.Bundle
import de.mm20.launcher2.plugin.config.StorageStrategy
data class SearchPluginConfig(
/**
* Icon resource to indicate that a result is from this provider
*/
val providerIconRes: Int? = null,
/**
* Strategy to store items from this provider in the launcher database
* @see [StorageStrategy]
*/
val storageStrategy: StorageStrategy = StorageStrategy.StoreCopy,
) {
fun toBundle(): Bundle {
return Bundle().apply {
putInt("providerIconRes", providerIconRes ?: 0)
putString("storageStrategy", storageStrategy.name)
}
}
companion object {
operator fun invoke(bundle: Bundle): SearchPluginConfig? {
return SearchPluginConfig(
providerIconRes = bundle.getInt("providerIconRes", 0).takeIf { it != 0 },
storageStrategy = StorageStrategy.valueOfOrElse(
bundle.getString(
"storageStrategy",
StorageStrategy.StoreCopy.name
),
StorageStrategy.StoreCopy,
)
)
}
}
}
@@ -21,5 +21,14 @@ enum class StorageStrategy {
* Use this strategy if your plugin needs to perform network requests to retrieve search
* results and if you don't want to implement a cache for search results.
*/
StoreCopy,
StoreCopy;
companion object {
fun valueOfOrElse(value: String, default: StorageStrategy): StorageStrategy {
return try {
valueOf(value)
} catch (e: IllegalArgumentException) {
default
}
}
}
}
@@ -42,8 +42,6 @@ abstract class FilePluginContract {
const val ThumbnailUri = "thumbnail_uri"
const val StorageStrategy = "storage_strategy"
/**
* Whether the file is a directory.
* Type: Int
@@ -6,5 +6,6 @@ object PluginContract {
object Methods {
const val GetType = "getType"
const val GetState = "getState"
const val GetConfig = "getConfig"
}
}