aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/src/main/assets/js/menu_click.js4
-rw-r--r--app/src/main/assets/js/menu_click.min.js5
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt16
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt7
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt2
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClientMenu.kt7
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt11
7 files changed, 33 insertions, 19 deletions
diff --git a/app/src/main/assets/js/menu_click.js b/app/src/main/assets/js/menu_click.js
index 82041b0e..403689eb 100644
--- a/app/src/main/assets/js/menu_click.js
+++ b/app/src/main/assets/js/menu_click.js
@@ -1,11 +1,11 @@
// we will handle click events
console.log('Registering menu click');
-document.addEventListener('click', function(e) {
+document.addEventListener('click', function _menuClick(e) {
var element = e.target || e.srcElement;
if (element.tagName !== 'A')
element = element.parentNode;
if (element.tagName === 'A' && element.getAttribute('href') !== '#') {
- var url = element.href;
+ var url = element.getAttribute('href');
console.log('Click Intercept');
console.log(url);
Frost.loadUrl(url);
diff --git a/app/src/main/assets/js/menu_click.min.js b/app/src/main/assets/js/menu_click.min.js
index 4d508f71..60671265 100644
--- a/app/src/main/assets/js/menu_click.min.js
+++ b/app/src/main/assets/js/menu_click.min.js
@@ -1,8 +1,9 @@
console.log("Registering menu click"),document.addEventListener("click",function(e){
var t=e.target||e.srcElement
;if("A"!==t.tagName&&(t=t.parentNode),"A"===t.tagName&&"#"!==t.getAttribute("href")){
-var o=t.href
-;console.log("Click Intercept"),console.log(o),Frost.loadUrl(o),e.stopPropagation(),
+var o=t.getAttribute("href")
+;console.log("Click Intercept"),console.log(o),Frost.loadUrl(o),
+e.stopPropagation(),
e.preventDefault()
}
},!0); \ No newline at end of file
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
index 8dfceaad..0d99d67a 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
@@ -12,6 +12,7 @@ import com.pitchedapps.frost.LoginActivity
import com.pitchedapps.frost.R
import com.pitchedapps.frost.WebOverlayActivity
import com.pitchedapps.frost.dbflow.CookieModel
+import com.pitchedapps.frost.facebook.FB_URL_BASE
import com.pitchedapps.frost.facebook.FbTab
/**
@@ -30,10 +31,23 @@ fun Activity.cookies(): ArrayList<CookieModel> {
return intent?.extras?.getParcelableArrayList<CookieModel>(EXTRA_COOKIES) ?: arrayListOf()
}
+val String.formattedFbUrl: String
+ get() {
+ var url = this
+ if (url.startsWith("#!/")) url = url.substring(2)
+ if (url.startsWith('/')) url = FB_URL_BASE + url.substring(1)
+ url = url.replace("/#!/", "/")
+ val ref = url.indexOf("?ref")
+ if (ref != -1) url = url.substring(0, ref)
+ return url
+ }
+
fun Context.launchWebOverlay(url: String) {
+ val argUrl = url.formattedFbUrl
+ L.i("Launch web overlay: $argUrl")
val intent = Intent(this, WebOverlayActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
- intent.putExtra(ARG_URL, url)
+ intent.putExtra(ARG_URL, argUrl)
val bundle = ActivityOptionsCompat.makeCustomAnimation(this, R.anim.slide_in_right, R.anim.slide_out_right).toBundle()
ContextCompat.startActivity(this, intent, bundle)
}
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 f81c6a15..36193b8b 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt
@@ -19,14 +19,9 @@ class FrostJSI(val context: Context, val webView: FrostWebViewCore) {
val cookies: ArrayList<CookieModel>
get() = (context as? MainActivity)?.cookies() ?: arrayListOf()
- var lastUrl: String = ""
-
@JavascriptInterface
fun loadUrl(url: String) {
- if (url != lastUrl) {
- lastUrl = url
- context.launchWebOverlay(url)
- }
+ context.launchWebOverlay(url)
}
@JavascriptInterface
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 8cd36b86..ac2af3cb 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt
@@ -45,11 +45,11 @@ open class FrostWebViewClient(val webCore: FrostWebViewCore) : WebViewClient() {
override fun onPageFinished(view: WebView, url: String) {
super.onPageFinished(view, url)
+ L.i("Page finished $url")
if (!url.contains(FACEBOOK_COM)) {
refreshObservable.onNext(false)
return
}
- L.i("Page finished $url")
JsActions.LOGIN_CHECK.inject(view)
onPageFinishedActions(url)
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClientMenu.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClientMenu.kt
index 2a1a5b74..af13c459 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClientMenu.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClientMenu.kt
@@ -15,7 +15,7 @@ class FrostWebViewClientMenu(webCore: FrostWebViewCore) : FrostWebViewClient(web
var content: String? = null
val progressObservable: Subject<Int> = webCore.progressObservable
- private val contentBaseUrl = "https://touch.facebook.com/notifications"
+ private val contentBaseUrl = "${FB_URL_BASE}notifications"
override fun onPageStarted(view: WebView, url: String, favicon: Bitmap?) {
super.onPageStarted(view, url, favicon)
@@ -38,7 +38,10 @@ class FrostWebViewClientMenu(webCore: FrostWebViewCore) : FrostWebViewClient(web
jsInject(JsAssets.MENU, callback = {
jsInject(JsAssets.MENU_CLICK) //menu injection must be after or we will have a loop from the click listener
})
- } else if (url == contentBaseUrl) jsInject(JsAssets.MENU_CLICK)
+ } else if (url == contentBaseUrl) {
+ L.i("Inject content")
+ jsInject(JsAssets.MENU_CLICK)
+ }
}
override fun emit(flag: Int) {
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 5ba312f4..b6353252 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt
@@ -22,6 +22,7 @@ import io.reactivex.Scheduler
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.subjects.BehaviorSubject
+import io.reactivex.subjects.PublishSubject
/**
* Created by Allan Wang on 2017-05-29.
@@ -36,8 +37,8 @@ class FrostWebViewCore @JvmOverloads constructor(
private val scrollOffset = IntArray(2)
private val scrollConsumed = IntArray(2)
private var nestedOffsetY: Int = 0
- val progressObservable: BehaviorSubject<Int> // Keeps track of every progress change
- val refreshObservable: BehaviorSubject<Boolean> // Only emits on page loads
+ val progressObservable: PublishSubject<Int> // Keeps track of every progress change
+ val refreshObservable: PublishSubject<Boolean> // Only emits on page loads
val titleObservable: BehaviorSubject<String> // Only emits on different non http titles
var baseUrl: String? = null
@@ -46,8 +47,8 @@ class FrostWebViewCore @JvmOverloads constructor(
init {
isNestedScrollingEnabled = true
- progressObservable = BehaviorSubject.create<Int>()
- refreshObservable = BehaviorSubject.create<Boolean>()
+ progressObservable = PublishSubject.create<Int>()
+ refreshObservable = PublishSubject.create<Boolean>()
titleObservable = BehaviorSubject.create<String>()
}
@@ -79,8 +80,8 @@ class FrostWebViewCore @JvmOverloads constructor(
/**
* Hook onto the refresh observable for one cycle
- * Note that this is a behaviour subject so the first 'false' emission should be ignored
* Animate toggles between the fancy ripple and the basic fade
+ * The cycle only starts on the first load since there may have been another process when this is registered
*/
fun registerTransition(animate: Boolean) {
var dispose: Disposable? = null