diff options
author | Allan Wang <me@allanwang.ca> | 2018-12-24 01:49:57 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-24 01:49:57 -0500 |
commit | 2c02356c498b3db6f13bd7a3af8689c24ca224ea (patch) | |
tree | 726ad142a8a373715493cf602786361226f624ee /app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt | |
parent | fce0bf0a6df09de78a804dc874f48f67336d9d9c (diff) | |
parent | 697d01882ba8b1dbb85484ba3bf6e810e32448fc (diff) | |
download | frost-2c02356c498b3db6f13bd7a3af8689c24ca224ea.tar.gz frost-2c02356c498b3db6f13bd7a3af8689c24ca224ea.tar.bz2 frost-2c02356c498b3db6f13bd7a3af8689c24ca224ea.zip |
Merge branch 'dev' into update/coroutines
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.kt | 34 |
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 +} |