mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-24 17:51:14 +01:00
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>
This commit is contained in:
@@ -35,6 +35,7 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co
|
|||||||
- Fix reader "Unable to edit key" error ([@AntsyLich](https://github.com/AntsyLich)) ([#2634](https://github.com/mihonapp/mihon/pull/2634))
|
- Fix reader "Unable to edit key" error ([@AntsyLich](https://github.com/AntsyLich)) ([#2634](https://github.com/mihonapp/mihon/pull/2634))
|
||||||
- Fix extension download stuck in pending state in some cases ([@c2y5](https://github.com/c2y5)) ([#2483](https://github.com/mihonapp/mihon/pull/2483))
|
- Fix extension download stuck in pending state in some cases ([@c2y5](https://github.com/c2y5)) ([#2483](https://github.com/mihonapp/mihon/pull/2483))
|
||||||
- Fix scrollbar not showing when animator duration scale animation is turned off ([@anirudhsnayak](https://github.com/anirudhsnayak)) ([#2398](https://github.com/mihonapp/mihon/pull/2398))
|
- Fix scrollbar not showing when animator duration scale animation is turned off ([@anirudhsnayak](https://github.com/anirudhsnayak)) ([#2398](https://github.com/mihonapp/mihon/pull/2398))
|
||||||
|
- Fix date picker not allowing the same start and finish date in negative time zones ([@AntsyLich](https://github.com/AntsyLich), [@kashish-aggarwal21](https://github.com/kashish-aggarwal21)) ([#2617](https://github.com/mihonapp/mihon/pull/2617))
|
||||||
|
|
||||||
### Other
|
### Other
|
||||||
- Fix Kitsu tracker to conform to tracker data structure properly ([@cpiber](https://github.com/cpiber)) ([#2609](https://github.com/mihonapp/mihon/pull/2609))
|
- Fix Kitsu tracker to conform to tracker data structure properly ([@cpiber](https://github.com/cpiber)) ([#2609](https://github.com/mihonapp/mihon/pull/2609))
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ import eu.kanade.tachiyomi.data.track.Tracker
|
|||||||
import eu.kanade.tachiyomi.data.track.TrackerManager
|
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.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
|
||||||
@@ -84,7 +85,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(
|
||||||
@@ -220,7 +220,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) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -446,56 +446,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