From 24b4827e0b7152b72c391018dab2abee588cc9c4 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Thu, 28 Jul 2022 14:49:02 +0200 Subject: [PATCH] fixes --- .../java/com/github/libretube/util/NotificationHelper.kt | 6 ++++-- .../java/com/github/libretube/util/NotificationWorker.kt | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/github/libretube/util/NotificationHelper.kt b/app/src/main/java/com/github/libretube/util/NotificationHelper.kt index 9261c4665..ebdeb74e9 100644 --- a/app/src/main/java/com/github/libretube/util/NotificationHelper.kt +++ b/app/src/main/java/com/github/libretube/util/NotificationHelper.kt @@ -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 -> { diff --git a/app/src/main/java/com/github/libretube/util/NotificationWorker.kt b/app/src/main/java/com/github/libretube/util/NotificationWorker.kt index 1038d0506..711aecb4e 100644 --- a/app/src/main/java/com/github/libretube/util/NotificationWorker.kt +++ b/app/src/main/java/com/github/libretube/util/NotificationWorker.kt @@ -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() }