use of m.co.rh.id.a_medic_log.base.entity.MedicineReminder in project a-medic-log by rh-id.
the class MedicineReminderDetailPage method createView.
@Override
protected View createView(Activity activity, ViewGroup container) {
View rootLayout = activity.getLayoutInflater().inflate(R.layout.page_medicine_reminder_detail, container, false);
ViewGroup containerAppBar = rootLayout.findViewById(R.id.container_app_bar);
containerAppBar.addView(mAppBarSv.buildView(activity, container));
EditText inputStartDateTime = rootLayout.findViewById(R.id.input_text_start_date_time);
inputStartDateTime.setOnClickListener(this);
inputStartDateTime.addTextChangedListener(mStartDateTimeTextWatcher);
EditText inputMessage = rootLayout.findViewById(R.id.input_text_message);
inputMessage.addTextChangedListener(mMessageTextWatcher);
TextView reminderDaysText = rootLayout.findViewById(R.id.text_reminder_days);
Button reminderDaysMon = rootLayout.findViewById(R.id.reminder_days_mon);
reminderDaysMon.setOnClickListener(this);
Button reminderDaysTue = rootLayout.findViewById(R.id.reminder_days_tue);
reminderDaysTue.setOnClickListener(this);
Button reminderDaysWed = rootLayout.findViewById(R.id.reminder_days_wed);
reminderDaysWed.setOnClickListener(this);
Button reminderDaysThu = rootLayout.findViewById(R.id.reminder_days_thu);
reminderDaysThu.setOnClickListener(this);
Button reminderDaysFri = rootLayout.findViewById(R.id.reminder_days_fri);
reminderDaysFri.setOnClickListener(this);
Button reminderDaysSat = rootLayout.findViewById(R.id.reminder_days_sat);
reminderDaysSat.setOnClickListener(this);
Button reminderDaysSun = rootLayout.findViewById(R.id.reminder_days_sun);
reminderDaysSun.setOnClickListener(this);
mRxDisposer.add("createView_onMedicineReminderUpdated", mMedicineReminderSubject.getSubject().observeOn(AndroidSchedulers.mainThread()).subscribe(medicineReminder -> {
if (medicineReminder.startDateTime != null) {
inputStartDateTime.setText(mDateFormat.format(medicineReminder.startDateTime));
} else {
inputStartDateTime.setText(null);
}
inputMessage.setText(medicineReminder.message);
}));
mRxDisposer.add("createView_onStartDateTimeValidated", mNewMedicineReminderCmd.getStartDateTimeValid().observeOn(AndroidSchedulers.mainThread()).subscribe(s -> {
if (s != null && !s.isEmpty()) {
inputMessage.setError(s);
} else {
inputMessage.setError(null);
}
}));
mRxDisposer.add("createView_onInputMessageValidated", mNewMedicineReminderCmd.getMessageValid().observeOn(AndroidSchedulers.mainThread()).subscribe(s -> {
if (s != null && !s.isEmpty()) {
inputMessage.setError(s);
} else {
inputMessage.setError(null);
}
}));
mRxDisposer.add("createView_onReminderDaysValidated", mNewMedicineReminderCmd.getReminderDaysValid().observeOn(AndroidSchedulers.mainThread()).subscribe(s -> {
if (s != null && !s.isEmpty()) {
reminderDaysText.setError(s);
} else {
reminderDaysText.setError(null);
}
}));
mRxDisposer.add("createView_onReminderDaysChanged", mReminderDaysSubject.getSubject().observeOn(AndroidSchedulers.mainThread()).subscribe(integers -> {
if (!integers.isEmpty()) {
reminderDaysMon.setActivated(integers.contains(Calendar.MONDAY));
reminderDaysTue.setActivated(integers.contains(Calendar.TUESDAY));
reminderDaysWed.setActivated(integers.contains(Calendar.WEDNESDAY));
reminderDaysThu.setActivated(integers.contains(Calendar.THURSDAY));
reminderDaysFri.setActivated(integers.contains(Calendar.FRIDAY));
reminderDaysSat.setActivated(integers.contains(Calendar.SATURDAY));
reminderDaysSun.setActivated(integers.contains(Calendar.SUNDAY));
} else {
reminderDaysMon.setActivated(false);
reminderDaysTue.setActivated(false);
reminderDaysWed.setActivated(false);
reminderDaysThu.setActivated(false);
reminderDaysFri.setActivated(false);
reminderDaysSat.setActivated(false);
reminderDaysSun.setActivated(false);
}
mNewMedicineReminderCmd.valid(mMedicineReminderSubject.getValue());
}));
return rootLayout;
}
use of m.co.rh.id.a_medic_log.base.entity.MedicineReminder in project a-medic-log by rh-id.
the class MedicineReminderDetailPage method initState.
@Override
protected void initState(Activity activity) {
super.initState(activity);
mDateFormat = new SimpleDateFormat("dd MMM yyyy, HH:mm");
MedicineReminder medicineReminder = getMedicineReminder();
mMedicineReminderSubject = new SerialBehaviorSubject<>(medicineReminder);
mReminderDaysSubject = new SerialBehaviorSubject<>(medicineReminder.reminderDays);
}
use of m.co.rh.id.a_medic_log.base.entity.MedicineReminder in project a-medic-log by rh-id.
the class MedicineDetailPage method createView.
@Override
protected View createView(Activity activity, ViewGroup container) {
View rootLayout = activity.getLayoutInflater().inflate(R.layout.page_medicine_detail, container, false);
ViewGroup containerAppBar = rootLayout.findViewById(R.id.container_app_bar);
containerAppBar.addView(mAppBarSv.buildView(activity, container));
mSuggestionAdapter = new SuggestionAdapter(activity, android.R.layout.select_dialog_item, mSuggestionQuery);
AutoCompleteTextView inputName = rootLayout.findViewById(R.id.input_text_name);
inputName.addTextChangedListener(mNameTextWatcher);
inputName.setThreshold(1);
inputName.setAdapter(mSuggestionAdapter);
EditText inputDescription = rootLayout.findViewById(R.id.input_text_description);
inputDescription.addTextChangedListener(mDescriptionTextWatcher);
Button addMedicineReminderButton = rootLayout.findViewById(R.id.button_add_medicine_reminder);
addMedicineReminderButton.setOnClickListener(this);
RecyclerView medicineReminderRecyclerView = rootLayout.findViewById(R.id.recyclerView_medicine_reminder);
medicineReminderRecyclerView.addItemDecoration(new DividerItemDecoration(activity, DividerItemDecoration.VERTICAL));
medicineReminderRecyclerView.setAdapter(mMedicineReminderRecyclerViewAdapter);
mRxDisposer.add("createView_onMedicineChanged", mMedicineState.getMedicineFlow().observeOn(AndroidSchedulers.mainThread()).subscribe(medicine -> {
inputName.setText(medicine.name);
inputDescription.setText(medicine.description);
}));
mRxDisposer.add("createView_onInputNameValidated", mNewMedicineCmd.getNameValid().observeOn(AndroidSchedulers.mainThread()).subscribe(s -> {
if (s != null && !s.isEmpty()) {
inputName.setError(s);
} else {
inputName.setError(null);
}
}));
mRxDisposer.add("createView_onMedicineReminderListChanged", mMedicineState.getMedicineReminderListFlow().observeOn(AndroidSchedulers.mainThread()).subscribe(medicineReminders -> mMedicineReminderRecyclerViewAdapter.notifyItemRefreshed()));
mRxDisposer.add("createView_onMedicineReminderAdded", mMedicineReminderChangeNotifier.getAddedMedicineReminder().observeOn(Schedulers.from(mExecutorService)).subscribe(medicineReminder -> {
if (isUpdate() && shouldSave()) {
mMedicineState.addMedicineReminder(medicineReminder);
}
}));
mRxDisposer.add("createView_onMedicineReminderUpdated", mMedicineReminderChangeNotifier.getUpdatedMedicineReminder().observeOn(Schedulers.from(mExecutorService)).subscribe(updateMedicineReminderEvent -> {
if (isUpdate() && shouldSave()) {
mMedicineState.updateMedicineReminder(updateMedicineReminderEvent.getAfter());
}
}));
mRxDisposer.add("createView_onMedicineReminderDeleted", mMedicineReminderChangeNotifier.getDeletedMedicineReminder().observeOn(Schedulers.from(mExecutorService)).subscribe(medicineReminder -> {
if (isUpdate() && shouldSave()) {
mMedicineState.deleteMedicineReminder(medicineReminder);
}
}));
return rootLayout;
}
use of m.co.rh.id.a_medic_log.base.entity.MedicineReminder in project a-medic-log by rh-id.
the class MedicineReminderNotificationWorker method doWork.
@NonNull
@Override
public Result doWork() {
long medicineReminderId = getInputData().getLong(Keys.LONG_MEDICINE_REMINDER_ID, -1);
MedicineReminder medicineReminder = mMedicineDao.get().findMedicineReminderById(medicineReminderId);
if (medicineReminder != null) {
Date today = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(today);
int currentDay = calendar.get(Calendar.DAY_OF_WEEK);
if (medicineReminder.reminderDays.contains(currentDay)) {
AppNotificationHandler appNotificationHandler = mAppNotificationHandler.get();
appNotificationHandler.cancelNotificationSync(medicineReminder);
appNotificationHandler.postMedicineReminder(medicineReminder);
}
mMedicineReminderEventHandler.get().startMedicineReminderNotificationWork(Collections.singletonList(medicineReminder));
}
// previously this worker is enqueued as periodic work, so remove it
Set<String> tags = getTags();
String tag = tags.iterator().next();
mWorkManager.get().cancelUniqueWork(tag);
return Result.success();
}
use of m.co.rh.id.a_medic_log.base.entity.MedicineReminder in project a-medic-log by rh-id.
the class MedicineDao method insertMedicine.
@Transaction
public void insertMedicine(Medicine medicine, List<MedicineReminder> medicineReminders) {
long medsId = insert(medicine);
medicine.id = medsId;
if (medicineReminders != null && !medicineReminders.isEmpty()) {
for (MedicineReminder medicineReminder : medicineReminders) {
medicineReminder.medicineId = medsId;
insertMedicineReminder(medicineReminder);
}
}
}
Aggregations