Optimize imports, disallow wildcard imports because of klint, run linter

This commit is contained in:
jobobby04
2020-04-04 16:30:05 -04:00
committed by Jobobby04
parent f18891a07e
commit 23ac3d18e5
138 changed files with 1192 additions and 1027 deletions
@@ -7,14 +7,14 @@ import com.afollestad.materialdialogs.MaterialDialog
import eu.kanade.tachiyomi.ui.base.controller.DialogController
import eu.kanade.tachiyomi.util.lang.launchUI
import eu.kanade.tachiyomi.util.system.toast
import timber.log.Timber
import kotlin.concurrent.thread
import timber.log.Timber
class ConfiguringDialogController : DialogController() {
private var materialDialog: MaterialDialog? = null
override fun onCreateDialog(savedViewState: Bundle?): Dialog {
if(savedViewState == null)
if (savedViewState == null)
thread {
try {
EHConfigurator().configureAll()
@@ -62,4 +62,3 @@ class ConfiguringDialogController : DialogController() {
router.popController(this)
}
}
+27 -25
View File
@@ -24,11 +24,13 @@ class EHConfigurator {
private fun EHentai.requestWithCreds(sp: Int = 1) = Request.Builder()
.addHeader("Cookie", cookiesHeader(sp))
private fun EHentai.execProfileActions(action: String,
name: String,
set: String,
sp: Int)
= configuratorClient.newCall(requestWithCreds(sp)
private fun EHentai.execProfileActions(
action: String,
name: String,
set: String,
sp: Int
) =
configuratorClient.newCall(requestWithCreds(sp)
.url(uconfigUrl)
.post(FormBody.Builder()
.add("profile_action", action)
@@ -44,7 +46,7 @@ class EHConfigurator {
val ehSource = sources.get(EH_SOURCE_ID) as EHentai
val exhSource = sources.get(EXH_SOURCE_ID) as EHentai
//Get hath perks
// Get hath perks
val perksPage = configuratorClient.newCall(ehSource.requestWithCreds()
.url(HATH_PERKS_URL)
.build())
@@ -56,13 +58,13 @@ class EHConfigurator {
val name = it.child(0).text().toLowerCase()
val purchased = it.child(2).getElementsByTag("form").isEmpty()
when(name) {
//Thumbnail rows
when (name) {
// Thumbnail rows
"more thumbs" -> hathPerks.moreThumbs = purchased
"thumbs up" -> hathPerks.thumbsUp = purchased
"all thumbs" -> hathPerks.allThumbs = purchased
//Pagination sizing
// Pagination sizing
"paging enlargement i" -> hathPerks.pagingEnlargementI = purchased
"paging enlargement ii" -> hathPerks.pagingEnlargementII = purchased
"paging enlargement iii" -> hathPerks.pagingEnlargementIII = purchased
@@ -76,45 +78,45 @@ class EHConfigurator {
}
fun configure(source: EHentai, hathPerks: EHHathPerksResponse) {
//Delete old app profiles
// Delete old app profiles
val scanReq = source.requestWithCreds().url(source.uconfigUrl).build()
val resp = configuratorClient.newCall(scanReq).execute().asJsoup()
var lastDoc = resp
resp.select(PROFILE_SELECTOR).forEach {
if(it.text() == PROFILE_NAME) {
if (it.text() == PROFILE_NAME) {
val id = it.attr("value")
//Delete old profile
// Delete old profile
lastDoc = source.execProfileActions("delete", "", id, id.toInt()).asJsoup()
}
}
//Find available profile slot
val availableProfiles = (1 .. 3).toMutableList()
// Find available profile slot
val availableProfiles = (1..3).toMutableList()
lastDoc.select(PROFILE_SELECTOR).forEach {
availableProfiles.remove(it.attr("value").toInt())
}
//No profile slots left :(
if(availableProfiles.isEmpty())
// No profile slots left :(
if (availableProfiles.isEmpty())
throw IllegalStateException("You are out of profile slots on ${source.name}, please delete a profile!")
//Create profile in available slot
// Create profile in available slot
val slot = availableProfiles.first()
val response = source.execProfileActions("create",
PROFILE_NAME,
slot.toString(),
1)
//Build new profile
// Build new profile
val form = EhUConfigBuilder().build(hathPerks)
//Send new profile to server
// Send new profile to server
configuratorClient.newCall(source.requestWithCreds(sp = slot)
.url(source.uconfigUrl)
.post(form)
.build()).execute()
//Persist slot + sk
// Persist slot + sk
source.spPref().set(slot)
val keyCookie = response.headers.toMultimap()["Set-Cookie"]?.find {
@@ -127,19 +129,19 @@ class EHConfigurator {
it.startsWith("hath_perks=")
}?.removePrefix("hath_perks=")?.substringBefore(';')
if(keyCookie != null)
if (keyCookie != null)
prefs.eh_settingsKey().set(keyCookie)
if(sessionCookie != null)
if (sessionCookie != null)
prefs.eh_sessionCookie().set(sessionCookie)
if(hathPerksCookie != null)
if (hathPerksCookie != null)
prefs.eh_hathPerksCookies().set(hathPerksCookie)
}
companion object {
private const val PROFILE_NAME = "TachiyomiEH App"
private const val UCONFIG_URL = "/uconfig.php"
//Always use E-H here as EXH does not have a perks page
// Always use E-H here as EXH does not have a perks page
private const val HATH_PERKS_URL = "https://e-hentai.org/hathperks.php"
private const val PROFILE_SELECTOR = "[name=profile_set] > option"
}
}
}
@@ -9,7 +9,6 @@ class EHHathPerksResponse {
var pagingEnlargementII = false
var pagingEnlargementIII = false
override fun toString()
= "EHHathPerksResponse(moreThumbs=$moreThumbs, thumbsUp=$thumbsUp, allThumbs=$allThumbs, pagingEnlargementI=$pagingEnlargementI, pagingEnlargementII=$pagingEnlargementII, pagingEnlargementIII=$pagingEnlargementIII)"
override fun toString() =
"EHHathPerksResponse(moreThumbs=$moreThumbs, thumbsUp=$thumbsUp, allThumbs=$allThumbs, pagingEnlargementI=$pagingEnlargementI, pagingEnlargementII=$pagingEnlargementII, pagingEnlargementIII=$pagingEnlargementIII)"
}
@@ -11,7 +11,7 @@ class EhUConfigBuilder {
fun build(hathPerks: EHHathPerksResponse): FormBody {
val configItems = mutableListOf<ConfigItem>()
configItems += when(prefs.imageQuality()
configItems += when (prefs.imageQuality()
.getOrDefault()
.toLowerCase()) {
"ovrs_2400" -> Entry.ImageSize.`2400`
@@ -23,17 +23,17 @@ class EhUConfigBuilder {
else -> Entry.ImageSize.AUTO
}
configItems += if(prefs.useHentaiAtHome().getOrDefault())
configItems += if (prefs.useHentaiAtHome().getOrDefault())
Entry.UseHentaiAtHome.YES
else
Entry.UseHentaiAtHome.NO
configItems += if(prefs.useJapaneseTitle().getOrDefault())
configItems += if (prefs.useJapaneseTitle().getOrDefault())
Entry.TitleDisplayLanguage.JAPANESE
else
Entry.TitleDisplayLanguage.DEFAULT
configItems += if(prefs.eh_useOriginalImages().getOrDefault())
configItems += if (prefs.eh_useOriginalImages().getOrDefault())
Entry.UseOriginalImages.YES
else
Entry.UseOriginalImages.NO
@@ -56,7 +56,7 @@ class EhUConfigBuilder {
configItems += Entry.UseMPV()
configItems += Entry.ShowPopularRightNowPane()
//Actually build form body
// Actually build form body
val formBody = FormBody.Builder()
configItems.forEach {
formBody.add(it.key, it.value)
@@ -67,14 +67,14 @@ class EhUConfigBuilder {
}
object Entry {
enum class UseHentaiAtHome(override val value: String): ConfigItem {
enum class UseHentaiAtHome(override val value: String) : ConfigItem {
YES("0"),
NO("1");
override val key = "uh"
}
enum class ImageSize(override val value: String): ConfigItem {
enum class ImageSize(override val value: String) : ConfigItem {
AUTO("0"),
`2400`("5"),
`1600`("4"),
@@ -85,20 +85,20 @@ object Entry {
override val key = "xr"
}
enum class TitleDisplayLanguage(override val value: String): ConfigItem {
enum class TitleDisplayLanguage(override val value: String) : ConfigItem {
DEFAULT("0"),
JAPANESE("1");
override val key = "tl"
}
//Locked to extended mode as that's what the parser and toplists use
class DisplayMode: ConfigItem {
// Locked to extended mode as that's what the parser and toplists use
class DisplayMode : ConfigItem {
override val key = "dm"
override val value = "2"
}
enum class SearchResultsCount(override val value: String): ConfigItem {
enum class SearchResultsCount(override val value: String) : ConfigItem {
`25`("0"),
`50`("1"),
`100`("2"),
@@ -107,7 +107,7 @@ object Entry {
override val key = "rc"
}
enum class ThumbnailRows(override val value: String): ConfigItem {
enum class ThumbnailRows(override val value: String) : ConfigItem {
`4`("0"),
`10`("1"),
`20`("2"),
@@ -116,21 +116,21 @@ object Entry {
override val key = "tr"
}
enum class UseOriginalImages(override val value: String): ConfigItem {
enum class UseOriginalImages(override val value: String) : ConfigItem {
NO("0"),
YES("1");
override val key = "oi"
}
//Locked to no MPV as that's what the parser uses
class UseMPV: ConfigItem {
// Locked to no MPV as that's what the parser uses
class UseMPV : ConfigItem {
override val key = "qb"
override val value = "0"
}
//Locked to no popular pane as we can't parse it
class ShowPopularRightNowPane: ConfigItem {
// Locked to no popular pane as we can't parse it
class ShowPopularRightNowPane : ConfigItem {
override val key = "pp"
override val value = "1"
}
@@ -139,4 +139,4 @@ object Entry {
interface ConfigItem {
val key: String
val value: String
}
}
@@ -32,10 +32,10 @@ class WarnConfigureDialogController : DialogController() {
companion object {
fun uploadSettings(router: Router) {
if(Injekt.get<PreferencesHelper>().eh_showSettingsUploadWarning().getOrDefault())
if (Injekt.get<PreferencesHelper>().eh_showSettingsUploadWarning().getOrDefault())
WarnConfigureDialogController().showDialog(router)
else
ConfiguringDialogController().showDialog(router)
}
}
}
}