aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/web
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/web')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClients.kt2
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt12
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt8
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt2
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt78
5 files changed, 47 insertions, 55 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClients.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClients.kt
index 343674d5..6bc27256 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClients.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClients.kt
@@ -70,4 +70,6 @@ class FrostChromeClient(webCore: FrostWebViewCore) : WebChromeClient() {
callback(origin, granted, true)
}
}
+
+
} \ No newline at end of file
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 1679d7a3..79ca1fdf 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt
@@ -9,15 +9,12 @@ import android.util.AttributeSet
import android.view.View
import android.widget.FrameLayout
import android.widget.ProgressBar
-import ca.allanwang.kau.utils.bindView
-import ca.allanwang.kau.utils.tint
-import ca.allanwang.kau.utils.visible
-import ca.allanwang.kau.utils.withAlpha
+import ca.allanwang.kau.utils.*
import com.pitchedapps.frost.R
import com.pitchedapps.frost.facebook.FbTab
import com.pitchedapps.frost.facebook.USER_AGENT_BASIC
-import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.Prefs
+import com.pitchedapps.frost.utils.frostDownload
import io.reactivex.android.schedulers.AndroidSchedulers
/**
@@ -37,7 +34,7 @@ class FrostWebView @JvmOverloads constructor(
refresh.setColorSchemeColors(Prefs.iconColor)
refresh.setProgressBackgroundColorSchemeColor(Prefs.headerColor.withAlpha(255))
web.progressObservable.observeOn(AndroidSchedulers.mainThread()).subscribe {
- progress.visibility = if (it == 100) View.INVISIBLE else View.VISIBLE
+ progress.invisibleIf(it == 100)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) progress.setProgress(it, true)
else progress.progress = it
}
@@ -62,7 +59,7 @@ class FrostWebView @JvmOverloads constructor(
baseEnum = enum
with(settings) {
javaScriptEnabled = true
- if (url.contains("/message"))
+ if (url.contains("facebook.com/message"))
userAgentString = USER_AGENT_BASIC
allowFileAccess = true
textZoom = Prefs.webTextScaling
@@ -73,6 +70,7 @@ class FrostWebView @JvmOverloads constructor(
webChromeClient = FrostChromeClient(this)
addJavascriptInterface(FrostJSI(this), "Frost")
setBackgroundColor(Color.TRANSPARENT)
+ setDownloadListener { downloadUrl, _, _, _, _ -> context.frostDownload(downloadUrl) }
}
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt
index 9f7dd916..94bff3c3 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt
@@ -132,13 +132,7 @@ open class FrostWebViewClient(val webCore: FrostWebViewCore) : BaseWebViewClient
if (path.startsWith("/composer/")) return launchRequest(request)
if (request.url.toString().contains("scontent-sea1-1.xx.fbcdn.net") && (path.endsWith(".jpg") || path.endsWith(".png")))
return launchImage(request)
- if (!request.url.toString().contains(FACEBOOK_COM)) {
- val intent = Intent(Intent.ACTION_VIEW, request.url)
- if (intent.resolveActivity(view.context.packageManager) != null) {
- view.context.startActivity(Intent(Intent.ACTION_VIEW, request.url))
- return true
- }
- }
+ if (view.context.resolveActivityForUri(request.url)) return true
return super.shouldOverrideUrlLoading(view, request)
}
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 d96fba55..d8edc15c 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt
@@ -1,6 +1,7 @@
package com.pitchedapps.frost.web
import android.animation.ValueAnimator
+import android.annotation.SuppressLint
import android.content.Context
import android.support.v4.view.NestedScrollingChild
import android.support.v4.view.NestedScrollingChildHelper
@@ -94,6 +95,7 @@ class FrostWebViewCore @JvmOverloads constructor(
*
* https://github.com/takahirom/webview-in-coordinatorlayout/blob/master/app/src/main/java/com/github/takahirom/webview_in_coodinator_layout/NestedWebView.java
*/
+ @SuppressLint("ClickableViewAccessibility")
override fun onTouchEvent(ev: MotionEvent): Boolean {
val event = MotionEvent.obtain(ev)
val action = event.action
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 b178f66c..31be4450 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt
@@ -4,23 +4,19 @@ import android.annotation.SuppressLint
import android.content.Context
import android.util.AttributeSet
import android.view.View
-import android.webkit.ConsoleMessage
-import android.webkit.CookieManager
-import android.webkit.WebChromeClient
-import android.webkit.WebView
+import android.webkit.*
import ca.allanwang.kau.utils.fadeIn
-import com.pitchedapps.frost.R
+import ca.allanwang.kau.utils.isVisible
import com.pitchedapps.frost.dbflow.CookieModel
import com.pitchedapps.frost.facebook.FACEBOOK_COM
+import com.pitchedapps.frost.facebook.FB_URL_BASE
import com.pitchedapps.frost.facebook.FbCookie
import com.pitchedapps.frost.injectors.CssHider
import com.pitchedapps.frost.injectors.jsInject
import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.Prefs
-import com.pitchedapps.frost.utils.frostSnackbar
-import io.reactivex.subjects.PublishSubject
-import io.reactivex.subjects.SingleSubject
-import io.reactivex.subjects.Subject
+import org.jetbrains.anko.doAsync
+import org.jetbrains.anko.uiThread
/**
* Created by Allan Wang on 2017-05-29.
@@ -30,27 +26,15 @@ class LoginWebView @JvmOverloads constructor(
) : WebView(context, attrs, defStyleAttr) {
companion object {
- const val LOGIN_URL = "https://touch.facebook.com/login"
- private val userMatcher: Regex by lazy { Regex("c_user=([0-9]*);") }
+ const val LOGIN_URL = "${FB_URL_BASE}login"
+ private val userMatcher: Regex = Regex("c_user=([0-9]*);")
}
- val cookieObservable = PublishSubject.create<Pair<String, String?>>()
- lateinit var loginObservable: SingleSubject<CookieModel>
- lateinit var progressObservable: Subject<Int>
+ private lateinit var loginCallback: (CookieModel) -> Unit
+ private lateinit var progressCallback: (Int) -> Unit
init {
- FbCookie.reset({
- cookieObservable.filter { (_, cookie) -> cookie?.contains(userMatcher) ?: false }
- .subscribe {
- (url, cookie) ->
- L.d("Checking cookie for login", "$url\n\t$cookie")
- val id = userMatcher.find(cookie!!)?.groups?.get(1)?.value!!
- FbCookie.save(id.toLong())
- cookieObservable.onComplete()
- loginObservable.onSuccess(CookieModel(id.toLong(), "", cookie))
- }
- setupWebview()
- })
+ FbCookie.reset { setupWebview() }
}
@SuppressLint("SetJavaScriptEnabled")
@@ -61,27 +45,39 @@ class LoginWebView @JvmOverloads constructor(
webChromeClient = LoginChromeClient()
}
- fun loadLogin() {
+ fun loadLogin(progressCallback: (Int) -> Unit, loginCallback: (CookieModel) -> Unit) {
+ this.progressCallback = progressCallback
+ this.loginCallback = loginCallback
loadUrl(LOGIN_URL)
}
-
- inner class LoginClient : BaseWebViewClient() {
+ private inner class LoginClient : BaseWebViewClient() {
override fun onPageFinished(view: WebView, url: String?) {
super.onPageFinished(view, url)
- if (url == null || !url.contains(FACEBOOK_COM)) {
- view.frostSnackbar(R.string.no_longer_facebook)
- loadLogin()
- return
+ val containsFacebook = url?.contains(FACEBOOK_COM) ?: false
+ checkForLogin(url) { id, cookie -> loginCallback(CookieModel(id, "", cookie)) }
+ view.jsInject(CssHider.HEADER.maybe(containsFacebook),
+ CssHider.CORE.maybe(containsFacebook),
+ Prefs.themeInjector.maybe(containsFacebook),
+ callback = { if (!view.isVisible) view.fadeIn(offset = 150L) })
+ }
+
+ fun checkForLogin(url: String?, onFound: (id: Long, cookie: String) -> Unit) {
+ doAsync {
+ if (url == null || !url.contains(FACEBOOK_COM)) return@doAsync
+ val cookie = CookieManager.getInstance().getCookie(url) ?: return@doAsync
+ L.d("Checking cookie for login", cookie)
+ val id = userMatcher.find(cookie)?.groups?.get(1)?.value?.toLong() ?: return@doAsync
+ uiThread { onFound(id, cookie) }
}
- cookieObservable.onNext(Pair(url, CookieManager.getInstance().getCookie(url)))
- view.jsInject(CssHider.HEADER, CssHider.CORE,
- Prefs.themeInjector,
- callback = {
- if (view.visibility != View.VISIBLE)
- view.fadeIn(offset = 150L)
- })
+ }
+
+ override fun shouldOverrideUrlLoading(view: WebView, request: WebResourceRequest): Boolean {
+ //For now, we will ignore all attempts to launch external apps during login
+ if (request.url == null || request.url.scheme == "intent" || request.url.scheme == "android-app")
+ return true
+ return super.shouldOverrideUrlLoading(view, request)
}
}
@@ -93,7 +89,7 @@ class LoginWebView @JvmOverloads constructor(
override fun onProgressChanged(view: WebView, newProgress: Int) {
super.onProgressChanged(view, newProgress)
- progressObservable.onNext(newProgress)
+ progressCallback(newProgress)
}
}
} \ No newline at end of file