Merge branch 'bugfix/TimeZone_error' into develop

This commit is contained in:
jacques 2021-11-15 10:49:03 +01:00
commit 88903b59a8
2 changed files with 10 additions and 43 deletions

View file

@ -38,8 +38,8 @@ public class AlarmReceiver extends BroadcastReceiver {
Log.d(TAG, "StartUpBootReceiver BOOT_COMPLETED"); Log.d(TAG, "StartUpBootReceiver BOOT_COMPLETED");
scheduleAlarm(context); scheduleAlarm(context);
} }
Toast.makeText(context, "New stock calculated", Toast.LENGTH_LONG).show(); if (BuildConfig.DEBUG) { Toast.makeText(context, "New stock calculated", Toast.LENGTH_LONG).show(); }
createNotificationChannel(context); createNotificationChannel(context);
DBHelper dbHelper = new DBHelper(context); DBHelper dbHelper = new DBHelper(context);
dbHelper.getAllDrugs(); dbHelper.getAllDrugs();
@ -123,34 +123,19 @@ public class AlarmReceiver extends BroadcastReceiver {
Date today; Date today;
Date tomorrow; Date tomorrow;
/*if (BuildConfig.DEBUG) { calendar.set(Calendar.HOUR_OF_DAY, 11);
calendar.add(Calendar.HOUR_OF_DAY, 12); today = calendar.getTime();
today = calendar.getTime(); calendar.add(Calendar.DAY_OF_YEAR, 1);
calendar.add(Calendar.DAY_OF_YEAR, 1); tomorrow = calendar.getTime();
tomorrow = calendar.getTime();
} else {*/
calendar.set(Calendar.HOUR_OF_DAY, 11);
today = calendar.getTime();
calendar.add(Calendar.DAY_OF_YEAR, 1);
tomorrow = calendar.getTime();
// }
LocalTime todayNow = LocalTime.now(); LocalTime todayNow = LocalTime.now();
if (todayNow.isBefore(LocalTime.NOON)) { if (todayNow.isBefore(LocalTime.NOON)) {
// schedule date = today
//calendar.setTimeInMillis(dateAtNoon(today).getTime());
calendar.setTimeInMillis(today.getTime()); calendar.setTimeInMillis(today.getTime());
} else { } else {
// schedule date = tomorrow
calendar.setTimeInMillis(tomorrow.getTime()); calendar.setTimeInMillis(tomorrow.getTime());
} }
/* if (BuildConfig.DEBUG)
{
calendar.setTimeInMillis(today.getTime());
}*/
PendingIntent alarmIntent; PendingIntent alarmIntent;
Intent intent = new Intent(context, AlarmReceiver.class); Intent intent = new Intent(context, AlarmReceiver.class);
@ -158,18 +143,11 @@ public class AlarmReceiver extends BroadcastReceiver {
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
boolean alarmUp = (PendingIntent.getBroadcast(context, 0, intent,
PendingIntent.FLAG_NO_CREATE) != null);
if (alarmUp) {
Log.d(TAG, "Alarm already active");
}
alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP,(calendar.getTimeInMillis()), alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP,(calendar.getTimeInMillis()),
AlarmManager.INTERVAL_DAY, alarmIntent); AlarmManager.INTERVAL_DAY, alarmIntent);
Log.d(TAG, "Alarm scheduled for " + UtilDate.convertDate(calendar.getTimeInMillis())); Log.d(TAG, "Alarm scheduled for " + UtilDate.convertDate(calendar.getTimeInMillis()));
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

@ -93,14 +93,6 @@ public class DrugListActivity extends AppCompatActivity {
private SimpleItemRecyclerViewAdapter mAdapter; private SimpleItemRecyclerViewAdapter mAdapter;
public int getCount() {
return drugs.size();
}
public Drug getItem(int position) {
return drugs.get(position);
}
public void constructDrugsList() public void constructDrugsList()
{ {
dbHelper = new DBHelper(getApplicationContext()); dbHelper = new DBHelper(getApplicationContext());
@ -413,8 +405,6 @@ public class DrugListActivity extends AppCompatActivity {
public class SimpleItemRecyclerViewAdapter extends RecyclerView.Adapter<SimpleItemRecyclerViewAdapter.ViewHolder> { public class SimpleItemRecyclerViewAdapter extends RecyclerView.Adapter<SimpleItemRecyclerViewAdapter.ViewHolder> {
private final List<Drug> mValues; private final List<Drug> mValues;
private int position;
SimpleItemRecyclerViewAdapter(List<Drug> items) { SimpleItemRecyclerViewAdapter(List<Drug> items) {
mValues = items; mValues = items;
} }
@ -422,10 +412,11 @@ public class DrugListActivity extends AppCompatActivity {
void addItem(Drug scannedDrug) { void addItem(Drug scannedDrug) {
if (!dbHelper.isDrugExist(scannedDrug.getCip13())) { if (!dbHelper.isDrugExist(scannedDrug.getCip13())) {
mValues.add(scannedDrug); mValues.add(scannedDrug);
notifyDataSetChanged(); //notifyDataSetChanged();
notifyItemInserted(mValues.size());
dbHelper.addDrug(scannedDrug); dbHelper.addDrug(scannedDrug);
} else { } else {
Toast.makeText(getApplicationContext(), "already in the database", Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(), "already in the database", Toast.LENGTH_LONG).show();
} }
} }
@ -494,7 +485,6 @@ public class DrugListActivity extends AppCompatActivity {
class ViewHolder extends RecyclerView.ViewHolder { class ViewHolder extends RecyclerView.ViewHolder {
final View mView; final View mView;
// final TextView mIDView;
final TextView mContentView; final TextView mContentView;
final TextView mEndOfStock; final TextView mEndOfStock;
final ImageView mIconView; final ImageView mIconView;
@ -504,7 +494,6 @@ public class DrugListActivity extends AppCompatActivity {
ViewHolder(View view) { ViewHolder(View view) {
super(view); super(view);
mView = view; mView = view;
// mIDView = view.findViewById(R.id.cip13);
mContentView = view.findViewById(R.id.value); mContentView = view.findViewById(R.id.value);
mEndOfStock = view.findViewById(R.id.endOfStock); mEndOfStock = view.findViewById(R.id.endOfStock);
mIconView = view.findViewById(R.id.list_image); mIconView = view.findViewById(R.id.list_image);