aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/views
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-05-31 17:11:46 -0700
committerAllan Wang <me@allanwang.ca>2017-05-31 17:11:46 -0700
commit8618670b82641d5fbaec9c333f1290bab429ce27 (patch)
tree737c9a04f108ea68547eef2db1ae6e96caa64df6 /app/src/main/kotlin/com/pitchedapps/frost/views
parent9a41937a33539dbfaae4d072361caaec79865c29 (diff)
downloadfrost-8618670b82641d5fbaec9c333f1290bab429ce27.tar.gz
frost-8618670b82641d5fbaec9c333f1290bab429ce27.tar.bz2
frost-8618670b82641d5fbaec9c333f1290bab429ce27.zip
add more cookie handling
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/views')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt138
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/views/LoginWebView.kt73
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/views/SwipeRefreshBase.kt31
3 files changed, 0 insertions, 242 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
deleted file mode 100644
index d537d623..00000000
--- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt
+++ /dev/null
@@ -1,138 +0,0 @@
-package com.pitchedapps.frost.views
-
-import android.annotation.SuppressLint
-import android.content.Context
-import android.graphics.Bitmap
-import android.support.v4.view.MotionEventCompat
-import android.support.v4.view.NestedScrollingChild
-import android.support.v4.view.NestedScrollingChildHelper
-import android.support.v4.view.ViewCompat
-import android.util.AttributeSet
-import android.view.MotionEvent
-import android.view.View
-import android.webkit.*
-import com.pitchedapps.frost.facebook.FbCookie
-import com.pitchedapps.frost.utils.L
-import com.pitchedapps.frost.utils.ObservableContainer
-import io.reactivex.subjects.BehaviorSubject
-import io.reactivex.subjects.Subject
-
-enum class WebStatus {
- LOADING, LOADED, ERROR
-}
-
-/**
- * Created by Allan Wang on 2017-05-29.
- *
- * Courtesy of takahirom
- *
- * https://github.com/takahirom/webview-in-coordinatorlayout/blob/master/app/src/main/java/com/github/takahirom/webview_in_coodinator_layout/NestedWebView.java
- */
-class FrostWebView @JvmOverloads constructor(
- context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
-) : WebView(context, attrs, defStyleAttr), NestedScrollingChild, ObservableContainer<WebStatus> {
-
- private val childHelper = NestedScrollingChildHelper(this)
- private var lastY: Int = 0
- private val scrollOffset = IntArray(2)
- private val scrollConsumed = IntArray(2)
- private var nestedOffsetY: Int = 0
- override val observable: Subject<WebStatus>
-
- init {
- isNestedScrollingEnabled = true
- observable = BehaviorSubject.create<WebStatus>()
- 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)
- observable.onNext(WebStatus.ERROR)
- L.e("FWV Error ${request}")
- }
-
- override fun onPageStarted(view: WebView, url: String, favicon: Bitmap?) {
- super.onPageStarted(view, url, favicon)
- observable.onNext(WebStatus.LOADING)
- L.d("FWV Loading $url")
- }
-
- override fun onPageFinished(view: WebView, url: String) {
- super.onPageFinished(view, url)
- observable.onNext(WebStatus.LOADED)
- FbCookie.checkUserId(url, CookieManager.getInstance().getCookie(url))
- }
- })
- }
-
- override fun onTouchEvent(ev: MotionEvent): Boolean {
- val event = MotionEvent.obtain(ev)
- val action = MotionEventCompat.getActionMasked(event)
- if (action == MotionEvent.ACTION_DOWN)
- nestedOffsetY = 0
- val eventY = event.y.toInt()
- event.offsetLocation(0f, nestedOffsetY.toFloat())
- val returnValue: Boolean
- when (action) {
- MotionEvent.ACTION_MOVE -> {
- var deltaY = lastY - eventY
- // NestedPreScroll
- if (dispatchNestedPreScroll(0, deltaY, scrollConsumed, scrollOffset)) {
- deltaY -= scrollConsumed[1]
- event.offsetLocation(0f, -scrollOffset[1].toFloat())
- nestedOffsetY += scrollOffset[1]
- }
- lastY = eventY - scrollOffset[1]
- returnValue = super.onTouchEvent(event)
- // NestedScroll
- if (dispatchNestedScroll(0, scrollOffset[1], 0, deltaY, scrollOffset)) {
- event.offsetLocation(0f, scrollOffset[1].toFloat())
- nestedOffsetY += scrollOffset[1]
- lastY -= scrollOffset[1]
- }
- }
- MotionEvent.ACTION_DOWN -> {
- returnValue = super.onTouchEvent(event)
- lastY = eventY
- startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL)
- }
- MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
- returnValue = super.onTouchEvent(event)
- stopNestedScroll()
- }
- else -> return false
- }
- return returnValue
- }
-
- // Nested Scroll implements
- override fun setNestedScrollingEnabled(enabled: Boolean) {
- childHelper.isNestedScrollingEnabled = enabled
- }
-
- override fun isNestedScrollingEnabled() = childHelper.isNestedScrollingEnabled
-
- override fun startNestedScroll(axes: Int) = childHelper.startNestedScroll(axes)
-
- override fun stopNestedScroll() = childHelper.stopNestedScroll()
-
- override fun hasNestedScrollingParent() = childHelper.hasNestedScrollingParent()
-
- override fun dispatchNestedScroll(dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int, offsetInWindow: IntArray?)
- = childHelper.dispatchNestedScroll(dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, offsetInWindow)
-
- override fun dispatchNestedPreScroll(dx: Int, dy: Int, consumed: IntArray?, offsetInWindow: IntArray?)
- = childHelper.dispatchNestedPreScroll(dx, dy, consumed, offsetInWindow)
-
- override fun dispatchNestedFling(velocityX: Float, velocityY: Float, consumed: Boolean)
- = childHelper.dispatchNestedFling(velocityX, velocityY, consumed)
-
- override fun dispatchNestedPreFling(velocityX: Float, velocityY: Float)
- = childHelper.dispatchNestedPreFling(velocityX, velocityY)
-
-} \ No newline at end of file
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/LoginWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/LoginWebView.kt
deleted file mode 100644
index 17557b4d..00000000
--- a/app/src/main/kotlin/com/pitchedapps/frost/views/LoginWebView.kt
+++ /dev/null
@@ -1,73 +0,0 @@
-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.facebook.retro.enqueueFrost
-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().enqueueFrost { call, response ->
-
- }
-
- }
-
-}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/SwipeRefreshBase.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/SwipeRefreshBase.kt
deleted file mode 100644
index 59d42722..00000000
--- a/app/src/main/kotlin/com/pitchedapps/frost/views/SwipeRefreshBase.kt
+++ /dev/null
@@ -1,31 +0,0 @@
-package com.pitchedapps.frost.views
-
-import android.content.Context
-import android.support.v4.widget.SwipeRefreshLayout
-import android.util.AttributeSet
-import android.view.MotionEvent
-import android.webkit.WebView
-import com.pitchedapps.frost.utils.L
-import com.pitchedapps.frost.utils.Utils
-
-
-/**
- * Created by Allan Wang on 2017-05-28.
- */
-class SwipeRefreshBase @JvmOverloads constructor(
- context: Context?, attrs: AttributeSet? = null
-) : SwipeRefreshLayout(context, attrs) {
-
- lateinit var shouldSwipe: (ev: MotionEvent) -> Boolean
-
- companion object {
- private val SCROLL_BUFFER by lazy { Utils.dpToPx(5) }
- fun shouldScroll(webview: WebView) = webview.scrollY <= SCROLL_BUFFER
- }
-
-// override fun onInterceptTouchEvent(ev: MotionEvent):Boolean {
-// val b = shouldSwipe.invoke(ev) && super.onInterceptTouchEvent(ev)
-// L.e("Should swipe $b")
-// return b
-// }
-} \ No newline at end of file