mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
fix: Scanlator filter not working properly
This commit is contained in:
parent
0e2c336a37
commit
7e1b532f83
6 changed files with 70 additions and 22 deletions
|
@ -186,17 +186,12 @@ class MangaDetailsPresenter(
|
|||
|
||||
private suspend fun getChapters() {
|
||||
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 getChapter.awaitAll(manga.id!!, false).map { it.toModel() }
|
||||
allChapterScanlators = allChapters.mapNotNull { it.chapter.scanlator }.toSet()
|
||||
|
||||
this.chapters = applyChapterFilters(chapters)
|
||||
}
|
||||
|
||||
|
|
|
@ -166,11 +166,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()
|
||||
|
|
|
@ -206,10 +206,7 @@ private fun List<Chapter>.filterChaptersByScanlators(manga: Manga): List<Chapter
|
|||
if (manga.filtered_scanlators == null) return this
|
||||
|
||||
return this.filter { chapter ->
|
||||
ChapterUtil.getScanlators(chapter.scanlator)
|
||||
.none { group ->
|
||||
ChapterUtil.getScanlators(manga.filtered_scanlators).contains(group)
|
||||
}
|
||||
!ChapterUtil.getScanlators(manga.filtered_scanlators).contains(chapter.scanlator)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -156,7 +156,7 @@ class ChapterUtil {
|
|||
return chapters.size > 20
|
||||
}
|
||||
|
||||
const val scanlatorSeparator = " & "
|
||||
const val scanlatorSeparator = " [.] "
|
||||
|
||||
fun getScanlators(scanlators: String?): List<String> {
|
||||
if (scanlators.isNullOrBlank()) return emptyList()
|
||||
|
|
57
data/src/commonMain/sqldelight/tachiyomi/migrations/24.sqm
Normal file
57
data/src/commonMain/sqldelight/tachiyomi/migrations/24.sqm
Normal file
|
@ -0,0 +1,57 @@
|
|||
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);
|
||||
|
||||
-- To sync the project
|
||||
DROP VIEW IF EXISTS library_view;
|
||||
CREATE VIEW library_view AS
|
||||
SELECT
|
||||
M.*,
|
||||
coalesce(C.total, 0) AS total,
|
||||
coalesce(C.read_count, 0) AS has_read,
|
||||
coalesce(C.bookmark_count, 0) AS bookmark_count,
|
||||
coalesce(MC.category_id, 0) AS category,
|
||||
coalesce(C.latestUpload, 0) AS latestUpload,
|
||||
coalesce(C.lastRead, 0) AS lastRead,
|
||||
coalesce(C.lastFetch, 0) AS lastFetch
|
||||
FROM mangas AS M
|
||||
LEFT JOIN (
|
||||
SELECT
|
||||
chapters.manga_id,
|
||||
count(*) AS total,
|
||||
sum(read) AS read_count,
|
||||
sum(bookmark) AS bookmark_count,
|
||||
coalesce(max(chapters.date_upload), 0) AS latestUpload,
|
||||
coalesce(max(history.history_last_read), 0) AS lastRead,
|
||||
coalesce(max(chapters.date_fetch), 0) AS lastFetch
|
||||
FROM chapters
|
||||
LEFT JOIN scanlators_view AS filtered_scanlators
|
||||
ON chapters.manga_id = filtered_scanlators.manga_id
|
||||
AND ifnull(chapters.scanlator, 'N/A') = ifnull(filtered_scanlators.name, '/<INVALID>/')
|
||||
LEFT JOIN history
|
||||
ON chapters._id = history.history_chapter_id
|
||||
WHERE filtered_scanlators.name IS NULL
|
||||
GROUP BY chapters.manga_id
|
||||
) AS C
|
||||
ON M._id = C.manga_id
|
||||
LEFT JOIN (SELECT * FROM mangas_categories) AS MC
|
||||
ON MC.manga_id = M._id
|
||||
WHERE M.favorite = 1
|
||||
ORDER BY M.title;
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue