Merge branch 'bugfix/alarmFix' into develop

This commit is contained in:
jacques 2021-12-28 15:11:39 +01:00
commit 5e01590e6e
6 changed files with 32 additions and 12 deletions

View file

@ -65,7 +65,7 @@ public class AlarmReceiver extends BroadcastReceiver {
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_IMMUTABLE);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "PillDroid")
.setSmallIcon(R.drawable.ic_pill_alarm)
@ -139,7 +139,7 @@ public class AlarmReceiver extends BroadcastReceiver {
PendingIntent alarmIntent;
Intent intent = new Intent(context, AlarmReceiver.class);
alarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
alarmIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_IMMUTABLE);
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

View file

@ -315,6 +315,7 @@ class DBHelper extends SQLiteOpenHelper {
public void updateDrug(Drug drug) {
Log.d(TAG, "Update Drug == " + drug.toString());
Log.d(TAG, "drug last_update == " + UtilDate.convertDate(drug.getDateLastUpdate()));
// Get reference to writable DB
SQLiteDatabase db = this.getWritableDatabase();

View file

@ -5,6 +5,7 @@ import android.util.Log;
import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import java.util.Objects;
import static net.foucry.pilldroid.UtilDate.dateAtNoon;
import static net.foucry.pilldroid.UtilDate.nbOfDaysBetweenDateAndToday;
@ -148,17 +149,17 @@ public class Drug implements Serializable {
}
void setDateEndOfStock() {
int numberDayOfPrise;
int numberDayOfTake;
if (this.take > 0) {
numberDayOfPrise = (int) Math.floor(this.stock / this.take);
numberDayOfTake = (int) Math.floor(this.stock / this.take);
} else {
numberDayOfPrise = 0;
numberDayOfTake = 0;
}
Date aDate = dateAtNoon(new Date());
Calendar calendar = Calendar.getInstance();
calendar.setTime(aDate);
calendar.add(Calendar.DAY_OF_YEAR, numberDayOfPrise);
calendar.add(Calendar.DAY_OF_YEAR, numberDayOfTake);
this.dateEndOfStock = calendar.getTime();
}
@ -175,4 +176,15 @@ public class Drug implements Serializable {
setDateLastUpdate(new Date().getTime());
}
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Drug drug = (Drug) o;
return stock == drug.stock &&
take == drug.take &&
alertThreshold == drug.alertThreshold &&
warnThreshold == drug.warnThreshold &&
Objects.equals(name, drug.name);
}
}

View file

@ -28,6 +28,8 @@ public class DrugDetailActivity extends AppCompatActivity {
private static final String TAG = DrugDetailActivity.class.getName();
Drug drug;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -109,8 +111,7 @@ public class DrugDetailActivity extends AppCompatActivity {
return super.onOptionsItemSelected(item);
}
private void getMDrugChanges()
{
private void getMDrugChanges() {
Log.d(TAG, "Time to save new values");
DBHelper dbHelper = new DBHelper(this);
@ -142,9 +143,14 @@ public class DrugDetailActivity extends AppCompatActivity {
newDrug.setTake(Double.parseDouble(takeValue));
newDrug.setWarnThreshold(Integer.parseInt(warningValue));
newDrug.setAlertThreshold(Integer.parseInt(alertValue));
newDrug.setDateLastUpdate(new Date().getTime());
newDrug.setDateEndOfStock();
dbHelper.updateDrug(newDrug);
if (drug.equals(newDrug)) {
Log.d(TAG, "drug and newDrug are Equals");
} else {
Log.d(TAG, "drug and newDrug are NOT Equals");
newDrug.setDateLastUpdate(new Date().getTime());
dbHelper.updateDrug(newDrug);
}
}
}

View file

@ -5,6 +5,7 @@ import android.util.Log;
import java.text.DateFormat;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.time.LocalTime;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
@ -95,7 +96,7 @@ class UtilDate {
* @return formatted Date String
*/
static String convertDate(long dateInMilliseconds) {
DateFormat formatter = new SimpleDateFormat("dd/MM/yy HH:mm:ss", Locale.FRANCE);
DateFormat formatter = new SimpleDateFormat("dd/MM/yy HH:mm:ss", Locale.getDefault());
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(dateInMilliseconds);
return formatter.format(calendar.getTime());

View file

@ -9,7 +9,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.3'
classpath 'com.android.tools.build:gradle:7.0.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files