From aa4b3c7ed3a2112057d1d800f46de02fbb02216e Mon Sep 17 00:00:00 2001 From: Carlos <2092019+CarlosEsco@users.noreply.github.com> Date: Wed, 11 Jan 2023 09:14:10 -0500 Subject: [PATCH] Fix small bug with chapter comments that don't exist --- .../tachiyomi/ui/manga/MangaConstants.kt | 2 +- .../ui/manga/MangaDetailPresenter.kt | 35 ++++++++++++++----- .../tachiyomi/util/ChapterExtensions.kt | 9 +++-- .../screens/mangadetails/InformationBlock.kt | 4 +-- 4 files changed, 36 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaConstants.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaConstants.kt index 3ee2620b7b..4371887969 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaConstants.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaConstants.kt @@ -62,7 +62,7 @@ object MangaConstants { val isPornographic: Boolean = false, val langFlag: String? = null, val missingChapters: String? = null, - val estimatedMissingChapters: ImmutableList? = null, + val estimatedMissingChapters: String? = null, val originalTitle: String = "", val stats: Stats? = null, val status: Int = 0, diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailPresenter.kt index 4956d76814..4a6e70fb78 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailPresenter.kt @@ -1564,7 +1564,7 @@ class MangaDetailPresenter( presenterScope.launchIO { val missingChapterHolder = generalState.value.allChapters.getMissingChapters() _mangaState.update { - it.copy(estimatedMissingChapters = missingChapterHolder.estimatedChapters?.toImmutableList()) + it.copy(estimatedMissingChapters = missingChapterHolder.estimatedChapters) } val currentMissingChapters = missingChapterHolder.count if (currentMissingChapters != currentManga().missing_chapters) { @@ -1597,14 +1597,31 @@ class MangaDetailPresenter( } suspend fun lookupComment(chapterId: String): String? { - return sourceManager.mangaDex.getChapterCommentId(chapterId).onFailure { - loggycat(LogPriority.ERROR) { it.message() } - _snackbarState.emit( - SnackbarState( - messageRes = R.string.comments_unavailable, - ), - ) - }.getOrElse { null } + if (!isOnline()) { + presenterScope.launch { _snackbarState.emit(SnackbarState(message = "No network connection, cannot open comments")) } + return null + } else { + presenterScope.launch { + _isRefreshing.value = true + } + + val threadId = sourceManager.mangaDex.getChapterCommentId(chapterId).onFailure { + loggycat(LogPriority.ERROR) { it.message() } + + }.getOrElse { + null + } + presenterScope.launch { + _isRefreshing.value = false + if (threadId == null) + _snackbarState.emit( + SnackbarState( + messageRes = R.string.comments_unavailable, + ), + ) + } + return threadId + } } fun blockScanlator(scanlator: String) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/ChapterExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/ChapterExtensions.kt index 8deeea8275..cc33db96f2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/ChapterExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/ChapterExtensions.kt @@ -5,7 +5,7 @@ import org.nekomanga.domain.chapter.ChapterItem data class MissingChapterHolder( val count: String? = null, - val estimatedChapters: List? = null, + val estimatedChapters: String? = null, ) fun List.getMissingChapters(): MissingChapterHolder { @@ -55,9 +55,14 @@ fun List.getMissingChapters(): MissingChapterHolder { count.toString() } + val estimateChapterString = when (estimateChapters.isEmpty()) { + true -> null + false -> estimateChapters.joinToString(" • ") + } + return MissingChapterHolder( count = actualCount, - estimatedChapters = estimateChapters, + estimatedChapters = estimateChapterString, ) } diff --git a/app/src/main/java/org/nekomanga/presentation/screens/mangadetails/InformationBlock.kt b/app/src/main/java/org/nekomanga/presentation/screens/mangadetails/InformationBlock.kt index 000efe7df0..212d4df8db 100644 --- a/app/src/main/java/org/nekomanga/presentation/screens/mangadetails/InformationBlock.kt +++ b/app/src/main/java/org/nekomanga/presentation/screens/mangadetails/InformationBlock.kt @@ -57,7 +57,7 @@ fun InformationBlock( statusProvider: () -> Int, isPornographicProvider: () -> Boolean, missingChaptersProvider: () -> String?, - estimatedMissingChapterProvider: () -> List?, + estimatedMissingChapterProvider: () -> String?, modifier: Modifier = Modifier, isExpandedProvider: () -> Boolean, showMergedIconProvider: () -> Boolean, @@ -230,7 +230,7 @@ fun InformationBlock( Column { Gap(4.dp) NoRippleText( - text = estimates.joinToString(" ● "), + text = estimates, maxLines = 4, style = MaterialTheme.typography.bodySmall, color = mediumAlpha,