aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-12-21 02:16:34 -0500
committerGitHub <noreply@github.com>2017-12-21 02:16:34 -0500
commitd683cae6ffe644a9f63eea6cf3b7e59d2bde617b (patch)
tree517fe1d44c27084ccd87507d9804ba28f15c1647 /app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt
parent82f9aca96493316bc62008f2b3167d34a6029b38 (diff)
downloadfrost-d683cae6ffe644a9f63eea6cf3b7e59d2bde617b.tar.gz
frost-d683cae6ffe644a9f63eea6cf3b7e59d2bde617b.tar.bz2
frost-d683cae6ffe644a9f63eea6cf3b7e59d2bde617b.zip
Enhancement/fragment interface (#564)
* Begin fragment interfaces and themable contracts * Prepare swiperefresh interface * Snapshot * Add compilable version * Revamp once more * Finalize layouts * Cleanup
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt39
1 files changed, 16 insertions, 23 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt
index 6bdb459e..e8135f5b 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt
@@ -1,31 +1,24 @@
package com.pitchedapps.frost.web
-import android.content.Context
import android.support.v4.widget.SwipeRefreshLayout
import android.webkit.JavascriptInterface
import com.pitchedapps.frost.activities.MainActivity
import com.pitchedapps.frost.contracts.VideoViewHolder
-import com.pitchedapps.frost.dbflow.CookieModel
import com.pitchedapps.frost.facebook.FbCookie
import com.pitchedapps.frost.utils.*
+import com.pitchedapps.frost.views.FrostWebView
import io.reactivex.subjects.Subject
/**
* Created by Allan Wang on 2017-06-01.
*/
-class FrostJSI(val webView: FrostWebViewCore) {
+class FrostJSI(val web: FrostWebView) {
- val context: Context
- get() = webView.context
-
- val activity: MainActivity?
- get() = (context as? MainActivity)
-
- val headerObservable: Subject<String>? = activity?.headerBadgeObservable
-
- val cookies: ArrayList<CookieModel>
- get() = activity?.cookies() ?: arrayListOf()
+ private val context = web.context
+ private val activity = context as? MainActivity
+ private val header: Subject<String>? = activity?.headerBadgeObservable
+ private val cookies = activity?.cookies() ?: arrayListOf()
/**
* Attempts to load the url in an overlay
@@ -34,12 +27,12 @@ class FrostJSI(val webView: FrostWebViewCore) {
*/
@JavascriptInterface
fun loadUrl(url: String?): Boolean
- = if (url == null) false else webView.requestWebOverlay(url)
+ = if (url == null) false else web.requestWebOverlay(url)
@JavascriptInterface
fun loadVideo(url: String?, isGif: Boolean) {
if (url != null)
- webView.post {
+ web.post {
(context as? VideoViewHolder)?.showVideo(url, isGif)
?: L.d("Could not load video; contract not implemented")
}
@@ -48,9 +41,9 @@ class FrostJSI(val webView: FrostWebViewCore) {
@JavascriptInterface
fun reloadBaseUrl(animate: Boolean) {
L.d("FrostJSI reload")
- webView.post {
- webView.stopLoading()
- webView.loadBaseUrl(animate)
+ web.post {
+ web.stopLoading()
+ web.reloadBase(animate)
}
}
@@ -58,7 +51,7 @@ class FrostJSI(val webView: FrostWebViewCore) {
fun contextMenu(url: String, text: String?) {
if (!text.isIndependent) return
//url will be formatted through webcontext
- webView.post { context.showWebContextMenu(WebContext(url, text)) }
+ web.post { context.showWebContextMenu(WebContext(url, text)) }
}
/**
@@ -75,7 +68,7 @@ class FrostJSI(val webView: FrostWebViewCore) {
*/
@JavascriptInterface
fun disableSwipeRefresh(disable: Boolean) {
- webView.post { (webView.parent as? SwipeRefreshLayout)?.isEnabled = !disable }
+ web.post { (web.parent as? SwipeRefreshLayout)?.isEnabled = !disable }
}
@JavascriptInterface
@@ -93,19 +86,19 @@ class FrostJSI(val webView: FrostWebViewCore) {
@JavascriptInterface
fun emit(flag: Int) {
- webView.post { webView.frostWebClient.emit(flag) }
+ web.post { web.frostWebClient.emit(flag) }
}
@JavascriptInterface
fun handleHtml(html: String?) {
html ?: return
- webView.post { webView.frostWebClient.handleHtml(html) }
+ web.post { web.frostWebClient.handleHtml(html) }
}
@JavascriptInterface
fun handleHeader(html: String?) {
html ?: return
- headerObservable?.onNext(html)
+ header?.onNext(html)
}
} \ No newline at end of file