diff --git a/app/src/main/java/com/example/taskmanager/service/ForegroundService.java b/app/src/main/java/com/example/taskmanager/service/ForegroundService.java index 4c8a652..ae75fe3 100644 --- a/app/src/main/java/com/example/taskmanager/service/ForegroundService.java +++ b/app/src/main/java/com/example/taskmanager/service/ForegroundService.java @@ -1,5 +1,7 @@ package com.example.taskmanager.service; +import static androidx.core.content.ContentProviderCompat.requireContext; + import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; @@ -12,14 +14,25 @@ import android.util.Log; import androidx.core.app.NotificationCompat; +import androidx.lifecycle.LifecycleOwner; + +import com.example.taskmanager.Database.RoomDB; +import com.example.taskmanager.Utility.TaskModel; + +import java.util.List; public class ForegroundService extends Service { private static final String CHANNEL_ID = "notification_channel"; + private RoomDB instance; + + private static List tasks; + @Override public void onCreate() { super.onCreate(); + instance = RoomDB.getInstance(getApplicationContext()); } @Override @@ -33,9 +46,15 @@ public int onStartCommand(Intent intent, int flags, int startId) { .build(); startForeground(1, notification); timer.start(); + instance.taskDAO().getAllOngoingTasks().observeForever( ForegroundService::updateTasks); return START_STICKY; } + private static void updateTasks(List taskModels) { + Log.wtf("foreground", "update tasks called"); + tasks = taskModels; + } + public static void startService (Context context) { Intent i = new Intent(context, ForegroundService.class); context.startForegroundService(i); @@ -57,6 +76,18 @@ public void onTick(long millisUntilFinished) { public void onFinish() { //generate the notifications Log.wtf("notificationz", "test"); + for(TaskModel task: tasks){ + if (task.getCurrentPriority().contains("Low")){ + //check deadline if multiple of 24 hours remaining send a notification + + } else if (task.getCurrentPriority().contains("Medium")){ + //check deadline if multiple of 5 hours remaining send a notification + + } else if (task.getCurrentPriority().contains("High")) { + //check deadline if multiple of 1 hours remaining send a notification + } + } + start(); } };