aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt34
1 files changed, 26 insertions, 8 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt b/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt
index acda2d9b..8ae3a2f4 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
package com.pitchedapps.frost.injectors
import android.webkit.WebView
@@ -8,7 +24,7 @@ import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.subjects.SingleSubject
import org.apache.commons.text.StringEscapeUtils
-import java.util.*
+import java.util.Locale
class JsBuilder {
private val css = StringBuilder()
@@ -90,10 +106,10 @@ fun WebView.jsInject(vararg injectors: InjectorContract, callback: ((Int) -> Uni
}
val observables = Array(validInjectors.size) { SingleSubject.create<Unit>() }
val disposable = Single.zip<Unit, Int>(observables.asList()) { it.size }
- .observeOn(AndroidSchedulers.mainThread())
- .subscribe { res, _ ->
- callback(res)
- }
+ .observeOn(AndroidSchedulers.mainThread())
+ .subscribe { res, _ ->
+ callback(res)
+ }
(0 until validInjectors.size).forEach { i ->
validInjectors[i].inject(this) {
observables[i].onSuccess(Unit)
@@ -102,8 +118,10 @@ fun WebView.jsInject(vararg injectors: InjectorContract, callback: ((Int) -> Uni
return disposable
}
-fun FrostWebViewClient.jsInject(vararg injectors: InjectorContract,
- callback: ((Int) -> Unit)? = null) = web.jsInject(*injectors, callback = callback)
+fun FrostWebViewClient.jsInject(
+ vararg injectors: InjectorContract,
+ callback: ((Int) -> Unit)? = null
+) = web.jsInject(*injectors, callback = callback)
/**
* Wrapper class to convert a function into an injector
@@ -112,4 +130,4 @@ class JsInjector(val function: String) : InjectorContract {
override fun inject(webView: WebView, callback: (() -> Unit)?) {
webView.evaluateJavascript(function) { callback?.invoke() }
}
-} \ No newline at end of file
+}