From e1cfc2a37560dc9612d4bc4d92a018e4d042b88a Mon Sep 17 00:00:00 2001 From: jacques Date: Thu, 14 Jul 2022 13:23:32 +0200 Subject: [PATCH 01/16] Add newStock calculation forgot in previous versions --- .../java/net/foucry/pilldroid/AlarmReceiver.java | 8 +++++++- .../foucry/pilldroid/models/Prescription.java | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java b/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java index 02c043e..95d67ef 100644 --- a/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java +++ b/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java @@ -50,8 +50,14 @@ public class AlarmReceiver extends BroadcastReceiver { PrescriptionDatabase prescriptions = PrescriptionDatabase.getInstanceDatabase(context.getApplicationContext()); PrescriptionsDAO prescriptionsDAO = prescriptions.getPrescriptionsDAO(); List prescriptionList = prescriptionsDAO.getAllMedics(); - Prescription firstPrescription = null ; + Prescription firstPrescription = null; + Prescription currentPrescription; + for (int i=0 ; i < prescriptionList.size(); i++ ) { + currentPrescription = prescriptionList.get(i); + currentPrescription.newStock(); + prescriptionsDAO.update(currentPrescription); + } // Sorting list by dateEndOfStock Utils.sortPrescriptionList(prescriptionList); diff --git a/app/src/main/java/net/foucry/pilldroid/models/Prescription.java b/app/src/main/java/net/foucry/pilldroid/models/Prescription.java index 709bad1..6d200f3 100644 --- a/app/src/main/java/net/foucry/pilldroid/models/Prescription.java +++ b/app/src/main/java/net/foucry/pilldroid/models/Prescription.java @@ -1,5 +1,9 @@ package net.foucry.pilldroid.models; +import static net.foucry.pilldroid.UtilDate.nbOfDaysBetweenDateAndToday; + +import android.util.Log; + import androidx.annotation.NonNull; import androidx.room.Entity; import androidx.room.PrimaryKey; @@ -129,6 +133,7 @@ public class Prescription implements Serializable { public void setGeneric_type(Integer generic_type) { this.generic_type = generic_type; } + public Date getDateEndOfStock() { int numberDayOfTake; if (this.getTake() > 0) { @@ -144,6 +149,17 @@ public class Prescription implements Serializable { return calendar.getTime(); } + + public void newStock() { + Date lastUpdate = new Date(getLast_update()); + + int numberOfDays = UtilDate.nbOfDaysBetweenDateAndToday(lastUpdate); + if (numberOfDays > 0) { + double takeDuringPeriod = this.take * numberOfDays; + setStock((float) (getStock() - takeDuringPeriod)); + setLast_update(new Date().getTime()); + } + } } From 59ca6554529fdc4ae0696c0f90392d9c25c4386d Mon Sep 17 00:00:00 2001 From: jacques Date: Mon, 18 Jul 2022 18:22:46 +0200 Subject: [PATCH 02/16] Change method to public --- app/src/main/java/net/foucry/pilldroid/UtilDate.java | 2 +- 1 file changed, 1 insertion(+), 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 fe7075a..9a67307 100644 --- a/app/src/main/java/net/foucry/pilldroid/UtilDate.java +++ b/app/src/main/java/net/foucry/pilldroid/UtilDate.java @@ -82,7 +82,7 @@ public class UtilDate { * @return int numbers of days between date and today * Number of days between date (older than today) and today */ - static int nbOfDaysBetweenDateAndToday(Date date) { + public static int nbOfDaysBetweenDateAndToday(Date date) { Date oldDate = dateAtNoon(date); // Be sure that the old date is at Noon Date todayDate = dateAtNoon(new Date()); // Be sure that we use today at Noon From ccdd37b865045edc658a1260c306451a617ae889 Mon Sep 17 00:00:00 2001 From: jacques Date: Mon, 18 Jul 2022 18:23:13 +0200 Subject: [PATCH 03/16] optimize import --- .../main/java/net/foucry/pilldroid/models/Prescription.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/models/Prescription.java b/app/src/main/java/net/foucry/pilldroid/models/Prescription.java index 6d200f3..410f435 100644 --- a/app/src/main/java/net/foucry/pilldroid/models/Prescription.java +++ b/app/src/main/java/net/foucry/pilldroid/models/Prescription.java @@ -1,9 +1,5 @@ package net.foucry.pilldroid.models; -import static net.foucry.pilldroid.UtilDate.nbOfDaysBetweenDateAndToday; - -import android.util.Log; - import androidx.annotation.NonNull; import androidx.room.Entity; import androidx.room.PrimaryKey; From 978fb755bd6b64280d242127d51376e4ef2bc04b Mon Sep 17 00:00:00 2001 From: jacques Date: Mon, 18 Jul 2022 18:24:43 +0200 Subject: [PATCH 04/16] try to fix bug unsuccessfully --- app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java b/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java index 95d67ef..afe9ec7 100644 --- a/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java +++ b/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java @@ -59,6 +59,7 @@ public class AlarmReceiver extends BroadcastReceiver { prescriptionsDAO.update(currentPrescription); } // Sorting list by dateEndOfStock + prescriptionList = prescriptionsDAO.getAllMedics(); // Reread the database Utils.sortPrescriptionList(prescriptionList); try { From 5c2866a5431575879f283a6a4b99e274bb8f70aa Mon Sep 17 00:00:00 2001 From: jacques Date: Sun, 24 Jul 2022 10:55:01 +0200 Subject: [PATCH 05/16] commented zxingBuildConfig in order to use net.foucry.pilldroid.BuildConfig --- app/src/main/java/net/foucry/pilldroid/DrugListActivity.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java index 7806f72..a6261d7 100644 --- a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java @@ -39,7 +39,6 @@ import androidx.recyclerview.widget.RecyclerView; import androidx.room.Room; import com.google.android.material.snackbar.Snackbar; -import com.google.zxing.client.android.BuildConfig; import com.google.zxing.client.android.Intents; import com.journeyapps.barcodescanner.ScanOptions; @@ -49,12 +48,14 @@ import net.foucry.pilldroid.databases.MedicineDatabase; import net.foucry.pilldroid.databases.PrescriptionDatabase; import net.foucry.pilldroid.models.Medicine; import net.foucry.pilldroid.models.Prescription; - +import net.foucry.pilldroid.BuildConfig; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.util.Locale; +//import com.google.zxing.client.android.BuildConfig; + /** * An activity representing a list of Drugs is activity * has different presentations for handset and tablet-size devices. On From 4620ca0f988a4341d48fd3e9cf43f4b4942280a2 Mon Sep 17 00:00:00 2001 From: jacques Date: Sun, 24 Jul 2022 10:55:34 +0200 Subject: [PATCH 06/16] Add debug code --- .../net/foucry/pilldroid/AlarmReceiver.java | 17 +- .../foucry/pilldroid/models/Prescription.java | 293 +++++++++--------- 2 files changed, 166 insertions(+), 144 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java b/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java index afe9ec7..a829160 100644 --- a/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java +++ b/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java @@ -14,7 +14,7 @@ import android.widget.Toast; import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationManagerCompat; -import com.google.zxing.client.android.BuildConfig; +//import com.google.zxing.client.android.BuildConfig; import net.foucry.pilldroid.dao.PrescriptionsDAO; import net.foucry.pilldroid.databases.PrescriptionDatabase; @@ -137,7 +137,7 @@ public class AlarmReceiver extends BroadcastReceiver { LocalTime todayNow = LocalTime.now(); if (BuildConfig.DEBUG) { - calendar.add(Calendar.MINUTE, 2); + calendar.add(Calendar.MINUTE, 2); Date nextSchedule = calendar.getTime(); calendar.setTimeInMillis(nextSchedule.getTime()); } else { @@ -159,10 +159,19 @@ public class AlarmReceiver extends BroadcastReceiver { AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); - alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP,(calendar.getTimeInMillis()), - AlarmManager.INTERVAL_DAY, alarmIntent); + if (BuildConfig.DEBUG) { + alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP,(calendar.getTimeInMillis()), + AlarmManager.ELAPSED_REALTIME, alarmIntent); + } else { + + alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, (calendar.getTimeInMillis()), + AlarmManager.INTERVAL_DAY, alarmIntent); + } Log.d(TAG, "Alarm scheduled for " + UtilDate.convertDate(calendar.getTimeInMillis())); + if (BuildConfig.DEBUG) { + Toast.makeText(context, "Alarm scheduled for " + UtilDate.convertDate(calendar.getTimeInMillis()), Toast.LENGTH_LONG).show(); + } if (BuildConfig.DEBUG) { Toast.makeText(context, "Alarm scheduled for " + UtilDate.convertDate(calendar.getTimeInMillis()), Toast.LENGTH_SHORT).show(); } } diff --git a/app/src/main/java/net/foucry/pilldroid/models/Prescription.java b/app/src/main/java/net/foucry/pilldroid/models/Prescription.java index 410f435..cdc947f 100644 --- a/app/src/main/java/net/foucry/pilldroid/models/Prescription.java +++ b/app/src/main/java/net/foucry/pilldroid/models/Prescription.java @@ -1,9 +1,13 @@ package net.foucry.pilldroid.models; +import android.util.Log; +import android.widget.Toast; + import androidx.annotation.NonNull; import androidx.room.Entity; import androidx.room.PrimaryKey; +import net.foucry.pilldroid.BuildConfig; import net.foucry.pilldroid.UtilDate; import java.io.Serializable; @@ -12,150 +16,159 @@ import java.util.Date; @Entity(tableName = "prescriptions") public class Prescription implements Serializable { - @PrimaryKey - @NonNull private String cis; - private String cip13; - private String name; - private String administration_mode; - private String presentation; - private Float stock; - private Float take; - private Integer warning; - private Integer alert; - private Long last_update; - private String label_group; - private Integer generic_type; + private static final String TAG = Prescription.class.getName();; + @PrimaryKey + @NonNull + private String cis; + private String cip13; + private String name; + private String administration_mode; + private String presentation; + private Float stock; + private Float take; + private Integer warning; + private Integer alert; + private Long last_update; + private String label_group; + private Integer generic_type; - public void setCis(@NonNull String cis) -{ - this.cis = cis; -} - - public void setCip13(String cip13) { - this.cip13 = cip13; - } - - public void setName(String name) { - this.name = name; - } - - public void setAdministration_mode(String administration_mode) { - this.administration_mode = administration_mode; - } - - public void setPresentation(String presentation) { - this.presentation = presentation; -} - public void setStock(Float stock) { - this.stock = stock; -} - - public void setTake(Float take) { - this.take = take; -} - - public void setWarning(Integer warning) { - this.warning = warning; -} - - public void setAlert(Integer alert) { - this.alert = alert; -} - - public void setLast_update(Long last_update) { - this.last_update = last_update; -} - - @NonNull - public String getCis() { - return this.cis; -} - - public Integer getWarning() { - return warning; - } - - public String getCip13() { - return cip13; - } - - public String getName() { - return name; - } - - public String getAdministration_mode() { - return administration_mode; - } - - public String getPresentation() { - return presentation; - } - - public Float getStock() { - return stock; - } - - public Float getTake() { - return take; - } - - public Integer getAlert() { - return alert; - } - - public Long getLast_update() { - return last_update; - } - - public int getAlertThreshold() { - return this.alert; - } - - public int getWarnThreshold() { - return this.warning; - } - public String getLabel_group() { - return label_group; - } - - public void setLabel_group(String label_group) { - this.label_group = label_group; - } - - public Integer getGeneric_type() { - return generic_type; - } - - public void setGeneric_type(Integer generic_type) { - this.generic_type = generic_type; - } - - public Date getDateEndOfStock() { - int numberDayOfTake; - if (this.getTake() > 0) { - numberDayOfTake = (int) Math.floor(this.getStock() / this.getTake()); - } else { - numberDayOfTake = 0; + public void setCis(@NonNull String cis) { + this.cis = cis; } - Date aDate = UtilDate.dateAtNoon(new Date()); - Calendar calendar = Calendar.getInstance(); - calendar.setTime(aDate); - calendar.add(Calendar.DAY_OF_YEAR, numberDayOfTake); - - return calendar.getTime(); - } - - public void newStock() { - Date lastUpdate = new Date(getLast_update()); - - int numberOfDays = UtilDate.nbOfDaysBetweenDateAndToday(lastUpdate); - if (numberOfDays > 0) { - double takeDuringPeriod = this.take * numberOfDays; - setStock((float) (getStock() - takeDuringPeriod)); - setLast_update(new Date().getTime()); + public void setCip13(String cip13) { + this.cip13 = cip13; + } + + public void setName(String name) { + this.name = name; + } + + public void setAdministration_mode(String administration_mode) { + this.administration_mode = administration_mode; + } + + public void setPresentation(String presentation) { + this.presentation = presentation; + } + + public void setStock(Float stock) { + this.stock = stock; + } + + public void setTake(Float take) { + this.take = take; + } + + public void setWarning(Integer warning) { + this.warning = warning; + } + + public void setAlert(Integer alert) { + this.alert = alert; + } + + public void setLast_update(Long last_update) { + this.last_update = last_update; + } + + @NonNull + public String getCis() { + return this.cis; + } + + public Integer getWarning() { + return warning; + } + + public String getCip13() { + return cip13; + } + + public String getName() { + return name; + } + + public String getAdministration_mode() { + return administration_mode; + } + + public String getPresentation() { + return presentation; + } + + public Float getStock() { + return stock; + } + + public Float getTake() { + return take; + } + + public Integer getAlert() { + return alert; + } + + public Long getLast_update() { + return last_update; + } + + public int getAlertThreshold() { + return this.alert; + } + + public int getWarnThreshold() { + return this.warning; + } + + public String getLabel_group() { + return label_group; + } + + public void setLabel_group(String label_group) { + this.label_group = label_group; + } + + public Integer getGeneric_type() { + return generic_type; + } + + public void setGeneric_type(Integer generic_type) { + this.generic_type = generic_type; + } + + public Date getDateEndOfStock() { + int numberDayOfTake; + if (this.getTake() > 0) { + numberDayOfTake = (int) Math.floor(this.getStock() / this.getTake()); + } else { + numberDayOfTake = 0; + } + + Date aDate = UtilDate.dateAtNoon(new Date()); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(aDate); + calendar.add(Calendar.DAY_OF_YEAR, numberDayOfTake); + + return calendar.getTime(); + } + + public void newStock() { + Date lastUpdate = new Date(getLast_update()); + + int numberOfDays = UtilDate.nbOfDaysBetweenDateAndToday(lastUpdate); + + if (BuildConfig.DEBUG) { + numberOfDays = 1; + Log.d(TAG, "Set NumberOfDays = 1"); + } + + if (numberOfDays > 0) { + double takeDuringPeriod = this.take * numberOfDays; + setStock((float) (getStock() - takeDuringPeriod)); + setLast_update(new Date().getTime()); + } } - } } From 0c8fa4812bfbf1502938bb91d028ad99eaaa5115 Mon Sep 17 00:00:00 2001 From: jacques Date: Sun, 24 Jul 2022 10:56:48 +0200 Subject: [PATCH 07/16] Remove prerelease build config and predproduct build flavor --- app/build.gradle | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index f1e663a..9685264 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -58,12 +58,6 @@ android { debuggable false signingConfig signingConfigs.release } - prerelease { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - debuggable false - signingConfig signingConfigs.prerelease - } } flavorDimensions "version" productFlavors { @@ -76,10 +70,6 @@ android { resValue "string", "app_name", "PillDroid" dimension ="version" } - preproduct { - resValue "string", "app_name", "PillDroid Pre-Release" - dimension ="version" - } } compileOptions { From e8d3b8f85ef6b5fb1bc853f4a3a4f96df8b2c42b Mon Sep 17 00:00:00 2001 From: jacques Date: Sat, 30 Jul 2022 08:27:27 +0200 Subject: [PATCH 08/16] upgrade to gradle 7.3.3 --- gradle/wrapper/gradle-wrapper.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 0a9913d..769daa4 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Wed Sep 29 16:41:02 CEST 2021 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME From 564be244d6e96a5854029526f00da827cd8c1c38 Mon Sep 17 00:00:00 2001 From: jacques Date: Sat, 30 Jul 2022 08:28:46 +0200 Subject: [PATCH 09/16] upgrade to gradle 7.2.1 --- .../net/foucry/pilldroid/AlarmReceiver.java | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java b/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java index a829160..002dc35 100644 --- a/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java +++ b/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java @@ -14,7 +14,7 @@ import android.widget.Toast; import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationManagerCompat; -//import com.google.zxing.client.android.BuildConfig; +import com.google.zxing.client.android.BuildConfig; import net.foucry.pilldroid.dao.PrescriptionsDAO; import net.foucry.pilldroid.databases.PrescriptionDatabase; @@ -61,7 +61,7 @@ public class AlarmReceiver extends BroadcastReceiver { // Sorting list by dateEndOfStock prescriptionList = prescriptionsDAO.getAllMedics(); // Reread the database Utils.sortPrescriptionList(prescriptionList); - + //Utils.rearrangePrescriptionList(prescriptionList); try { firstPrescription = prescriptionList.get(0); } @@ -100,7 +100,6 @@ public class AlarmReceiver extends BroadcastReceiver { } } } - } private void createNotificationChannel(Context context) { @@ -136,11 +135,10 @@ public class AlarmReceiver extends BroadcastReceiver { Date tomorrow; LocalTime todayNow = LocalTime.now(); - if (BuildConfig.DEBUG) { - calendar.add(Calendar.MINUTE, 2); + /*if (BuildConfig.DEBUG) { Date nextSchedule = calendar.getTime(); calendar.setTimeInMillis(nextSchedule.getTime()); - } else { + } else {*/ calendar.set(Calendar.HOUR_OF_DAY, 11); today = calendar.getTime(); calendar.add(Calendar.DAY_OF_YEAR, 1); @@ -150,7 +148,7 @@ public class AlarmReceiver extends BroadcastReceiver { } else { calendar.setTimeInMillis(tomorrow.getTime()); } - } + //} PendingIntent alarmIntent; @@ -159,26 +157,21 @@ public class AlarmReceiver extends BroadcastReceiver { AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); - if (BuildConfig.DEBUG) { + /*if (BuildConfig.DEBUG) { alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP,(calendar.getTimeInMillis()), AlarmManager.ELAPSED_REALTIME, alarmIntent); - } else { + } else {*/ alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, (calendar.getTimeInMillis()), AlarmManager.INTERVAL_DAY, alarmIntent); - } + //} Log.d(TAG, "Alarm scheduled for " + UtilDate.convertDate(calendar.getTimeInMillis())); - if (BuildConfig.DEBUG) { - Toast.makeText(context, "Alarm scheduled for " + UtilDate.convertDate(calendar.getTimeInMillis()), Toast.LENGTH_LONG).show(); - } - if (BuildConfig.DEBUG) { Toast.makeText(context, "Alarm scheduled for " + UtilDate.convertDate(calendar.getTimeInMillis()), Toast.LENGTH_SHORT).show(); } } public static Boolean isAlarmScheduled(Context context) { AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); - return alarmManager.getNextAlarmClock() != null; } } From 536070ceb3cda2884a67f26ebba3757e34ce712a Mon Sep 17 00:00:00 2001 From: jacques Date: Sat, 30 Jul 2022 08:29:25 +0200 Subject: [PATCH 10/16] upgrade to gradle 7.2.1 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index f0bbbef..7e8b67e 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:7.1.3' + classpath 'com.android.tools.build:gradle:7.2.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files From 60e6b957c584e3501b8f50f4166974242a4d0904 Mon Sep 17 00:00:00 2001 From: jacques Date: Sat, 30 Jul 2022 08:30:17 +0200 Subject: [PATCH 11/16] remove old comment --- app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java b/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java index 5e7cd07..5dbd2ad 100644 --- a/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/DrugDetailActivity.java @@ -148,7 +148,6 @@ public class DrugDetailActivity extends AppCompatActivity { Log.d(TAG, "medic and newPrescription are NOT Equals"); newPrescription.setLast_update(new Date().getTime()); prescriptionsDAO.update(newPrescription); - //dbHelper.updateDrug(newDrug); } } } From 57d9b7b01070b232c962a75aef68ff6e9a8b5613 Mon Sep 17 00:00:00 2001 From: jacques Date: Sat, 30 Jul 2022 08:31:31 +0200 Subject: [PATCH 12/16] CHange in newStock call --- .../foucry/pilldroid/DrugListActivity.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java index a6261d7..363a9be 100644 --- a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java @@ -48,13 +48,13 @@ import net.foucry.pilldroid.databases.MedicineDatabase; import net.foucry.pilldroid.databases.PrescriptionDatabase; import net.foucry.pilldroid.models.Medicine; import net.foucry.pilldroid.models.Prescription; -import net.foucry.pilldroid.BuildConfig; + import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.util.Locale; -//import com.google.zxing.client.android.BuildConfig; +import com.google.zxing.client.android.BuildConfig; /** * An activity representing a list of Drugs is activity @@ -283,19 +283,21 @@ public class DrugListActivity extends AppCompatActivity { PrescriptionsDAO prescriptionsDAO = prescriptions.getPrescriptionsDAO(); prescriptionList = prescriptionsDAO.getAllMedics(); - Prescription currentPrescription; + //Prescription currentPrescription; // Sorting list by dateEndOfStock Utils.sortPrescriptionList(prescriptionList); // Move Prescription with take==0 to the end of the list - for (int i=0 ; i < prescriptionList.size(); i++ ){ + //Utils.rearrangePrescriptionList(prescriptionList); + /*for (int i=0 ; i < prescriptionList.size(); i++ ){ currentPrescription = prescriptionList.get(i); + //currentPrescription.newStock(); if (currentPrescription.getTake() == 0) { prescriptionList.remove(currentPrescription); prescriptionList.add(prescriptionList.size(), currentPrescription); } - } + }*/ View mRecyclerView = findViewById(R.id.drug_list); assert mRecyclerView != null; @@ -598,7 +600,7 @@ public class DrugListActivity extends AppCompatActivity { @NonNull @Override - public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { View view = LayoutInflater.from(parent.getContext()) .inflate(R.layout.drug_list_content, parent, false); return new ViewHolder(view); @@ -606,7 +608,7 @@ public class DrugListActivity extends AppCompatActivity { @Override @SuppressWarnings("deprecation") - public void onBindViewHolder(final ViewHolder holder, int dummy) { + public void onBindViewHolder(@NonNull final ViewHolder holder, int dummy) { final int position = holder.getBindingAdapterPosition(); SimpleDateFormat dateFormat = new SimpleDateFormat("EEEE d MMMM yyyy", Locale.getDefault()); String dateEndOfStock = date2String(mValues.get(position).getDateEndOfStock(), dateFormat); @@ -620,7 +622,11 @@ public class DrugListActivity extends AppCompatActivity { holder.mItem = mValues.get(position); holder.mContentView.setText(mValues.get(position).getName()); - holder.mEndOfStock.setText(dateEndOfStock); + if (mValues.get(position).getTake() > 0) { + holder.mEndOfStock.setText(dateEndOfStock); + } else { + holder.mEndOfStock.setText(""); + } // Test to change background programmatically if (mValues.get(position).getTake() == 0) { @@ -662,7 +668,6 @@ public class DrugListActivity extends AppCompatActivity { intent.putExtra("prescription", prescription); startActivityForResult(intent, CUSTOMIZED_REQUEST_CODE); overridePendingTransition(R.anim.slide_from_right, R.anim.slide_to_left); - } }); } From 295ba5f52bb5f0592f444c5bfed63b06b3ccb9a3 Mon Sep 17 00:00:00 2001 From: jacques Date: Sat, 30 Jul 2022 08:32:53 +0200 Subject: [PATCH 13/16] Change in getDateEndOfStock comment old code --- .../foucry/pilldroid/models/Prescription.java | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/models/Prescription.java b/app/src/main/java/net/foucry/pilldroid/models/Prescription.java index cdc947f..7ce3ea9 100644 --- a/app/src/main/java/net/foucry/pilldroid/models/Prescription.java +++ b/app/src/main/java/net/foucry/pilldroid/models/Prescription.java @@ -7,7 +7,6 @@ import androidx.annotation.NonNull; import androidx.room.Entity; import androidx.room.PrimaryKey; -import net.foucry.pilldroid.BuildConfig; import net.foucry.pilldroid.UtilDate; import java.io.Serializable; @@ -138,18 +137,22 @@ public class Prescription implements Serializable { } public Date getDateEndOfStock() { - int numberDayOfTake; - if (this.getTake() > 0) { - numberDayOfTake = (int) Math.floor(this.getStock() / this.getTake()); - } else { - numberDayOfTake = 0; - } - Date aDate = UtilDate.dateAtNoon(new Date()); Calendar calendar = Calendar.getInstance(); - calendar.setTime(aDate); - calendar.add(Calendar.DAY_OF_YEAR, numberDayOfTake); + int numberDayOfTake = 0; + if (getTake() > 0) { + calendar.setTime(aDate); + numberDayOfTake = (int) Math.floor(this.getStock() / this.getTake()); + calendar.add(Calendar.DAY_OF_YEAR, numberDayOfTake); + } else { + calendar.set(Calendar.YEAR, 9999); + calendar.set(Calendar.DAY_OF_YEAR, 1); + calendar.set(Calendar.MONTH, 1); + calendar.set(Calendar.HOUR_OF_DAY, 0); + calendar.set(Calendar.MINUTE, 0); + calendar.set(Calendar.SECOND, 0); + } return calendar.getTime(); } @@ -158,10 +161,10 @@ public class Prescription implements Serializable { int numberOfDays = UtilDate.nbOfDaysBetweenDateAndToday(lastUpdate); - if (BuildConfig.DEBUG) { + /*if (BuildConfig.DEBUG) { numberOfDays = 1; Log.d(TAG, "Set NumberOfDays = 1"); - } + }*/ if (numberOfDays > 0) { double takeDuringPeriod = this.take * numberOfDays; From 01723797026d80082099c76c838006cc8651593c Mon Sep 17 00:00:00 2001 From: jacques Date: Sat, 30 Jul 2022 08:33:16 +0200 Subject: [PATCH 14/16] optimize code --- .../net/foucry/pilldroid/databases/PrescriptionDatabase.java | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/net/foucry/pilldroid/databases/PrescriptionDatabase.java b/app/src/main/java/net/foucry/pilldroid/databases/PrescriptionDatabase.java index e0a4e46..406f05e 100644 --- a/app/src/main/java/net/foucry/pilldroid/databases/PrescriptionDatabase.java +++ b/app/src/main/java/net/foucry/pilldroid/databases/PrescriptionDatabase.java @@ -44,7 +44,6 @@ public abstract class PrescriptionDatabase extends RoomDatabase { } return INSTANCE; } - public static void destroyInstance() { INSTANCE = null; } From b3079837d3d51cbe90b0e51686fb1a3b36411bba Mon Sep 17 00:00:00 2001 From: jacques Date: Sat, 30 Jul 2022 08:34:11 +0200 Subject: [PATCH 15/16] factorize a non-use method (after finding another method --- app/src/main/java/net/foucry/pilldroid/Utils.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/src/main/java/net/foucry/pilldroid/Utils.java b/app/src/main/java/net/foucry/pilldroid/Utils.java index 41f5766..dc942a6 100644 --- a/app/src/main/java/net/foucry/pilldroid/Utils.java +++ b/app/src/main/java/net/foucry/pilldroid/Utils.java @@ -59,4 +59,15 @@ public class Utils { } }); } + + public static void rearrangePrescriptionList(List prescriptionList) { + Prescription currentPrescription = null; + for (int i=0 ; i < prescriptionList.size(); i++ ){ + currentPrescription = prescriptionList.get(i); + if (currentPrescription.getTake() == 0) { + prescriptionList.remove(currentPrescription); + prescriptionList.add(prescriptionList.size(), currentPrescription); + } + } + } } From 9fce7a2e8a22fefdd558ff4522487e7bac8cdc84 Mon Sep 17 00:00:00 2001 From: jacques Date: Mon, 1 Aug 2022 08:01:11 +0200 Subject: [PATCH 16/16] Clean code, remove unused methods, comments --- .../java/net/foucry/pilldroid/AlarmReceiver.java | 1 - .../java/net/foucry/pilldroid/DrugListActivity.java | 13 ------------- app/src/main/java/net/foucry/pilldroid/Utils.java | 10 ---------- 3 files changed, 24 deletions(-) diff --git a/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java b/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java index 002dc35..7555267 100644 --- a/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java +++ b/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java @@ -61,7 +61,6 @@ public class AlarmReceiver extends BroadcastReceiver { // Sorting list by dateEndOfStock prescriptionList = prescriptionsDAO.getAllMedics(); // Reread the database Utils.sortPrescriptionList(prescriptionList); - //Utils.rearrangePrescriptionList(prescriptionList); try { firstPrescription = prescriptionList.get(0); } diff --git a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java index 363a9be..049fc81 100644 --- a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java @@ -283,22 +283,9 @@ public class DrugListActivity extends AppCompatActivity { PrescriptionsDAO prescriptionsDAO = prescriptions.getPrescriptionsDAO(); prescriptionList = prescriptionsDAO.getAllMedics(); - //Prescription currentPrescription; - // Sorting list by dateEndOfStock Utils.sortPrescriptionList(prescriptionList); - // Move Prescription with take==0 to the end of the list - //Utils.rearrangePrescriptionList(prescriptionList); - /*for (int i=0 ; i < prescriptionList.size(); i++ ){ - currentPrescription = prescriptionList.get(i); - //currentPrescription.newStock(); - if (currentPrescription.getTake() == 0) { - prescriptionList.remove(currentPrescription); - prescriptionList.add(prescriptionList.size(), currentPrescription); - } - }*/ - View mRecyclerView = findViewById(R.id.drug_list); assert mRecyclerView != null; setupRecyclerView((RecyclerView) mRecyclerView); diff --git a/app/src/main/java/net/foucry/pilldroid/Utils.java b/app/src/main/java/net/foucry/pilldroid/Utils.java index dc942a6..b5b65ff 100644 --- a/app/src/main/java/net/foucry/pilldroid/Utils.java +++ b/app/src/main/java/net/foucry/pilldroid/Utils.java @@ -60,14 +60,4 @@ public class Utils { }); } - public static void rearrangePrescriptionList(List prescriptionList) { - Prescription currentPrescription = null; - for (int i=0 ; i < prescriptionList.size(); i++ ){ - currentPrescription = prescriptionList.get(i); - if (currentPrescription.getTake() == 0) { - prescriptionList.remove(currentPrescription); - prescriptionList.add(prescriptionList.size(), currentPrescription); - } - } - } }