mirror of
https://github.com/jfoucry/Pilldroid.git
synced 2024-11-22 04:29:22 +01:00
Merge branch 'bugfix/new_stock_calculation' into develop
This commit is contained in:
commit
974fdcb44a
8 changed files with 186 additions and 168 deletions
|
@ -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 {
|
||||
|
|
|
@ -50,11 +50,17 @@ public class AlarmReceiver extends BroadcastReceiver {
|
|||
PrescriptionDatabase prescriptions = PrescriptionDatabase.getInstanceDatabase(context.getApplicationContext());
|
||||
PrescriptionsDAO prescriptionsDAO = prescriptions.getPrescriptionsDAO();
|
||||
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
|
||||
prescriptionList = prescriptionsDAO.getAllMedics(); // Reread the database
|
||||
Utils.sortPrescriptionList(prescriptionList);
|
||||
|
||||
try {
|
||||
firstPrescription = prescriptionList.get(0);
|
||||
}
|
||||
|
@ -93,7 +99,6 @@ public class AlarmReceiver extends BroadcastReceiver {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void createNotificationChannel(Context context) {
|
||||
|
@ -129,11 +134,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);
|
||||
|
@ -143,7 +147,7 @@ public class AlarmReceiver extends BroadcastReceiver {
|
|||
} else {
|
||||
calendar.setTimeInMillis(tomorrow.getTime());
|
||||
}
|
||||
}
|
||||
//}
|
||||
|
||||
PendingIntent alarmIntent;
|
||||
|
||||
|
@ -152,17 +156,21 @@ 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_SHORT).show(); }
|
||||
}
|
||||
|
||||
public static Boolean isAlarmScheduled(Context context) {
|
||||
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
|
||||
|
||||
return alarmManager.getNextAlarmClock() != null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -55,6 +54,8 @@ 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
|
||||
|
@ -282,20 +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
|
||||
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);
|
||||
assert mRecyclerView != null;
|
||||
setupRecyclerView((RecyclerView) mRecyclerView);
|
||||
|
@ -597,7 +587,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);
|
||||
|
@ -605,7 +595,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);
|
||||
|
@ -619,7 +609,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) {
|
||||
|
@ -661,7 +655,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);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -59,4 +59,5 @@ public class Utils {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -44,7 +44,6 @@ public abstract class PrescriptionDatabase extends RoomDatabase {
|
|||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public static void destroyInstance() {
|
||||
INSTANCE = null;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
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;
|
||||
|
@ -12,138 +15,163 @@ 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);
|
||||
public void setCip13(String cip13) {
|
||||
this.cip13 = cip13;
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue