aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/views
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-05-30 01:03:01 -0700
committerAllan Wang <me@allanwang.ca>2017-05-30 01:03:01 -0700
commit4c44dbc9933bd726c1da0bf326102835c4974d6b (patch)
tree18be2954a53c292eef132f9a3dc630c4071c7a9b /app/src/main/kotlin/com/pitchedapps/frost/views
parent461425eb6054f18cea1990a4117fe8c78e888ddf (diff)
downloadfrost-4c44dbc9933bd726c1da0bf326102835c4974d6b.tar.gz
frost-4c44dbc9933bd726c1da0bf326102835c4974d6b.tar.bz2
frost-4c44dbc9933bd726c1da0bf326102835c4974d6b.zip
create retrofacebook and token retrieval
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/views')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt1
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/views/LoginWebView.kt78
2 files changed, 79 insertions, 0 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt
index 62115276..f09887d8 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt
@@ -68,6 +68,7 @@ class FrostWebView @JvmOverloads constructor(
super.onPageFinished(view, url)
observable.onNext(WebStatus.LOADED)
// CookieManager.getInstance().flush()
+ L.d("Loaded $url")
}
})
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/LoginWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/LoginWebView.kt
new file mode 100644
index 00000000..7d1948fe
--- /dev/null
+++ b/app/src/main/kotlin/com/pitchedapps/frost/views/LoginWebView.kt
@@ -0,0 +1,78 @@
+package com.pitchedapps.frost.views
+
+import android.annotation.SuppressLint
+import android.content.Context
+import android.graphics.Bitmap
+import android.net.UrlQuerySanitizer
+import android.util.AttributeSet
+import android.view.View
+import android.webkit.WebResourceError
+import android.webkit.WebResourceRequest
+import android.webkit.WebView
+import android.webkit.WebViewClient
+import com.facebook.AccessToken
+import com.pitchedapps.frost.facebook.FB_KEY
+import com.pitchedapps.frost.facebook.retro.FrostApi.frostApi
+import com.pitchedapps.frost.facebook.retro.Me
+import com.pitchedapps.frost.utils.L
+import retrofit2.Call
+import retrofit2.Callback
+import retrofit2.Response
+
+/**
+ * Created by Allan Wang on 2017-05-29.
+ */
+class LoginWebView @JvmOverloads constructor(
+ context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
+) : WebView(context, attrs, defStyleAttr) {
+
+ init {
+ setupWebview()
+ }
+
+ @SuppressLint("SetJavaScriptEnabled")
+ fun setupWebview() {
+ settings.javaScriptEnabled = true
+ setLayerType(View.LAYER_TYPE_HARDWARE, null)
+ setWebViewClient(object : WebViewClient() {
+ override fun onReceivedError(view: WebView?, request: WebResourceRequest?, error: WebResourceError?) {
+ super.onReceivedError(view, request, error)
+ L.e("Error ${request}")
+ }
+
+ override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
+ super.onPageStarted(view, url, favicon)
+ L.d("Loading $url")
+ }
+
+ override fun onPageFinished(view: WebView?, url: String?) {
+ super.onPageFinished(view, url)
+ if (url == null) return
+ val sanitizer = UrlQuerySanitizer(url)
+ val accessToken = sanitizer.getValue("access_token")
+ val expiresIn = sanitizer.getValue("expires_in")
+ val grantedScopes = sanitizer.getValue("granted_scopes")
+ val deniedScopes = sanitizer.getValue("deniedScopes")
+
+
+ L.d("Loaded $url")
+ }
+ })
+ }
+
+ fun saveAccessToken(accessToken: String, expiresIn: String, grantedScopes: String?, deniedScopes: String?) {
+ L.d("Granted $grantedScopes")
+ L.d("Denied $deniedScopes")
+ frostApi.me(accessToken).enqueue(object : Callback<Me> {
+ override fun onFailure(call: Call<Me>?, t: Throwable?) {
+ TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
+ }
+
+ override fun onResponse(call: Call<Me>, response: Response<Me>) {
+ AccessToken.setCurrentAccessToken(AccessToken(accessToken, FB_KEY.toString(), response.body().id, null, null, null, null, null))
+ }
+ })
+
+ }
+
+}