mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 08:20:32 +05:30
add logic
This commit is contained in:
parent
e0512fcfbf
commit
49bbe312d1
@ -6,7 +6,6 @@ import android.util.Log
|
|||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.TextView
|
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.recyclerview.widget.ItemTouchHelper
|
import androidx.recyclerview.widget.ItemTouchHelper
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.github.libretube.ui.views
|
package com.github.libretube.ui.views
|
||||||
|
|
||||||
import android.app.Activity
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.text.format.DateFormat.is24HourFormat
|
import android.text.format.DateFormat.is24HourFormat
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
@ -17,7 +16,7 @@ class TimePickerPreference(
|
|||||||
) : Preference(context, attributeSet) {
|
) : Preference(context, attributeSet) {
|
||||||
override fun getSummary(): CharSequence {
|
override fun getSummary(): CharSequence {
|
||||||
val prefStr = PreferenceHelper.getString(key, "")
|
val prefStr = PreferenceHelper.getString(key, "")
|
||||||
return if (prefStr != "") prefStr else "00:00"
|
return if (prefStr != "") prefStr else DEFAULT_VALUE
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onClick() {
|
override fun onClick() {
|
||||||
@ -61,5 +60,6 @@ class TimePickerPreference(
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val SEPARATOR = ":"
|
const val SEPARATOR = ":"
|
||||||
|
const val DEFAULT_VALUE = "12:00"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,11 +13,14 @@ import com.github.libretube.R
|
|||||||
import com.github.libretube.api.RetrofitInstance
|
import com.github.libretube.api.RetrofitInstance
|
||||||
import com.github.libretube.api.SubscriptionHelper
|
import com.github.libretube.api.SubscriptionHelper
|
||||||
import com.github.libretube.constants.PUSH_CHANNEL_ID
|
import com.github.libretube.constants.PUSH_CHANNEL_ID
|
||||||
|
import com.github.libretube.constants.PreferenceKeys
|
||||||
import com.github.libretube.extensions.toID
|
import com.github.libretube.extensions.toID
|
||||||
import com.github.libretube.ui.activities.MainActivity
|
import com.github.libretube.ui.activities.MainActivity
|
||||||
|
import com.github.libretube.ui.views.TimePickerPreference
|
||||||
import com.github.libretube.util.PreferenceHelper
|
import com.github.libretube.util.PreferenceHelper
|
||||||
import kotlinx.coroutines.async
|
import kotlinx.coroutines.async
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
|
import java.time.LocalTime
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The notification worker which checks for new streams in a certain frequency
|
* The notification worker which checks for new streams in a certain frequency
|
||||||
@ -36,12 +39,43 @@ class NotificationWorker(appContext: Context, parameters: WorkerParameters) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun doWork(): Result {
|
override fun doWork(): Result {
|
||||||
|
if (!checkTime()) Result.success()
|
||||||
// check whether there are new streams and notify if there are some
|
// check whether there are new streams and notify if there are some
|
||||||
val result = checkForNewStreams()
|
val result = checkForNewStreams()
|
||||||
// return success if the API request succeeded
|
// return success if the API request succeeded
|
||||||
return if (result) Result.success() else Result.retry()
|
return if (result) Result.success() else Result.retry()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the time is valid to notify
|
||||||
|
*/
|
||||||
|
private fun checkTime(): Boolean {
|
||||||
|
if (!PreferenceHelper.getBoolean(
|
||||||
|
PreferenceKeys.NOTIFICATION_TIME_ENABLED,
|
||||||
|
false
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
val start = getTimePickerPref(PreferenceKeys.NOTIFICATION_START_TIME)
|
||||||
|
val end = getTimePickerPref(PreferenceKeys.NOTIFICATION_END_TIME)
|
||||||
|
|
||||||
|
val currentTime = LocalTime.now()
|
||||||
|
val isOverNight = start > end
|
||||||
|
|
||||||
|
val startValid = if (isOverNight) start > currentTime else start < currentTime
|
||||||
|
val endValid = if (isOverNight) end < currentTime else start > currentTime
|
||||||
|
|
||||||
|
return (startValid && endValid)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getTimePickerPref(key: String): LocalTime {
|
||||||
|
return LocalTime.parse(
|
||||||
|
PreferenceHelper.getString(key, TimePickerPreference.DEFAULT_VALUE)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check whether new streams are available in subscriptions
|
* check whether new streams are available in subscriptions
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user