mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 19:41:50 +01:00
Fix incorrect saved tracker dates (#5581)
This commit is contained in:
parent
116fec208b
commit
be28e0b559
@ -18,6 +18,7 @@ import eu.kanade.tachiyomi.source.SourceManager
|
|||||||
import eu.kanade.tachiyomi.ui.base.controller.openInBrowser
|
import eu.kanade.tachiyomi.ui.base.controller.openInBrowser
|
||||||
import eu.kanade.tachiyomi.ui.manga.MangaController
|
import eu.kanade.tachiyomi.ui.manga.MangaController
|
||||||
import eu.kanade.tachiyomi.util.lang.launchIO
|
import eu.kanade.tachiyomi.util.lang.launchIO
|
||||||
|
import eu.kanade.tachiyomi.util.lang.toLocalCalendar
|
||||||
import eu.kanade.tachiyomi.util.lang.toUtcCalendar
|
import eu.kanade.tachiyomi.util.lang.toUtcCalendar
|
||||||
import eu.kanade.tachiyomi.util.lang.withUIContext
|
import eu.kanade.tachiyomi.util.lang.withUIContext
|
||||||
import eu.kanade.tachiyomi.util.system.copyToClipboard
|
import eu.kanade.tachiyomi.util.system.copyToClipboard
|
||||||
@ -154,8 +155,11 @@ class TrackSheet(
|
|||||||
.setSelection(selection)
|
.setSelection(selection)
|
||||||
.setCalendarConstraints(constraints)
|
.setCalendarConstraints(constraints)
|
||||||
.build()
|
.build()
|
||||||
picker.addOnPositiveButtonClickListener {
|
picker.addOnPositiveButtonClickListener { utcMillis ->
|
||||||
controller.presenter.setTrackerStartDate(item, it)
|
val result = utcMillis.toLocalCalendar()?.timeInMillis
|
||||||
|
if (result != null) {
|
||||||
|
controller.presenter.setTrackerStartDate(item, result)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
picker.show(fragmentManager, null)
|
picker.show(fragmentManager, null)
|
||||||
}
|
}
|
||||||
@ -171,7 +175,7 @@ class TrackSheet(
|
|||||||
val constraints = CalendarConstraints.Builder().apply {
|
val constraints = CalendarConstraints.Builder().apply {
|
||||||
val startMillis = item.track.started_reading_date.toUtcCalendar()?.timeInMillis
|
val startMillis = item.track.started_reading_date.toUtcCalendar()?.timeInMillis
|
||||||
if (startMillis != null) {
|
if (startMillis != null) {
|
||||||
setValidator(DateValidatorPointForward.from(item.track.started_reading_date))
|
setValidator(DateValidatorPointForward.from(startMillis))
|
||||||
}
|
}
|
||||||
}.build()
|
}.build()
|
||||||
|
|
||||||
@ -180,8 +184,11 @@ class TrackSheet(
|
|||||||
.setSelection(selection)
|
.setSelection(selection)
|
||||||
.setCalendarConstraints(constraints)
|
.setCalendarConstraints(constraints)
|
||||||
.build()
|
.build()
|
||||||
picker.addOnPositiveButtonClickListener {
|
picker.addOnPositiveButtonClickListener { utcMillis ->
|
||||||
controller.presenter.setTrackerFinishDate(item, it)
|
val result = utcMillis.toLocalCalendar()?.timeInMillis
|
||||||
|
if (result != null) {
|
||||||
|
controller.presenter.setTrackerFinishDate(item, result)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
picker.show(fragmentManager, null)
|
picker.show(fragmentManager, null)
|
||||||
}
|
}
|
||||||
|
@ -46,9 +46,9 @@ fun Long.toCalendar(): Calendar? {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert epoch long to Calendar instance in UTC
|
* Convert local time millisecond value to Calendar instance in UTC
|
||||||
*
|
*
|
||||||
* @return UTC Calendar instance at supplied epoch time. Null if epoch was 0.
|
* @return UTC Calendar instance at supplied time. Null if time is 0.
|
||||||
*/
|
*/
|
||||||
fun Long.toUtcCalendar(): Calendar? {
|
fun Long.toUtcCalendar(): Calendar? {
|
||||||
if (this == 0L) {
|
if (this == 0L) {
|
||||||
@ -69,3 +69,28 @@ fun Long.toUtcCalendar(): Calendar? {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert UTC time millisecond to Calendar instance in local time zone
|
||||||
|
*
|
||||||
|
* @return local Calendar instance at supplied UTC time. Null if time is 0.
|
||||||
|
*/
|
||||||
|
fun Long.toLocalCalendar(): Calendar? {
|
||||||
|
if (this == 0L) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
val rawCalendar = Calendar.getInstance(TimeZone.getTimeZone("UTC")).apply {
|
||||||
|
timeInMillis = this@toLocalCalendar
|
||||||
|
}
|
||||||
|
return Calendar.getInstance().apply {
|
||||||
|
clear()
|
||||||
|
set(
|
||||||
|
rawCalendar.get(Calendar.YEAR),
|
||||||
|
rawCalendar.get(Calendar.MONTH),
|
||||||
|
rawCalendar.get(Calendar.DAY_OF_MONTH),
|
||||||
|
rawCalendar.get(Calendar.HOUR_OF_DAY),
|
||||||
|
rawCalendar.get(Calendar.MINUTE),
|
||||||
|
rawCalendar.get(Calendar.SECOND)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user