Skip to content

Commit

Permalink
Fix small bug with chapter comments that don't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
nonproto committed Jan 11, 2023
1 parent 44260af commit aa4b3c7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ object MangaConstants {
val isPornographic: Boolean = false,
val langFlag: String? = null,
val missingChapters: String? = null,
val estimatedMissingChapters: ImmutableList<String>? = null,
val estimatedMissingChapters: String? = null,
val originalTitle: String = "",
val stats: Stats? = null,
val status: Int = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.nekomanga.domain.chapter.ChapterItem

data class MissingChapterHolder(
val count: String? = null,
val estimatedChapters: List<String>? = null,
val estimatedChapters: String? = null,
)

fun List<ChapterItem>.getMissingChapters(): MissingChapterHolder {
Expand Down Expand Up @@ -55,9 +55,14 @@ fun List<ChapterItem>.getMissingChapters(): MissingChapterHolder {
count.toString()
}

val estimateChapterString = when (estimateChapters.isEmpty()) {
true -> null
false -> estimateChapters.joinToString("")
}


return MissingChapterHolder(
count = actualCount,
estimatedChapters = estimateChapters,
estimatedChapters = estimateChapterString,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fun InformationBlock(
statusProvider: () -> Int,
isPornographicProvider: () -> Boolean,
missingChaptersProvider: () -> String?,
estimatedMissingChapterProvider: () -> List<String>?,
estimatedMissingChapterProvider: () -> String?,
modifier: Modifier = Modifier,
isExpandedProvider: () -> Boolean,
showMergedIconProvider: () -> Boolean,
Expand Down Expand Up @@ -230,7 +230,7 @@ fun InformationBlock(
Column {
Gap(4.dp)
NoRippleText(
text = estimates.joinToString(""),
text = estimates,
maxLines = 4,
style = MaterialTheme.typography.bodySmall,
color = mediumAlpha,
Expand Down

0 comments on commit aa4b3c7

Please sign in to comment.