mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 02:34:39 +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 {
|
||||
this.id = id
|
||||
this.chapter_id = chapterId
|
||||
this.last_read = lastRead ?: 0L
|
||||
this.time_read = timeRead ?: 0L
|
||||
lastRead?.let { this.last_read = it }
|
||||
timeRead?.let { this.time_read = it }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ data class MangaChapterHistory(val manga: Manga, val chapter: Chapter, val histo
|
|||
coverLastModified: Long,
|
||||
// chapter
|
||||
chapterId: Long?,
|
||||
_mangaId: Long?,
|
||||
chapterMangaId: Long?,
|
||||
chapterUrl: String?,
|
||||
name: String?,
|
||||
scanlator: String?,
|
||||
|
@ -80,36 +80,38 @@ data class MangaChapterHistory(val manga: Manga, val chapter: Chapter, val histo
|
|||
)
|
||||
|
||||
val chapter = try {
|
||||
chapterId?.let {
|
||||
Chapter.mapper(
|
||||
id = chapterId,
|
||||
mangaId = _mangaId ?: mangaId,
|
||||
url = chapterUrl!!,
|
||||
name = name!!,
|
||||
scanlator = scanlator,
|
||||
read = read!!,
|
||||
bookmark = bookmark!!,
|
||||
lastPageRead = lastPageRead!!,
|
||||
pagesLeft = pagesLeft!!,
|
||||
chapterNumber = chapterNumber!!,
|
||||
sourceOrder = sourceOrder!!,
|
||||
dateFetch = dateFetch!!,
|
||||
dateUpload = dateUpload!!,
|
||||
)
|
||||
}
|
||||
} catch (_: NullPointerException) { null } ?: Chapter.create()
|
||||
Chapter.mapper(
|
||||
id = chapterId!!,
|
||||
mangaId = chapterMangaId!!,
|
||||
url = chapterUrl!!,
|
||||
name = name!!,
|
||||
scanlator = scanlator,
|
||||
read = read!!,
|
||||
bookmark = bookmark!!,
|
||||
lastPageRead = lastPageRead!!,
|
||||
pagesLeft = pagesLeft!!,
|
||||
chapterNumber = chapterNumber!!,
|
||||
sourceOrder = sourceOrder!!,
|
||||
dateFetch = dateFetch!!,
|
||||
dateUpload = dateUpload!!,
|
||||
)
|
||||
} catch (_: NullPointerException) {
|
||||
ChapterImpl()
|
||||
}
|
||||
|
||||
val history = try {
|
||||
historyId?.let {
|
||||
History.mapper(
|
||||
id = historyId,
|
||||
chapterId = historyChapterId ?: chapterId ?: 0L,
|
||||
lastRead = historyLastRead,
|
||||
timeRead = historyTimeRead,
|
||||
)
|
||||
History.mapper(
|
||||
id = historyId!!,
|
||||
chapterId = historyChapterId!!,
|
||||
lastRead = historyLastRead,
|
||||
timeRead = historyTimeRead,
|
||||
)
|
||||
} catch (_: NullPointerException) {
|
||||
HistoryImpl().apply {
|
||||
historyChapterId?.let { chapter_id = it }
|
||||
historyLastRead?.let { last_read = it }
|
||||
historyTimeRead?.let { time_read = it }
|
||||
}
|
||||
} catch (_: NullPointerException) { null } ?: History.create().apply {
|
||||
historyLastRead?.let { last_read = it }
|
||||
}
|
||||
|
||||
return MangaChapterHistory(manga, chapter, history)
|
||||
|
|
|
@ -157,7 +157,7 @@ class ReaderViewModel(
|
|||
private var finished = false
|
||||
private var chapterToDownload: Download? = null
|
||||
|
||||
private var chapterList = emptyList<ReaderChapter>()
|
||||
private var chapterList: List<ReaderChapter>? = null
|
||||
|
||||
private var chapterItems = emptyList<ReaderChapterItem>()
|
||||
|
||||
|
@ -215,7 +215,7 @@ class ReaderViewModel(
|
|||
* Whether this presenter is initialized yet.
|
||||
*/
|
||||
fun needsInit(): Boolean {
|
||||
return manga == null
|
||||
return manga == null || chapterList == null
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -246,7 +246,7 @@ class ReaderViewModel(
|
|||
loader = ChapterLoader(context, downloadManager, downloadProvider, manga, source)
|
||||
|
||||
chapterList = getChapterList()
|
||||
loadChapter(loader!!, chapterList.first { chapterId == it.chapter.id })
|
||||
loadChapter(loader!!, chapterList!!.first { chapterId == it.chapter.id })
|
||||
Result.success(true)
|
||||
} else {
|
||||
// Unlikely but okay
|
||||
|
@ -402,11 +402,11 @@ class ReaderViewModel(
|
|||
): ViewerChapters {
|
||||
loader.loadChapter(chapter)
|
||||
|
||||
val chapterPos = chapterList.indexOf(chapter)
|
||||
val chapterPos = chapterList?.indexOf(chapter) ?: -1
|
||||
val newChapters = ViewerChapters(
|
||||
chapter,
|
||||
chapterList.getOrNull(chapterPos - 1),
|
||||
chapterList.getOrNull(chapterPos + 1),
|
||||
chapterList?.getOrNull(chapterPos - 1),
|
||||
chapterList?.getOrNull(chapterPos + 1),
|
||||
)
|
||||
|
||||
withUIContext {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue