blob: 980481a44506b0306dede967662954e4622a59e5 (
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
|
package com.pitchedapps.frost.injectors
import android.webkit.WebView
import ca.allanwang.kau.kotlin.lazyContext
import com.pitchedapps.frost.utils.L
import java.io.BufferedReader
import java.io.FileNotFoundException
import java.util.*
/**
* Created by Allan Wang on 2017-05-31.
* Mapping of the available assets
* The enum name must match the css file name
*/
enum class JsAssets : InjectorContract {
MENU, MENU_DEBUG, CLICK_A, CONTEXT_A, MEDIA, HEADER_BADGES, HEADER_HIDER, TEXTAREA_LISTENER, NOTIF_MSG,
DOCUMENT_WATCHER
;
var file = "${name.toLowerCase(Locale.CANADA)}.js"
var injector = lazyContext {
try {
val content = it.assets.open("js/$file").bufferedReader().use(BufferedReader::readText)
JsBuilder().js(content).single(name).build()
} catch (e: FileNotFoundException) {
L.e(e) { "JsAssets file not found" }
JsInjector(JsActions.EMPTY.function)
}
}
override fun inject(webView: WebView, callback: (() -> Unit)?) {
injector(webView.context).inject(webView, callback)
}
}
|