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

View File

@ -4,11 +4,16 @@ import android.content.Context
import androidx.work.Worker import androidx.work.Worker
import androidx.work.WorkerParameters 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) { class NotificationWorker(appContext: Context, parameters: WorkerParameters) : Worker(appContext, parameters) {
private val TAG = "NotificationWorker" private val TAG = "NotificationWorker"
override fun doWork(): Result { override fun doWork(): Result {
// schedule the next task of the worker
NotificationHelper.enqueueWork(applicationContext) NotificationHelper.enqueueWork(applicationContext)
// check whether there are new streams and notify if there are some
NotificationHelper.checkForNewStreams(applicationContext) NotificationHelper.checkForNewStreams(applicationContext)
return Result.success() return Result.success()
} }