aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/web
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-06-13 00:42:31 -0700
committerAllan Wang <me@allanwang.ca>2017-06-13 00:42:31 -0700
commite4377fed20ce1e3f4a0b236271eecdb1fe573b7a (patch)
treeaa0b14e328daa4ece41f65cfed5a4422f2c9e898 /app/src/main/kotlin/com/pitchedapps/frost/web
parenta7a37f8f5b1955f006a83d4713a2c6af500c28af (diff)
downloadfrost-e4377fed20ce1e3f4a0b236271eecdb1fe573b7a.tar.gz
frost-e4377fed20ce1e3f4a0b236271eecdb1fe573b7a.tar.bz2
frost-e4377fed20ce1e3f4a0b236271eecdb1fe573b7a.zip
Created js base for facebook menu
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/web')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClient.kt2
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt15
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt18
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt10
4 files changed, 24 insertions, 21 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClient.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClient.kt
index 7ad12c3a..720026e6 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClient.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClient.kt
@@ -13,7 +13,7 @@ import io.reactivex.subjects.Subject
class FrostChromeClient(val progressObservable: Subject<Int>, val titleObservable: BehaviorSubject<String>) : WebChromeClient() {
override fun onConsoleMessage(consoleMessage: ConsoleMessage): Boolean {
- L.v("Chrome Console ${consoleMessage.lineNumber()}: ${consoleMessage.message()}")
+ L.i("Chrome Console ${consoleMessage.lineNumber()}: ${consoleMessage.message()}")
return super.onConsoleMessage(consoleMessage)
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt
index d4bf8e07..4554e0a4 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt
@@ -7,9 +7,9 @@ import android.util.AttributeSet
import android.view.View
import android.widget.FrameLayout
import android.widget.ProgressBar
-import butterknife.ButterKnife
-import com.pitchedapps.frost.R
import ca.allanwang.kau.utils.bindView
+import com.pitchedapps.frost.R
+import com.pitchedapps.frost.facebook.FbTab
import io.reactivex.android.schedulers.AndroidSchedulers
/**
@@ -17,11 +17,6 @@ import io.reactivex.android.schedulers.AndroidSchedulers
*/
class FrostWebView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0, defStyleRes: Int = 0)
: FrameLayout(context, attrs, defStyleAttr, defStyleRes), SwipeRefreshLayout.OnRefreshListener {
- var baseUrl: String?
- get() = web.baseUrl
- set(value) {
- web.baseUrl = value
- }
val refresh: SwipeRefreshLayout by bindView(R.id.swipe_refresh)
val web: FrostWebViewCore by bindView(R.id.frost_webview_core)
val progress: ProgressBar by bindView(R.id.progressBar)
@@ -46,8 +41,12 @@ class FrostWebView @JvmOverloads constructor(context: Context, attrs: AttributeS
})
}
+ //Some urls have javascript injections so make sure we load the base url
override fun onRefresh() {
- web.reload()
+ when (web.baseUrl) {
+ FbTab.MENU.url -> web.loadBaseUrl()
+ else -> web.reload()
+ }
}
fun onBackPressed(): Boolean {
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt
index 922d527b..28048a1d 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt
@@ -24,15 +24,6 @@ import io.reactivex.subjects.Subject
*/
class FrostWebViewClient(val refreshObservable: Subject<Boolean>) : WebViewClient() {
- companion object {
- //Collections of jewels mapped with url match -> id
- val jewelMap: Map<String, String> = mapOf("a" to "b")
-
- fun test() {
-
- }
- }
-
override fun onPageStarted(view: WebView, url: String, favicon: Bitmap?) {
super.onPageStarted(view, url, favicon)
L.i("FWV Loading $url")
@@ -55,6 +46,15 @@ class FrostWebViewClient(val refreshObservable: Subject<Boolean>) : WebViewClien
super.onPageFinished(view, url)
refreshObservable.onNext(false)
if (!url.contains(FACEBOOK_COM)) return
+ L.i("Page finished $url")
+ with(view as FrostWebViewCore) {
+ if (url == view.baseUrl && view.baseJavascript != null) {
+ L.i("Base inject ${view.baseJavascript!!.name}")
+ view.baseJavascript!!.inject(view, {
+ L.i("Base injection done")
+ })
+ }
+ }
JsActions.LOGIN_CHECK.inject(view)
CssAssets.HEADER.inject(view, {
view.circularReveal(offset = 150L)
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt
index 1d3f348a..f0596f7c 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt
@@ -12,6 +12,7 @@ import android.view.View
import android.view.animation.DecelerateInterpolator
import android.webkit.WebView
import com.pitchedapps.frost.facebook.USER_AGENT_BASIC
+import com.pitchedapps.frost.injectors.JsAssets
import io.reactivex.Scheduler
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
@@ -38,6 +39,7 @@ class FrostWebViewCore @JvmOverloads constructor(
val titleObservable: BehaviorSubject<String> // Only emits on different non http titles
var baseUrl: String? = null
+ var baseJavascript: JsAssets? = null
init {
isNestedScrollingEnabled = true
@@ -53,8 +55,8 @@ class FrostWebViewCore @JvmOverloads constructor(
settings.userAgentString = USER_AGENT_BASIC
// settings.domStorageEnabled = true
setLayerType(View.LAYER_TYPE_HARDWARE, null)
- setWebViewClient(FrostWebViewClient(refreshObservable))
- setWebChromeClient(FrostChromeClient(progressObservable, titleObservable))
+ webViewClient = FrostWebViewClient(refreshObservable)
+ webChromeClient = FrostChromeClient(progressObservable, titleObservable)
addJavascriptInterface(FrostJSI(context), "Frost")
}
@@ -63,7 +65,9 @@ class FrostWebViewCore @JvmOverloads constructor(
super.loadUrl(url)
}
- fun loadBaseUrl() = loadUrl(baseUrl)
+ fun loadBaseUrl() {
+ loadUrl(baseUrl)
+ }
fun addTitleListener(subscriber: (title: String) -> Unit, scheduler: Scheduler = AndroidSchedulers.mainThread()): Disposable
= titleObservable.observeOn(scheduler).subscribe(subscriber)