Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed feature try no.1 #5

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.app.TimePickerDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
Expand All @@ -15,11 +16,18 @@
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;

import com.example.taskmanager.Database.RoomDB;
import com.example.taskmanager.Utility.TaskModel;
import com.example.taskmanager.R;

import java.text.ParseException;
import java.time.LocalDate;
import java.util.Calendar;
import java.text.SimpleDateFormat;
import java.util.Date;


public class ModifyTaskActivity extends AppCompatActivity {
private static TextView titleLb;
Expand Down Expand Up @@ -135,10 +143,18 @@ public void changeTime(View v) {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
Calendar selectedTime = Calendar.getInstance();
// TO DO:
// USE DATE STORED HERE
selectedTime.set(Calendar.HOUR_OF_DAY, hourOfDay);
selectedTime.set(Calendar.MINUTE, minute);
try{
String selectedDate = ((TextView)findViewById(R.id.dateView)).getText().toString();
// Define the date format to match the string
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
Date date = sdf.parse(selectedDate);
selectedTime.setTime(date);
selectedTime.set(Calendar.HOUR_OF_DAY, hourOfDay);
selectedTime.set(Calendar.MINUTE, minute);
Log.i("timechange",selectedTime.getTime().toString());
} catch (ParseException e) {
e.printStackTrace();
}

String amPm;
if (hourOfDay >= 12) {
Expand All @@ -152,7 +168,7 @@ public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
// Prompt user to select a future time
// Show message
AlertDialog.Builder builder = new AlertDialog.Builder(ModifyTaskActivity.this);
builder.setTitle("Incorrect Info").setMessage(hourOfDay + ":" + minute + amPm + " has passed buddy!");
builder.setTitle("Incorrect Info").setMessage((hourOfDay%12) + ":" + minute + amPm + " has passed buddy!");
builder.show();
} else {
((TextView) findViewById(R.id.timeView)).setText((hourOfDay % 12) + ":" + minute + " " + amPm);
Expand Down Expand Up @@ -190,6 +206,9 @@ public void save(View v) {

RoomDB instance = RoomDB.getInstance(this);

Toast.makeText(getApplicationContext(),"Your task \""+name+"\" has been saved successfully!"
, Toast.LENGTH_SHORT).show();

new Thread(() -> instance.taskDAO().updateTask(task)).start();

finish();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
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 @@ -14,25 +12,14 @@
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 @@ -46,15 +33,9 @@ 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 @@ -76,18 +57,6 @@ 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
Loading