mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 22:30:30 +05:30
Merge pull request #3470 from Isira-Seneviratne/Improve_time_check
Improve time check in NotificationWorker.
This commit is contained in:
commit
21541b9578
@ -54,24 +54,19 @@ class NotificationWorker(appContext: Context, parameters: WorkerParameters) :
|
|||||||
* Determine whether the time is valid to notify
|
* Determine whether the time is valid to notify
|
||||||
*/
|
*/
|
||||||
private fun checkTime(): Boolean {
|
private fun checkTime(): Boolean {
|
||||||
if (!PreferenceHelper.getBoolean(
|
if (!PreferenceHelper.getBoolean(PreferenceKeys.NOTIFICATION_TIME_ENABLED, false)) {
|
||||||
PreferenceKeys.NOTIFICATION_TIME_ENABLED,
|
|
||||||
false
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
val start = getTimePickerPref(PreferenceKeys.NOTIFICATION_START_TIME)
|
val start = getTimePickerPref(PreferenceKeys.NOTIFICATION_START_TIME)
|
||||||
val end = getTimePickerPref(PreferenceKeys.NOTIFICATION_END_TIME)
|
val end = getTimePickerPref(PreferenceKeys.NOTIFICATION_END_TIME)
|
||||||
|
|
||||||
val currentTime = LocalTime.now()
|
val currentTime = LocalTime.now()
|
||||||
val isOverNight = start > end
|
|
||||||
|
|
||||||
val startValid = if (isOverNight) start > currentTime else start < currentTime
|
return if (start > end) {
|
||||||
val endValid = if (isOverNight) end < currentTime else start > currentTime
|
currentTime !in end..start
|
||||||
|
} else {
|
||||||
return (startValid && endValid)
|
currentTime in start..end
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getTimePickerPref(key: String): LocalTime {
|
private fun getTimePickerPref(key: String): LocalTime {
|
||||||
|
Loading…
Reference in New Issue
Block a user