aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-07-16 17:26:58 -0700
committerGitHub <noreply@github.com>2017-07-16 17:26:58 -0700
commitd90cb9b61cd2e033b46f4780ad1340c5f35b7751 (patch)
tree0294ce22bacb463c9cc95de8dc5581c1bd59a108 /app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt
parentc3f1fc6a8b3216442a018bb04843dfa68d738918 (diff)
downloadfrost-d90cb9b61cd2e033b46f4780ad1340c5f35b7751.tar.gz
frost-d90cb9b61cd2e033b46f4780ad1340c5f35b7751.tar.bz2
frost-d90cb9b61cd2e033b46f4780ad1340c5f35b7751.zip
Add image viewing and downloading (#63)v1.3
* Commence aggressive image caching * Add glide toggle and css url parsing * Add image hook and refractor activities * Update version analytics * Implemented imageactivity but glide will not load * Create working image loader * Finalize image view * Finalize image view logic * Remove custom cache experiment
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.kt31
1 files changed, 23 insertions, 8 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 3340e7d2..3f976fb8 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt
@@ -2,8 +2,9 @@ package com.pitchedapps.frost.web
import android.content.Context
import android.webkit.JavascriptInterface
-import ca.allanwang.kau.logging.KL
-import com.pitchedapps.frost.MainActivity
+import ca.allanwang.kau.utils.startActivity
+import com.pitchedapps.frost.activities.ImageActivity
+import com.pitchedapps.frost.activities.MainActivity
import com.pitchedapps.frost.dbflow.CookieModel
import com.pitchedapps.frost.facebook.formattedFbUrl
import com.pitchedapps.frost.utils.*
@@ -13,12 +14,18 @@ import io.reactivex.subjects.Subject
/**
* Created by Allan Wang on 2017-06-01.
*/
-class FrostJSI(val context: Context, val webView: FrostWebViewCore) {
+class FrostJSI(val webView: FrostWebViewCore) {
- val headerObservable: Subject<String>? = (context as? MainActivity)?.headerBadgeObservable
+ val context: Context
+ get() = webView.context
+
+ val activity: MainActivity?
+ get() = (context as? MainActivity)
+
+ val headerObservable: Subject<String>? = activity?.headerBadgeObservable
val cookies: ArrayList<CookieModel>
- get() = (context as? MainActivity)?.cookies() ?: arrayListOf()
+ get() = activity?.cookies() ?: arrayListOf()
@JavascriptInterface
fun loadUrl(url: String) {
@@ -35,8 +42,8 @@ class FrostJSI(val context: Context, val webView: FrostWebViewCore) {
}
@JavascriptInterface
- fun contextMenu(url: String, text: String) {
- webView.post { webView.context.showWebContextMenu(WebContext(url.formattedFbUrl, text)) }
+ fun contextMenu(url: String, text: String?) {
+ webView.post { context.showWebContextMenu(WebContext(url.formattedFbUrl, text)) }
}
/**
@@ -45,7 +52,7 @@ class FrostJSI(val context: Context, val webView: FrostWebViewCore) {
*/
@JavascriptInterface
fun longClick(start: Boolean) {
- (webView.context as? MainActivity)?.viewPager?.enableSwipe = !start
+ activity?.viewPager?.enableSwipe = !start
}
@JavascriptInterface
@@ -53,6 +60,14 @@ class FrostJSI(val context: Context, val webView: FrostWebViewCore) {
context.launchLogin(cookies, true)
}
+ /**
+ * Launch image overlay
+ */
+ @JavascriptInterface
+ fun loadImage(imageUrl: String, text: String?) {
+ context.launchImageActivity(imageUrl, text)
+ }
+
@JavascriptInterface
fun emit(flag: Int) {
webView.post { webView.frostWebClient.emit(flag) }