fix: Fix lateinit error

This commit is contained in:
Ahmad Ansori Palembani 2025-01-13 13:22:19 +07:00
parent 33fa77d527
commit 9e5d13f261
Signed by: null2264
GPG key ID: BA64F8B60AF3EFB6

View file

@ -185,7 +185,7 @@ open class GlobalSearchPresenter(
MangasPage(emptyList(), false) MangasPage(emptyList(), false)
} }
.mangas.take(10) .mangas.take(10)
.map { networkToLocalManga(it, source.id) } .mapNotNull { networkToLocalManga(it, source.id) }
fetchImage(mangas, source) fetchImage(mangas, source)
if (mangas.isNotEmpty() && !loadTime.containsKey(source.id)) { if (mangas.isNotEmpty() && !loadTime.containsKey(source.id)) {
loadTime[source.id] = Date().time loadTime[source.id] = Date().time
@ -275,14 +275,18 @@ open class GlobalSearchPresenter(
* @param sManga the manga from the source. * @param sManga the manga from the source.
* @return a manga from the database. * @return a manga from the database.
*/ */
protected open suspend fun networkToLocalManga(sManga: SManga, sourceId: Long): Manga { protected open suspend fun networkToLocalManga(sManga: SManga, sourceId: Long): Manga? {
var localManga = getManga.awaitByUrlAndSource(sManga.url, sourceId) var localManga = getManga.awaitByUrlAndSource(sManga.url, sourceId)
if (localManga == null) { if (localManga == null) {
if (!sManga::title.isInitialized) return null
val newManga = Manga.create(sManga.url, sManga.title, sourceId) val newManga = Manga.create(sManga.url, sManga.title, sourceId)
newManga.copyFrom(sManga) newManga.copyFrom(sManga)
newManga.id = insertManga.await(newManga) newManga.id = insertManga.await(newManga)
localManga = newManga localManga = newManga
} else if (!localManga.favorite) { } else if (!localManga.favorite) {
if (!sManga::title.isInitialized) return localManga
// if the manga isn't a favorite, set its display title from source // if the manga isn't a favorite, set its display title from source
// if it later becomes a favorite, updated title will go to db // if it later becomes a favorite, updated title will go to db
localManga.title = sManga.title localManga.title = sManga.title