From ac3928ffe909809cfbc8393cc5d27203c8e46d4e Mon Sep 17 00:00:00 2001 From: Omar Gamal <112751175+ElecSpartan@users.noreply.github.com> Date: Mon, 13 May 2024 19:39:23 +0300 Subject: [PATCH 1/5] fixed a feature try no.1 --- .../Activity/ModifyTaskActivity.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/app/src/main/java/com/example/taskmanager/Activity/ModifyTaskActivity.java b/app/src/main/java/com/example/taskmanager/Activity/ModifyTaskActivity.java index 567dc38..bbf05b1 100644 --- a/app/src/main/java/com/example/taskmanager/Activity/ModifyTaskActivity.java +++ b/app/src/main/java/com/example/taskmanager/Activity/ModifyTaskActivity.java @@ -18,8 +18,13 @@ 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; @@ -140,6 +145,22 @@ public void onTimeSet(TimePicker view, int hourOfDay, int minute) { 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); + // Extract day, month, and year from the Date object + int day = date.getDate(); + int month = date.getMonth() + 1; // Adding 1 because month index starts from 0 + int year = date.getYear() + 1900; // Adding 1900 because getYear() returns years since 1900 + selectedTime.set(year,month,day); + + } catch (ParseException e) { + e.printStackTrace(); + } + + String amPm; if (hourOfDay >= 12) { amPm = "PM"; From 33b1a6d319cf9c100a34fbcc831e4397088443d7 Mon Sep 17 00:00:00 2001 From: Omar Gamal <112751175+ElecSpartan@users.noreply.github.com> Date: Mon, 13 May 2024 19:45:20 +0300 Subject: [PATCH 2/5] Revert "Merge branch 'main' of https://github.com/mohamedAdhamc/TaskManager" This reverts commit 2a5cbddc7f295a9443b1ef0cd2475c4a99b5552e, reversing changes made to ac3928ffe909809cfbc8393cc5d27203c8e46d4e. --- .../service/ForegroundService.java | 31 ------------------- 1 file changed, 31 deletions(-) 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 ae75fe3..4c8a652 100644 --- a/app/src/main/java/com/example/taskmanager/service/ForegroundService.java +++ b/app/src/main/java/com/example/taskmanager/service/ForegroundService.java @@ -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; @@ -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 tasks; - @Override public void onCreate() { super.onCreate(); - instance = RoomDB.getInstance(getApplicationContext()); } @Override @@ -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 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); @@ -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(); } }; From 36dfa2b79c3dcc1705acb93d23238c6732ed2d79 Mon Sep 17 00:00:00 2001 From: Omar Gamal <112751175+ElecSpartan@users.noreply.github.com> Date: Tue, 14 May 2024 19:34:58 +0300 Subject: [PATCH 3/5] feature fixed!! --- .../Activity/ModifyTaskActivity.java | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/example/taskmanager/Activity/ModifyTaskActivity.java b/app/src/main/java/com/example/taskmanager/Activity/ModifyTaskActivity.java index bbf05b1..511e375 100644 --- a/app/src/main/java/com/example/taskmanager/Activity/ModifyTaskActivity.java +++ b/app/src/main/java/com/example/taskmanager/Activity/ModifyTaskActivity.java @@ -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; @@ -140,27 +141,19 @@ 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); - // Extract day, month, and year from the Date object - int day = date.getDate(); - int month = date.getMonth() + 1; // Adding 1 because month index starts from 0 - int year = date.getYear() + 1900; // Adding 1900 because getYear() returns years since 1900 - selectedTime.set(year,month,day); - + 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) { amPm = "PM"; From 9bc162a50bd38d5bf46a6f608ac9b6c2ca409abf Mon Sep 17 00:00:00 2001 From: Ahmed Ayman 2000128 Date: Tue, 14 May 2024 20:15:25 +0300 Subject: [PATCH 4/5] 12 hours change --- .idea/deploymentTargetDropDown.xml | 3 --- .../com/example/taskmanager/Activity/ModifyTaskActivity.java | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml index 9c96b2b..0c0c338 100644 --- a/.idea/deploymentTargetDropDown.xml +++ b/.idea/deploymentTargetDropDown.xml @@ -2,9 +2,6 @@ - - - diff --git a/app/src/main/java/com/example/taskmanager/Activity/ModifyTaskActivity.java b/app/src/main/java/com/example/taskmanager/Activity/ModifyTaskActivity.java index 511e375..3389c85 100644 --- a/app/src/main/java/com/example/taskmanager/Activity/ModifyTaskActivity.java +++ b/app/src/main/java/com/example/taskmanager/Activity/ModifyTaskActivity.java @@ -166,7 +166,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); From 243482c87a6be8a33e6b1702b1ff449f2733dfba Mon Sep 17 00:00:00 2001 From: Omar Gamal <112751175+ElecSpartan@users.noreply.github.com> Date: Wed, 15 May 2024 08:44:56 +0300 Subject: [PATCH 5/5] added a friendly cool feature --- .../com/example/taskmanager/Activity/ModifyTaskActivity.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/src/main/java/com/example/taskmanager/Activity/ModifyTaskActivity.java b/app/src/main/java/com/example/taskmanager/Activity/ModifyTaskActivity.java index 3389c85..f1ac569 100644 --- a/app/src/main/java/com/example/taskmanager/Activity/ModifyTaskActivity.java +++ b/app/src/main/java/com/example/taskmanager/Activity/ModifyTaskActivity.java @@ -16,6 +16,8 @@ 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; @@ -204,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();