From 99ba84c8100eebba8b20729c396dfe206674f375 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 20 Mar 2021 16:36:31 -0400 Subject: [PATCH] Handle null Anilist start dates (fixes #4685) --- .../data/track/anilist/AnilistApi.kt | 9 +++---- .../ui/manga/track/TrackSearchAdapter.kt | 24 +++++++++---------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistApi.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistApi.kt index 9e9f11ce0a..cd0fcad186 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistApi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistApi.kt @@ -246,12 +246,9 @@ class AnilistApi(val client: OkHttpClient, interceptor: AnilistInterceptor) { val date = try { val date = Calendar.getInstance() date.set( - struct["startDate"]!!.jsonObject["year"]!!.jsonPrimitive.intOrNull ?: 0, - ( - struct["startDate"]!!.jsonObject["month"]!!.jsonPrimitive.intOrNull - ?: 0 - ) - 1, - struct["startDate"]!!.jsonObject["day"]!!.jsonPrimitive.intOrNull ?: 0 + struct["startDate"]!!.jsonObject["year"]!!.jsonPrimitive.int, + struct["startDate"]!!.jsonObject["month"]!!.jsonPrimitive.int - 1, + struct["startDate"]!!.jsonObject["day"]!!.jsonPrimitive.int ) date.timeInMillis } catch (_: Exception) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchAdapter.kt index 0520f4260a..2ee8ba3526 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchAdapter.kt @@ -55,24 +55,24 @@ class TrackSearchAdapter(context: Context) : .into(binding.trackSearchCover) } - if (track.publishing_status.isBlank()) { - binding.trackSearchStatus.isVisible = false - binding.trackSearchStatusResult.isVisible = false - } else { + val hasStatus = track.publishing_status.isNotBlank() + binding.trackSearchStatus.isVisible = hasStatus + binding.trackSearchStatusResult.isVisible = hasStatus + if (hasStatus) { binding.trackSearchStatusResult.text = track.publishing_status.capitalize() } - if (track.publishing_type.isBlank()) { - binding.trackSearchType.isVisible = false - binding.trackSearchTypeResult.isVisible = false - } else { + val hasType = track.publishing_type.isNotBlank() + binding.trackSearchType.isVisible = hasType + binding.trackSearchTypeResult.isVisible = hasType + if (hasType) { binding.trackSearchTypeResult.text = track.publishing_type.capitalize() } - if (track.start_date.isBlank()) { - binding.trackSearchStart.isVisible = false - binding.trackSearchStartResult.isVisible = false - } else { + val hasStartDate = track.start_date.isNotBlank() + binding.trackSearchStart.isVisible = hasStartDate + binding.trackSearchStartResult.isVisible = hasStartDate + if (hasStartDate) { binding.trackSearchStartResult.text = track.start_date } }