diff options
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/facebook')
6 files changed, 35 insertions, 20 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt index d98241f1..f1bf55b1 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt @@ -6,10 +6,22 @@ package com.pitchedapps.frost.facebook const val FACEBOOK_COM = "facebook.com" const val HTTPS_FACEBOOK_COM = "https://$FACEBOOK_COM" -const val FB_URL_BASE = "https://touch.$FACEBOOK_COM/" +const val FB_URL_BASE = "https://m.$FACEBOOK_COM/" fun PROFILE_PICTURE_URL(id: Long) = "https://graph.facebook.com/$id/picture?type=large" const val FB_LOGIN_URL = "${FB_URL_BASE}login" const val USER_AGENT_FULL = "Mozilla/5.0 (Linux; Android 4.4.2; en-us; SAMSUNG SM-G900T Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Version/1.6 Chrome/28.0.1500.94 Mobile Safari/537.36" const val USER_AGENT_BASIC = "Mozilla/5.0 (BB10; Kbd) AppleWebKit/537.10+ (KHTML, like Gecko) Version/10.1.0.4633 Mobile Safari/537.10+" -const val USER_AGENT_MESSENGER = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"
\ No newline at end of file +const val USER_AGENT_MESSENGER = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36" + +/** + * Animation transition delay, just to ensure that the styles + * have properly set in + */ +const val WEB_LOAD_DELAY = 50L +/** + * Additional delay for transition when called from commit. + * Note that transitions are also called from onFinish, so this value + * will never make a load slower than it is + */ +const val WEB_COMMIT_LOAD_DELAY = 200L
\ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt index ccb23b93..e5f0b8fe 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt @@ -33,12 +33,14 @@ object FbCookie { L.d { "Setting cookie" } val cookies = cookie.split(";").map { Pair(it, SingleSubject.create<Boolean>()) } cookies.forEach { (cookie, callback) -> setCookie(FB_URL_BASE, cookie, { callback.onSuccess(it) }) } - Observable.zip<Boolean, Unit>(cookies.map { (_, callback) -> callback.toObservable() }, {}).subscribeOn(AndroidSchedulers.mainThread()).subscribe { - callback?.invoke() - L.d { "Cookies set" } - L._d { cookie } - flush() - } + Observable.zip<Boolean, Unit>(cookies.map { (_, callback) -> callback.toObservable() }, {}) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe { + callback?.invoke() + L.d { "Cookies set" } + L._d { cookie } + flush() + } } } } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt index 76eb2c0c..cbb6087a 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt @@ -32,8 +32,10 @@ class FbUrlFormatter(url: String) { fun clean(url: String): String { if (url.isBlank()) return "" var cleanedUrl = url + if (cleanedUrl.startsWith("#!")) cleanedUrl = cleanedUrl.substring(2) + val urlRef = cleanedUrl discardable.forEach { cleanedUrl = cleanedUrl.replace(it, "", true) } - val changed = cleanedUrl != url + val changed = cleanedUrl != urlRef converter.forEach { (k, v) -> cleanedUrl = cleanedUrl.replace(k, v, true) } try { cleanedUrl = URLDecoder.decode(cleanedUrl, StandardCharsets.UTF_8.name()) @@ -54,7 +56,6 @@ class FbUrlFormatter(url: String) { discardableQueries.forEach { queries.remove(it) } //final cleanup misc.forEach { (k, v) -> cleanedUrl = cleanedUrl.replace(k, v, true) } - if (cleanedUrl.startsWith("#!")) cleanedUrl = cleanedUrl.substring(2) if (cleanedUrl.startsWith("/")) cleanedUrl = FB_URL_BASE + cleanedUrl.substring(1) cleanedUrl = cleanedUrl.replaceFirst(".facebook.com//", ".facebook.com/") //sometimes we are given a bad url L.v { "Formatted url from $url to $cleanedUrl" } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/FbRequest.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/FbRequest.kt index 3ca37bb4..45545336 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/FbRequest.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/FbRequest.kt @@ -21,6 +21,7 @@ private class RxAuth : RxFlyweight<String, Long, RequestAuth>() { System.currentTimeMillis() - cond < 3600000 // valid for an hour override fun cache(input: String) = System.currentTimeMillis() + } private val auth = RxAuth() @@ -32,13 +33,12 @@ private val auth = RxAuth() */ fun String?.fbRequest(fail: () -> Unit = {}, action: RequestAuth.() -> Unit) { if (this == null) return fail() - auth(this).subscribe { a: RequestAuth?, _ -> - if (a?.isValid == true) - a.action() - else { - L.e { "Failed auth for ${hashCode()}" } - fail() - } + try { + val auth = auth(this).blockingGet() + auth.action() + } catch (e: Exception) { + L.e { "Failed auth for ${hashCode()}: ${e.message}" } + fail() } } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/Images.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/Images.kt index fa78bbfa..094e7fc9 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/Images.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/Images.kt @@ -67,7 +67,7 @@ class HdImageLoading : ModelLoader<HdImageMaybe, InputStream> { override fun buildLoadData(model: HdImageMaybe, width: Int, height: Int, - options: Options?): ModelLoader.LoadData<InputStream>? = + options: Options): ModelLoader.LoadData<InputStream>? = if (!model.isValid) null else ModelLoader.LoadData(ObjectKey(model), HdImageFetcher(model)) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/Menu.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/Menu.kt index 72b6e0a4..6f327662 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/Menu.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/Menu.kt @@ -117,7 +117,7 @@ data class MenuHeader(val id: String? = null, ) : this(id, header, visible ?: emptyList(), all ?: emptyList()) override val isValid: Boolean - get() = header != null + get() = !header.isNullOrBlank() } @JsonIgnoreProperties(ignoreUnknown = true) @@ -139,7 +139,7 @@ data class MenuItem(val id: String? = null, ) : this(id, name, pic?.formattedFbUrl, url?.formattedFbUrl, count ?: 0, countDetails) override val isValid: Boolean - get() = name != null && url != null + get() = !name.isNullOrBlank() && !url.isNullOrBlank() } data class MenuFooter(val data: List<MenuFooterItem> = emptyList(), |