aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/web/SearchWebView.kt
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/web/SearchWebView.kt')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/SearchWebView.kt14
1 files changed, 8 insertions, 6 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/SearchWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/SearchWebView.kt
index 05d56f92..fb4e5bf7 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/SearchWebView.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/SearchWebView.kt
@@ -27,7 +27,7 @@ import java.util.concurrent.TimeUnit
*/
class SearchWebView(context: Context, val contract: SearchContract) : WebView(context) {
- val searchSubject = PublishSubject.create<String>()
+ val searchSubject = PublishSubject.create<String>()!!
init {
gone()
@@ -39,11 +39,11 @@ class SearchWebView(context: Context, val contract: SearchContract) : WebView(co
* Contains the last item's href (search more) as well as the number of items found
* This holder is synchronized
*/
- var previousResult: Pair<String?, Int> = Pair(null, 0)
+ var previousResult: Pair<String, Int> = Pair("", 0)
fun saveResultFrame(result: List<Pair<List<String>, String>>) {
synchronized(previousResult) {
- previousResult = Pair(result.lastOrNull()?.second, result.size)
+ previousResult = Pair(result.last().second, result.size)
}
}
@@ -60,13 +60,14 @@ class SearchWebView(context: Context, val contract: SearchContract) : WebView(co
element ->
//split text into separate items
L.v("Search element ${element.attr("href")}")
- val texts = element.select("div").map { (it.text()) }.filter { it.isNotBlank() }
+ val texts = element.select("div").map { it.text() }.filter { !it.isNullOrBlank() }
val pair = Pair(texts, element.attr("href"))
L.v("Search element potential $pair")
pair
}.filter { it.first.isNotEmpty() }
}
- .filter { content -> Pair(content.lastOrNull()?.second, content.size) != previousResult }
+ .filter { it.isNotEmpty() }
+ .filter { Pair(it.last().second, it.size) != previousResult }
.subscribe {
content: List<Pair<List<String>, String>> ->
saveResultFrame(content)
@@ -104,7 +105,8 @@ class SearchWebView(context: Context, val contract: SearchContract) : WebView(co
inner class SearchJSI {
@JavascriptInterface
- fun handleHtml(html: String) {
+ fun handleHtml(html: String?) {
+ html ?: return
L.d("Search received response ${contract.isSearchOpened}")
if (!contract.isSearchOpened) pauseLoad = true
searchSubject.onNext(html)