Merge branch 'bugfix/new_stock_calculation' into develop

This commit is contained in:
jacques 2022-08-01 08:04:45 +02:00
commit 974fdcb44a
8 changed files with 186 additions and 168 deletions

View file

@ -58,12 +58,6 @@ android {
debuggable false debuggable false
signingConfig signingConfigs.release signingConfig signingConfigs.release
} }
prerelease {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
debuggable false
signingConfig signingConfigs.prerelease
}
} }
flavorDimensions "version" flavorDimensions "version"
productFlavors { productFlavors {
@ -76,10 +70,6 @@ android {
resValue "string", "app_name", "PillDroid" resValue "string", "app_name", "PillDroid"
dimension ="version" dimension ="version"
} }
preproduct {
resValue "string", "app_name", "PillDroid Pre-Release"
dimension ="version"
}
} }
compileOptions { compileOptions {

View file

@ -50,11 +50,17 @@ public class AlarmReceiver extends BroadcastReceiver {
PrescriptionDatabase prescriptions = PrescriptionDatabase.getInstanceDatabase(context.getApplicationContext()); PrescriptionDatabase prescriptions = PrescriptionDatabase.getInstanceDatabase(context.getApplicationContext());
PrescriptionsDAO prescriptionsDAO = prescriptions.getPrescriptionsDAO(); PrescriptionsDAO prescriptionsDAO = prescriptions.getPrescriptionsDAO();
List<Prescription> prescriptionList = prescriptionsDAO.getAllMedics(); List<Prescription> 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 // Sorting list by dateEndOfStock
prescriptionList = prescriptionsDAO.getAllMedics(); // Reread the database
Utils.sortPrescriptionList(prescriptionList); Utils.sortPrescriptionList(prescriptionList);
try { try {
firstPrescription = prescriptionList.get(0); firstPrescription = prescriptionList.get(0);
} }
@ -93,7 +99,6 @@ public class AlarmReceiver extends BroadcastReceiver {
} }
} }
} }
} }
private void createNotificationChannel(Context context) { private void createNotificationChannel(Context context) {
@ -129,11 +134,10 @@ public class AlarmReceiver extends BroadcastReceiver {
Date tomorrow; Date tomorrow;
LocalTime todayNow = LocalTime.now(); LocalTime todayNow = LocalTime.now();
if (BuildConfig.DEBUG) { /*if (BuildConfig.DEBUG) {
calendar.add(Calendar.MINUTE, 2);
Date nextSchedule = calendar.getTime(); Date nextSchedule = calendar.getTime();
calendar.setTimeInMillis(nextSchedule.getTime()); calendar.setTimeInMillis(nextSchedule.getTime());
} else { } else {*/
calendar.set(Calendar.HOUR_OF_DAY, 11); calendar.set(Calendar.HOUR_OF_DAY, 11);
today = calendar.getTime(); today = calendar.getTime();
calendar.add(Calendar.DAY_OF_YEAR, 1); calendar.add(Calendar.DAY_OF_YEAR, 1);
@ -143,7 +147,7 @@ public class AlarmReceiver extends BroadcastReceiver {
} else { } else {
calendar.setTimeInMillis(tomorrow.getTime()); calendar.setTimeInMillis(tomorrow.getTime());
} }
} //}
PendingIntent alarmIntent; PendingIntent alarmIntent;
@ -152,17 +156,21 @@ public class AlarmReceiver extends BroadcastReceiver {
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP,(calendar.getTimeInMillis()), /*if (BuildConfig.DEBUG) {
AlarmManager.INTERVAL_DAY, alarmIntent); 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())); 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_SHORT).show(); } if (BuildConfig.DEBUG) { Toast.makeText(context, "Alarm scheduled for " + UtilDate.convertDate(calendar.getTimeInMillis()), Toast.LENGTH_SHORT).show(); }
} }
public static Boolean isAlarmScheduled(Context context) { public static Boolean isAlarmScheduled(Context context) {
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
return alarmManager.getNextAlarmClock() != null; return alarmManager.getNextAlarmClock() != null;
} }
} }

View file

@ -148,7 +148,6 @@ public class DrugDetailActivity extends AppCompatActivity {
Log.d(TAG, "medic and newPrescription are NOT Equals"); Log.d(TAG, "medic and newPrescription are NOT Equals");
newPrescription.setLast_update(new Date().getTime()); newPrescription.setLast_update(new Date().getTime());
prescriptionsDAO.update(newPrescription); prescriptionsDAO.update(newPrescription);
//dbHelper.updateDrug(newDrug);
} }
} }
} }

View file

@ -39,7 +39,6 @@ import androidx.recyclerview.widget.RecyclerView;
import androidx.room.Room; import androidx.room.Room;
import com.google.android.material.snackbar.Snackbar; import com.google.android.material.snackbar.Snackbar;
import com.google.zxing.client.android.BuildConfig;
import com.google.zxing.client.android.Intents; import com.google.zxing.client.android.Intents;
import com.journeyapps.barcodescanner.ScanOptions; import com.journeyapps.barcodescanner.ScanOptions;
@ -55,6 +54,8 @@ import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import com.google.zxing.client.android.BuildConfig;
/** /**
* An activity representing a list of Drugs is activity * An activity representing a list of Drugs is activity
* has different presentations for handset and tablet-size devices. On * has different presentations for handset and tablet-size devices. On
@ -282,20 +283,9 @@ public class DrugListActivity extends AppCompatActivity {
PrescriptionsDAO prescriptionsDAO = prescriptions.getPrescriptionsDAO(); PrescriptionsDAO prescriptionsDAO = prescriptions.getPrescriptionsDAO();
prescriptionList = prescriptionsDAO.getAllMedics(); prescriptionList = prescriptionsDAO.getAllMedics();
Prescription currentPrescription;
// Sorting list by dateEndOfStock // Sorting list by dateEndOfStock
Utils.sortPrescriptionList(prescriptionList); Utils.sortPrescriptionList(prescriptionList);
// Move Prescription with take==0 to the end of the list
for (int i=0 ; i < prescriptionList.size(); i++ ){
currentPrescription = prescriptionList.get(i);
if (currentPrescription.getTake() == 0) {
prescriptionList.remove(currentPrescription);
prescriptionList.add(prescriptionList.size(), currentPrescription);
}
}
View mRecyclerView = findViewById(R.id.drug_list); View mRecyclerView = findViewById(R.id.drug_list);
assert mRecyclerView != null; assert mRecyclerView != null;
setupRecyclerView((RecyclerView) mRecyclerView); setupRecyclerView((RecyclerView) mRecyclerView);
@ -597,7 +587,7 @@ public class DrugListActivity extends AppCompatActivity {
@NonNull @NonNull
@Override @Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()) View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.drug_list_content, parent, false); .inflate(R.layout.drug_list_content, parent, false);
return new ViewHolder(view); return new ViewHolder(view);
@ -605,7 +595,7 @@ public class DrugListActivity extends AppCompatActivity {
@Override @Override
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void onBindViewHolder(final ViewHolder holder, int dummy) { public void onBindViewHolder(@NonNull final ViewHolder holder, int dummy) {
final int position = holder.getBindingAdapterPosition(); final int position = holder.getBindingAdapterPosition();
SimpleDateFormat dateFormat = new SimpleDateFormat("EEEE d MMMM yyyy", Locale.getDefault()); SimpleDateFormat dateFormat = new SimpleDateFormat("EEEE d MMMM yyyy", Locale.getDefault());
String dateEndOfStock = date2String(mValues.get(position).getDateEndOfStock(), dateFormat); String dateEndOfStock = date2String(mValues.get(position).getDateEndOfStock(), dateFormat);
@ -619,7 +609,11 @@ public class DrugListActivity extends AppCompatActivity {
holder.mItem = mValues.get(position); holder.mItem = mValues.get(position);
holder.mContentView.setText(mValues.get(position).getName()); 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 // Test to change background programmatically
if (mValues.get(position).getTake() == 0) { if (mValues.get(position).getTake() == 0) {
@ -661,7 +655,6 @@ public class DrugListActivity extends AppCompatActivity {
intent.putExtra("prescription", prescription); intent.putExtra("prescription", prescription);
startActivityForResult(intent, CUSTOMIZED_REQUEST_CODE); startActivityForResult(intent, CUSTOMIZED_REQUEST_CODE);
overridePendingTransition(R.anim.slide_from_right, R.anim.slide_to_left); overridePendingTransition(R.anim.slide_from_right, R.anim.slide_to_left);
} }
}); });
} }

View file

@ -82,7 +82,7 @@ public class UtilDate {
* @return int numbers of days between date and today * @return int numbers of days between date and today
* Number of days between date (older than today) 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 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 Date todayDate = dateAtNoon(new Date()); // Be sure that we use today at Noon

View file

@ -59,4 +59,5 @@ public class Utils {
} }
}); });
} }
} }

View file

@ -44,7 +44,6 @@ public abstract class PrescriptionDatabase extends RoomDatabase {
} }
return INSTANCE; return INSTANCE;
} }
public static void destroyInstance() { public static void destroyInstance() {
INSTANCE = null; INSTANCE = null;
} }

View file

@ -1,5 +1,8 @@
package net.foucry.pilldroid.models; package net.foucry.pilldroid.models;
import android.util.Log;
import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.room.Entity; import androidx.room.Entity;
import androidx.room.PrimaryKey; import androidx.room.PrimaryKey;
@ -12,138 +15,163 @@ import java.util.Date;
@Entity(tableName = "prescriptions") @Entity(tableName = "prescriptions")
public class Prescription implements Serializable { public class Prescription implements Serializable {
@PrimaryKey private static final String TAG = Prescription.class.getName();;
@NonNull private String cis; @PrimaryKey
private String cip13; @NonNull
private String name; private String cis;
private String administration_mode; private String cip13;
private String presentation; private String name;
private Float stock; private String administration_mode;
private Float take; private String presentation;
private Integer warning; private Float stock;
private Integer alert; private Float take;
private Long last_update; private Integer warning;
private String label_group; private Integer alert;
private Integer generic_type; private Long last_update;
private String label_group;
private Integer generic_type;
public void setCis(@NonNull String cis) public void setCis(@NonNull String cis) {
{ this.cis = 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;
} }
Date aDate = UtilDate.dateAtNoon(new Date()); public void setCip13(String cip13) {
Calendar calendar = Calendar.getInstance(); this.cip13 = cip13;
calendar.setTime(aDate); }
calendar.add(Calendar.DAY_OF_YEAR, numberDayOfTake);
return calendar.getTime(); 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() {
Date aDate = UtilDate.dateAtNoon(new Date());
Calendar calendar = Calendar.getInstance();
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();
}
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());
}
}
} }