Skip to content

Commit

Permalink
Add support for openHAB 3 log
Browse files Browse the repository at this point in the history
  • Loading branch information
cyb3rko committed Jun 15, 2021
1 parent 93e0479 commit 1a7fe3b
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 15 deletions.
1 change: 1 addition & 0 deletions app/src/main/java/com/cyb3rko/logviewerforopenhab/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ internal const val HOSTNAME_STRING = "hostname_string"
internal const val LINK = "link"
internal const val NIGHTMODE = "nightmode"
internal const val ORIENTATION = "orientation"
internal const val OPENHAB_VERSION = "openhab_version"
internal const val PORT_CHECK = "port_check"
internal const val PORT_INT = "port_int"
internal const val TEXTSIZE_AUTO = "textsize_auto"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,25 @@ class PreferenceFragment : PreferenceFragmentCompat() {
private lateinit var mySPR: SharedPreferences
private lateinit var nightModeList: ListPreference
private lateinit var orientationList: ListPreference
private lateinit var openhabVersionList: ListPreference

override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.preferences)
preferenceManager.sharedPreferencesName = SHARED_PREFERENCE
mySPR = preferenceManager.sharedPreferences
openhabVersionList = findPreference(OPENHAB_VERSION)!!
hideTopbarSwitch = findPreference(HIDE_TOPBAR)!!
orientationList = findPreference(ORIENTATION)!!
connectionOverviewSwitch = findPreference(CONNECTION_OVERVIEW_ENABLED)!!
nightModeList = findPreference(NIGHTMODE)!!
hideTopbarSwitch = findPreference(HIDE_TOPBAR)!!
analyticsCollectionSwitch = findPreference(ANALYTICS_COLLECTION)!!
crashlyticsCollectionSwitch = findPreference(CRASHLYTICS_COLLECTION)!!

openhabVersionList.value = mySPR.getString(OPENHAB_VERSION, "3")
hideTopbarSwitch.isChecked = mySPR.getBoolean(HIDE_TOPBAR, false)
orientationList.value = mySPR.getString(ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED.toString())
connectionOverviewSwitch.isChecked = mySPR.getBoolean(CONNECTION_OVERVIEW_ENABLED, true)
nightModeList.value = mySPR.getString(NIGHTMODE, AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM.toString())
hideTopbarSwitch.isChecked = mySPR.getBoolean(HIDE_TOPBAR, false)
analyticsCollectionSwitch.isChecked = mySPR.getBoolean(ANALYTICS_COLLECTION, true)
crashlyticsCollectionSwitch.isChecked = mySPR.getBoolean(CRASHLYTICS_COLLECTION, true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,14 @@ class WebViewFragment : Fragment() {

override fun onPageFinished(view: WebView?, url: String?) {
if (mySPR.getBoolean(HIDE_TOPBAR, false)) {
view?.loadUrl("javascript:document.getElementsByClassName(\"topbar navbar navbar-inverse navbar-fixed-top\")[0].setAttribute" +
"(\"style\",\"display:none;\");")
val command = when (mySPR.getString(OPENHAB_VERSION, "3")) {
"3" -> "javascript:document.getElementsByClassName(\"topbar navbar navbar-inverse fixed-top\")[0].setAttribute(\"style\"," +
"\"display:none;\");"
"2" -> "javascript:document.getElementsByClassName(\"topbar navbar navbar-inverse navbar-fixed-top\")[0].setAttribute" +
"(\"style\",\"display:none;\");"
else -> "javascript:"
}
view?.loadUrl(command)
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
<string name="menu_about">About</string>
<string name="menu_end_user_consent">End User Consent</string>

<string name="settings_openhab_log">openHAB Log</string>
<string name="settings_openhab_version_title">openHAB Version</string>
<string name="settings_openhab_version_summary">Select the openHAB version you are using</string>
<string name="settings_hide_topbar_title">Hide topbar</string>
<string name="settings_hide_topbar_summary">Hide the topbar of the log</string>
<string name="settings_user_experience">User Experience</string>
<string name="settings_data_collection">Data Collection</string>
<string name="settings_orientation_title">Orientation</string>
Expand All @@ -60,8 +65,6 @@
<string name="settings_connection_overview_summary">En-/Disable the overview of recent connections in the Navigation Drawer</string>
<string name="settings_nightmode_title">Night Mode</string>
<string name="settings_nightmode_summary">Toggle the dark appearance of the app (logview excluded)</string>
<string name="settings_hide_topbar_title">Hide topbar</string>
<string name="settings_hide_topbar_summary">Hide the topbar of the log</string>
<string name="settings_analytics_title">Analytics Data Collection</string>
<string name="settings_analytics_summary">En-/Disable data collection via Firebase Analytics</string>
<string name="settings_crashlytics_title">Crashlytics Data Collection</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,13 @@
<item>1</item>
<item>0</item>
</string-array>

<string-array name="openhab_versions">
<item>openHAB 3</item>
<item>openHAB 2</item>
</string-array>
<string-array name="openhab_versions_values">
<item>3</item>
<item>2</item>
</string-array>
</resources>
7 changes: 5 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
<string name="menu_about">About</string>
<string name="menu_end_user_consent">End User Consent</string>

<string name="settings_openhab_log">openHAB Log</string>
<string name="settings_openhab_version_title">openHAB Version</string>
<string name="settings_openhab_version_summary">Select the openHAB version you are using</string>
<string name="settings_hide_topbar_title">Hide topbar</string>
<string name="settings_hide_topbar_summary">Hide the topbar of the log</string>
<string name="settings_user_experience">User Experience</string>
<string name="settings_data_collection">Data Collection</string>
<string name="settings_orientation_title">Orientation</string>
Expand All @@ -60,8 +65,6 @@
<string name="settings_connection_overview_summary">En-/Disable the overview of recent connections in the Navigation Drawer</string>
<string name="settings_nightmode_title">Night Mode</string>
<string name="settings_nightmode_summary">Toggle the dark appearance of the app (logview excluded)</string>
<string name="settings_hide_topbar_title">Hide topbar</string>
<string name="settings_hide_topbar_summary">Hide the topbar of the log</string>
<string name="settings_analytics_title">Analytics Data Collection</string>
<string name="settings_analytics_summary">En-/Disable data collection via Firebase Analytics</string>
<string name="settings_crashlytics_title">Crashlytics Data Collection</string>
Expand Down
29 changes: 22 additions & 7 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,28 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<PreferenceCategory
android:title="@string/settings_openhab_log"
app:iconSpaceReserved="false">

<ListPreference
android:title="@string/settings_openhab_version_title"
android:summary="@string/settings_openhab_version_summary"
app:iconSpaceReserved="false"
android:defaultValue=""
android:entries="@array/openhab_versions"
android:entryValues="@array/openhab_versions_values"
android:key="openhab_version" />

<SwitchPreferenceCompat
android:title="@string/settings_hide_topbar_title"
android:summary="@string/settings_hide_topbar_summary"
app:iconSpaceReserved="false"
android:defaultValue="false"
android:key="hide_topbar" />

</PreferenceCategory>

<PreferenceCategory
android:title="@string/settings_user_experience"
app:iconSpaceReserved="false">
Expand Down Expand Up @@ -31,13 +53,6 @@
android:entryValues="@array/night_modes_values"
android:key="nightmode"/>

<SwitchPreferenceCompat
android:title="@string/settings_hide_topbar_title"
android:summary="@string/settings_hide_topbar_summary"
app:iconSpaceReserved="false"
android:defaultValue="false"
android:key="hide_topbar" />

</PreferenceCategory>

<PreferenceCategory
Expand Down

0 comments on commit 1a7fe3b

Please sign in to comment.