Linting Fixes AZ

This commit is contained in:
Jobobby04
2020-05-02 00:46:24 -04:00
parent 03e5c5ca10
commit 7e99a9f789
108 changed files with 2962 additions and 2412 deletions
@@ -14,7 +14,7 @@ class ConfiguringDialogController : DialogController() {
private var materialDialog: MaterialDialog? = null
override fun onCreateDialog(savedViewState: Bundle?): Dialog {
if (savedViewState == null)
if (savedViewState == null) {
thread {
try {
EHConfigurator().configureAll()
@@ -25,10 +25,10 @@ class ConfiguringDialogController : DialogController() {
activity?.let {
it.runOnUiThread {
MaterialDialog(it)
.title(text = "Configuration failed!")
.message(text = "An error occurred during the configuration process: " + e.message)
.positiveButton(android.R.string.ok)
.show()
.title(text = "Configuration failed!")
.message(text = "An error occurred during the configuration process: " + e.message)
.positiveButton(android.R.string.ok)
.show()
}
}
Timber.e(e, "Configuration error!")
@@ -37,14 +37,15 @@ class ConfiguringDialogController : DialogController() {
finish()
}
}
}
return MaterialDialog(activity!!)
.title(text = "Uploading settings to server")
.message(text = "Please wait, this may take some time...")
.cancelable(false)
.also {
materialDialog = it
}
.title(text = "Uploading settings to server")
.message(text = "Please wait, this may take some time...")
.cancelable(false)
.also {
materialDialog = it
}
}
override fun onDestroyView(view: View) {
+36 -22
View File
@@ -18,11 +18,11 @@ class EHConfigurator {
private val sources: SourceManager by injectLazy()
private val configuratorClient = OkHttpClient.Builder()
.maybeInjectEHLogger()
.build()
.maybeInjectEHLogger()
.build()
private fun EHentai.requestWithCreds(sp: Int = 1) = Request.Builder()
.addHeader("Cookie", cookiesHeader(sp))
.addHeader("Cookie", cookiesHeader(sp))
private fun EHentai.execProfileActions(
action: String,
@@ -30,15 +30,19 @@ class EHConfigurator {
set: String,
sp: Int
) =
configuratorClient.newCall(requestWithCreds(sp)
configuratorClient.newCall(
requestWithCreds(sp)
.url(uconfigUrl)
.post(FormBody.Builder()
.post(
FormBody.Builder()
.add("profile_action", action)
.add("profile_name", name)
.add("profile_set", set)
.build())
.build())
.execute()
.build()
)
.build()
)
.execute()
private val EHentai.uconfigUrl get() = baseUrl + UCONFIG_URL
@@ -47,10 +51,12 @@ class EHConfigurator {
val exhSource = sources.get(EXH_SOURCE_ID) as EHentai
// Get hath perks
val perksPage = configuratorClient.newCall(ehSource.requestWithCreds()
val perksPage = configuratorClient.newCall(
ehSource.requestWithCreds()
.url(HATH_PERKS_URL)
.build())
.execute().asJsoup()
.build()
)
.execute().asJsoup()
val hathPerks = EHHathPerksResponse()
@@ -97,24 +103,29 @@ class EHConfigurator {
}
// No profile slots left :(
if (availableProfiles.isEmpty())
if (availableProfiles.isEmpty()) {
throw IllegalStateException("You are out of profile slots on ${source.name}, please delete a profile!")
}
// Create profile in available slot
val slot = availableProfiles.first()
val response = source.execProfileActions("create",
PROFILE_NAME,
slot.toString(),
1)
val response = source.execProfileActions(
"create",
PROFILE_NAME,
slot.toString(),
1
)
// Build new profile
val form = EhUConfigBuilder().build(hathPerks)
// Send new profile to server
configuratorClient.newCall(source.requestWithCreds(sp = slot)
configuratorClient.newCall(
source.requestWithCreds(sp = slot)
.url(source.uconfigUrl)
.post(form)
.build()).execute()
.build()
).execute()
// Persist slot + sk
source.spPref().set(slot)
@@ -129,12 +140,15 @@ 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 {
@@ -11,9 +11,11 @@ class EhUConfigBuilder {
fun build(hathPerks: EHHathPerksResponse): FormBody {
val configItems = mutableListOf<ConfigItem>()
configItems += when (prefs.imageQuality()
configItems += when (
prefs.imageQuality()
.getOrDefault()
.toLowerCase()) {
.toLowerCase()
) {
"ovrs_2400" -> Entry.ImageSize.`2400`
"ovrs_1600" -> Entry.ImageSize.`1600`
"high" -> Entry.ImageSize.`1280`
@@ -23,20 +25,23 @@ class EhUConfigBuilder {
else -> Entry.ImageSize.AUTO
}
configItems += if (prefs.useHentaiAtHome().getOrDefault())
configItems += if (prefs.useHentaiAtHome().getOrDefault()) {
Entry.UseHentaiAtHome.YES
else
} else {
Entry.UseHentaiAtHome.NO
}
configItems += if (prefs.useJapaneseTitle().getOrDefault())
configItems += if (prefs.useJapaneseTitle().getOrDefault()) {
Entry.TitleDisplayLanguage.JAPANESE
else
} else {
Entry.TitleDisplayLanguage.DEFAULT
}
configItems += if (prefs.eh_useOriginalImages().getOrDefault())
configItems += if (prefs.eh_useOriginalImages().getOrDefault()) {
Entry.UseOriginalImages.YES
else
} else {
Entry.UseOriginalImages.NO
}
configItems += when {
hathPerks.allThumbs -> Entry.ThumbnailRows.`40`
@@ -14,25 +14,29 @@ class WarnConfigureDialogController : DialogController() {
private val prefs: PreferencesHelper by injectLazy()
override fun onCreateDialog(savedViewState: Bundle?): Dialog {
return MaterialDialog(activity!!)
.title(text = "Settings profile note")
.message(text = """
.title(text = "Settings profile note")
.message(
text =
"""
The app will now add a new settings profile on E-Hentai and ExHentai to optimize app performance. Please ensure that you have less than three profiles on both sites.
If you have no idea what settings profiles are, then it probably doesn't matter, just hit 'OK'.
""".trimIndent())
.positiveButton(android.R.string.ok) {
prefs.eh_showSettingsUploadWarning().set(false)
ConfiguringDialogController().showDialog(router)
}
.cancelable(false)
""".trimIndent()
)
.positiveButton(android.R.string.ok) {
prefs.eh_showSettingsUploadWarning().set(false)
ConfiguringDialogController().showDialog(router)
}
.cancelable(false)
}
companion object {
fun uploadSettings(router: Router) {
if (Injekt.get<PreferencesHelper>().eh_showSettingsUploadWarning().get())
if (Injekt.get<PreferencesHelper>().eh_showSettingsUploadWarning().get()) {
WarnConfigureDialogController().showDialog(router)
else
} else {
ConfiguringDialogController().showDialog(router)
}
}
}
}