aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt
blob: 14fcc22a083ab52dc5ae42a962ef4201bb58c7dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package com.pitchedapps.frost.web

import android.graphics.Bitmap
import android.webkit.*
import com.pitchedapps.frost.facebook.FbCookie
import com.pitchedapps.frost.utils.L
import io.reactivex.subjects.Subject

/**
 * Created by Allan Wang on 2017-05-31.
 */
class FrostWebViewClient(val observable: Subject<WebStatus>) : WebViewClient() {

    private var injectionCount: Int = 0

    companion object {
        //Collections of jewels mapped with url match -> id
        val jewelMap: Map<String, String> = mapOf("a" to "b")
        fun test() {

        }
    }

    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)
        injectionCount = 0
        observable.onNext(WebStatus.LOADING)
        L.d("FWV Loading $url")
        if (url.contains("logout.php")) FbCookie.logout()
    }

    override fun onPageFinished(view: WebView, url: String) {
        super.onPageFinished(view, url)
        observable.onNext(WebStatus.LOADED)
        FbCookie.checkUserId(url, CookieManager.getInstance().getCookie(url))
    }

    fun logout() {

    }

}