Skip to content

Commit

Permalink
* update for browser refresh on network issue
Browse files Browse the repository at this point in the history
* new setting to turn off browser refresh on disconnect
  • Loading branch information
thanksmister committed Jun 20, 2021
1 parent b72f983 commit f79d471
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 8 deletions.
2 changes: 1 addition & 1 deletion WallPanelApp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
})
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -88,6 +89,10 @@ class SettingsFragment : BaseSettingsFragment() {
findPreference<SwitchPreference>(PREF_SETTINGS_BUTTON_TRANSPARENT) as SwitchPreference
}

private val browserRefreshOnDisconnect: SwitchPreference by lazy {
findPreference<SwitchPreference>(PREF_SETTINGS_REFRESH_ON_DISCONNECT) as SwitchPreference
}

private val settingsDisablePreference: SwitchPreference by lazy {
findPreference<SwitchPreference>(PREF_SETTINGS_BUTTON_DISABLE) as SwitchPreference
}
Expand Down Expand Up @@ -191,6 +196,7 @@ class SettingsFragment : BaseSettingsFragment() {
screenBrightness = findPreference<SwitchPreference>(PREF_SCREEN_BRIGHTNESS) as SwitchPreference
ignoreSSLErrorsPreference = findPreference<SwitchPreference>(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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
}
Expand Down
6 changes: 6 additions & 0 deletions WallPanelApp/src/main/res/xml/pref_general.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@
android:summary="@string/pref_browser_refresh_summary"
android:title="@string/pref_browser_refresh_title"/>

<SwitchPreference
android:defaultValue="true"
android:key="pref_settings_refresh_on_disconnect"
android:summary="Refreshes the dashboard on network disconnect."
android:title="Network Disconnect" />

<EditTextPreference
android:defaultValue="@string/default_browser_user_agent"
android:summary="@string/pref_user_agent_summary"
Expand Down

0 comments on commit f79d471

Please sign in to comment.