diff options
author | Allan Wang <me@allanwang.ca> | 2017-08-03 22:21:51 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-03 22:21:51 -0700 |
commit | 7746e63373c905faa6d7e45e45fffc48d3ffff85 (patch) | |
tree | 5d1bd4338a722619bb892abb308b369abc61f396 /app/src/main/kotlin/com/pitchedapps/frost/web | |
parent | 5583f519dd7c4843f045029b0e48fd882dd79c71 (diff) | |
download | frost-7746e63373c905faa6d7e45e45fffc48d3ffff85.tar.gz frost-7746e63373c905faa6d7e45e45fffc48d3ffff85.tar.bz2 frost-7746e63373c905faa6d7e45e45fffc48d3ffff85.zip |
Add IM notifications, FAQ, video uploading, and geolocations (#107)
* Test canary
* Update activities to use kau base
* Update dependencies
* Cherry pick faq
* Update kau and add faq
* Add readme badges
* Add im notifications and video uploading
* Update theme
* Update and fix unit tests
* Add geolocation
* Prepare alpha test
* Remove explicit nonnull request
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/web')
4 files changed, 39 insertions, 44 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 b8ba0d1d..343674d5 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClients.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClients.kt @@ -1,10 +1,9 @@ package com.pitchedapps.frost.web import android.net.Uri -import android.webkit.ConsoleMessage -import android.webkit.ValueCallback -import android.webkit.WebChromeClient -import android.webkit.WebView +import android.webkit.* +import ca.allanwang.kau.permissions.PERMISSION_ACCESS_FINE_LOCATION +import ca.allanwang.kau.permissions.kauRequestPermissions import ca.allanwang.kau.utils.snackbar import com.pitchedapps.frost.contracts.ActivityWebContract import com.pitchedapps.frost.utils.L @@ -33,6 +32,7 @@ class FrostChromeClient(webCore: FrostWebViewCore) : WebChromeClient() { val progressObservable: Subject<Int> = webCore.progressObservable val titleObservable: BehaviorSubject<String> = webCore.titleObservable val activityContract = (webCore.context as? ActivityWebContract) + val context = webCore.context!! companion object { val consoleBlacklist = setOf( @@ -62,4 +62,12 @@ class FrostChromeClient(webCore: FrostWebViewCore) : WebChromeClient() { return activityContract != null } + override fun onGeolocationPermissionsShowPrompt(origin: String, callback: GeolocationPermissions.Callback) { + L.d("Requesting geolocation") + context.kauRequestPermissions(PERMISSION_ACCESS_FINE_LOCATION) { + granted, _ -> + L.d("Geolocation response received; ${if (granted) "granted" else "denied"}") + 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 6ec1aec5..1679d7a3 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt @@ -16,6 +16,7 @@ import ca.allanwang.kau.utils.withAlpha 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 io.reactivex.android.schedulers.AndroidSchedulers @@ -61,7 +62,7 @@ class FrostWebView @JvmOverloads constructor( baseEnum = enum with(settings) { javaScriptEnabled = true - if (url.contains("com/message")) + if (url.contains("/message")) userAgentString = USER_AGENT_BASIC allowFileAccess = true textZoom = Prefs.webTextScaling 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 cb5125c4..9f7dd916 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt @@ -1,6 +1,5 @@ package com.pitchedapps.frost.web -import android.content.ActivityNotFoundException import android.content.Context import android.content.Intent import android.graphics.Bitmap @@ -17,6 +16,7 @@ import com.pitchedapps.frost.facebook.FB_URL_BASE import com.pitchedapps.frost.facebook.FbCookie import com.pitchedapps.frost.injectors.* import com.pitchedapps.frost.utils.* +import com.pitchedapps.frost.utils.iab.IS_FROST_PRO import io.reactivex.subjects.Subject /** @@ -71,8 +71,8 @@ open class FrostWebViewClient(val webCore: FrostWebViewCore) : BaseWebViewClient } view.jsInject( CssAssets.ROUND_ICONS.maybe(Prefs.showRoundedIcons), - CssHider.PEOPLE_YOU_MAY_KNOW.maybe(!Prefs.showSuggestedFriends && Prefs.pro), - CssHider.ADS.maybe(!Prefs.showFacebookAds && Prefs.pro) + CssHider.PEOPLE_YOU_MAY_KNOW.maybe(!Prefs.showSuggestedFriends && IS_FROST_PRO), + CssHider.ADS.maybe(!Prefs.showFacebookAds && IS_FROST_PRO) ) onPageFinishedActions(url) } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/MessageWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/MessageWebView.kt index 0f3a12b6..53fa0657 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/MessageWebView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/MessageWebView.kt @@ -6,23 +6,24 @@ import android.webkit.JavascriptInterface import android.webkit.WebView import ca.allanwang.kau.utils.gone import com.pitchedapps.frost.dbflow.CookieModel -import com.pitchedapps.frost.facebook.FbCookie import com.pitchedapps.frost.facebook.FbTab import com.pitchedapps.frost.facebook.USER_AGENT_BASIC -import com.pitchedapps.frost.injectors.JsActions +import com.pitchedapps.frost.injectors.JsAssets import com.pitchedapps.frost.services.NotificationService import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.frostAnswersCustom import org.jetbrains.anko.doAsync -import org.jetbrains.anko.runOnUiThread -@SuppressLint("ViewConstructor") /** * Created by Allan Wang on 2017-07-17. * * Bare boned headless view made solely to extract conversation info */ -class MessageWebView(val service: NotificationService, val params: JobParameters?) : WebView(service) { +@SuppressLint("ViewConstructor") +class MessageWebView(val service: NotificationService, val params: JobParameters?, val cookie: CookieModel) : WebView(service) { + + private val startTime = System.currentTimeMillis() + private var isCancelled = false init { gone() @@ -33,48 +34,33 @@ class MessageWebView(val service: NotificationService, val params: JobParameters private fun setupWebview() { settings.javaScriptEnabled = true settings.userAgentString = USER_AGENT_BASIC - webViewClient = HeadlessWebViewClient("MessageNotifs", JsActions.GET_MESSAGES) + webViewClient = HeadlessWebViewClient("MessageNotifs", JsAssets.NOTIF_MSG) webChromeClient = QuietChromeClient() addJavascriptInterface(MessageJSI(), "Frost") + loadUrl(FbTab.MESSAGES.url) } - private val startTime = System.currentTimeMillis() - private val endTime: Long by lazy { System.currentTimeMillis() } - private var inProgress = false - private val pendingRequests: MutableList<CookieModel> = mutableListOf() - private lateinit var data: CookieModel - - fun request(data: CookieModel) { - pendingRequests.add(data) - if (inProgress) return - inProgress = true - load(data) + fun finish() { + if (isCancelled) return + isCancelled = true + post { destroy() } + service.finish(params) } - private fun load(data: CookieModel) { - L.d("Notif retrieving messages", data.toString()) - this.data = data - FbCookie.setWebCookie(data.cookie) { context.runOnUiThread { L.d("Notif messages load"); loadUrl(FbTab.MESSAGES.url) } } + override fun destroy() { + L.d("MessageWebView destroyed") + super.destroy() } inner class MessageJSI { @JavascriptInterface fun handleHtml(html: String) { - L.d("Notif messages received", data.toString()) - doAsync { service.fetchMessageNotifications(data, html) } - pendingRequests.remove(data) - if (pendingRequests.isEmpty()) { - val time = endTime - startTime - L.d("Notif messages finished $time") - frostAnswersCustom("Notifications") { - putCustomAttribute("Message retrieval duration", time) - } - post { destroy() } - service.jobFinished(params, false) - service.future = null - } else { - load(pendingRequests.first()) - } + if (isCancelled) return + if (html.length < 10) return finish() + val time = System.currentTimeMillis() - startTime + L.d("Notif messages fetched in $time ms") + frostAnswersCustom("NotificationTime", "Type" to "IM Headless", "Duration" to time) + doAsync { service.fetchMessageNotifications(cookie, html); finish() } } } |