Dashboard URL and label configured in dashboards.yaml; each entry becomes a product flavor with BuildConfig.DASHBOARD_URL injected at build time. APKs output as <flavor>-release.apk.
This commit is contained in:
+32
-3
@@ -1,8 +1,14 @@
|
||||
import org.yaml.snakeyaml.Yaml
|
||||
|
||||
plugins {
|
||||
id("com.android.application")
|
||||
id("org.jetbrains.kotlin.android")
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val dashboards: Map<String, Map<String, String>> =
|
||||
Yaml().load(rootProject.file("dashboards.yaml").inputStream())
|
||||
|
||||
android {
|
||||
namespace = "cz.c3c.webviewkiosk"
|
||||
compileSdk = 34
|
||||
@@ -15,11 +21,12 @@ android {
|
||||
versionName = "0.1.0"
|
||||
}
|
||||
|
||||
buildFeatures {
|
||||
buildConfig = true
|
||||
}
|
||||
|
||||
signingConfigs {
|
||||
create("release") {
|
||||
// Keystore is committed (private repo, LAN kiosk app) so every
|
||||
// machine/CI produces the same signature and `adb install -r`
|
||||
// upgrades work without uninstalling. Created in Task 6.
|
||||
storeFile = rootProject.file("signing/release.keystore")
|
||||
storePassword = "android-webview-kiosk"
|
||||
keyAlias = "kiosk"
|
||||
@@ -34,6 +41,28 @@ android {
|
||||
}
|
||||
}
|
||||
|
||||
flavorDimensions += "dashboard"
|
||||
|
||||
productFlavors {
|
||||
dashboards.forEach { (name, config) ->
|
||||
create(name) {
|
||||
dimension = "dashboard"
|
||||
buildConfigField("String", "DASHBOARD_URL", "\"${config["url"]}\"")
|
||||
resValue("string", "app_name", config["label"] ?: name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
applicationVariants.all {
|
||||
val flavor = productFlavors.first().name
|
||||
val type = buildType.name
|
||||
outputs.all {
|
||||
(this as com.android.build.gradle.internal.api.BaseVariantOutputImpl)
|
||||
.outputFileName = "$flavor-$type.apk"
|
||||
}
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
android:allowBackup="false"
|
||||
android:banner="@drawable/banner"
|
||||
android:icon="@drawable/icon"
|
||||
android:label="Grafana Kiosk"
|
||||
android:label="@string/app_name"
|
||||
android:usesCleartextTraffic="true"
|
||||
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
|
||||
|
||||
|
||||
@@ -15,11 +15,6 @@ import android.webkit.WebViewClient
|
||||
|
||||
class MainActivity : Activity() {
|
||||
|
||||
companion object {
|
||||
const val DASHBOARD_URL =
|
||||
"https://grafana.c3c.cz/public-dashboards/381fe3e71e164eb99dd0b10e246a36e2"
|
||||
}
|
||||
|
||||
private lateinit var webView: WebView
|
||||
private val handler = Handler(Looper.getMainLooper())
|
||||
private val backoff = BackoffPolicy(initialDelayMs = 2_000, maxDelayMs = 60_000)
|
||||
@@ -55,7 +50,7 @@ class MainActivity : Activity() {
|
||||
if (!request.isForMainFrame) return
|
||||
lastLoadFailed = true
|
||||
handler.postDelayed(
|
||||
{ view.loadUrl(DASHBOARD_URL) },
|
||||
{ view.loadUrl(BuildConfig.DASHBOARD_URL) },
|
||||
backoff.nextDelayMs(),
|
||||
)
|
||||
}
|
||||
@@ -63,7 +58,7 @@ class MainActivity : Activity() {
|
||||
|
||||
setContentView(webView)
|
||||
hideSystemUi()
|
||||
webView.loadUrl(DASHBOARD_URL)
|
||||
webView.loadUrl(BuildConfig.DASHBOARD_URL)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
|
||||
Reference in New Issue
Block a user