blob: 14ea4df8622d3e129dfd8d22d795a0e8f7301a24 (
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
49
50
51
52
|
package com.pitchedapps.frost.web
import android.content.Context
import android.webkit.JavascriptInterface
import com.pitchedapps.frost.LoginActivity
import com.pitchedapps.frost.MainActivity
import com.pitchedapps.frost.SelectorActivity
import com.pitchedapps.frost.dbflow.CookieModel
import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.cookies
import com.pitchedapps.frost.utils.launchNewTask
import com.pitchedapps.frost.utils.launchWebOverlay
/**
* Created by Allan Wang on 2017-06-01.
*/
class FrostJSI(val context: Context, val webView: FrostWebViewCore) {
val cookies: ArrayList<CookieModel>
get() = (context as? MainActivity)?.cookies() ?: arrayListOf()
@JavascriptInterface
fun loadUrl(url: String) = context.launchWebOverlay(url)
@JavascriptInterface
fun reloadBaseUrl() {
L.d("FrostJSI reload")
webView.post {
webView.stopLoading()
webView.loadBaseUrl()
}
}
@JavascriptInterface
fun loadLogin() {
if (cookies.isNotEmpty())
context.launchNewTask(SelectorActivity::class.java, cookies)
else
context.launchNewTask(LoginActivity::class.java)
}
@JavascriptInterface
fun emit(flag: Int) {
webView.post { webView.frostWebClient!!.emit(flag) }
}
@JavascriptInterface
fun handleHtml(html: String) {
webView.post { webView.frostWebClient!!.handleHtml(html) }
}
}
|