From f8e121ee060f6fb38b5187921b441964ea87e904 Mon Sep 17 00:00:00 2001 From: DitFranXX <45893338+DitFranXX@users.noreply.github.com> Date: Mon, 28 Jan 2019 17:03:03 +0900 Subject: [PATCH] [Anilist] Fix date parsing error (#1805) fix #1804 --- .../tachiyomi/data/track/anilist/AnilistApi.kt | 13 +++++++++++-- .../tachiyomi/data/track/anilist/AnilistModels.kt | 11 ++++------- 2 files changed, 15 insertions(+), 9 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 74d02bbd4..041852ea0 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 @@ -12,6 +12,7 @@ import okhttp3.OkHttpClient import okhttp3.Request import okhttp3.RequestBody import rx.Observable +import java.util.Calendar class AnilistApi(val client: OkHttpClient, interceptor: AnilistInterceptor) { @@ -246,10 +247,18 @@ class AnilistApi(val client: OkHttpClient, interceptor: AnilistInterceptor) { } fun jsonToALManga(struct: JsonObject): ALManga{ + val date = try { + val date = Calendar.getInstance() + date.set(struct["startDate"]["year"].nullInt ?: 0, (struct["startDate"]["month"].nullInt ?: 0) - 1, + struct["startDate"]["day"].nullInt ?: 0) + date.timeInMillis + } catch (_: Exception) { + 0L + } + return ALManga(struct["id"].asInt, struct["title"]["romaji"].asString, struct["coverImage"]["large"].asString, struct["description"].nullString.orEmpty(), struct["type"].asString, struct["status"].asString, - struct["startDate"]["year"].nullString.orEmpty() + struct["startDate"]["month"].nullString.orEmpty() - + struct["startDate"]["day"].nullString.orEmpty(), struct["chapters"].nullInt ?: 0) + date, struct["chapters"].nullInt ?: 0) } fun jsonToALUserManga(struct: JsonObject): ALUserManga{ diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistModels.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistModels.kt index abfe5d427..8f96723d0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistModels.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistModels.kt @@ -1,6 +1,5 @@ package eu.kanade.tachiyomi.data.track.anilist -import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.data.database.models.Track import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.getOrDefault @@ -17,7 +16,7 @@ data class ALManga( val description: String?, val type: String, val publishing_status: String, - val start_date_fuzzy: String, + val start_date_fuzzy: Long, val total_chapters: Int) { fun toTrack() = TrackSearch.create(TrackManager.ANILIST).apply { @@ -29,14 +28,12 @@ data class ALManga( tracking_url = AnilistApi.mangaUrl(media_id) publishing_status = this@ALManga.publishing_status publishing_type = type - if (!start_date_fuzzy.isNullOrBlank()) { + if (start_date_fuzzy != 0L) { start_date = try { - val inputDf = SimpleDateFormat("yyyyMMdd", Locale.US) val outputDf = SimpleDateFormat("yyyy-MM-dd", Locale.US) - val date = inputDf.parse(BuildConfig.BUILD_TIME) - outputDf.format(date) + outputDf.format(start_date_fuzzy) } catch (e: Exception) { - start_date_fuzzy.orEmpty() + "" } } }