Add debug code

This commit is contained in:
jacques 2022-07-24 10:55:34 +02:00
parent 5c2866a543
commit 4620ca0f98
2 changed files with 166 additions and 144 deletions

View file

@ -14,7 +14,7 @@ import android.widget.Toast;
import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat; 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.dao.PrescriptionsDAO;
import net.foucry.pilldroid.databases.PrescriptionDatabase; import net.foucry.pilldroid.databases.PrescriptionDatabase;
@ -137,7 +137,7 @@ public class AlarmReceiver extends BroadcastReceiver {
LocalTime todayNow = LocalTime.now(); LocalTime todayNow = LocalTime.now();
if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) {
calendar.add(Calendar.MINUTE, 2); calendar.add(Calendar.MINUTE, 2);
Date nextSchedule = calendar.getTime(); Date nextSchedule = calendar.getTime();
calendar.setTimeInMillis(nextSchedule.getTime()); calendar.setTimeInMillis(nextSchedule.getTime());
} else { } else {
@ -159,10 +159,19 @@ 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_LONG).show();
}
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(); }
} }

View file

@ -1,9 +1,13 @@
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;
import net.foucry.pilldroid.BuildConfig;
import net.foucry.pilldroid.UtilDate; import net.foucry.pilldroid.UtilDate;
import java.io.Serializable; import java.io.Serializable;
@ -12,150 +16,159 @@ 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);
public void setName(String name) {
return calendar.getTime(); this.name = name;
} }
public void newStock() { public void setAdministration_mode(String administration_mode) {
Date lastUpdate = new Date(getLast_update()); this.administration_mode = administration_mode;
}
int numberOfDays = UtilDate.nbOfDaysBetweenDateAndToday(lastUpdate);
if (numberOfDays > 0) { public void setPresentation(String presentation) {
double takeDuringPeriod = this.take * numberOfDays; this.presentation = presentation;
setStock((float) (getStock() - takeDuringPeriod)); }
setLast_update(new Date().getTime());
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());
}
} }
}
} }