Skip to content

Commit

Permalink
fix: fix the fix for the fix for MangaUpdates
Browse files Browse the repository at this point in the history
null is better than a crash
  • Loading branch information
rebelonion committed Apr 6, 2024
1 parent 04538c5 commit 58d5b5b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/ani/dantotsu/Functions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ fun countDown(media: Media, view: ViewGroup) {
fun sinceWhen(media: Media, view: ViewGroup) {
CoroutineScope(Dispatchers.IO).launch {
MangaUpdates().search(media.name ?: media.nameRomaji, media.startDate)?.let {
val latestChapter = MangaUpdates.getLatestChapter(it)
val latestChapter = MangaUpdates.getLatestChapter(it) ?: return@let
val timeSince = (System.currentTimeMillis() -
(it.metadata.series.lastUpdated!!.timestamp * 1000)) / 1000

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ class MangaUpdates {
}

companion object {
fun getLatestChapter(results: MangaUpdatesResponse.Results): Int {
fun getLatestChapter(results: MangaUpdatesResponse.Results): Int? {
return results.metadata.series.latestChapter
?: results.record.chapter!!.substringAfterLast("-").trim().toInt()
?: results.record.chapter!!.substringAfterLast("-").trim().toIntOrNull()
}
}

Expand Down

3 comments on commit 58d5b5b

@rebelonion
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not about it being null, it's about the passed value not able to be converted to an Int. toInt will throw an exception in that case. I've seen things like 5e or even words passed into it.

@rebelonion
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a silent voice: empty
deadman wonderland: "57 (end)"
Fullmetal alchemist: "Gaiden"
Steins Gate Mugen Enten: "Oneshot"
Alien 9 Next: "Champion Red Special"
etc etc

@rebelonion
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Literally can't be null, so...

toInt can throw a NumberFormatException while toIntOrNull catches the exception and returns null instead

Please sign in to comment.