aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/web
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-12-21 20:55:51 -0500
committerGitHub <noreply@github.com>2017-12-21 20:55:51 -0500
commitf1e1aec8487fd148eb8e75fe016a8438958989ad (patch)
treec4d614e6a3e7d6ef9fa7c04452c357d06bc50279 /app/src/main/kotlin/com/pitchedapps/frost/web
parentd683cae6ffe644a9f63eea6cf3b7e59d2bde617b (diff)
downloadfrost-f1e1aec8487fd148eb8e75fe016a8438958989ad.tar.gz
frost-f1e1aec8487fd148eb8e75fe016a8438958989ad.tar.bz2
frost-f1e1aec8487fd148eb8e75fe016a8438958989ad.zip
misc (#566)
* Fix click validator * Update tests * Feature/fb requests (#567) * Add initial requesting interface * Update unit tests and dependencies * Resolve lint * Fix lint 2 * Fix toolbar location, closes #439 * Add prev version code, closes #551 * Clear test val * Update changelog
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/web')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt3
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt38
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt12
3 files changed, 12 insertions, 41 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 e8135f5b..b567801b 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt
@@ -1,6 +1,5 @@
package com.pitchedapps.frost.web
-import android.support.v4.widget.SwipeRefreshLayout
import android.webkit.JavascriptInterface
import com.pitchedapps.frost.activities.MainActivity
import com.pitchedapps.frost.contracts.VideoViewHolder
@@ -68,7 +67,7 @@ class FrostJSI(val web: FrostWebView) {
*/
@JavascriptInterface
fun disableSwipeRefresh(disable: Boolean) {
- web.post { (web.parent as? SwipeRefreshLayout)?.isEnabled = !disable }
+ web.post { web.parent.swipeEnabled = !disable }
}
@JavascriptInterface
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt
index 9255b5bb..253d4801 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt
@@ -29,15 +29,16 @@ import org.jetbrains.anko.runOnUiThread
* as we have no need of sending a new intent to the same activity
*/
fun FrostWebView.requestWebOverlay(url: String): Boolean {
- if (url == "#" || !url.isIndependent) {
- L.i("Forbid overlay switch", url)
- return false
- }
+ val context = context // finalize reference
if (url.isVideoUrl && context is VideoViewHolder) {
L.i("Found video", url)
- context.runOnUiThread { (context as VideoViewHolder).showVideo(url) }
+ context.runOnUiThread { context.showVideo(url) }
return true
}
+ if (!url.isIndependent) {
+ L.i("Forbid overlay switch", url)
+ return false
+ }
if (!Prefs.overlayEnabled) return false
if (context is WebOverlayActivityBase) {
L.v("Check web request from overlay", url)
@@ -55,26 +56,6 @@ fun FrostWebView.requestWebOverlay(url: String): Boolean {
L.i("return false switch")
return false
}
- /*
- * Non facebook urls can be loaded
- */
- if (!url.formattedFbUrl.isFacebookUrl) {
- context.launchWebOverlay(url)
- L.d("Request web overlay is not a facebook url", url)
- return true
- }
- /*
- * Check blacklist
- */
- if (overlayBlacklist.any { url.contains(it) }) return false
- /*
- * Facebook messages have the following cases for the tid query
- * mid* or id* for newer threads, which can be launched in new windows
- * or a hash for old threads, which must be loaded on old threads
- */
- if (url.contains("/messages/read/?tid=")) {
- if (!url.contains("?tid=id") && !url.contains("?tid=mid")) return false
- }
L.v("Request web overlay passed", url)
context.launchWebOverlay(url)
return true
@@ -87,9 +68,4 @@ val messageWhitelist = setOf(FbItem.MESSAGES, FbItem.CHAT, FbItem.FEED_MOST_RECE
val String.shouldUseBasicAgent
get() = !contains("story.php") //we will use basic agent for anything that isn't a comment section
-// get() = (messageWhitelist.any { contains(it) }) || this == FB_URL_BASE
-
-/**
- * The following components should never be launched in a new overlay
- */
-val overlayBlacklist = setOf("messages/?pageNum", "photoset_token", "sharer.php") \ No newline at end of file
+// get() = (messageWhitelist.any { contains(it) }) || this == FB_URL_BASE \ No newline at end of file
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 73d2476c..3a10ed32 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt
@@ -9,8 +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_URL_BASE
+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
@@ -26,11 +27,6 @@ class LoginWebView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : WebView(context, attrs, defStyleAttr) {
- companion object {
- const val LOGIN_URL = "${FB_URL_BASE}login"
- private val userMatcher: Regex = Regex("c_user=([0-9]*);")
- }
-
private lateinit var loginCallback: (CookieModel) -> Unit
private lateinit var progressCallback: (Int) -> Unit
@@ -50,7 +46,7 @@ class LoginWebView @JvmOverloads constructor(
this.progressCallback = progressCallback
this.loginCallback = loginCallback
L.d("Begin loading login")
- loadUrl(LOGIN_URL)
+ loadUrl(FB_LOGIN_URL)
}
private inner class LoginClient : BaseWebViewClient() {
@@ -66,7 +62,7 @@ class LoginWebView @JvmOverloads constructor(
if (!url.isFacebookUrl) 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
+ val id = FB_USER_MATCHER.find(cookie)?.groupValues?.get(1)?.toLong() ?: return@doAsync
uiThread { onFound(id, cookie) }
}
}