From ee4f2eab359b83618d314ded2fa3d442c280bbfa Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sun, 11 Mar 2018 21:23:29 -0400 Subject: [PATCH] Enhancement/auto refresh (#780) * Add auto refresh * Update changelog * Clean url queries * Do not discard h --- .../com/pitchedapps/frost/activities/BaseMainActivity.kt | 8 ++++++++ .../com/pitchedapps/frost/facebook/FbUrlFormatter.kt | 2 +- .../com/pitchedapps/frost/fragments/FragmentBase.kt | 3 ++- app/src/main/kotlin/com/pitchedapps/frost/utils/Const.kt | 4 +++- app/src/main/res/xml/frost_changelog.xml | 5 +++-- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt index 02f9134cd..809e8a565 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt @@ -91,6 +91,7 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract, override var videoViewer: FrostVideoViewer? = null private lateinit var drawer: Drawer private lateinit var drawerHeader: AccountHeader + private var lastAccessTime = -1L override var searchView: SearchView? = null private val searchViewCache = mutableMapOf>() @@ -131,6 +132,7 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract, setupDrawer(savedInstanceState) L.i { "Main started in ${System.currentTimeMillis() - start} ms" } initFab() + lastAccessTime = System.currentTimeMillis() } /** @@ -301,6 +303,7 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract, } private fun refreshAll() { + L.d { "Refresh all" } fragmentSubject.onNext(REQUEST_REFRESH) } @@ -403,11 +406,16 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract, super.onResume() FbCookie.switchBackUser {} controlWebview?.resumeTimers() + if (System.currentTimeMillis() - lastAccessTime > MAIN_TIMEOUT_DURATION) { + refreshAll() + } + lastAccessTime = System.currentTimeMillis() // precaution to avoid loops } override fun onPause() { controlWebview?.pauseTimers() L.v { "Pause main web timers" } + lastAccessTime = System.currentTimeMillis() super.onPause() } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt index cbb6087a8..4386d0c98 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt @@ -103,7 +103,7 @@ class FbUrlFormatter(url: String) { val misc = arrayOf("&" to "&") - val discardableQueries = arrayOf("ref", "refid") + val discardableQueries = arrayOf("ref", "refid", "acontext", "SharedWith") val converter = listOf( "\\3C " to "%3C", "\\3E " to "%3E", "\\23 " to "%23", "\\25 " to "%25", diff --git a/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt b/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt index b77847dec..a644e966e 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt @@ -117,8 +117,9 @@ abstract class BaseFragment : Fragment(), FragmentContract, DynamicUiContract { when (it) { REQUEST_REFRESH -> { core?.apply { - reload(true) clearHistory() + firstLoad = true + firstLoadRequest() } } position -> { diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Const.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Const.kt index 61ba4a09d..0cb57ed50 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Const.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Const.kt @@ -13,4 +13,6 @@ const val REQUEST_RESTART = 1 shl 12 const val REQUEST_REFRESH = 1 shl 13 const val REQUEST_TEXT_ZOOM = 1 shl 14 const val REQUEST_NAV = 1 shl 15 -const val REQUEST_SEARCH = 1 shl 16 \ No newline at end of file +const val REQUEST_SEARCH = 1 shl 16 + +const val MAIN_TIMEOUT_DURATION = 30 * 60 * 1000 // 30 min \ No newline at end of file diff --git a/app/src/main/res/xml/frost_changelog.xml b/app/src/main/res/xml/frost_changelog.xml index 674619606..2b343ba5d 100644 --- a/app/src/main/res/xml/frost_changelog.xml +++ b/app/src/main/res/xml/frost_changelog.xml @@ -9,8 +9,9 @@ - - + + +