This commit is contained in:
Bnyro 2022-07-28 14:49:02 +02:00
parent d39d4de2d4
commit 24b4827e0b
2 changed files with 9 additions and 2 deletions

View File

@ -42,8 +42,8 @@ object NotificationHelper {
val myWorkBuilder = PeriodicWorkRequest.Builder(
NotificationWorker::class.java,
1,
TimeUnit.SECONDS
checkingFrequency,
TimeUnit.MINUTES
)
.setConstraints(constraints)
@ -70,6 +70,7 @@ object NotificationHelper {
val task = async {
RetrofitInstance.authApi.getFeed(token)
}
// fetch the users feed
val videoFeed = try {
task.await()
} catch (e: Exception) {
@ -87,6 +88,7 @@ object NotificationHelper {
newStreamIndex = index
}
}
if (newStreamIndex == -1) return@runBlocking
val (title, description) = when (newStreamIndex) {
// only one new stream available
1 -> {

View File

@ -4,11 +4,16 @@ import android.content.Context
import androidx.work.Worker
import androidx.work.WorkerParameters
/**
* The notification worker which checks for new streams in a certain frequency
*/
class NotificationWorker(appContext: Context, parameters: WorkerParameters) : Worker(appContext, parameters) {
private val TAG = "NotificationWorker"
override fun doWork(): Result {
// schedule the next task of the worker
NotificationHelper.enqueueWork(applicationContext)
// check whether there are new streams and notify if there are some
NotificationHelper.checkForNewStreams(applicationContext)
return Result.success()
}