diff --git a/.gitignore b/.gitignore index 9a7fac0857..55d58e37f5 100644 --- a/.gitignore +++ b/.gitignore @@ -51,6 +51,7 @@ captures/ # Comment next line if keeping position of elements in Navigation Editor is relevant for you .idea/navEditor.xml .idea/workspace.xml +.idea/deploymentTargetSelector.xml # Keystore files *.jks diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml index fe63bb677d..148fdd2469 100644 --- a/.idea/kotlinc.xml +++ b/.idea/kotlinc.xml @@ -1,6 +1,6 @@ - \ No newline at end of file diff --git a/mobile/src/main/java/org/openhab/habdroid/core/UpdateBroadcastReceiver.kt b/mobile/src/main/java/org/openhab/habdroid/core/UpdateBroadcastReceiver.kt index ff3dbb0d88..1b2e5de82c 100644 --- a/mobile/src/main/java/org/openhab/habdroid/core/UpdateBroadcastReceiver.kt +++ b/mobile/src/main/java/org/openhab/habdroid/core/UpdateBroadcastReceiver.kt @@ -150,6 +150,7 @@ class UpdateBroadcastReceiver : BroadcastReceiver() { defaultSitemap, null, false, + null, null ) config.saveToPrefs(prefs, secretPrefs) diff --git a/mobile/src/main/java/org/openhab/habdroid/model/ServerConfiguration.kt b/mobile/src/main/java/org/openhab/habdroid/model/ServerConfiguration.kt index 4470c4d233..5a7538aa76 100644 --- a/mobile/src/main/java/org/openhab/habdroid/model/ServerConfiguration.kt +++ b/mobile/src/main/java/org/openhab/habdroid/model/ServerConfiguration.kt @@ -67,7 +67,8 @@ data class ServerConfiguration( val defaultSitemap: DefaultSitemap?, val wifiSsids: Set?, val restrictToWifiSsids: Boolean, - val frontailUrl: String? + val frontailUrl: String?, + val mainUiStartPage: String? ) : Parcelable { fun saveToPrefs(prefs: SharedPreferences, secretPrefs: SharedPreferences) { Log.d(TAG, "saveToPrefs: ${this.toRedactedString()}") @@ -78,6 +79,7 @@ data class ServerConfiguration( putString(PrefKeys.buildServerKey(id, PrefKeys.LOCAL_URL_PREFIX), localPath?.url) putString(PrefKeys.buildServerKey(id, PrefKeys.REMOTE_URL_PREFIX), remotePath?.url) putString(PrefKeys.buildServerKey(id, PrefKeys.FRONTAIL_URL_PREFIX), frontailUrl) + putString(PrefKeys.buildServerKey(id, PrefKeys.MAIN_UI_START_PAGE_PREFIX), mainUiStartPage) putString(PrefKeys.buildServerKey(id, PrefKeys.SSL_CLIENT_CERT_PREFIX), sslClientCert) putStringSet(PrefKeys.buildServerKey(id, PrefKeys.WIFI_SSID_PREFIX), wifiSsids) putBoolean(PrefKeys.buildServerKey(id, PrefKeys.RESTRICT_TO_SSID_PREFIX), restrictToWifiSsids) @@ -109,6 +111,7 @@ data class ServerConfiguration( remove(PrefKeys.buildServerKey(id, PrefKeys.LOCAL_URL_PREFIX)) remove(PrefKeys.buildServerKey(id, PrefKeys.REMOTE_URL_PREFIX)) remove(PrefKeys.buildServerKey(id, PrefKeys.FRONTAIL_URL_PREFIX)) + remove(PrefKeys.buildServerKey(id, PrefKeys.MAIN_UI_START_PAGE_PREFIX)) remove(PrefKeys.buildServerKey(id, PrefKeys.SSL_CLIENT_CERT_PREFIX)) remove(PrefKeys.buildServerKey(id, PrefKeys.DEFAULT_SITEMAP_NAME_PREFIX)) remove(PrefKeys.buildServerKey(id, PrefKeys.DEFAULT_SITEMAP_LABEL_PREFIX)) @@ -140,16 +143,10 @@ data class ServerConfiguration( ) } - return ServerConfiguration( - id, - name, - redactCredentials(localPath), - redactCredentials(remotePath), - sslClientCert, - defaultSitemap, - wifiSsids, - restrictToWifiSsids, - frontailUrl + return createFrom( + this, + localPath = redactCredentials(localPath), + remotePath = redactCredentials(remotePath) ).toString() } @@ -185,7 +182,8 @@ data class ServerConfiguration( } val restrictToWifiSsids = prefs.getBoolean(PrefKeys.buildServerKey(id, PrefKeys.RESTRICT_TO_SSID_PREFIX), false) - val frontailPort = prefs.getStringOrNull(PrefKeys.buildServerKey(id, PrefKeys.FRONTAIL_URL_PREFIX)) + val frontailUrl = prefs.getStringOrNull(PrefKeys.buildServerKey(id, PrefKeys.FRONTAIL_URL_PREFIX)) + val mainUiStartPage = prefs.getStringOrNull(PrefKeys.buildServerKey(id, PrefKeys.MAIN_UI_START_PAGE_PREFIX)) val config = ServerConfiguration( id, @@ -196,7 +194,8 @@ data class ServerConfiguration( getDefaultSitemap(prefs, id), wifiSsids, restrictToWifiSsids, - frontailPort + frontailUrl, + mainUiStartPage ) Log.d(TAG, "load: ${config.toRedactedString()}") return config @@ -220,6 +219,31 @@ data class ServerConfiguration( null } } + + fun createFrom( + config: ServerConfiguration, + id: Int = config.id, + name: String = config.name, + localPath: ServerPath? = config.localPath, + remotePath: ServerPath? = config.remotePath, + sslClientCert: String? = config.sslClientCert, + defaultSitemap: DefaultSitemap? = config.defaultSitemap, + wifiSsids: Set? = config.wifiSsids, + restrictToWifiSsids: Boolean = config.restrictToWifiSsids, + frontailUrl: String? = config.frontailUrl, + mainUiStartPage: String? = config.mainUiStartPage + ) = ServerConfiguration( + id, + name, + localPath, + remotePath, + sslClientCert, + defaultSitemap, + wifiSsids, + restrictToWifiSsids, + frontailUrl, + mainUiStartPage + ) } } diff --git a/mobile/src/main/java/org/openhab/habdroid/ui/activity/MainUiWebViewFragment.kt b/mobile/src/main/java/org/openhab/habdroid/ui/activity/MainUiWebViewFragment.kt index 1c2438bf0d..0553e7bc1a 100644 --- a/mobile/src/main/java/org/openhab/habdroid/ui/activity/MainUiWebViewFragment.kt +++ b/mobile/src/main/java/org/openhab/habdroid/ui/activity/MainUiWebViewFragment.kt @@ -16,6 +16,7 @@ package org.openhab.habdroid.ui.activity import okhttp3.HttpUrl import org.openhab.habdroid.R import org.openhab.habdroid.ui.MainActivity +import org.openhab.habdroid.util.loadActiveServerConfig class MainUiWebViewFragment : AbstractWebViewFragment() { override val titleRes = R.string.mainmenu_openhab_main_ui @@ -27,11 +28,17 @@ class MainUiWebViewFragment : AbstractWebViewFragment() { override val shortcutAction = MainActivity.ACTION_MAIN_UI_SELECTED override fun modifyUrl(orig: HttpUrl): HttpUrl { + var modified = orig if (orig.host == "myopenhab.org") { - return orig.newBuilder() + modified = modified.newBuilder() .host("home.myopenhab.org") .build() } - return orig + context?.loadActiveServerConfig()?.mainUiStartPage?.let { + modified = modified.newBuilder() + .encodedPath(it) + .build() + } + return modified } } diff --git a/mobile/src/main/java/org/openhab/habdroid/ui/preference/fragments/MainSettingsFragment.kt b/mobile/src/main/java/org/openhab/habdroid/ui/preference/fragments/MainSettingsFragment.kt index e10c61e100..bc54174879 100644 --- a/mobile/src/main/java/org/openhab/habdroid/ui/preference/fragments/MainSettingsFragment.kt +++ b/mobile/src/main/java/org/openhab/habdroid/ui/preference/fragments/MainSettingsFragment.kt @@ -140,7 +140,7 @@ class MainSettingsFragment : AbstractSettingsFragment(), ConnectionFactory.Updat getString(R.string.settings_server_default_name, nextServerId) } val f = ServerEditorFragment.newInstance( - ServerConfiguration(nextServerId, nextName, null, null, null, null, null, false, null) + ServerConfiguration(nextServerId, nextName, null, null, null, null, null, false, null, null) ) parentActivity.openSubScreen(f) true diff --git a/mobile/src/main/java/org/openhab/habdroid/ui/preference/fragments/ServerEditorFragment.kt b/mobile/src/main/java/org/openhab/habdroid/ui/preference/fragments/ServerEditorFragment.kt index 8d4aa29862..da62f12c67 100644 --- a/mobile/src/main/java/org/openhab/habdroid/ui/preference/fragments/ServerEditorFragment.kt +++ b/mobile/src/main/java/org/openhab/habdroid/ui/preference/fragments/ServerEditorFragment.kt @@ -161,17 +161,7 @@ class ServerEditorFragment : val serverNamePref = getPreference("name") as EditTextPreference serverNamePref.text = config.name serverNamePref.setOnPreferenceChangeListener { _, newValue -> - config = ServerConfiguration( - config.id, - newValue as String, - config.localPath, - config.remotePath, - config.sslClientCert, - config.defaultSitemap, - config.wifiSsids, - config.restrictToWifiSsids, - config.frontailUrl - ) + config = ServerConfiguration.createFrom(config, name = newValue as String) parentActivity.invalidateOptionsMenu() true } @@ -208,17 +198,7 @@ class ServerEditorFragment : val clientCertPref = getPreference("clientcert") as SslClientCertificatePreference clientCertPref.setOnPreferenceChangeListener { _, newValue -> - config = ServerConfiguration( - config.id, - config.name, - config.localPath, - config.remotePath, - newValue as String?, - config.defaultSitemap, - config.wifiSsids, - config.restrictToWifiSsids, - config.frontailUrl - ) + config = ServerConfiguration.createFrom(config, sslClientCert = newValue as String?) true } clientCertPref.setValue(config.sslClientCert) @@ -270,16 +250,10 @@ class ServerEditorFragment : val ssids = value.first.toWifiSsids() // Don't restrict if no SSID is set val restrictToSsids = if (ssids.isEmpty()) false else value.second - config = ServerConfiguration( - config.id, - config.name, - config.localPath, - config.remotePath, - config.sslClientCert, - config.defaultSitemap, - ssids, - restrictToSsids, - config.frontailUrl + config = ServerConfiguration.createFrom( + config, + wifiSsids = ssids, + restrictToWifiSsids = restrictToSsids ) true } @@ -295,17 +269,19 @@ class ServerEditorFragment : frontailUrlPref.setOnPreferenceChangeListener { _, newValue -> val newUrl = newValue as String? frontailUrlPref.summary = summaryGenerator(newUrl) - config = ServerConfiguration( - config.id, - config.name, - config.localPath, - config.remotePath, - config.sslClientCert, - config.defaultSitemap, - config.wifiSsids, - config.restrictToWifiSsids, - newUrl - ) + config = ServerConfiguration.createFrom(config, frontailUrl = newUrl) + true + } + + val mainUiStartPagePref = getPreference("main_ui_start_page") as EditTextPreference + mainUiStartPagePref.text = config.mainUiStartPage + mainUiStartPagePref.setOnPreferenceChangeListener { _, newValue -> + var newPage = newValue as String? + if (!newPage.isNullOrEmpty() && !newPage.startsWith("/")) { + newPage = "/$newPage" + mainUiStartPagePref.text = newPage + } + config = ServerConfiguration.createFrom(config, mainUiStartPage = newPage) true } @@ -335,29 +311,9 @@ class ServerEditorFragment : fun onPathChanged(key: String, path: ServerPath) { config = if (key == "local") { - ServerConfiguration( - config.id, - config.name, - path, - config.remotePath, - config.sslClientCert, - config.defaultSitemap, - config.wifiSsids, - config.restrictToWifiSsids, - config.frontailUrl - ) + ServerConfiguration.createFrom(config, localPath = path) } else { - ServerConfiguration( - config.id, - config.name, - config.localPath, - path, - config.sslClientCert, - config.defaultSitemap, - config.wifiSsids, - config.restrictToWifiSsids, - config.frontailUrl - ) + ServerConfiguration.createFrom(config, remotePath = path) } parentActivity.invalidateOptionsMenu() } diff --git a/mobile/src/main/java/org/openhab/habdroid/util/ExtensionFuncs.kt b/mobile/src/main/java/org/openhab/habdroid/util/ExtensionFuncs.kt index 7b0de2daff..14675ef2fc 100644 --- a/mobile/src/main/java/org/openhab/habdroid/util/ExtensionFuncs.kt +++ b/mobile/src/main/java/org/openhab/habdroid/util/ExtensionFuncs.kt @@ -590,6 +590,7 @@ fun ServiceInfo.addToPrefs(context: Context) { null, null, false, + null, null ) config.saveToPrefs(context.getPrefs(), context.getSecretPrefs()) diff --git a/mobile/src/main/java/org/openhab/habdroid/util/PrefKeys.kt b/mobile/src/main/java/org/openhab/habdroid/util/PrefKeys.kt index 168a319030..7064e486c7 100644 --- a/mobile/src/main/java/org/openhab/habdroid/util/PrefKeys.kt +++ b/mobile/src/main/java/org/openhab/habdroid/util/PrefKeys.kt @@ -35,6 +35,7 @@ object PrefKeys { const val WIFI_SSID_PREFIX = "wifi_ssid_" const val RESTRICT_TO_SSID_PREFIX = "restrict_to_ssid_" const val FRONTAIL_URL_PREFIX = "frontail_url_" + const val MAIN_UI_START_PAGE_PREFIX = "main_ui_start_page_" const val CLEAR_DEFAULT_SITEMAP = "clear_default_sitemap" fun buildServerKey(id: Int, prefix: String) = "$prefix$id" diff --git a/mobile/src/main/res/values/strings.xml b/mobile/src/main/res/values/strings.xml index ed37634802..014be7afcd 100644 --- a/mobile/src/main/res/values/strings.xml +++ b/mobile/src/main/res/values/strings.xml @@ -84,6 +84,7 @@ No default Sitemap selected Current default Sitemap: %1$s + Main UI start page https://www.openhab.org/docs/apps/android.html#ui-command-item UI command Item Sitemap can be controlled via Item \"%s\" diff --git a/mobile/src/main/res/xml/preferences_server.xml b/mobile/src/main/res/xml/preferences_server.xml index ff92ddc82b..49c4ef3d36 100644 --- a/mobile/src/main/res/xml/preferences_server.xml +++ b/mobile/src/main/res/xml/preferences_server.xml @@ -22,6 +22,13 @@ android:clickable="true" android:key="clear_default_sitemap" android:title="@string/settings_clear_default_sitemap" /> +