aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-12-22 01:51:43 -0500
committerGitHub <noreply@github.com>2017-12-22 01:51:43 -0500
commitbd96905dbfa6c1d4bde4257d61f381d4ee8e1fd0 (patch)
treee28732e64f6fc0bba715ae2b0a0383ea780d3a22 /app/src/main/kotlin/com/pitchedapps
parentbd99aebf4388515273dfd720eb5c59b6e45da44f (diff)
downloadfrost-bd96905dbfa6c1d4bde4257d61f381d4ee8e1fd0.tar.gz
frost-bd96905dbfa6c1d4bde4257d61f381d4ee8e1fd0.tar.bz2
frost-bd96905dbfa6c1d4bde4257d61f381d4ee8e1fd0.zip
Update webview components (#571)
* Add volume binding * Remove key override * Add pause timers to webview
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt11
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt12
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt26
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/HeadlessHtmlExtractor.kt9
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt2
5 files changed, 46 insertions, 14 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 4a9cbb55..80d248bc 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt
@@ -23,6 +23,7 @@ import android.view.Menu
import android.view.MenuItem
import android.webkit.ValueCallback
import android.webkit.WebChromeClient
+import android.webkit.WebView
import android.widget.FrameLayout
import ca.allanwang.kau.searchview.SearchItem
import ca.allanwang.kau.searchview.SearchView
@@ -92,6 +93,7 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
override var searchView: SearchView? = null
private val searchViewCache = mutableMapOf<String, List<SearchItem>>()
+ private lateinit var controlWebview: WebView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@@ -108,6 +110,7 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
"Frost id" to Prefs.frostId)
}
}
+ controlWebview = WebView(this)
setFrameContentView(Prefs.mainActivityLayout.layoutRes)
setSupportActionBar(toolbar)
adapter = SectionsPagerAdapter(supportFragmentManager, loadFbTabs())
@@ -333,6 +336,13 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
override fun onResume() {
super.onResume()
FbCookie.switchBackUser { }
+ controlWebview.resumeTimers()
+ }
+
+ override fun onPause() {
+ controlWebview.pauseTimers()
+ L.v("Pause main web timers")
+ super.onPause()
}
override fun onStart() {
@@ -345,6 +355,7 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
override fun onDestroy() {
onDestroyBilling()
+ controlWebview.destroy()
super.onDestroy()
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt
index 0dbbacbc..5b565d96 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt
@@ -208,7 +208,19 @@ open class WebOverlayActivityBase(private val forceBasicAgent: Boolean) : BaseAc
toolbar.overflowIcon?.setTint(Prefs.iconColor)
}
+ override fun onResume() {
+ super.onResume()
+ web.resumeTimers()
+ }
+
+ override fun onPause() {
+ web.pauseTimers()
+ L.v("Pause overlay web timers")
+ super.onPause()
+ }
+
override fun onDestroy() {
+ web.destroy()
super.onDestroy()
kauSwipeOnDestroy()
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt
index e6e1f0e2..0d04fcd9 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt
@@ -6,7 +6,7 @@ import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import android.view.View
-import android.view.animation.DecelerateInterpolator
+import ca.allanwang.kau.utils.AnimHolder
import com.pitchedapps.frost.contracts.FrostContentContainer
import com.pitchedapps.frost.contracts.FrostContentCore
import com.pitchedapps.frost.contracts.FrostContentParent
@@ -106,23 +106,29 @@ class FrostWebView @JvmOverloads constructor(
private fun scrollToTop() {
flingScroll(0, 0) // stop fling
- if (scrollY > 10000) {
+ if (scrollY > 10000)
scrollTo(0, 0)
- } else {
- ValueAnimator.ofInt(scrollY, 0).apply {
- duration = Math.min(scrollY, 500).toLong()
- interpolator = DecelerateInterpolator()
- addUpdateListener { scrollY = it.animatedValue as Int }
- start()
- }
+ else
+ smoothScrollTo(0)
+ }
+
+ private fun smoothScrollTo(y: Int) {
+ ValueAnimator.ofInt(scrollY, y).apply {
+ duration = Math.min(Math.abs(scrollY - y), 500).toLong()
+ interpolator = AnimHolder.fastOutSlowInInterpolator(context)
+ addUpdateListener { scrollY = it.animatedValue as Int }
+ start()
}
}
+ private fun smoothScrollBy(y: Int) = smoothScrollTo(Math.max(0, scrollY + y))
+
override var active: Boolean = true
set(value) {
if (field == value) return
field = value
- // todo
+ if (field) onResume()
+ else onPause()
}
override fun reloadTheme() {
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/HeadlessHtmlExtractor.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/HeadlessHtmlExtractor.kt
index 471731dd..2c7735a4 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/HeadlessHtmlExtractor.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/HeadlessHtmlExtractor.kt
@@ -29,8 +29,12 @@ import java.util.concurrent.TimeUnit
fun Context.launchHeadlessHtmlExtractor(url: String, injector: InjectorContract, action: (Single<Pair<String, Int>>) -> Unit) {
val single = Single.create<Pair<String, Int>> { e: SingleEmitter<Pair<String, Int>> ->
val extractor = HeadlessHtmlExtractor(this, url, injector, e)
+ extractor.resumeTimers()
e.setCancellable {
- runOnUiThread { extractor.destroy() }
+ runOnUiThread {
+ extractor.pauseTimers()
+ extractor.destroy()
+ }
e.onSuccess("" to R.string.html_extraction_cancelled)
}
}.subscribeOn(AndroidSchedulers.mainThread())
@@ -74,14 +78,13 @@ private class HeadlessHtmlExtractor(
emitter.onSuccess((html ?: "") to -1)
post {
L.d("HeadlessHtmlExtractor fetched $url in $time ms")
- settings.javaScriptEnabled = false
- settings.blockNetworkLoads = true
destroy()
}
}
}
override fun destroy() {
+ pauseTimers()
super.destroy()
L.d("HeadlessHtmlExtractor destroyed")
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt
index 3a10ed32..f8b487a2 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt
@@ -9,9 +9,9 @@ import android.webkit.*
import ca.allanwang.kau.utils.fadeIn
import ca.allanwang.kau.utils.isVisible
import com.pitchedapps.frost.dbflow.CookieModel
+import com.pitchedapps.frost.facebook.FB_LOGIN_URL
import com.pitchedapps.frost.facebook.FB_USER_MATCHER
import com.pitchedapps.frost.facebook.FbCookie
-import com.pitchedapps.frost.facebook.FB_LOGIN_URL
import com.pitchedapps.frost.injectors.CssHider
import com.pitchedapps.frost.injectors.jsInject
import com.pitchedapps.frost.utils.L