mirror of
https://github.com/AllanWang/Frost-for-Facebook.git
synced 2024-11-08 20:12:39 +01:00
Merge pull request #1624 from AllanWang/search-ui-fix
Only use mbasic for parsing search
This commit is contained in:
commit
9b958725a7
@ -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"
|
||||
|
@ -59,6 +59,14 @@ enum class FbItem(
|
||||
* Note that this url only works if a query (?q=) is provided
|
||||
*/
|
||||
_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",
|
||||
|
@ -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.
|
||||
|
@ -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="" />
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user