Skip to content

Commit

Permalink
get tasks in foreground service
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamedAdhamc committed May 13, 2024
1 parent 09db212 commit f6fd9aa
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<TaskModel> tasks;

@Override
public void onCreate() {
super.onCreate();
instance = RoomDB.getInstance(getApplicationContext());
}

@Override
Expand All @@ -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<TaskModel> 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);
Expand All @@ -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();
}
};
Expand Down

0 comments on commit f6fd9aa

Please sign in to comment.