mirror of
https://github.com/null2264/yokai.git
synced 2025-07-16 22:06:54 +00:00
refactor(recents): Some adjustments
This commit is contained in:
parent
07ed81454f
commit
22978ab8bf
4 changed files with 80 additions and 78 deletions
|
@ -49,8 +49,8 @@ interface History : Serializable {
|
||||||
): History = HistoryImpl().apply {
|
): History = HistoryImpl().apply {
|
||||||
this.id = id
|
this.id = id
|
||||||
this.chapter_id = chapterId
|
this.chapter_id = chapterId
|
||||||
this.last_read = lastRead ?: 0L
|
lastRead?.let { this.last_read = it }
|
||||||
this.time_read = timeRead ?: 0L
|
timeRead?.let { this.time_read = it }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ data class MangaChapterHistory(val manga: Manga, val chapter: Chapter, val histo
|
||||||
coverLastModified: Long,
|
coverLastModified: Long,
|
||||||
// chapter
|
// chapter
|
||||||
chapterId: Long?,
|
chapterId: Long?,
|
||||||
_mangaId: Long?,
|
chapterMangaId: Long?,
|
||||||
chapterUrl: String?,
|
chapterUrl: String?,
|
||||||
name: String?,
|
name: String?,
|
||||||
scanlator: String?,
|
scanlator: String?,
|
||||||
|
@ -80,10 +80,9 @@ data class MangaChapterHistory(val manga: Manga, val chapter: Chapter, val histo
|
||||||
)
|
)
|
||||||
|
|
||||||
val chapter = try {
|
val chapter = try {
|
||||||
chapterId?.let {
|
|
||||||
Chapter.mapper(
|
Chapter.mapper(
|
||||||
id = chapterId,
|
id = chapterId!!,
|
||||||
mangaId = _mangaId ?: mangaId,
|
mangaId = chapterMangaId!!,
|
||||||
url = chapterUrl!!,
|
url = chapterUrl!!,
|
||||||
name = name!!,
|
name = name!!,
|
||||||
scanlator = scanlator,
|
scanlator = scanlator,
|
||||||
|
@ -96,20 +95,23 @@ data class MangaChapterHistory(val manga: Manga, val chapter: Chapter, val histo
|
||||||
dateFetch = dateFetch!!,
|
dateFetch = dateFetch!!,
|
||||||
dateUpload = dateUpload!!,
|
dateUpload = dateUpload!!,
|
||||||
)
|
)
|
||||||
|
} catch (_: NullPointerException) {
|
||||||
|
ChapterImpl()
|
||||||
}
|
}
|
||||||
} catch (_: NullPointerException) { null } ?: Chapter.create()
|
|
||||||
|
|
||||||
val history = try {
|
val history = try {
|
||||||
historyId?.let {
|
|
||||||
History.mapper(
|
History.mapper(
|
||||||
id = historyId,
|
id = historyId!!,
|
||||||
chapterId = historyChapterId ?: chapterId ?: 0L,
|
chapterId = historyChapterId!!,
|
||||||
lastRead = historyLastRead,
|
lastRead = historyLastRead,
|
||||||
timeRead = historyTimeRead,
|
timeRead = historyTimeRead,
|
||||||
)
|
)
|
||||||
}
|
} catch (_: NullPointerException) {
|
||||||
} catch (_: NullPointerException) { null } ?: History.create().apply {
|
HistoryImpl().apply {
|
||||||
|
historyChapterId?.let { chapter_id = it }
|
||||||
historyLastRead?.let { last_read = it }
|
historyLastRead?.let { last_read = it }
|
||||||
|
historyTimeRead?.let { time_read = it }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return MangaChapterHistory(manga, chapter, history)
|
return MangaChapterHistory(manga, chapter, history)
|
||||||
|
|
|
@ -157,7 +157,7 @@ class ReaderViewModel(
|
||||||
private var finished = false
|
private var finished = false
|
||||||
private var chapterToDownload: Download? = null
|
private var chapterToDownload: Download? = null
|
||||||
|
|
||||||
private var chapterList = emptyList<ReaderChapter>()
|
private var chapterList: List<ReaderChapter>? = null
|
||||||
|
|
||||||
private var chapterItems = emptyList<ReaderChapterItem>()
|
private var chapterItems = emptyList<ReaderChapterItem>()
|
||||||
|
|
||||||
|
@ -215,7 +215,7 @@ class ReaderViewModel(
|
||||||
* Whether this presenter is initialized yet.
|
* Whether this presenter is initialized yet.
|
||||||
*/
|
*/
|
||||||
fun needsInit(): Boolean {
|
fun needsInit(): Boolean {
|
||||||
return manga == null
|
return manga == null || chapterList == null
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -246,7 +246,7 @@ class ReaderViewModel(
|
||||||
loader = ChapterLoader(context, downloadManager, downloadProvider, manga, source)
|
loader = ChapterLoader(context, downloadManager, downloadProvider, manga, source)
|
||||||
|
|
||||||
chapterList = getChapterList()
|
chapterList = getChapterList()
|
||||||
loadChapter(loader!!, chapterList.first { chapterId == it.chapter.id })
|
loadChapter(loader!!, chapterList!!.first { chapterId == it.chapter.id })
|
||||||
Result.success(true)
|
Result.success(true)
|
||||||
} else {
|
} else {
|
||||||
// Unlikely but okay
|
// Unlikely but okay
|
||||||
|
@ -402,11 +402,11 @@ class ReaderViewModel(
|
||||||
): ViewerChapters {
|
): ViewerChapters {
|
||||||
loader.loadChapter(chapter)
|
loader.loadChapter(chapter)
|
||||||
|
|
||||||
val chapterPos = chapterList.indexOf(chapter)
|
val chapterPos = chapterList?.indexOf(chapter) ?: -1
|
||||||
val newChapters = ViewerChapters(
|
val newChapters = ViewerChapters(
|
||||||
chapter,
|
chapter,
|
||||||
chapterList.getOrNull(chapterPos - 1),
|
chapterList?.getOrNull(chapterPos - 1),
|
||||||
chapterList.getOrNull(chapterPos + 1),
|
chapterList?.getOrNull(chapterPos + 1),
|
||||||
)
|
)
|
||||||
|
|
||||||
withUIContext {
|
withUIContext {
|
||||||
|
|
|
@ -69,7 +69,7 @@ ON C._id = H.history_chapter_id
|
||||||
AND H.history_last_read > 0
|
AND H.history_last_read > 0
|
||||||
LEFT JOIN scanlators_view AS S
|
LEFT JOIN scanlators_view AS S
|
||||||
ON C.manga_id = S.manga_id
|
ON C.manga_id = S.manga_id
|
||||||
AND ifnull(C.scanlator, 'N/A') = ifnull(S.name, '/<INVALID>/') -- I assume if it's N/A it shouldn't be filtered
|
AND C.scanlator = S.name
|
||||||
WHERE lower(M.title) LIKE '%' || :search || '%'
|
WHERE lower(M.title) LIKE '%' || :search || '%'
|
||||||
AND (
|
AND (
|
||||||
:apply_filter = 0 OR S.name IS NULL
|
:apply_filter = 0 OR S.name IS NULL
|
||||||
|
@ -101,7 +101,7 @@ AND max_last_read.history_chapter_id = H.history_chapter_id
|
||||||
AND max_last_read.history_last_read > 0
|
AND max_last_read.history_last_read > 0
|
||||||
LEFT JOIN scanlators_view AS S
|
LEFT JOIN scanlators_view AS S
|
||||||
ON C.manga_id = S.manga_id
|
ON C.manga_id = S.manga_id
|
||||||
AND ifnull(C.scanlator, 'N/A') = ifnull(S.name, '/<INVALID>/') -- I assume if it's N/A it shouldn't be filtered
|
AND C.scanlator = S.name
|
||||||
WHERE lower(M.title) LIKE '%' || :search || '%'
|
WHERE lower(M.title) LIKE '%' || :search || '%'
|
||||||
AND (
|
AND (
|
||||||
:apply_filter = 0 OR S.name IS NULL
|
:apply_filter = 0 OR S.name IS NULL
|
||||||
|
@ -110,10 +110,10 @@ ORDER BY max_last_read.history_last_read DESC
|
||||||
LIMIT :limit OFFSET :offset;
|
LIMIT :limit OFFSET :offset;
|
||||||
|
|
||||||
getRecentsAll:
|
getRecentsAll:
|
||||||
SELECT R.* FROM (
|
SELECT R1.* FROM (
|
||||||
SELECT
|
SELECT
|
||||||
M.*,
|
M.*,
|
||||||
chapters.*,
|
C.*,
|
||||||
history.history_id AS history_id,
|
history.history_id AS history_id,
|
||||||
history.history_chapter_id AS history_chapter_id,
|
history.history_chapter_id AS history_chapter_id,
|
||||||
history.history_last_read AS history_last_read,
|
history.history_last_read AS history_last_read,
|
||||||
|
@ -122,71 +122,71 @@ FROM (
|
||||||
SELECT M2.*
|
SELECT M2.*
|
||||||
FROM mangas AS M2
|
FROM mangas AS M2
|
||||||
LEFT JOIN (
|
LEFT JOIN (
|
||||||
SELECT manga_id, COUNT(*) AS unread
|
SELECT manga_id, COUNT(*) AS value
|
||||||
FROM chapters
|
FROM chapters
|
||||||
WHERE read = 0
|
WHERE read = 0
|
||||||
GROUP BY manga_id
|
GROUP BY manga_id
|
||||||
) AS C
|
) AS unread
|
||||||
ON M2._id = C.manga_id
|
ON M2._id = unread.manga_id
|
||||||
WHERE (
|
WHERE (
|
||||||
:include_read = 0 OR C.unread > 0
|
:include_read = 0 OR unread.value > 0
|
||||||
)
|
)
|
||||||
GROUP BY M2._id
|
GROUP BY M2._id
|
||||||
ORDER BY title
|
ORDER BY title
|
||||||
) AS M
|
) AS M
|
||||||
JOIN chapters
|
JOIN chapters AS C
|
||||||
ON M._id = chapters.manga_id
|
ON M._id = C.manga_id
|
||||||
JOIN history
|
JOIN history
|
||||||
ON chapters._id = history.history_chapter_id
|
ON C._id = history.history_chapter_id
|
||||||
JOIN (
|
JOIN (
|
||||||
SELECT
|
SELECT
|
||||||
chapters.manga_id AS manga_id,
|
C2.manga_id AS manga_id,
|
||||||
chapters._id AS history_chapter_id,
|
C2._id AS history_chapter_id,
|
||||||
MAX(history.history_last_read) AS history_last_read
|
MAX(H2.history_last_read) AS history_last_read
|
||||||
FROM chapters JOIN history
|
FROM chapters AS C2 JOIN history AS H2
|
||||||
ON chapters._id = history.history_chapter_id
|
ON C2._id = H2.history_chapter_id
|
||||||
GROUP BY chapters.manga_id
|
GROUP BY C2.manga_id
|
||||||
) AS max_last_read
|
) AS max_last_read
|
||||||
ON chapters.manga_id = max_last_read.manga_id
|
ON C.manga_id = max_last_read.manga_id
|
||||||
AND max_last_read.history_chapter_id = history.history_chapter_id
|
AND max_last_read.history_chapter_id = history.history_chapter_id
|
||||||
AND max_last_read.history_last_read > 0
|
AND max_last_read.history_last_read > 0
|
||||||
LEFT JOIN scanlators_view AS S
|
LEFT JOIN scanlators_view AS S
|
||||||
ON chapters.manga_id = S.manga_id
|
ON C.manga_id = S.manga_id
|
||||||
AND ifnull(chapters.scanlator, 'N/A') = ifnull(S.name, '/<INVALID>/') -- I assume if it's N/A it shouldn't be filtered
|
AND C.scanlator = S.name
|
||||||
WHERE lower(title) LIKE '%' || :search || '%'
|
WHERE lower(title) LIKE '%' || :search || '%'
|
||||||
AND (
|
AND (
|
||||||
:apply_filter = 0 OR S.name IS NULL
|
:apply_filter = 0 OR S.name IS NULL
|
||||||
)
|
)
|
||||||
) AS R
|
) AS R1
|
||||||
|
|
||||||
UNION --
|
UNION -- Newly added chapter
|
||||||
|
|
||||||
SELECT R.* FROM (
|
SELECT R2.* FROM (
|
||||||
SELECT
|
SELECT
|
||||||
M.*,
|
M.*,
|
||||||
chapters.*,
|
C.*,
|
||||||
NULL AS history_id,
|
NULL AS history_id,
|
||||||
NULL AS history_chapter_id,
|
NULL AS history_chapter_id,
|
||||||
chapters.date_fetch AS history_last_read,
|
C.date_fetch AS history_last_read,
|
||||||
NULL AS history_time_read
|
NULL AS history_time_read
|
||||||
FROM mangas AS M
|
FROM mangas AS M
|
||||||
JOIN chapters
|
JOIN chapters AS C
|
||||||
ON M._id = chapters.manga_id
|
ON M._id = C.manga_id
|
||||||
JOIN history
|
JOIN history
|
||||||
ON chapters._id = history.history_chapter_id
|
ON C._id = history.history_chapter_id
|
||||||
JOIN (
|
JOIN (
|
||||||
SELECT
|
SELECT
|
||||||
manga_id,
|
C2.manga_id,
|
||||||
chapters._id AS history_chapter_id,
|
C2._id AS history_chapter_id,
|
||||||
max(date_upload)
|
max(date_upload)
|
||||||
FROM chapters JOIN mangas AS M2
|
FROM chapters AS C2 JOIN mangas AS M2
|
||||||
ON M2._id = manga_id
|
ON M2._id = C2.manga_id
|
||||||
WHERE read = 0
|
WHERE C2.read = 0
|
||||||
GROUP BY manga_id
|
GROUP BY C2.manga_id
|
||||||
) AS newest_chapter
|
) AS newest_chapter
|
||||||
LEFT JOIN scanlators_view AS S
|
LEFT JOIN scanlators_view AS S
|
||||||
ON chapters.manga_id = S.manga_id
|
ON C.manga_id = S.manga_id
|
||||||
AND ifnull(chapters.scanlator, 'N/A') = ifnull(S.name, '/<INVALID>/') -- I assume if it's N/A it shouldn't be filtered
|
AND C.scanlator = S.name
|
||||||
WHERE favorite = 1
|
WHERE favorite = 1
|
||||||
AND newest_chapter.history_chapter_id = history.history_chapter_id
|
AND newest_chapter.history_chapter_id = history.history_chapter_id
|
||||||
AND date_fetch > date_added
|
AND date_fetch > date_added
|
||||||
|
@ -194,14 +194,14 @@ AND lower(title) LIKE '%' || :search || '%'
|
||||||
AND (
|
AND (
|
||||||
:apply_filter = 0 OR S.name IS NULL
|
:apply_filter = 0 OR S.name IS NULL
|
||||||
)
|
)
|
||||||
) AS R
|
) AS R2
|
||||||
|
|
||||||
UNION --
|
UNION -- Newly added manga
|
||||||
|
|
||||||
SELECT R.* FROM (
|
SELECT R3.* FROM (
|
||||||
SELECT
|
SELECT
|
||||||
M.*,
|
M.*,
|
||||||
chapters.*,
|
C.*,
|
||||||
NULL AS history_id,
|
NULL AS history_id,
|
||||||
NULL AS history_chapter_id,
|
NULL AS history_chapter_id,
|
||||||
M.date_added AS history_last_read,
|
M.date_added AS history_last_read,
|
||||||
|
@ -222,9 +222,9 @@ JOIN (
|
||||||
NULL AS pages_left,
|
NULL AS pages_left,
|
||||||
NULL AS chapter_number,
|
NULL AS chapter_number,
|
||||||
NULL AS source_order
|
NULL AS source_order
|
||||||
) AS chapters
|
) AS C
|
||||||
WHERE favorite = 1
|
WHERE favorite = 1
|
||||||
AND lower(title) LIKE '%' || :search || '%'
|
AND lower(title) LIKE '%' || :search || '%'
|
||||||
) AS R
|
) AS R3
|
||||||
ORDER BY history_last_read DESC
|
ORDER BY history_last_read DESC
|
||||||
LIMIT :limit OFFSET :offset;
|
LIMIT :limit OFFSET :offset;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue