fix: Scanlator filter not working properly

This commit is contained in:
Ahmad Ansori Palembani 2024-08-10 10:29:52 +07:00
parent da5d1f4203
commit 699927fcc1
Signed by: null2264
GPG key ID: BA64F8B60AF3EFB6
8 changed files with 40 additions and 25 deletions

View file

@ -8,4 +8,4 @@
## Other ?? Technical stuff, what happened behind the scene
-->
## Fixes
- Fixed incorrect library entry chapter count
- Fixed scanlator filter not working properly if it contains " & "

View file

@ -47,7 +47,7 @@ android {
targetSdk = AndroidConfig.targetSdk
applicationId = "eu.kanade.tachiyomi"
versionCode = 139
versionName = "1.8.4.5"
versionName = "1.8.4.6"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled = true

View file

@ -175,18 +175,13 @@ class MangaDetailsPresenter(
}
private suspend fun getChapters() {
val chapters = getChapters.await(manga.id!!, isScanlatorFiltered()).map { it.toModel() }
val chapters = getChapter.awaitAll(manga.id!!, isScanlatorFiltered()).map { it.toModel() }
allChapters = if (!isScanlatorFiltered()) chapters else getChapter.awaitAll(manga.id!!, false).map { it.toModel() }
// Find downloaded chapters
setDownloadedChapters(chapters)
allChapterScanlators =
if (!isScanlatorFiltered()) {
chapters.flatMap { ChapterUtil.getScanlators(it.chapter.scanlator) }
} else {
getAvailableScanlators.await(manga.id!!)
}.toSet()
// Store the last emission
allChapters = if (!isScanlatorFiltered()) chapters else getChapters.await(manga.id!!, false).map { it.toModel() }
allChapterScanlators = allChapters.mapNotNull { it.chapter.scanlator }.toSet()
this.chapters = applyChapterFilters(chapters)
}

View file

@ -161,11 +161,9 @@ class ChaptersSortBottomSheet(controller: MangaDetailsController) :
binding.filterGroupsButton.setOnClickListener {
val scanlators = presenter.allChapterScanlators.toList()
val filteredScanlators =
(
presenter.manga.filtered_scanlators?.let { ChapterUtil.getScanlators(it) }
?.toMutableSet()
?: mutableSetOf()
)
presenter.manga.filtered_scanlators?.let { ChapterUtil.getScanlators(it) }.orEmpty()
.filter { it in scanlators }
.toMutableSet()
val preselected = scanlators.map { it in filteredScanlators }.toBooleanArray()
var alertDialog: AlertDialog? = null
activity.materialAlertDialog()

View file

@ -86,10 +86,11 @@ class ChapterFilter(val preferences: PreferencesHelper = Injekt.get(), val downl
/** filters chapters for scanlators */
@Deprecated("Filter it from SQL instead if possible")
fun <T : Chapter> List<T>.filterChaptersByScanlators(manga: Manga): List<T> {
return manga.filtered_scanlators?.let { filteredScanlatorString ->
val filteredScanlators = ChapterUtil.getScanlators(filteredScanlatorString)
filter { ChapterUtil.getScanlators(it.scanlator).none { group -> filteredScanlators.contains(group) } }
} ?: this
if (manga.filtered_scanlators == null) return this
return this.filter { chapter ->
!ChapterUtil.getScanlators(manga.filtered_scanlators).contains(chapter.scanlator)
}
}
}
}

View file

@ -153,7 +153,7 @@ class ChapterUtil {
return chapters.size > 20
}
const val scanlatorSeparator = " & "
const val scanlatorSeparator = " [.] "
fun getScanlators(scanlators: String?): List<String> {
if (scanlators.isNullOrBlank()) return emptyList()

View file

@ -0,0 +1,20 @@
DROP VIEW IF EXISTS scanlators_view;
CREATE VIEW scanlators_view AS
SELECT S.* FROM (
WITH RECURSIVE split(seq, _id, name, str) AS (
SELECT 0, mangas._id, NULL, ifnull(mangas.filtered_scanlators, '')||' [.] ' FROM mangas WHERE mangas._id
UNION ALL SELECT
seq+1,
_id,
substr(str, 0, instr(str, ' [.] ')),
substr(str, instr(str, ' [.] ')+5)
FROM split WHERE str != ''
)
SELECT _id AS manga_id, name FROM split WHERE split.seq != 0 ORDER BY split.seq ASC
) AS S;
-- Replace seperator from ' & ' to less common ' [.] '
WITH tmp(_id, filtered_scanlators) AS (SELECT _id, replace(filtered_scanlators, ' & ', ' [.] ') FROM mangas)
UPDATE mangas
SET filtered_scanlators = (SELECT filtered_scanlators FROM tmp)
WHERE _id IN (SELECT _id FROM tmp);

View file

@ -1,12 +1,13 @@
-- FIXME: Turn this to its own table
CREATE VIEW scanlators_view AS
SELECT S.* FROM (
WITH RECURSIVE split(seq, _id, name, str) AS ( -- Probably should migrate this to its own table someday
SELECT 0, mangas._id, NULL, replace(ifnull(mangas.filtered_scanlators, ''), ' & ', '[.]')||'[.]' FROM mangas WHERE mangas._id
WITH RECURSIVE split(seq, _id, name, str) AS (
SELECT 0, mangas._id, NULL, ifnull(mangas.filtered_scanlators, '')||' [.] ' FROM mangas WHERE mangas._id
UNION ALL SELECT
seq+1,
_id,
substr(str, 0, instr(str, '[.]')),
substr(str, instr(str, '[.]')+3)
substr(str, 0, instr(str, ' [.] ')),
substr(str, instr(str, ' [.] ')+5)
FROM split WHERE str != ''
)
SELECT _id AS manga_id, name FROM split WHERE split.seq != 0 ORDER BY split.seq ASC