diff --git a/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java b/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java index 2ae95e0..0f7c8a9 100644 --- a/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java +++ b/app/src/main/java/net/foucry/pilldroid/AlarmReceiver.java @@ -50,8 +50,11 @@ public class AlarmReceiver extends BroadcastReceiver { List prescriptionList = prescriptionsDAO.getAllMedics(); Prescription firstPrescription = null ; + // Sorting list by dateEndOfStock + Utils.sortPrescriptionList(prescriptionList); + try { - firstPrescription = prescriptionList.get(1); + firstPrescription = prescriptionList.get(0); } catch (Exception e){ Log.e(TAG, e.toString()); @@ -122,18 +125,22 @@ public class AlarmReceiver extends BroadcastReceiver { Calendar calendar = Calendar.getInstance(); Date today; Date tomorrow; - - calendar.set(Calendar.HOUR_OF_DAY, 11); - today = calendar.getTime(); - calendar.add(Calendar.DAY_OF_YEAR, 1); - tomorrow = calendar.getTime(); - LocalTime todayNow = LocalTime.now(); - if (todayNow.isBefore(LocalTime.NOON)) { - calendar.setTimeInMillis(today.getTime()); + if (BuildConfig.DEBUG) { + calendar.add(Calendar.MINUTE, 2); + Date nextSchedule = calendar.getTime(); + calendar.setTimeInMillis(nextSchedule.getTime()); } else { - calendar.setTimeInMillis(tomorrow.getTime()); + calendar.set(Calendar.HOUR_OF_DAY, 11); + today = calendar.getTime(); + calendar.add(Calendar.DAY_OF_YEAR, 1); + tomorrow = calendar.getTime(); + if (todayNow.isBefore(LocalTime.NOON)) { + calendar.setTimeInMillis(today.getTime()); + } else { + calendar.setTimeInMillis(tomorrow.getTime()); + } } PendingIntent alarmIntent; diff --git a/app/src/main/java/net/foucry/pilldroid/CustomScannerActivity.java b/app/src/main/java/net/foucry/pilldroid/CustomScannerActivity.java index 3186aad..14d90a8 100644 --- a/app/src/main/java/net/foucry/pilldroid/CustomScannerActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/CustomScannerActivity.java @@ -3,7 +3,6 @@ package net.foucry.pilldroid; import android.app.Activity; import android.content.Intent; import android.content.pm.PackageManager; -import android.graphics.Color; import android.os.Bundle; import android.util.Log; import android.view.KeyEvent; @@ -18,8 +17,6 @@ import com.journeyapps.barcodescanner.CaptureManager; import com.journeyapps.barcodescanner.DecoratedBarcodeView; import com.journeyapps.barcodescanner.ViewfinderView; -import java.util.Random; - /** * Custom Scanner Activity extending from Activity to display a custom layout form scanner view. */ diff --git a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java index b0846da..bb1f02a 100644 --- a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java @@ -51,7 +51,6 @@ import net.foucry.pilldroid.models.Medicine; import net.foucry.pilldroid.models.Prescription; import java.text.SimpleDateFormat; -import java.util.Comparator; import java.util.Date; import java.util.List; import java.util.Locale; @@ -286,15 +285,7 @@ public class DrugListActivity extends AppCompatActivity { Prescription currentPrescription; // Sorting list by dateEndOfStock - prescriptionList.sort(new Comparator<>() { - @Override - public int compare(Prescription lhs, Prescription rhs) { - if (lhs.getDateEndOfStock().compareTo(rhs.getDateEndOfStock()) != 0) - return lhs.getDateEndOfStock().compareTo(rhs.getDateEndOfStock()); - else - return (int) (lhs.getStock() - rhs.getStock()); - } - }); + Utils.sortPrescriptionList(prescriptionList); // Move Prescription with take==0 to the end of the list for (int i=0 ; i < prescriptionList.size(); i++ ){ diff --git a/app/src/main/java/net/foucry/pilldroid/Utils.java b/app/src/main/java/net/foucry/pilldroid/Utils.java index 6e2f416..41f5766 100644 --- a/app/src/main/java/net/foucry/pilldroid/Utils.java +++ b/app/src/main/java/net/foucry/pilldroid/Utils.java @@ -3,7 +3,9 @@ package net.foucry.pilldroid; import net.foucry.pilldroid.models.Medicine; import net.foucry.pilldroid.models.Prescription; +import java.util.Comparator; import java.util.Date; +import java.util.List; import java.util.Locale; import java.util.Random; @@ -45,4 +47,16 @@ public class Utils { return aPrescription; } + + public static void sortPrescriptionList(List prescriptionList) { + prescriptionList.sort(new Comparator<>() { + @Override + public int compare(Prescription lhs, Prescription rhs) { + if (lhs.getDateEndOfStock().compareTo(rhs.getDateEndOfStock()) != 0) + return lhs.getDateEndOfStock().compareTo(rhs.getDateEndOfStock()); + else + return (int) (lhs.getStock() - rhs.getStock()); + } + }); + } } diff --git a/app/src/main/java/net/foucry/pilldroid/WelcomeActivity.java b/app/src/main/java/net/foucry/pilldroid/WelcomeActivity.java index 1816f83..43791a2 100644 --- a/app/src/main/java/net/foucry/pilldroid/WelcomeActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/WelcomeActivity.java @@ -170,7 +170,6 @@ public class WelcomeActivity extends AppCompatActivity { window.setStatusBarColor(Color.TRANSPARENT); } - @SuppressWarnings("deprecation") private void setFullScreen(){ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { getWindow().setDecorFitsSystemWindows(false); 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 2ee418c..e0a4e46 100644 --- a/app/src/main/java/net/foucry/pilldroid/databases/PrescriptionDatabase.java +++ b/app/src/main/java/net/foucry/pilldroid/databases/PrescriptionDatabase.java @@ -12,9 +12,6 @@ import androidx.room.migration.AutoMigrationSpec; import net.foucry.pilldroid.dao.PrescriptionsDAO; import net.foucry.pilldroid.models.Prescription; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - @Database( version = 2, entities = {Prescription.class}, diff --git a/app/src/main/java/net/foucry/pilldroid/models/Medicine.java b/app/src/main/java/net/foucry/pilldroid/models/Medicine.java index 1fd10be..7f7240e 100644 --- a/app/src/main/java/net/foucry/pilldroid/models/Medicine.java +++ b/app/src/main/java/net/foucry/pilldroid/models/Medicine.java @@ -7,7 +7,7 @@ import androidx.room.PrimaryKey; @Entity(tableName = "drugs") public class Medicine { @PrimaryKey - @NonNull private Integer _id; + private Integer _id; private String cis; private String cip13; private String cip7; 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..11c9170 100644 --- a/app/src/main/java/net/foucry/pilldroid/models/Prescription.java +++ b/app/src/main/java/net/foucry/pilldroid/models/Prescription.java @@ -13,7 +13,7 @@ import java.util.Date; @Entity(tableName = "prescriptions") public class Prescription implements Serializable { @PrimaryKey - @NonNull private String cis; + private String cis; private String cip13; private String name; private String administration_mode;