use of m.co.rh.id.a_medic_log.base.entity.MedicineReminder in project a-medic-log by rh-id.
the class MedicineItemSV method createView.
@Override
protected View createView(Activity activity, ViewGroup container) {
View rootLayout = activity.getLayoutInflater().inflate(R.layout.item_medicine, container, false);
rootLayout.setOnClickListener(this);
TextView nameText = rootLayout.findViewById(R.id.text_name);
TextView descriptionText = rootLayout.findViewById(R.id.text_description);
TextView lastIntakeText = rootLayout.findViewById(R.id.text_last_intake);
Button editButton = rootLayout.findViewById(R.id.button_edit);
editButton.setOnClickListener(this);
Button deleteButton = rootLayout.findViewById(R.id.button_delete);
deleteButton.setOnClickListener(this);
Button moreAction = rootLayout.findViewById(R.id.button_more_action);
moreAction.setOnClickListener(this);
GridLayout containerReminder = rootLayout.findViewById(R.id.container_reminder);
mRxDisposer.add("createView_onMedicineStateChanged", mMedicineStateSubject.getSubject().debounce(16, TimeUnit.MILLISECONDS).observeOn(AndroidSchedulers.mainThread()).subscribe(medicineState -> {
nameText.setText(medicineState.getMedicineName());
descriptionText.setText(medicineState.getMedicineDescription());
if (medicineState.getMedicineId() != null) {
moreAction.setVisibility(View.VISIBLE);
} else {
moreAction.setVisibility(View.GONE);
}
queryLastMedicineIntake(medicineState.getMedicineId());
containerReminder.removeAllViews();
ArrayList<MedicineReminder> medicineReminders = medicineState.getMedicineReminderList();
if (medicineReminders != null && !medicineReminders.isEmpty()) {
containerReminder.setVisibility(View.VISIBLE);
for (MedicineReminder medicineReminder : medicineReminders) {
MaterialTextView materialTextView = new MaterialTextView(activity);
materialTextView.setText(mTimeFormat.format(medicineReminder.startDateTime));
GridLayout.LayoutParams params = new GridLayout.LayoutParams();
params.width = GridLayout.LayoutParams.WRAP_CONTENT;
params.height = GridLayout.LayoutParams.WRAP_CONTENT;
params.columnSpec = GridLayout.spec(GridLayout.UNDEFINED, 1.0f);
materialTextView.setLayoutParams(params);
materialTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
int tintColor = activity.getResources().getColor(R.color.daynight_black_white);
Drawable icon;
if (medicineReminder.reminderEnabled) {
icon = AppCompatResources.getDrawable(activity, R.drawable.ic_timer_black);
} else {
icon = AppCompatResources.getDrawable(activity, R.drawable.ic_timer_off_black);
}
icon = DrawableCompat.wrap(icon);
DrawableCompat.setTint(icon, tintColor);
materialTextView.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
containerReminder.addView(materialTextView);
}
} else {
containerReminder.setVisibility(View.GONE);
}
}));
mRxDisposer.add("createView_onLastMedicineIntakeChanged", mLastMedicineIntakeSubject.getSubject().debounce(100, TimeUnit.MILLISECONDS).observeOn(AndroidSchedulers.mainThread()).subscribe(medicineIntakeOpt -> {
if (medicineIntakeOpt.isPresent()) {
Date takenDateTime = medicineIntakeOpt.get().takenDateTime;
lastIntakeText.setText(mDateTimeFormat.format(takenDateTime));
lastIntakeText.setVisibility(View.VISIBLE);
} else {
lastIntakeText.setText(null);
lastIntakeText.setVisibility(View.GONE);
}
}));
mRxDisposer.add("createView_onMedicineIntakeAdded", mMedicineIntakeChangeNotifier.getAddedMedicineIntake().observeOn(Schedulers.from(mExecutorService)).subscribe(medicineIntake -> {
if (medicineIntake.medicineId != null && medicineIntake.medicineId.equals(mMedicineStateSubject.getValue().getMedicineId())) {
queryLastMedicineIntake(medicineIntake.medicineId);
}
}));
mRxDisposer.add("createView_onMedicineIntakeUpdated", mMedicineIntakeChangeNotifier.getUpdatedMedicineIntake().observeOn(Schedulers.from(mExecutorService)).subscribe(updateMedicineIntakeEvent -> {
MedicineIntake medicineIntake = updateMedicineIntakeEvent.getAfter();
if (medicineIntake.medicineId != null && medicineIntake.medicineId.equals(mMedicineStateSubject.getValue().getMedicineId())) {
queryLastMedicineIntake(medicineIntake.medicineId);
}
}));
mRxDisposer.add("createView_onMedicineIntakeDeleted", mMedicineIntakeChangeNotifier.getDeletedMedicineIntake().observeOn(Schedulers.from(mExecutorService)).subscribe(medicineIntake -> {
if (medicineIntake.medicineId != null && medicineIntake.medicineId.equals(mMedicineStateSubject.getValue().getMedicineId())) {
queryLastMedicineIntake(medicineIntake.medicineId);
}
}));
return rootLayout;
}
use of m.co.rh.id.a_medic_log.base.entity.MedicineReminder in project a-medic-log by rh-id.
the class QueryNoteCmd method queryMedicineStateList.
private void queryMedicineStateList(NoteState noteState) {
Long noteId = noteState.getNoteId();
List<Medicine> medicineList = mMedicineDao.findMedicinesByNoteId(noteId);
if (!medicineList.isEmpty()) {
ArrayList<MedicineState> medicineStates = new ArrayList<>();
for (Medicine medicine : medicineList) {
List<MedicineReminder> medicineReminders = mMedicineDao.findMedicineRemindersByMedicineId(medicine.id);
MedicineState medicineState = new MedicineState();
medicineState.updateMedicine(medicine);
medicineState.updateMedicineReminderList(medicineReminders);
medicineStates.add(medicineState);
}
noteState.updateMedicineStates(medicineStates);
}
}
use of m.co.rh.id.a_medic_log.base.entity.MedicineReminder in project a-medic-log by rh-id.
the class AppNotificationHandler method disableMedicineReminder.
public void disableMedicineReminder(Intent intent) {
Serializable serializable = intent.getSerializableExtra(KEY_INT_REQUEST_ID);
if (serializable instanceof Integer) {
mExecutorService.get().execute(() -> {
mLock.lock();
try {
AndroidNotification androidNotification = mAndroidNotificationRepo.get().findByRequestId((int) serializable);
if (androidNotification != null && androidNotification.groupKey.equals(GROUP_KEY_MEDICINE_REMINDER)) {
MedicineReminder medicineReminder = mMedicineDao.get().findMedicineReminderById(androidNotification.refId);
medicineReminder.reminderEnabled = false;
medicineReminder = mUpdateMedicineReminderCmd.get().execute(medicineReminder).blockingGet();
cancelNotificationSync(medicineReminder);
mMedicineReminderEventHandler.get().cancelMedicineReminderNotificationWork(Collections.singletonList(medicineReminder));
}
} catch (Exception e) {
mLogger.get().d(TAG, "Failed to disable medicine reminder: " + e.getMessage(), e);
} finally {
mLock.unlock();
}
});
}
}
use of m.co.rh.id.a_medic_log.base.entity.MedicineReminder in project a-medic-log by rh-id.
the class AppNotificationHandler method processNotification.
public void processNotification(Intent intent) {
Serializable serializable = intent.getSerializableExtra(KEY_INT_REQUEST_ID);
if (serializable instanceof Integer) {
mExecutorService.get().execute(() -> {
mLock.lock();
try {
AndroidNotification androidNotification = mAndroidNotificationRepo.get().findByRequestId((int) serializable);
if (androidNotification != null && androidNotification.groupKey.equals(GROUP_KEY_MEDICINE_REMINDER)) {
MedicineReminder medicineReminder = mMedicineDao.get().findMedicineReminderById(androidNotification.refId);
mMedicineReminderSubject.onNext(medicineReminder);
cancelNotificationSync(medicineReminder);
}
} catch (Exception e) {
mLogger.get().d(TAG, "Failed to process notification: " + e.getMessage(), e);
} finally {
mLock.unlock();
}
});
}
}
use of m.co.rh.id.a_medic_log.base.entity.MedicineReminder in project a-medic-log by rh-id.
the class MedicineReminderEventHandler method startMedicineReminderNotificationWork.
public void startMedicineReminderNotificationWork(List<MedicineReminder> medicineReminders) {
if (!medicineReminders.isEmpty()) {
for (MedicineReminder medicineReminder : medicineReminders) {
if (medicineReminder.reminderEnabled) {
long initialDelay = calculateInitialDelayMs(medicineReminder.startDateTime);
String tag = calculateTag(medicineReminder);
OneTimeWorkRequest notificationWorkRequest = new OneTimeWorkRequest.Builder(MedicineReminderNotificationWorker.class).setInitialDelay(initialDelay, TimeUnit.MILLISECONDS).addTag(tag).setInputData(calculateInputData(medicineReminder)).build();
mWorkManager.enqueue(notificationWorkRequest);
}
}
}
}
Aggregations