Fix date picker not allowing the same start and finish date in negative time zones (#2617)
Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com> (cherry picked from commit 8662f80fbf6b7c3aee4945bf656def8341cfdfd3)
This commit is contained in:
committed by
NGB-Was-Taken
parent
fc0d666366
commit
014bf97248
@@ -61,6 +61,7 @@ import eu.kanade.tachiyomi.data.track.TrackerManager
|
|||||||
import eu.kanade.tachiyomi.data.track.model.TrackSearch
|
import eu.kanade.tachiyomi.data.track.model.TrackSearch
|
||||||
import eu.kanade.tachiyomi.source.online.MetadataSource
|
import eu.kanade.tachiyomi.source.online.MetadataSource
|
||||||
import eu.kanade.tachiyomi.util.lang.convertEpochMillisZone
|
import eu.kanade.tachiyomi.util.lang.convertEpochMillisZone
|
||||||
|
import eu.kanade.tachiyomi.util.lang.toLocalDate
|
||||||
import eu.kanade.tachiyomi.util.system.copyToClipboard
|
import eu.kanade.tachiyomi.util.system.copyToClipboard
|
||||||
import eu.kanade.tachiyomi.util.system.openInBrowser
|
import eu.kanade.tachiyomi.util.system.openInBrowser
|
||||||
import eu.kanade.tachiyomi.util.system.toast
|
import eu.kanade.tachiyomi.util.system.toast
|
||||||
@@ -94,7 +95,6 @@ import uy.kohesive.injekt.Injekt
|
|||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
import java.time.LocalDate
|
import java.time.LocalDate
|
||||||
import java.time.ZoneId
|
|
||||||
import java.time.ZoneOffset
|
import java.time.ZoneOffset
|
||||||
|
|
||||||
data class TrackInfoDialogHomeScreen(
|
data class TrackInfoDialogHomeScreen(
|
||||||
@@ -250,7 +250,7 @@ data class TrackInfoDialogHomeScreen(
|
|||||||
try {
|
try {
|
||||||
val matchResult = item.tracker.match(manga) ?: throw Exception()
|
val matchResult = item.tracker.match(manga) ?: throw Exception()
|
||||||
item.tracker.register(matchResult, mangaId)
|
item.tracker.register(matchResult, mangaId)
|
||||||
} catch (e: Exception) {
|
} catch (_: Exception) {
|
||||||
withUIContext { Injekt.get<Application>().toast(MR.strings.error_no_match) }
|
withUIContext { Injekt.get<Application>().toast(MR.strings.error_no_match) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -552,56 +552,46 @@ private data class TrackDateSelectorScreen(
|
|||||||
@Transient
|
@Transient
|
||||||
private val selectableDates = object : SelectableDates {
|
private val selectableDates = object : SelectableDates {
|
||||||
override fun isSelectableDate(utcTimeMillis: Long): Boolean {
|
override fun isSelectableDate(utcTimeMillis: Long): Boolean {
|
||||||
val dateToCheck = Instant.ofEpochMilli(utcTimeMillis)
|
val targetDate = Instant.ofEpochMilli(utcTimeMillis).toLocalDate(ZoneOffset.UTC)
|
||||||
.atZone(ZoneOffset.systemDefault())
|
|
||||||
.toLocalDate()
|
|
||||||
|
|
||||||
if (dateToCheck > LocalDate.now()) {
|
// Disallow future dates
|
||||||
// Disallow future dates
|
if (targetDate > LocalDate.now(ZoneOffset.UTC)) return false
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return if (start && track.finishDate > 0) {
|
return when {
|
||||||
// Disallow start date to be set later than finish date
|
// Disallow setting start date after finish date
|
||||||
val dateFinished = Instant.ofEpochMilli(track.finishDate)
|
start && track.finishDate > 0 -> {
|
||||||
.atZone(ZoneId.systemDefault())
|
val finishDate = Instant.ofEpochMilli(track.finishDate).toLocalDate(ZoneOffset.UTC)
|
||||||
.toLocalDate()
|
targetDate <= finishDate
|
||||||
dateToCheck <= dateFinished
|
}
|
||||||
} else if (!start && track.startDate > 0) {
|
// Disallow setting finish date before start date
|
||||||
// Disallow end date to be set earlier than start date
|
!start && track.startDate > 0 -> {
|
||||||
val dateStarted = Instant.ofEpochMilli(track.startDate)
|
val startDate = Instant.ofEpochMilli(track.startDate).toLocalDate(ZoneOffset.UTC)
|
||||||
.atZone(ZoneId.systemDefault())
|
startDate <= targetDate
|
||||||
.toLocalDate()
|
}
|
||||||
dateToCheck >= dateStarted
|
else -> {
|
||||||
} else {
|
true
|
||||||
// Nothing set before
|
}
|
||||||
true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isSelectableYear(year: Int): Boolean {
|
override fun isSelectableYear(year: Int): Boolean {
|
||||||
if (year > LocalDate.now().year) {
|
// Disallow future years
|
||||||
// Disallow future dates
|
if (year > LocalDate.now(ZoneOffset.UTC).year) return false
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return if (start && track.finishDate > 0) {
|
return when {
|
||||||
// Disallow start date to be set later than finish date
|
// Disallow setting start year after finish year
|
||||||
val dateFinished = Instant.ofEpochMilli(track.finishDate)
|
start && track.finishDate > 0 -> {
|
||||||
.atZone(ZoneId.systemDefault())
|
val finishDate = Instant.ofEpochMilli(track.finishDate).toLocalDate(ZoneOffset.UTC)
|
||||||
.toLocalDate()
|
year <= finishDate.year
|
||||||
.year
|
}
|
||||||
year <= dateFinished
|
// Disallow setting finish year before start year
|
||||||
} else if (!start && track.startDate > 0) {
|
!start && track.startDate > 0 -> {
|
||||||
// Disallow end date to be set earlier than start date
|
val startDate = Instant.ofEpochMilli(track.startDate).toLocalDate(ZoneOffset.UTC)
|
||||||
val dateStarted = Instant.ofEpochMilli(track.startDate)
|
startDate.year <= year
|
||||||
.atZone(ZoneId.systemDefault())
|
}
|
||||||
.toLocalDate()
|
else -> {
|
||||||
.year
|
true
|
||||||
year >= dateStarted
|
}
|
||||||
} else {
|
|
||||||
// Nothing set before
|
|
||||||
true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user