Cleanup HttpUrl usage

This commit is contained in:
tarsin committed 2023-06-24 16:02:18 +08:00
1 parent be867d5d07
commit c84e86a5a1
3 files changed
+17 -23

No files matched your search

@@ -26,13 +26,11 @@ object EhUrl {
const val DOMAIN_LOFI = "lofi.e-hentai.org"
const val HOST_EX = "https://$DOMAIN_EX/"
const val API_EX = HOST_EX + "api.php"
const val URL_FAVORITES_EX = HOST_EX + "favorites.php"
const val URL_UCONFIG_EX = HOST_EX + "uconfig.php"
const val URL_MY_TAGS_EX = HOST_EX + "mytags"
const val URL_WATCHED_EX = HOST_EX + "watched"
const val HOST_E = "https://$DOMAIN_E/"
const val API_E = HOST_E + "api.php"
const val URL_FAVORITES_E = HOST_E + "favorites.php"
const val URL_UCONFIG_E = HOST_E + "uconfig.php"
const val URL_MY_TAGS_E = HOST_E + "mytags"
const val URL_WATCHED_E = HOST_E + "watched"
@@ -66,13 +64,6 @@ object EhUrl {
else -> HOST_E
}
val favoritesUrl: String
get() = when (Settings.gallerySite) {
SITE_E -> URL_FAVORITES_E
SITE_EX -> URL_FAVORITES_EX
else -> URL_FAVORITES_E
}
val apiUrl: String
get() = when (Settings.gallerySite) {
SITE_E -> API_E
@@ -162,4 +153,4 @@ object EhUrl {
}
}
inline fun httpsUrl(builder: HttpUrl.Builder.() -> Unit) = HttpUrl.Builder().apply(builder).host("https").build()
inline fun httpsUrl(builder: HttpUrl.Builder.() -> Unit) = HttpUrl.Builder().apply(builder).scheme("https").build()
@@ -17,10 +17,9 @@ package com.hippo.ehviewer.client.data
import android.os.Parcelable
import com.hippo.ehviewer.client.EhUrl
import com.hippo.ehviewer.network.UrlBuilder
import com.hippo.ehviewer.client.httpsUrl
import com.hippo.ehviewer.util.encodeUTF8
import kotlinx.parcelize.Parcelize
import okhttp3.HttpUrl.Companion.toHttpUrl
@Parcelize
class FavListUrlBuilder(
@@ -35,19 +34,19 @@ class FavListUrlBuilder(
mPrev = index.takeUnless { isNext }
}
fun build(): String {
val ub = UrlBuilder(EhUrl.favoritesUrl.toHttpUrl().newBuilder())
fun build() = httpsUrl {
host(EhUrl.domain)
addPathSegment("favorites.php")
if (isValidFavCat(favCat)) {
ub.url.addEncodedQueryParameter("favcat", favCat.toString())
addEncodedQueryParameter("favcat", favCat.toString())
} else if (favCat == FAV_CAT_ALL) {
ub.url.addEncodedQueryParameter("favcat", "all")
addEncodedQueryParameter("favcat", "all")
}
keyword?.takeIf { it.isNotBlank() }?.let { ub.url.addEncodedQueryParameter("f_search", encodeUTF8(it)) }
mPrev?.takeIf { it.isNotEmpty() }?.let { ub.url.addEncodedQueryParameter("prev", it) }
mNext?.takeIf { it.isNotEmpty() }?.let { ub.url.addEncodedQueryParameter("next", it) }
jumpTo?.takeIf { it.isNotEmpty() }?.let { ub.url.addEncodedQueryParameter("seek", it) }
return ub.url.toString()
}
keyword?.takeIf { it.isNotBlank() }?.let { addEncodedQueryParameter("f_search", encodeUTF8(it)) }
mPrev?.takeIf { it.isNotEmpty() }?.let { addEncodedQueryParameter("prev", it) }
mNext?.takeIf { it.isNotEmpty() }?.let { addEncodedQueryParameter("next", it) }
jumpTo?.takeIf { it.isNotEmpty() }?.let { addEncodedQueryParameter("seek", it) }
}.toString()
companion object {
const val FAV_CAT_ALL = -1
@@ -45,6 +45,7 @@ import com.hippo.ehviewer.client.EhEngine
import com.hippo.ehviewer.client.EhUrl
import com.hippo.ehviewer.client.data.FavListUrlBuilder
import com.hippo.ehviewer.client.data.GalleryInfo
import com.hippo.ehviewer.client.httpsUrl
import com.hippo.ehviewer.client.parser.FavoritesParser
import com.hippo.ehviewer.databinding.DrawerListRvBinding
import com.hippo.ehviewer.databinding.ItemDrawerFavoritesBinding
@@ -820,7 +821,10 @@ class FavoritesScene :
mModifyGiList.clear()
val url: String = if (local) {
// Local fav is shown now, but operation need be done for cloud fav
EhUrl.favoritesUrl
httpsUrl {
host(EhUrl.domain)
addPathSegments("favorites.php")
}.toString()
} else {
mUrlBuilder!!.build()
}