Skip to content

Commit ef4fdea

Browse files
authored
MangaDistrict: Option to not clean title during browsing/search (#17445)
1 parent 7a006d3 commit ef4fdea

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

src/en/mangadistrict/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44

55
keiyoushi {
66
name = "Manga District"
7-
versionCode = 16
7+
versionCode = 17
88
contentWarning = ContentWarning.NSFW
99
libVersion = "1.4"
1010
theme = "madara"

src/en/mangadistrict/src/eu/kanade/tachiyomi/extension/en/mangadistrict/MangaDistrict.kt

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,17 @@ abstract class MangaDistrict :
4949
} catch (_: Exception) {}
5050
}
5151

52-
override fun popularMangaFromElement(element: Element): SManga = super.popularMangaFromElement(element).cleanTitleIfNeeded()
52+
override fun popularMangaFromElement(element: Element): SManga = super.popularMangaFromElement(element).let {
53+
it.takeIf { noCleanTitlesWhileBrowsing() }
54+
?: it.cleanTitleIfNeeded()
55+
}
5356

5457
override fun popularMangaNextPageSelector() = "div[role=navigation] span.current + a.page"
5558

56-
override fun latestUpdatesFromElement(element: Element): SManga = super.latestUpdatesFromElement(element).cleanTitleIfNeeded()
59+
override fun latestUpdatesFromElement(element: Element): SManga = super.latestUpdatesFromElement(element).let {
60+
it.takeIf { noCleanTitlesWhileBrowsing() }
61+
?: it.cleanTitleIfNeeded()
62+
}
5763

5864
override fun searchMangaSelector() = popularMangaSelector()
5965
override fun searchMangaNextPageSelector() = popularMangaNextPageSelector()
@@ -286,6 +292,7 @@ abstract class MangaDistrict :
286292

287293
private fun isRemoveTitleVersion() = preferences.getBoolean(REMOVE_TITLE_VERSION_PREF, false)
288294
private fun customRemoveTitle(): String = preferences.getString("${REMOVE_TITLE_CUSTOM_PREF}_$lang", "")!!
295+
private fun noCleanTitlesWhileBrowsing(): Boolean = preferences.getBoolean(NO_REMOVE_TITLE_BROWSING_PREF, false)
289296
private fun getImgRes() = preferences.getString(IMG_RES_PREF, IMG_RES_DEFAULT)!!
290297

291298
private var SharedPreferences.dates: MutableMap<String, Long>
@@ -301,6 +308,14 @@ abstract class MangaDistrict :
301308
}
302309

303310
override fun setupPreferenceScreen(screen: PreferenceScreen) {
311+
val noRemoveTitleBrowsingPref = CheckBoxPreference(screen.context).apply {
312+
key = NO_REMOVE_TITLE_BROWSING_PREF
313+
title = "Don't apply title cleaning in browsing/search results"
314+
summary = "Don't apply the 2 options above when browsing or searching for manga, but still apply them in manga details."
315+
setVisible(isRemoveTitleVersion() || customRemoveTitle().isNotEmpty())
316+
setDefaultValue(false)
317+
}
318+
304319
CheckBoxPreference(screen.context).apply {
305320
key = REMOVE_TITLE_VERSION_PREF
306321
title = "Remove version information from entry titles"
@@ -309,6 +324,11 @@ abstract class MangaDistrict :
309324
"To update existing entries, remove them from your library (unfavorite) and refresh manually. " +
310325
"You might also want to clear the database in advanced settings."
311326
setDefaultValue(false)
327+
setOnPreferenceChangeListener { _, newValue ->
328+
val enabled = newValue as Boolean
329+
noRemoveTitleBrowsingPref.setVisible(enabled || customRemoveTitle().isNotEmpty())
330+
true
331+
}
312332
}.let(screen::addPreference)
313333

314334
EditTextPreference(screen.context).apply {
@@ -344,13 +364,16 @@ abstract class MangaDistrict :
344364
val (isValid, message) = validate(newValue as String)
345365
if (isValid) {
346366
summary = newValue
367+
noRemoveTitleBrowsingPref.setVisible(isRemoveTitleVersion() || newValue.isNotEmpty())
347368
} else {
348369
Toast.makeText(screen.context, message, Toast.LENGTH_LONG).show()
349370
}
350371
isValid
351372
}
352373
}.let(screen::addPreference)
353374

375+
screen.addPreference(noRemoveTitleBrowsingPref)
376+
354377
ListPreference(screen.context).apply {
355378
key = IMG_RES_PREF
356379
title = "Image quality"
@@ -376,6 +399,7 @@ abstract class MangaDistrict :
376399

377400
private const val REMOVE_TITLE_VERSION_PREF = "REMOVE_TITLE_VERSION"
378401
private const val REMOVE_TITLE_CUSTOM_PREF = "REMOVE_TITLE_CUSTOM"
402+
private const val NO_REMOVE_TITLE_BROWSING_PREF = "NO_REMOVE_TITLE_BROWSING"
379403
private const val TAG_LIST_PREF = "TAG_LIST"
380404

381405
private const val IMG_RES_PREF = "IMG_RES"

0 commit comments

Comments
 (0)