komikku/app/src/main/java/exh/uconfig/EhUConfigBuilder.kt

160 lines
4.3 KiB
Kotlin
Raw Normal View History

2018-02-12 22:22:54 +01:00
package exh.uconfig
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import okhttp3.FormBody
import uy.kohesive.injekt.injectLazy
class EhUConfigBuilder {
private val prefs: PreferencesHelper by injectLazy()
fun build(hathPerks: EHHathPerksResponse): FormBody {
val configItems = mutableListOf<ConfigItem>()
2020-05-02 06:46:24 +02:00
configItems += when (
prefs.imageQuality()
2020-05-11 01:22:10 +02:00
.get()
2020-05-02 06:46:24 +02:00
.toLowerCase()
) {
2018-02-12 22:22:54 +01:00
"ovrs_2400" -> Entry.ImageSize.`2400`
"ovrs_1600" -> Entry.ImageSize.`1600`
"high" -> Entry.ImageSize.`1280`
"med" -> Entry.ImageSize.`980`
"low" -> Entry.ImageSize.`780`
"auto" -> Entry.ImageSize.AUTO
else -> Entry.ImageSize.AUTO
}
2020-05-11 01:22:10 +02:00
configItems += if (prefs.useHentaiAtHome().get()) {
2018-02-12 22:22:54 +01:00
Entry.UseHentaiAtHome.YES
2020-05-02 06:46:24 +02:00
} else {
2018-02-12 22:22:54 +01:00
Entry.UseHentaiAtHome.NO
2020-05-02 06:46:24 +02:00
}
2018-02-12 22:22:54 +01:00
2020-05-11 01:22:10 +02:00
configItems += if (prefs.useJapaneseTitle().get()) {
2018-02-12 22:22:54 +01:00
Entry.TitleDisplayLanguage.JAPANESE
2020-05-02 06:46:24 +02:00
} else {
2018-02-12 22:22:54 +01:00
Entry.TitleDisplayLanguage.DEFAULT
2020-05-02 06:46:24 +02:00
}
2018-02-12 22:22:54 +01:00
2020-05-11 01:22:10 +02:00
configItems += if (prefs.eh_useOriginalImages().get()) {
2018-02-12 22:22:54 +01:00
Entry.UseOriginalImages.YES
2020-05-02 06:46:24 +02:00
} else {
2018-02-12 22:22:54 +01:00
Entry.UseOriginalImages.NO
2020-05-02 06:46:24 +02:00
}
2018-02-12 22:22:54 +01:00
configItems += when {
hathPerks.allThumbs -> Entry.ThumbnailRows.`40`
hathPerks.thumbsUp -> Entry.ThumbnailRows.`20`
hathPerks.moreThumbs -> Entry.ThumbnailRows.`10`
else -> Entry.ThumbnailRows.`4`
}
configItems += when {
hathPerks.pagingEnlargementIII -> Entry.SearchResultsCount.`200`
hathPerks.pagingEnlargementII -> Entry.SearchResultsCount.`100`
hathPerks.pagingEnlargementI -> Entry.SearchResultsCount.`50`
else -> Entry.SearchResultsCount.`25`
}
configItems += Entry.DisplayMode()
configItems += Entry.UseMPV()
configItems += Entry.ShowPopularRightNowPane()
configItems += Entry.TagFilteringThreshold(prefs.ehTagFilterValue().get())
configItems += Entry.TagWatchingThreshold(prefs.ehTagWatchingValue().get())
// Actually build form body
2018-02-12 22:22:54 +01:00
val formBody = FormBody.Builder()
configItems.forEach {
formBody.add(it.key, it.value)
}
formBody.add("apply", "Apply")
return formBody.build()
}
}
object Entry {
enum class UseHentaiAtHome(override val value: String) : ConfigItem {
2018-02-12 22:22:54 +01:00
YES("0"),
NO("1");
override val key = "uh"
}
enum class ImageSize(override val value: String) : ConfigItem {
2018-02-12 22:22:54 +01:00
AUTO("0"),
`2400`("5"),
`1600`("4"),
`1280`("3"),
`980`("2"),
`780`("1");
override val key = "xr"
}
enum class TitleDisplayLanguage(override val value: String) : ConfigItem {
2018-02-12 22:22:54 +01:00
DEFAULT("0"),
JAPANESE("1");
override val key = "tl"
}
// Locked to extended mode as that's what the parser and toplists use
class DisplayMode : ConfigItem {
2018-02-12 22:22:54 +01:00
override val key = "dm"
override val value = "2"
2018-02-12 22:22:54 +01:00
}
enum class SearchResultsCount(override val value: String) : ConfigItem {
2018-02-12 22:22:54 +01:00
`25`("0"),
`50`("1"),
`100`("2"),
`200`("3");
override val key = "rc"
}
enum class ThumbnailRows(override val value: String) : ConfigItem {
2018-02-12 22:22:54 +01:00
`4`("0"),
`10`("1"),
`20`("2"),
`40`("3");
override val key = "tr"
}
enum class UseOriginalImages(override val value: String) : ConfigItem {
2018-02-12 22:22:54 +01:00
NO("0"),
YES("1");
override val key = "oi"
}
// Locked to no MPV as that's what the parser uses
class UseMPV : ConfigItem {
2018-02-12 22:22:54 +01:00
override val key = "qb"
override val value = "0"
}
// Locked to no popular pane as we can't parse it
class ShowPopularRightNowPane : ConfigItem {
2018-02-12 22:22:54 +01:00
override val key = "pp"
override val value = "1"
}
class TagFilteringThreshold(value: Int) : ConfigItem {
2020-05-27 19:45:25 +02:00
override val key = "ft"
override val value = "$value"
}
class TagWatchingThreshold(value: Int) : ConfigItem {
override val key = "wt"
override val value = "$value"
}
2018-02-12 22:22:54 +01:00
}
interface ConfigItem {
val key: String
val value: String
}