aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/injectors/CssAssets.kt
blob: 0482fdc9f903de120d48a470d34be48c1629c8f1 (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
package com.pitchedapps.frost.injectors

import android.webkit.WebView
import com.pitchedapps.frost.utils.L

/**
 * Created by Allan Wang on 2017-05-31.
 */
enum class CssAssets(f: String) {
    BASE("facebook");

    var file = "$f.compact.css"
    var content: String? = null
    var injector: JsInjector? = null

    fun inject(webView: WebView, callback: ((String) -> Unit)?) {
        if (injector == null) {
            if (content == null)
                content = webView.context.assets.open(file).bufferedReader().use { it.readText() }
            injector = JsBuilder().css(content!!).build()
        }
        injector!!.inject(webView, callback)
        L.d("CSS ${injector!!.function}")
    }

}