Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .idea/kotlinc.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="KotlinJpsPluginSettings">
<option name="version" value="1.9.23" />
<option name="version" value="1.9.24" />
</component>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ class UpdateBroadcastReceiver : BroadcastReceiver() {
defaultSitemap,
null,
false,
null,
null
)
config.saveToPrefs(prefs, secretPrefs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ data class ServerConfiguration(
val defaultSitemap: DefaultSitemap?,
val wifiSsids: Set<String>?,
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()}")
Expand All @@ -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)
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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()
}

Expand Down Expand Up @@ -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,
Expand All @@ -196,7 +194,8 @@ data class ServerConfiguration(
getDefaultSitemap(prefs, id),
wifiSsids,
restrictToWifiSsids,
frontailPort
frontailUrl,
mainUiStartPage
)
Log.d(TAG, "load: ${config.toRedactedString()}")
return config
Expand All @@ -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<String>? = 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
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}

Expand Down Expand Up @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ fun ServiceInfo.addToPrefs(context: Context) {
null,
null,
false,
null,
null
)
config.saveToPrefs(context.getPrefs(), context.getSecretPrefs())
Expand Down
1 change: 1 addition & 0 deletions mobile/src/main/java/org/openhab/habdroid/util/PrefKeys.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions mobile/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
<string name="settings_no_default_sitemap">No default Sitemap selected</string>
<!-- %1$s: Default Sitemap label -->
<string name="settings_current_default_sitemap">Current default Sitemap: %1$s</string>
<string name="settings_main_ui_start_page">Main UI start page</string>
<string name="settings_ui_command_item_howto_url" translatable="false">https://www.openhab.org/docs/apps/android.html#ui-command-item</string>
<string name="settings_ui_command_item">UI command Item</string>
<string name="settings_ui_command_item_summary_on">Sitemap can be controlled via Item \"%s\"</string>
Expand Down
7 changes: 7 additions & 0 deletions mobile/src/main/res/xml/preferences_server.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
android:clickable="true"
android:key="clear_default_sitemap"
android:title="@string/settings_clear_default_sitemap" />
<org.openhab.habdroid.ui.preference.widgets.CustomInputTypePreference
android:key="main_ui_start_page"
android:title="@string/settings_main_ui_start_page"
android:persistent="false"
app:whitespaceBehavior="trim"
android:inputType="text"
app:useSimpleSummaryProvider="true" />
<org.openhab.habdroid.ui.preference.widgets.PrimaryServerPreference
android:key="primary_server_pref"
android:icon="@drawable/ic_star_border_grey_24dp"
Expand Down