aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2020-01-20 16:50:07 -0800
committerGitHub <noreply@github.com>2020-01-20 16:50:07 -0800
commit9b958725a74426ee3d2977d659327e6973dfb54a (patch)
tree4775dbd0fc52fbde0d06e63c0003a068097db05e
parenta6f97c81e0e33a649b137bc60b336b0b736e132a (diff)
parent59669214b1f7edbf2fa38d61903e8b48476726c0 (diff)
downloadfrost-9b958725a74426ee3d2977d659327e6973dfb54a.tar.gz
frost-9b958725a74426ee3d2977d659327e6973dfb54a.tar.bz2
frost-9b958725a74426ee3d2977d659327e6973dfb54a.zip
Merge pull request #1624 from AllanWang/search-ui-fix
Only use mbasic for parsing search
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt3
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/FbItem.kt8
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/SearchParser.kt20
-rw-r--r--app/src/main/res/xml/frost_changelog.xml2
4 files changed, 26 insertions, 7 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt
index f0f6ca7e..e36abd15 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt
@@ -25,7 +25,8 @@ const val FBCDN_NET = "fbcdn.net"
const val WWW_FACEBOOK_COM = "www.$FACEBOOK_COM"
const val FACEBOOK_BASE_COM = "m.$FACEBOOK_COM"
const val FB_URL_BASE = "https://$FACEBOOK_BASE_COM/"
-const val FB_URL_MBASIC_BASE = "https://mbasic.$FACEBOOK_COM/"
+const val FACEBOOK_MBASIC_COM = "mbasic.$FACEBOOK_COM"
+const val FB_URL_MBASIC_BASE = "https://$FACEBOOK_MBASIC_COM/"
fun profilePictureUrl(id: Long) = "https://graph.facebook.com/$id/picture?type=large"
const val FB_LOGIN_URL = "${FB_URL_BASE}login"
const val FB_HOME_URL = "${FB_URL_BASE}home.php"
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbItem.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbItem.kt
index 4df99878..8d200c4f 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbItem.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbItem.kt
@@ -61,6 +61,14 @@ enum class FbItem(
_SEARCH(
R.string.kau_search,
GoogleMaterial.Icon.gmd_search,
+ "search/top"
+ ),
+ /**
+ * Non mbasic search cannot be parsed.
+ */
+ _SEARCH_PARSE(
+ R.string.kau_search,
+ GoogleMaterial.Icon.gmd_search,
"search/top",
prefix = FB_URL_MBASIC_BASE
),
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/SearchParser.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/SearchParser.kt
index e4339d4f..28b4a556 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/SearchParser.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/SearchParser.kt
@@ -17,6 +17,8 @@
package com.pitchedapps.frost.facebook.parsers
import ca.allanwang.kau.searchview.SearchItem
+import com.pitchedapps.frost.facebook.FACEBOOK_BASE_COM
+import com.pitchedapps.frost.facebook.FACEBOOK_MBASIC_COM
import com.pitchedapps.frost.facebook.FbItem
import com.pitchedapps.frost.facebook.formattedFbUrl
import com.pitchedapps.frost.facebook.parsers.FrostSearch.Companion.create
@@ -29,7 +31,7 @@ import org.jsoup.nodes.Element
*/
object SearchParser : FrostParser<FrostSearches> by SearchParserImpl() {
fun query(cookie: String?, input: String): ParseResponse<FrostSearches>? {
- val url = "${FbItem._SEARCH.url}?q=${if (input.isNotBlank()) input else "a"}"
+ val url = "${FbItem._SEARCH_PARSE.url}?q=${if (input.isNotBlank()) input else "a"}"
L._i { "Search Query $url" }
return parseFromUrl(cookie, url)
}
@@ -74,9 +76,12 @@ data class FrostSearch(val href: String, val title: String, val description: Str
private class SearchParserImpl : FrostParserBase<FrostSearches>(false) {
- override var nameRes = FbItem._SEARCH.titleId
+ override var nameRes = FbItem._SEARCH_PARSE.titleId
- override val url = "${FbItem._SEARCH.url}?q=google"
+ override val url = "${FbItem._SEARCH_PARSE.url}?q=google"
+
+ private val String.formattedSearchUrl: String
+ get() = replace(FACEBOOK_MBASIC_COM, FACEBOOK_BASE_COM)
override fun parseImpl(doc: Document): FrostSearches? {
val container: Element = doc.getElementById("BrowseResultsContainer")
@@ -87,9 +92,14 @@ private class SearchParserImpl : FrostParserBase<FrostSearches>(false) {
// Our assumption is that search entries start with an image, followed by general info
// There may be other <td />s, but we will not be parsing them
// Furthermore, the <td /> entry wraps a link, containing all the necessary info
- val a = el.select("td").getOrNull(1)?.selectFirst("a") ?: return@mapNotNull null
+ val a = el.select("td")
+ .getOrNull(1)
+ ?.selectFirst("a")
+ ?: return@mapNotNull null
val url =
- a.attr("href").takeIf { it.isNotEmpty() }?.formattedFbUrl ?: return@mapNotNull null
+ a.attr("href").takeIf { it.isNotEmpty() }
+ ?.formattedFbUrl?.formattedSearchUrl
+ ?: return@mapNotNull null
// Currently, children should all be <div /> elements, where the first entry is the name/title
// And the other entries are additional info.
// There are also cases of nested tables, eg for the "join" button in groups.
diff --git a/app/src/main/res/xml/frost_changelog.xml b/app/src/main/res/xml/frost_changelog.xml
index 125c12cb..8e400347 100644
--- a/app/src/main/res/xml/frost_changelog.xml
+++ b/app/src/main/res/xml/frost_changelog.xml
@@ -9,7 +9,7 @@
<version title="v2.4.3" />
<item text="Fix Android theme" />
<item text="Fix nav header expansion when animations are disabled" />
- <item text="" />
+ <item text="Fix search page UI" />
<item text="" />
<item text="" />