mirror of
https://github.com/jfoucry/Pilldroid.git
synced 2024-11-22 04:29:22 +01:00
Merge branch 'bugfix/alarmFix' into develop
This commit is contained in:
commit
5e01590e6e
6 changed files with 32 additions and 12 deletions
|
@ -65,7 +65,7 @@ public class AlarmReceiver extends BroadcastReceiver {
|
||||||
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
|
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||||
| Intent.FLAG_ACTIVITY_SINGLE_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")
|
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "PillDroid")
|
||||||
.setSmallIcon(R.drawable.ic_pill_alarm)
|
.setSmallIcon(R.drawable.ic_pill_alarm)
|
||||||
|
@ -139,7 +139,7 @@ public class AlarmReceiver extends BroadcastReceiver {
|
||||||
PendingIntent alarmIntent;
|
PendingIntent alarmIntent;
|
||||||
|
|
||||||
Intent intent = new Intent(context, AlarmReceiver.class);
|
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);
|
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
|
||||||
|
|
||||||
|
|
|
@ -315,6 +315,7 @@ class DBHelper extends SQLiteOpenHelper {
|
||||||
public void updateDrug(Drug drug) {
|
public void updateDrug(Drug drug) {
|
||||||
|
|
||||||
Log.d(TAG, "Update Drug == " + drug.toString());
|
Log.d(TAG, "Update Drug == " + drug.toString());
|
||||||
|
Log.d(TAG, "drug last_update == " + UtilDate.convertDate(drug.getDateLastUpdate()));
|
||||||
|
|
||||||
// Get reference to writable DB
|
// Get reference to writable DB
|
||||||
SQLiteDatabase db = this.getWritableDatabase();
|
SQLiteDatabase db = this.getWritableDatabase();
|
||||||
|
|
|
@ -5,6 +5,7 @@ import android.util.Log;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import static net.foucry.pilldroid.UtilDate.dateAtNoon;
|
import static net.foucry.pilldroid.UtilDate.dateAtNoon;
|
||||||
import static net.foucry.pilldroid.UtilDate.nbOfDaysBetweenDateAndToday;
|
import static net.foucry.pilldroid.UtilDate.nbOfDaysBetweenDateAndToday;
|
||||||
|
@ -148,17 +149,17 @@ public class Drug implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
void setDateEndOfStock() {
|
void setDateEndOfStock() {
|
||||||
int numberDayOfPrise;
|
int numberDayOfTake;
|
||||||
if (this.take > 0) {
|
if (this.take > 0) {
|
||||||
numberDayOfPrise = (int) Math.floor(this.stock / this.take);
|
numberDayOfTake = (int) Math.floor(this.stock / this.take);
|
||||||
} else {
|
} else {
|
||||||
numberDayOfPrise = 0;
|
numberDayOfTake = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Date aDate = dateAtNoon(new Date());
|
Date aDate = dateAtNoon(new Date());
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
calendar.setTime(aDate);
|
calendar.setTime(aDate);
|
||||||
calendar.add(Calendar.DAY_OF_YEAR, numberDayOfPrise);
|
calendar.add(Calendar.DAY_OF_YEAR, numberDayOfTake);
|
||||||
|
|
||||||
this.dateEndOfStock = calendar.getTime();
|
this.dateEndOfStock = calendar.getTime();
|
||||||
}
|
}
|
||||||
|
@ -175,4 +176,15 @@ public class Drug implements Serializable {
|
||||||
setDateLastUpdate(new Date().getTime());
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -28,6 +28,8 @@ public class DrugDetailActivity extends AppCompatActivity {
|
||||||
private static final String TAG = DrugDetailActivity.class.getName();
|
private static final String TAG = DrugDetailActivity.class.getName();
|
||||||
|
|
||||||
Drug drug;
|
Drug drug;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
@ -109,8 +111,7 @@ public class DrugDetailActivity extends AppCompatActivity {
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getMDrugChanges()
|
private void getMDrugChanges() {
|
||||||
{
|
|
||||||
Log.d(TAG, "Time to save new values");
|
Log.d(TAG, "Time to save new values");
|
||||||
|
|
||||||
DBHelper dbHelper = new DBHelper(this);
|
DBHelper dbHelper = new DBHelper(this);
|
||||||
|
@ -142,9 +143,14 @@ public class DrugDetailActivity extends AppCompatActivity {
|
||||||
newDrug.setTake(Double.parseDouble(takeValue));
|
newDrug.setTake(Double.parseDouble(takeValue));
|
||||||
newDrug.setWarnThreshold(Integer.parseInt(warningValue));
|
newDrug.setWarnThreshold(Integer.parseInt(warningValue));
|
||||||
newDrug.setAlertThreshold(Integer.parseInt(alertValue));
|
newDrug.setAlertThreshold(Integer.parseInt(alertValue));
|
||||||
newDrug.setDateLastUpdate(new Date().getTime());
|
|
||||||
newDrug.setDateEndOfStock();
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import android.util.Log;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.ParsePosition;
|
import java.text.ParsePosition;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.time.LocalTime;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
@ -95,7 +96,7 @@ class UtilDate {
|
||||||
* @return formatted Date String
|
* @return formatted Date String
|
||||||
*/
|
*/
|
||||||
static String convertDate(long dateInMilliseconds) {
|
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 calendar = Calendar.getInstance();
|
||||||
calendar.setTimeInMillis(dateInMilliseconds);
|
calendar.setTimeInMillis(dateInMilliseconds);
|
||||||
return formatter.format(calendar.getTime());
|
return formatter.format(calendar.getTime());
|
||||||
|
|
|
@ -9,7 +9,7 @@ buildscript {
|
||||||
google()
|
google()
|
||||||
}
|
}
|
||||||
dependencies {
|
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
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
// in the individual module build.gradle files
|
// in the individual module build.gradle files
|
||||||
|
|
Loading…
Reference in a new issue