diff --git a/WallPanelApp/build.gradle b/WallPanelApp/build.gradle index 335f49a..e78286a 100644 --- a/WallPanelApp/build.gradle +++ b/WallPanelApp/build.gradle @@ -25,7 +25,7 @@ apply plugin: 'com.google.firebase.crashlytics' def versionMajor = 0 def versionMinor = 9 def versionPatch = 5 -def versionBuild = 4 // bump for dog food builds, public betas, etc. +def versionBuild = 5 // bump for dog food builds, public betas, etc. def CODE() { Properties properties = new Properties() diff --git a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/persistence/Configuration.kt b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/persistence/Configuration.kt index 39b7bf1..f04ff23 100644 --- a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/persistence/Configuration.kt +++ b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/persistence/Configuration.kt @@ -252,6 +252,12 @@ constructor(private val context: Context, private val sharedPreferences: SharedP settingsUpdated() } + var browserRefreshDisconnect: Boolean + get() = this.sharedPreferences.getBoolean(PREF_BROWSER_REFRESH_DISCONNECT, true) + set(value) { + sharedPreferences.edit().putBoolean(PREF_BROWSER_REFRESH_DISCONNECT, value).apply() + } + var browserRefresh: Boolean get() = this.sharedPreferences.getBoolean(context.getString(R.string.key_pref_browser_refresh), true) set(value) { @@ -380,6 +386,7 @@ constructor(private val context: Context, private val sharedPreferences: SharedP const val PREF_WRITE_SCREEN_PERMISSIONS = "pref_write_screen_permissions" const val PREF_CAMERA_PERMISSIONS = "pref_camera_permissions" const val PREF_CAMERA_ROTATE = "pref_camera_rotate" + const val PREF_BROWSER_REFRESH_DISCONNECT = "pref_browser_refresh_disconnect" const val PREF_SCREEN_BRIGHTNESS = "pref_use_screen_brightness" const val PREF_SCREENSAVER_DIM_VALUE = "pref_screensaver_dim_value" private val ROTATE_TIME_IN_MINUTES = 15 diff --git a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/ui/activities/BrowserActivityNative.kt b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/ui/activities/BrowserActivityNative.kt index e8d6aae..89da355 100644 --- a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/ui/activities/BrowserActivityNative.kt +++ b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/ui/activities/BrowserActivityNative.kt @@ -58,8 +58,9 @@ class BrowserActivityNative : BaseBrowserActivity(), LifecycleObserver { private val calendar: Calendar = Calendar.getInstance() private val reconnectionHandler = Handler() private var connectionLiveData: ConnectionLiveData? = null - private var isConnected = false + private var isConnected = true private var webkitPermissionRequest: PermissionRequest? = null + private var awaitingReconnect = false // To save current index private var playlistIndex = 0 @@ -113,11 +114,16 @@ class BrowserActivityNative : BaseBrowserActivity(), LifecycleObserver { } connectionLiveData = ConnectionLiveData(this) - connectionLiveData?.observe(this, androidx.lifecycle.Observer { connected -> - if (connected!! && isConnected.not()) { + connectionLiveData?.observe(this, { connected -> + if (connected && isConnected.not()) { isConnected = true - initWebPageLoad() - } else { + if(awaitingReconnect) { // reload the page if there was error initially loading page due to network disconnect + stopReloadDelay() + initWebPageLoad() + } else if(configuration.browserRefreshDisconnect) { // reload page on network reconnect + initWebPageLoad() + } + } else if (connected.not()) { isConnected = false } }) @@ -188,7 +194,7 @@ class BrowserActivityNative : BaseBrowserActivity(), LifecycleObserver { override fun onReceivedError(view: WebView, errorCode: Int, description: String, failingUrl: String) { if (!isFinishing) { view.loadUrl("about:blank") - view.loadUrl("file:///android_asset/error_page.html"); + view.loadUrl("file:///android_asset/error_page.html") isConnected = false startReloadDelay() } @@ -381,11 +387,13 @@ class BrowserActivityNative : BaseBrowserActivity(), LifecycleObserver { } private fun startReloadDelay() { + awaitingReconnect = true playlistHandler?.removeCallbacksAndMessages(null) reconnectionHandler.postDelayed(reloadPageRunnable, 30000) } private fun stopReloadDelay() { + awaitingReconnect = false reconnectionHandler.removeCallbacks(reloadPageRunnable) } diff --git a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/ui/fragments/SettingsFragment.kt b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/ui/fragments/SettingsFragment.kt index 29d9e71..14da6ed 100644 --- a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/ui/fragments/SettingsFragment.kt +++ b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/ui/fragments/SettingsFragment.kt @@ -74,6 +74,7 @@ class SettingsFragment : BaseSettingsFragment() { private var aboutPreference: Preference? = null private var brightnessPreference: Preference? = null private var browserRefreshPreference: SwitchPreference? = null + private var clockSaverPreference: SwitchPreference? = null private var inactivityPreference: ListPreference? = null private var screenBrightness: SwitchPreference? = null @@ -88,6 +89,10 @@ class SettingsFragment : BaseSettingsFragment() { findPreference(PREF_SETTINGS_BUTTON_TRANSPARENT) as SwitchPreference } + private val browserRefreshOnDisconnect: SwitchPreference by lazy { + findPreference(PREF_SETTINGS_REFRESH_ON_DISCONNECT) as SwitchPreference + } + private val settingsDisablePreference: SwitchPreference by lazy { findPreference(PREF_SETTINGS_BUTTON_DISABLE) as SwitchPreference } @@ -191,6 +196,7 @@ class SettingsFragment : BaseSettingsFragment() { screenBrightness = findPreference(PREF_SCREEN_BRIGHTNESS) as SwitchPreference ignoreSSLErrorsPreference = findPreference(getString(R.string.key_setting_ignore_ssl_errors)) as SwitchPreference + browserRefreshOnDisconnect.isChecked = configuration.browserRefreshDisconnect fullScreenPreference.isChecked = configuration.fullScreen settingsTransparentPreference.isChecked = configuration.settingsTransparent settingsDisablePreference.isChecked = configuration.settingsDisabled @@ -389,6 +395,10 @@ class SettingsFragment : BaseSettingsFragment() { configuration.hasScreenSaverWallpaper = value setWallPaperScreensaver(value) } + PREF_SETTINGS_REFRESH_ON_DISCONNECT -> { + val value = browserRefreshOnDisconnect.isChecked + configuration.browserRefreshDisconnect = value + } PREF_SETTINGS_WEB_SCREENSAVER -> { val value = webScreenSaver.isChecked configuration.webScreenSaver = value @@ -536,13 +546,13 @@ class SettingsFragment : BaseSettingsFragment() { const val PREF_SCREEN_INACTIVITY_TIME = "pref_screensaver_inactivity_time" const val PREF_SETTINGS_FULL_SCREEN = "pref_settings_fullscreen" const val PREF_SETTINGS_BUTTON_TRANSPARENT = "pref_settings_button_transparent" + const val PREF_SETTINGS_REFRESH_ON_DISCONNECT = "pref_settings_refresh_on_disconnect" const val PREF_SETTINGS_BUTTON_DISABLE = "pref_settings_button_disable" const val PREF_SETTINGS_BUTTON_LOCATION = "pref_settings_button_location" const val PREF_SETTINGS_THEME = "pref_settings_theme" const val PREF_SETTINGS_DASHBOARD_URL = "pref_settings_dashboard_url" const val PREF_SETTINGS_USER_AGENT = "pref_settings_user_agent" const val PREF_SETTINGS_SCREENSAVER_DIM = "settings_screensaver_dim" - const val PREF_SETTINGS_SCREENSAVER_BLANK = "settings_screensaver_blank" const val PREF_SETTINGS_WEB_SCREENSAVER = "settings_screensaver_web" const val PREF_SETTINGS_WEB_SCREENSAVER_URL = "settings_screensaver_web_url" } diff --git a/WallPanelApp/src/main/res/xml/pref_general.xml b/WallPanelApp/src/main/res/xml/pref_general.xml index 0ca50ad..25cbb02 100644 --- a/WallPanelApp/src/main/res/xml/pref_general.xml +++ b/WallPanelApp/src/main/res/xml/pref_general.xml @@ -51,6 +51,12 @@ android:summary="@string/pref_browser_refresh_summary" android:title="@string/pref_browser_refresh_title"/> + +