Fixed not being able to remove dates on Anilist

Fixes #833
This commit is contained in:
Jays2Kings 2021-07-04 13:36:56 -04:00
parent 505fa871e6
commit c4d9b66485
3 changed files with 9 additions and 4 deletions

View File

@ -87,10 +87,10 @@ class AnilistApi(val client: OkHttpClient, interceptor: AnilistInterceptor) {
val response = responseToJson(netResponse)
try {
val media = response["data"]["SaveMediaListEntry"].asJsonObject
if (track.started_reading_date == 0L) {
if (track.started_reading_date <= 0L) {
track.started_reading_date = parseDate(media, "startedAt")
}
if (track.finished_reading_date == 0L) {
if (track.finished_reading_date <= 0L) {
track.finished_reading_date = parseDate(media, "completedAt")
}
} catch (e: Exception) {
@ -236,6 +236,11 @@ class AnilistApi(val client: OkHttpClient, interceptor: AnilistInterceptor) {
}
private fun createDate(dateValue: Long): JsonObject? {
if (dateValue == -1L) return jsonObject(
"year" to null,
"month" to null,
"day" to null,
)
if (dateValue == 0L) return null
val calendar = Calendar.getInstance()
calendar.timeInMillis = dateValue

View File

@ -222,7 +222,7 @@ class MyAnimeListApi(private val client: OkHttpClient, interceptor: MyAnimeListI
}
private fun convertToIsoDate(epochTime: Long): String? {
if (epochTime == 0L) {
if (epochTime <= 0L) {
return ""
}
return try {

View File

@ -67,7 +67,7 @@ class SetTrackReadingDatesDialog<T> : DialogController
listener.setReadingDate(item, dateToUpdate, date.timeInMillis)
}
.neutralButton(R.string.remove) {
listener.setReadingDate(item, dateToUpdate, 0L)
listener.setReadingDate(item, dateToUpdate, -1L)
}.apply {
getSuggestedDate()?.let {
message(