Add managed location to weather plugin API

This commit is contained in:
MM20
2024-05-03 13:02:17 +02:00
parent b0f9ffd473
commit 1d6688831c
19 changed files with 256 additions and 100 deletions
@@ -0,0 +1,51 @@
package de.mm20.launcher2.plugin
import android.content.ContentResolver
import android.net.Uri
import android.util.Log
import de.mm20.launcher2.plugin.config.SearchPluginConfig
import de.mm20.launcher2.plugin.config.WeatherPluginConfig
import de.mm20.launcher2.plugin.contracts.PluginContract
class PluginApi(
private val pluginAuthority: String,
private val contentResolver: ContentResolver,
) {
fun getSearchPluginConfig(): SearchPluginConfig? {
val configBundle = try {
contentResolver.call(
Uri.Builder()
.scheme("content")
.authority(pluginAuthority)
.build(),
PluginContract.Methods.GetConfig,
null,
null
) ?: return null
} catch (e: Exception) {
Log.e("MM20", "Plugin $pluginAuthority threw exception", e)
return null
}
return SearchPluginConfig(configBundle)
}
fun getWeatherPluginConfig(): WeatherPluginConfig? {
val configBundle = try {
contentResolver.call(
Uri.Builder()
.scheme("content")
.authority(pluginAuthority)
.build(),
PluginContract.Methods.GetConfig,
null,
null
) ?: return null
} catch (e: Exception) {
Log.e("PluginWeatherProvider", "Plugin $pluginAuthority threw exception", e)
return null
}
return WeatherPluginConfig(configBundle)
}
}
@@ -8,5 +8,6 @@ fun WeatherPluginConfig(bundle: Bundle): WeatherPluginConfig {
"minUpdateInterval",
60 * 60 * 1000L
),
managedLocation = bundle.getBoolean("managedLocation", false)
)
}