diff options
author | Allan Wang <me@allanwang.ca> | 2017-10-11 01:51:21 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-11 01:51:21 -0400 |
commit | fe1df730a180316f76c334879da88515a0150a42 (patch) | |
tree | 49ef0590dfbbb7f01347746a8d1f78e15682346a /app/src/main/kotlin/com/pitchedapps/frost/parsers/MessageParser.kt | |
parent | d12e0697ad34c02a8f16143c4bddbc2a02e7b3dc (diff) | |
download | frost-fe1df730a180316f76c334879da88515a0150a42.tar.gz frost-fe1df730a180316f76c334879da88515a0150a42.tar.bz2 frost-fe1df730a180316f76c334879da88515a0150a42.zip |
Search Parsing (#379)
* Update parser interface and add search parsing
* Add custom jsoup method and search parse method
* Bind new searchview
* Add search view cache
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/parsers/MessageParser.kt')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/parsers/MessageParser.kt | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/parsers/MessageParser.kt b/app/src/main/kotlin/com/pitchedapps/frost/parsers/MessageParser.kt index 00ede417..7e6ef4bb 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/parsers/MessageParser.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/parsers/MessageParser.kt @@ -5,6 +5,7 @@ import com.pitchedapps.frost.facebook.formattedFbUrlCss import com.pitchedapps.frost.utils.L import org.apache.commons.text.StringEscapeUtils import org.jsoup.Jsoup +import org.jsoup.nodes.Document import org.jsoup.nodes.Element /** @@ -22,7 +23,7 @@ data class FrostLink(val text: String, val href: String) private class MessageParserImpl : FrostParserBase<Triple<List<FrostThread>, FrostLink?, List<FrostLink>>>() { - override fun parseImpl(text: String): Triple<List<FrostThread>, FrostLink?, List<FrostLink>>? { + override fun textToDoc(text: String): Document? { var content = StringEscapeUtils.unescapeEcmaScript(text) val begin = content.indexOf("id=\"threadlist_rows\"") if (begin <= 0) { @@ -36,11 +37,14 @@ private class MessageParserImpl : FrostParserBase<Triple<List<FrostThread>, Fros return null } content = content.substring(0, end).substringBeforeLast("</div>") - val body = Jsoup.parseBodyFragment("<div $content") - val threadList = body.getElementById("threadlist_rows") + return Jsoup.parseBodyFragment("<div $content") + } + + override fun parse(doc: Document): Triple<List<FrostThread>, FrostLink?, List<FrostLink>>? { + val threadList = doc.getElementById("threadlist_rows") val threads: List<FrostThread> = threadList.getElementsByAttributeValueContaining("id", "thread_fbid_") .mapNotNull { parseMessage(it) } - val seeMore = parseLink(body.getElementById("see_older_threads")) + val seeMore = parseLink(doc.getElementById("see_older_threads")) val extraLinks = threadList.nextElementSibling().select("a") .mapNotNull { parseLink(it) } return Triple(threads, seeMore, extraLinks) @@ -76,9 +80,9 @@ private class MessageParserImpl : FrostParserBase<Triple<List<FrostThread>, Fros } override fun debugImpl(data: Triple<List<FrostThread>, FrostLink?, List<FrostLink>>, result: MutableList<String>) { - result.addAll(data.first.map { it.toString() }) + result.addAll(data.first.map(FrostThread::toString)) result.add("See more link:") result.add("\t${data.second}") - result.addAll(data.third.map { it.toString() }) + result.addAll(data.third.map(FrostLink::toString)) } } |