From 14fa50b395b334cefc5be90babe7ee26ed57d1b5 Mon Sep 17 00:00:00 2001 From: jacques Date: Tue, 28 Dec 2021 15:03:38 +0100 Subject: [PATCH 1/6] Change pendingIntent flag according to IDE suggestion --- app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java b/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java index e94aaea..8883956 100644 --- a/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java +++ b/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java @@ -65,7 +65,7 @@ public class AlarmReceiver extends BroadcastReceiver { notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); - PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); + PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_IMMUTABLE); NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "PillDroid") .setSmallIcon(R.drawable.ic_pill_alarm) @@ -139,7 +139,7 @@ public class AlarmReceiver extends BroadcastReceiver { PendingIntent alarmIntent; Intent intent = new Intent(context, AlarmReceiver.class); - alarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0); + alarmIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_IMMUTABLE); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); From 075f439e405adac90a2c388214e0b4c474ed3f8b Mon Sep 17 00:00:00 2001 From: jacques Date: Tue, 28 Dec 2021 15:04:05 +0100 Subject: [PATCH 2/6] Update gradle version --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 0948da1..cfe6773 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:7.0.3' + classpath 'com.android.tools.build:gradle:7.0.4' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files From 5a28a9748d4d6c6393a08c87bc1ead72a24fb3ad Mon Sep 17 00:00:00 2001 From: jacques Date: Tue, 28 Dec 2021 15:06:11 +0100 Subject: [PATCH 3/6] Add human readable log --- app/src/main/java/net/foucry/pilldroid/DBHelper.java | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/net/foucry/pilldroid/DBHelper.java b/app/src/main/java/net/foucry/pilldroid/DBHelper.java index bfaf962..5d9954e 100644 --- a/app/src/main/java/net/foucry/pilldroid/DBHelper.java +++ b/app/src/main/java/net/foucry/pilldroid/DBHelper.java @@ -315,6 +315,7 @@ class DBHelper extends SQLiteOpenHelper { public void updateDrug(Drug drug) { Log.d(TAG, "Update Drug == " + drug.toString()); + Log.d(TAG, "drug last_update == " + UtilDate.convertDate(drug.getDateLastUpdate())); // Get reference to writable DB SQLiteDatabase db = this.getWritableDatabase(); From 592079bd01636abfe11d402c24edd50c41843228 Mon Sep 17 00:00:00 2001 From: jacques Date: Tue, 28 Dec 2021 15:08:07 +0100 Subject: [PATCH 4/6] Change prise by take add equals override to compare too drugs objects. --- .../main/java/net/foucry/pilldroid/Drug.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/Drug.java b/app/src/main/java/net/foucry/pilldroid/Drug.java index 7eba859..54a1686 100644 --- a/app/src/main/java/net/foucry/pilldroid/Drug.java +++ b/app/src/main/java/net/foucry/pilldroid/Drug.java @@ -5,6 +5,7 @@ import android.util.Log; import java.io.Serializable; import java.util.Calendar; import java.util.Date; +import java.util.Objects; import static net.foucry.pilldroid.UtilDate.dateAtNoon; import static net.foucry.pilldroid.UtilDate.nbOfDaysBetweenDateAndToday; @@ -148,17 +149,17 @@ public class Drug implements Serializable { } void setDateEndOfStock() { - int numberDayOfPrise; + int numberDayOfTake; if (this.take > 0) { - numberDayOfPrise = (int) Math.floor(this.stock / this.take); + numberDayOfTake = (int) Math.floor(this.stock / this.take); } else { - numberDayOfPrise = 0; + numberDayOfTake = 0; } Date aDate = dateAtNoon(new Date()); Calendar calendar = Calendar.getInstance(); calendar.setTime(aDate); - calendar.add(Calendar.DAY_OF_YEAR, numberDayOfPrise); + calendar.add(Calendar.DAY_OF_YEAR, numberDayOfTake); this.dateEndOfStock = calendar.getTime(); } @@ -175,4 +176,15 @@ public class Drug implements Serializable { setDateLastUpdate(new Date().getTime()); } } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Drug drug = (Drug) o; + return stock == drug.stock && + take == drug.take && + alertThreshold == drug.alertThreshold && + warnThreshold == drug.warnThreshold && + Objects.equals(name, drug.name); + } } \ No newline at end of file From b6d0322acd0f243127ac4582b42a93e631fa5450 Mon Sep 17 00:00:00 2001 From: jacques Date: Tue, 28 Dec 2021 15:09:52 +0100 Subject: [PATCH 5/6] Add drug comparaison between the original drug and the saved one. --- .../net/foucry/pilldroid/DrugDetailActivity.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java b/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java index d52e90d..f39b211 100644 --- a/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java @@ -28,6 +28,8 @@ public class DrugDetailActivity extends AppCompatActivity { private static final String TAG = DrugDetailActivity.class.getName(); Drug drug; + + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -109,8 +111,7 @@ public class DrugDetailActivity extends AppCompatActivity { return super.onOptionsItemSelected(item); } - private void getMDrugChanges() - { + private void getMDrugChanges() { Log.d(TAG, "Time to save new values"); DBHelper dbHelper = new DBHelper(this); @@ -142,9 +143,14 @@ public class DrugDetailActivity extends AppCompatActivity { newDrug.setTake(Double.parseDouble(takeValue)); newDrug.setWarnThreshold(Integer.parseInt(warningValue)); newDrug.setAlertThreshold(Integer.parseInt(alertValue)); - newDrug.setDateLastUpdate(new Date().getTime()); newDrug.setDateEndOfStock(); - dbHelper.updateDrug(newDrug); + if (drug.equals(newDrug)) { + Log.d(TAG, "drug and newDrug are Equals"); + } else { + Log.d(TAG, "drug and newDrug are NOT Equals"); + newDrug.setDateLastUpdate(new Date().getTime()); + dbHelper.updateDrug(newDrug); + } } } From d581492ee699683ada7271e3dda2cbc5b14addac Mon Sep 17 00:00:00 2001 From: jacques Date: Tue, 28 Dec 2021 15:10:36 +0100 Subject: [PATCH 6/6] Minor change in date formet --- app/src/main/java/net/foucry/pilldroid/UtilDate.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/net/foucry/pilldroid/UtilDate.java b/app/src/main/java/net/foucry/pilldroid/UtilDate.java index 6a596a2..1213256 100644 --- a/app/src/main/java/net/foucry/pilldroid/UtilDate.java +++ b/app/src/main/java/net/foucry/pilldroid/UtilDate.java @@ -5,6 +5,7 @@ import android.util.Log; import java.text.DateFormat; import java.text.ParsePosition; import java.text.SimpleDateFormat; +import java.time.LocalTime; import java.util.Calendar; import java.util.Date; import java.util.Locale; @@ -95,7 +96,7 @@ class UtilDate { * @return formatted Date String */ static String convertDate(long dateInMilliseconds) { - DateFormat formatter = new SimpleDateFormat("dd/MM/yy HH:mm:ss", Locale.FRANCE); + DateFormat formatter = new SimpleDateFormat("dd/MM/yy HH:mm:ss", Locale.getDefault()); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(dateInMilliseconds); return formatter.format(calendar.getTime());