Cleanup EH and AZ preferences

This commit is contained in:
Jobobby04
2020-11-30 14:35:31 -05:00
parent f1a6218a4b
commit 9a2ed755b7
38 changed files with 133 additions and 168 deletions
+2 -2
View File
@@ -48,7 +48,7 @@ object EXHMigrations {
*/
fun upgrade(preferences: PreferencesHelper): Boolean {
val context = preferences.context
val oldVersion = preferences.eh_lastVersionCode().get()
val oldVersion = preferences.ehLastVersionCode().get()
try {
if (oldVersion < BuildConfig.VERSION_CODE) {
// Fresh install
@@ -259,7 +259,7 @@ object EXHMigrations {
// TODO BE CAREFUL TO NOT FUCK UP MergedSources IF CHANGING URLs
preferences.eh_lastVersionCode().set(BuildConfig.VERSION_CODE)
preferences.ehLastVersionCode().set(BuildConfig.VERSION_CODE)
return true
}
+11 -11
View File
@@ -38,12 +38,12 @@ object DebugFunctions {
val sourceManager: SourceManager by injectLazy()
fun forceUpgradeMigration() {
prefs.eh_lastVersionCode().set(1)
prefs.ehLastVersionCode().set(1)
EXHMigrations.upgrade(prefs)
}
fun forceSetupJobs() {
prefs.eh_lastVersionCode().set(0)
prefs.ehLastVersionCode().set(0)
EXHMigrations.upgrade(prefs)
}
@@ -168,7 +168,7 @@ object DebugFunctions {
it.favorite && db.getSearchMetadataForManga(it.id!!).executeAsBlocking() == null
}
fun clearSavedSearches() = prefs.eh_savedSearches().set(emptySet())
fun clearSavedSearches() = prefs.savedSearches().set(emptySet())
fun listAllSources() = sourceManager.getCatalogueSources().joinToString("\n") {
"${it.id}: ${it.name} (${it.lang.toUpperCase()})"
@@ -233,7 +233,7 @@ object DebugFunctions {
runBlocking {
val source = sourceManager.get(EH_SOURCE_ID) as? CatalogueSource ?: return@runBlocking
val newSource = sourceManager.get(EXH_SOURCE_ID) as? CatalogueSource ?: return@runBlocking
val savedSearches = prefs.eh_savedSearches().get().mapNotNull {
val savedSearches = prefs.savedSearches().get().mapNotNull {
try {
val id = it.substringBefore(':').toLong()
if (id != source.id) return@mapNotNull null
@@ -245,7 +245,7 @@ object DebugFunctions {
null
}
}.toMutableList()
savedSearches += prefs.eh_savedSearches().get().mapNotNull {
savedSearches += prefs.savedSearches().get().mapNotNull {
try {
val id = it.substringBefore(':').toLong()
if (id != newSource.id) return@mapNotNull null
@@ -258,13 +258,13 @@ object DebugFunctions {
}
}.filterNot { newSavedSearch -> savedSearches.any { it.name == newSavedSearch.name } }
val otherSerialized = prefs.eh_savedSearches().get().filter {
val otherSerialized = prefs.savedSearches().get().filter {
!it.startsWith("${newSource.id}:")
}
val newSerialized = savedSearches.map {
"${newSource.id}:" + Json.encodeToString(it)
}
prefs.eh_savedSearches().set((otherSerialized + newSerialized).toSet())
prefs.savedSearches().set((otherSerialized + newSerialized).toSet())
}
}
@@ -272,7 +272,7 @@ object DebugFunctions {
runBlocking {
val source = sourceManager.get(EXH_SOURCE_ID) as? CatalogueSource ?: return@runBlocking
val newSource = sourceManager.get(EH_SOURCE_ID) as? CatalogueSource ?: return@runBlocking
val savedSearches = prefs.eh_savedSearches().get().mapNotNull {
val savedSearches = prefs.savedSearches().get().mapNotNull {
try {
val id = it.substringBefore(':').toLong()
if (id != source.id) return@mapNotNull null
@@ -284,7 +284,7 @@ object DebugFunctions {
null
}
}.toMutableList()
savedSearches += prefs.eh_savedSearches().get().mapNotNull {
savedSearches += prefs.savedSearches().get().mapNotNull {
try {
val id = it.substringBefore(':').toLong()
if (id != newSource.id) return@mapNotNull null
@@ -297,13 +297,13 @@ object DebugFunctions {
}
}.filterNot { newSavedSearch -> savedSearches.any { it.name == newSavedSearch.name } }
val otherSerialized = prefs.eh_savedSearches().get().filter {
val otherSerialized = prefs.savedSearches().get().filter {
!it.startsWith("${newSource.id}:")
}
val newSerialized = savedSearches.map {
"${newSource.id}:" + Json.encodeToString(it)
}
prefs.eh_savedSearches().set((otherSerialized + newSerialized).toSet())
prefs.savedSearches().set((otherSerialized + newSerialized).toSet())
}
}
}
@@ -239,7 +239,7 @@ class EHentaiUpdateWorker : JobService(), CoroutineScope {
updatedThisIteration++
}
} finally {
prefs.eh_autoUpdateStats().set(
prefs.exhAutoUpdateStats().set(
Json.encodeToString(
EHentaiUpdaterStats(
startTime,
@@ -355,9 +355,9 @@ class EHentaiUpdateWorker : JobService(), CoroutineScope {
cancelBackground(context)
val preferences = Injekt.get<PreferencesHelper>()
val duration = prefInterval ?: preferences.eh_autoUpdateFrequency().get()
val duration = prefInterval ?: preferences.exhAutoUpdateFrequency().get()
if (duration > 0) {
val restrictions = preferences.eh_autoUpdateRequirements()!!
val restrictions = preferences.exhAutoUpdateRequirements().get()
val acRestriction = "ac" in restrictions
val wifiRestriction = "wifi" in restrictions
@@ -14,7 +14,7 @@ class FavoritesIntroDialog {
.title(R.string.favorites_sync_notes)
.message(text = HtmlCompat.fromHtml(context.getString(R.string.favorites_sync_notes_message), HtmlCompat.FROM_HTML_MODE_LEGACY))
.positiveButton(android.R.string.ok) {
prefs.eh_showSyncIntro().set(false)
prefs.exhShowSyncIntro().set(false)
}
.cancelable(false)
.show()
@@ -138,7 +138,7 @@ class FavoritesSyncHelper(val context: Context) {
db.inTransaction {
status.onNext(FavoritesSyncStatus.Processing(context.getString(R.string.favorites_sync_calculating_remote_changes), context = context))
val remoteChanges = storage.getChangedRemoteEntries(realm, favorites.first)
val localChanges = if (prefs.eh_readOnlySync().get()) {
val localChanges = if (prefs.exhReadOnlySync().get()) {
null // Do not build local changes if they are not going to be applied
} else {
status.onNext(FavoritesSyncStatus.Processing(context.getString(R.string.favorites_sync_calculating_local_changes), context = context))
@@ -255,7 +255,7 @@ class FavoritesSyncHelper(val context: Context) {
if (!explicitlyRetryExhRequest(10, request)) {
val errorString = "Unable to add gallery to remote server: '${gallery.title}' (GID: ${gallery.gid})!"
if (prefs.eh_lenientSync().get()) {
if (prefs.exhLenientSync().get()) {
errorList += errorString
} else {
status.onNext(FavoritesSyncStatus.Error(errorString))
@@ -305,7 +305,7 @@ class FavoritesSyncHelper(val context: Context) {
if (!explicitlyRetryExhRequest(10, request)) {
val errorString = context.getString(R.string.favorites_sync_unable_to_delete)
if (prefs.eh_lenientSync().get()) {
if (prefs.exhLenientSync().get()) {
errorList += errorString
} else {
status.onNext(FavoritesSyncStatus.Error(errorString))
@@ -397,7 +397,7 @@ class FavoritesSyncHelper(val context: Context) {
is GalleryAddEvent.Fail.UnknownType -> context.getString(R.string.favorites_sync_failed_to_add_to_local_unknown_type, it.title, result.galleryUrl)
}
if (prefs.eh_lenientSync().get()) {
if (prefs.exhLenientSync().get()) {
errorList += errorString
} else {
status.onNext(FavoritesSyncStatus.Error(errorString))
@@ -59,7 +59,7 @@ class EHDebugModeOverlay(private val context: Context) : OverlayModule<String>(n
<b>Version code:</b> ${BuildConfig.VERSION_CODE}<br>
<b>Commit SHA:</b> ${BuildConfig.COMMIT_SHA}<br>
<b>Log level:</b> ${EHLogLevel.currentLogLevel.name.toLowerCase(Locale.getDefault())}<br>
<b>Source blacklist:</b> ${prefs.eh_enableSourceBlacklist().get().asEnabledString()}
<b>Source blacklist:</b> ${prefs.enableSourceBlacklist().get().asEnabledString()}
""".trimIndent()
private fun Boolean.asEnabledString() = if (this) "enabled" else "disabled"
@@ -20,7 +20,7 @@ fun OkHttpClient.Builder.injectPatches(sourceIdProducer: () -> Long): OkHttpClie
fun findAndApplyPatches(sourceId: Long): EHInterceptor {
// TODO make it so captcha doesnt auto open in manga eden while applying universal interceptors
return if (Injekt.get<PreferencesHelper>().eh_autoSolveCaptchas().get()) ((EH_INTERCEPTORS[sourceId].orEmpty()) + (EH_INTERCEPTORS[EH_UNIVERSAL_INTERCEPTOR].orEmpty())).merge()
return if (Injekt.get<PreferencesHelper>().autoSolveCaptcha().get()) ((EH_INTERCEPTORS[sourceId].orEmpty()) + (EH_INTERCEPTORS[EH_UNIVERSAL_INTERCEPTOR].orEmpty())).merge()
else (EH_INTERCEPTORS[sourceId].orEmpty()).merge()
}
@@ -229,7 +229,7 @@ class EnhancedHttpSource(
override fun getFilterList() = source().getFilterList()
fun source(): HttpSource {
return if (prefs.eh_delegateSources().get()) {
return if (prefs.delegateSources().get()) {
enhancedSource
} else {
originalSource
@@ -145,13 +145,13 @@ class EHConfigurator(val context: Context) {
}?.removePrefix("hath_perks=")?.substringBefore(';')
if (keyCookie != null) {
prefs.eh_settingsKey().set(keyCookie)
prefs.exhSettingsKey().set(keyCookie)
}
if (sessionCookie != null) {
prefs.eh_sessionCookie().set(sessionCookie)
prefs.exhSessionCookie().set(sessionCookie)
}
if (hathPerksCookie != null) {
prefs.eh_hathPerksCookies().set(hathPerksCookie)
prefs.exhHathPerksCookies().set(hathPerksCookie)
}
}
@@ -37,7 +37,7 @@ class EhUConfigBuilder {
Entry.TitleDisplayLanguage.DEFAULT
}
configItems += if (preferences.eh_useOriginalImages().get()) {
configItems += if (preferences.exhUseOriginalImages().get()) {
Entry.UseOriginalImages.YES
} else {
Entry.UseOriginalImages.NO
@@ -64,9 +64,9 @@ class EhUConfigBuilder {
configItems += Entry.TagFilteringThreshold(preferences.ehTagFilterValue().get())
configItems += Entry.TagWatchingThreshold(preferences.ehTagWatchingValue().get())
configItems += Entry.LanguageSystem().getLanguages(preferences.eh_settingsLanguages().get().split("\n"))
configItems += Entry.LanguageSystem().getLanguages(preferences.exhSettingsLanguages().get().split("\n"))
configItems += Entry.Categories().categoryConfigs(preferences.eh_EnabledCategories().get().split(",").map { it.toBoolean() })
configItems += Entry.Categories().categoryConfigs(preferences.exhEnabledCategories().get().split(",").map { it.toBoolean() })
// Actually build form body
val formBody = FormBody.Builder()
@@ -18,7 +18,7 @@ class WarnConfigureDialogController : DialogController() {
.title(R.string.settings_profile_note)
.message(R.string.settings_profile_note_message)
.positiveButton(android.R.string.ok) {
prefs.eh_showSettingsUploadWarning().set(false)
prefs.exhShowSettingsUploadWarning().set(false)
ConfiguringDialogController().showDialog(router)
}
.cancelable(false)
@@ -26,7 +26,7 @@ class WarnConfigureDialogController : DialogController() {
companion object {
fun uploadSettings(router: Router) {
if (Injekt.get<PreferencesHelper>().eh_showSettingsUploadWarning().get()) {
if (Injekt.get<PreferencesHelper>().exhShowSettingsUploadWarning().get()) {
WarnConfigureDialogController().showDialog(router)
} else {
ConfiguringDialogController().showDialog(router)
@@ -131,7 +131,7 @@ class BrowserActionActivity : AppCompatActivity() {
// Wait for both inner scripts to be loaded
if (loadedInners >= 2) {
// Attempt to autosolve captcha
if (preferencesHelper.eh_autoSolveCaptchas().get()) {
if (preferencesHelper.autoSolveCaptcha().get()) {
binding.webview.post {
// 10 seconds to auto-solve captcha
strictValidationStartTime = System.currentTimeMillis() + 1000 * 10
@@ -150,7 +150,7 @@ class BrowserActionActivity : AppCompatActivity() {
}
}
binding.webview.webViewClient = if (actionName == null && preferencesHelper.eh_autoSolveCaptchas().get()) {
binding.webview.webViewClient = if (actionName == null && preferencesHelper.autoSolveCaptcha().get()) {
// Fetch auto-solve credentials early for speed
credentialsObservable = httpClient.newCall(
Request.Builder()
@@ -62,14 +62,14 @@ class MangadexLoginDialog(bundle: Bundle? = null) : DialogController(bundle) {
binding!!.login.setMode(ActionProcessButton.Mode.ENDLESS)
binding!!.login.setOnClickListener { checkLogin() }
setCredentialsOnView(view)
setCredentialsOnView()
binding!!.twoFactorCheck.setOnCheckedChangeListener { _, isChecked ->
binding!!.twoFactorHolder.isVisible = isChecked
}
}
private fun setCredentialsOnView(view: View) {
private fun setCredentialsOnView() {
binding?.username?.setText(service.getUsername())
binding?.password?.setText(service.getPassword())
}