Search in sources :

Example 21 with MedicineReminder

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;
}
Also used : EditText(android.widget.EditText) Context(android.content.Context) Date(java.util.Date) ILogger(m.co.rh.id.alogger.ILogger) SimpleDateFormat(java.text.SimpleDateFormat) AppBarSV(m.co.rh.id.a_medic_log.app.ui.component.AppBarSV) Editable(android.text.Editable) MedicineReminder(m.co.rh.id.a_medic_log.base.entity.MedicineReminder) MenuItem(android.view.MenuItem) NavInject(m.co.rh.id.anavigator.annotation.NavInject) Calendar(java.util.Calendar) NavRoute(m.co.rh.id.anavigator.NavRoute) View(android.view.View) Button(android.widget.Button) RequireNavigator(m.co.rh.id.anavigator.component.RequireNavigator) UpdateMedicineReminderCmd(m.co.rh.id.a_medic_log.app.provider.command.UpdateMedicineReminderCmd) INavigator(m.co.rh.id.anavigator.component.INavigator) DateFormat(java.text.DateFormat) LinkedHashSet(java.util.LinkedHashSet) SerialBehaviorSubject(m.co.rh.id.a_medic_log.base.rx.SerialBehaviorSubject) StatefulView(m.co.rh.id.anavigator.StatefulView) Provider(m.co.rh.id.aprovider.Provider) NewMedicineReminderCmd(m.co.rh.id.a_medic_log.app.provider.command.NewMedicineReminderCmd) RequireNavRoute(m.co.rh.id.anavigator.component.RequireNavRoute) NavExtDialogConfig(m.co.rh.id.anavigator.extension.dialog.ui.NavExtDialogConfig) ViewGroup(android.view.ViewGroup) Serializable(java.io.Serializable) AndroidSchedulers(io.reactivex.rxjava3.android.schedulers.AndroidSchedulers) TextView(android.widget.TextView) StatefulViewProvider(m.co.rh.id.a_medic_log.app.provider.StatefulViewProvider) RequireComponent(m.co.rh.id.anavigator.component.RequireComponent) RxDisposer(m.co.rh.id.a_medic_log.app.rx.RxDisposer) Toolbar(androidx.appcompat.widget.Toolbar) R(m.co.rh.id.a_medic_log.R) Activity(android.app.Activity) EditText(android.widget.EditText) TextWatcher(android.text.TextWatcher) Button(android.widget.Button) ViewGroup(android.view.ViewGroup) TextView(android.widget.TextView) View(android.view.View) StatefulView(m.co.rh.id.anavigator.StatefulView) TextView(android.widget.TextView)

Example 22 with MedicineReminder

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);
}
Also used : MedicineReminder(m.co.rh.id.a_medic_log.base.entity.MedicineReminder) SimpleDateFormat(java.text.SimpleDateFormat)

Example 23 with MedicineReminder

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;
}
Also used : EditText(android.widget.EditText) DividerItemDecoration(androidx.recyclerview.widget.DividerItemDecoration) Context(android.content.Context) NewMedicineCmd(m.co.rh.id.a_medic_log.app.provider.command.NewMedicineCmd) MedicineReminderChangeNotifier(m.co.rh.id.a_medic_log.app.provider.notifier.MedicineReminderChangeNotifier) ILogger(m.co.rh.id.alogger.ILogger) AppBarSV(m.co.rh.id.a_medic_log.app.ui.component.AppBarSV) Function(java.util.function.Function) Editable(android.text.Editable) MedicineReminder(m.co.rh.id.a_medic_log.base.entity.MedicineReminder) MenuItem(android.view.MenuItem) Schedulers(io.reactivex.rxjava3.schedulers.Schedulers) NavInject(m.co.rh.id.anavigator.annotation.NavInject) NavRoute(m.co.rh.id.anavigator.NavRoute) SuggestionAdapter(m.co.rh.id.a_medic_log.app.ui.component.adapter.SuggestionAdapter) View(android.view.View) Button(android.widget.Button) RequireNavigator(m.co.rh.id.anavigator.component.RequireNavigator) UpdateMedicineReminderCmd(m.co.rh.id.a_medic_log.app.provider.command.UpdateMedicineReminderCmd) RecyclerView(androidx.recyclerview.widget.RecyclerView) INavigator(m.co.rh.id.anavigator.component.INavigator) QueryMedicineCmd(m.co.rh.id.a_medic_log.app.provider.command.QueryMedicineCmd) ExecutorService(java.util.concurrent.ExecutorService) DeleteMedicineReminderCmd(m.co.rh.id.a_medic_log.app.provider.command.DeleteMedicineReminderCmd) MedicineReminderRecyclerViewAdapter(m.co.rh.id.a_medic_log.app.ui.component.medicine.reminder.MedicineReminderRecyclerViewAdapter) UpdateMedicineCmd(m.co.rh.id.a_medic_log.app.provider.command.UpdateMedicineCmd) StatefulView(m.co.rh.id.anavigator.StatefulView) Provider(m.co.rh.id.aprovider.Provider) MedicineState(m.co.rh.id.a_medic_log.base.state.MedicineState) Collection(java.util.Collection) RequireNavRoute(m.co.rh.id.anavigator.component.RequireNavRoute) Routes(m.co.rh.id.a_medic_log.app.constants.Routes) MedicineReminderItemSV(m.co.rh.id.a_medic_log.app.ui.component.medicine.reminder.MedicineReminderItemSV) NavExtDialogConfig(m.co.rh.id.anavigator.extension.dialog.ui.NavExtDialogConfig) ViewGroup(android.view.ViewGroup) AutoCompleteTextView(android.widget.AutoCompleteTextView) Serializable(java.io.Serializable) ArrayAdapter(android.widget.ArrayAdapter) AndroidSchedulers(io.reactivex.rxjava3.android.schedulers.AndroidSchedulers) StatefulViewProvider(m.co.rh.id.a_medic_log.app.provider.StatefulViewProvider) RequireComponent(m.co.rh.id.anavigator.component.RequireComponent) RxDisposer(m.co.rh.id.a_medic_log.app.rx.RxDisposer) Toolbar(androidx.appcompat.widget.Toolbar) R(m.co.rh.id.a_medic_log.R) Activity(android.app.Activity) EditText(android.widget.EditText) TextWatcher(android.text.TextWatcher) Button(android.widget.Button) ViewGroup(android.view.ViewGroup) SuggestionAdapter(m.co.rh.id.a_medic_log.app.ui.component.adapter.SuggestionAdapter) RecyclerView(androidx.recyclerview.widget.RecyclerView) DividerItemDecoration(androidx.recyclerview.widget.DividerItemDecoration) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) StatefulView(m.co.rh.id.anavigator.StatefulView) AutoCompleteTextView(android.widget.AutoCompleteTextView) AutoCompleteTextView(android.widget.AutoCompleteTextView)

Example 24 with MedicineReminder

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();
}
Also used : Calendar(java.util.Calendar) AppNotificationHandler(m.co.rh.id.a_medic_log.app.provider.component.AppNotificationHandler) MedicineReminder(m.co.rh.id.a_medic_log.base.entity.MedicineReminder) Date(java.util.Date) NonNull(androidx.annotation.NonNull)

Example 25 with MedicineReminder

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);
        }
    }
}
Also used : MedicineReminder(m.co.rh.id.a_medic_log.base.entity.MedicineReminder) Transaction(androidx.room.Transaction)

Aggregations

MedicineReminder (m.co.rh.id.a_medic_log.base.entity.MedicineReminder)26 Serializable (java.io.Serializable)8 Activity (android.app.Activity)7 View (android.view.View)7 ViewGroup (android.view.ViewGroup)7 Button (android.widget.Button)7 AndroidSchedulers (io.reactivex.rxjava3.android.schedulers.AndroidSchedulers)7 R (m.co.rh.id.a_medic_log.R)7 StatefulViewProvider (m.co.rh.id.a_medic_log.app.provider.StatefulViewProvider)7 RxDisposer (m.co.rh.id.a_medic_log.app.rx.RxDisposer)7 MedicineState (m.co.rh.id.a_medic_log.base.state.MedicineState)7 StatefulView (m.co.rh.id.anavigator.StatefulView)7 RequireComponent (m.co.rh.id.anavigator.component.RequireComponent)7 Provider (m.co.rh.id.aprovider.Provider)7 MenuItem (android.view.MenuItem)6 Medicine (m.co.rh.id.a_medic_log.base.entity.Medicine)6 Context (android.content.Context)5 Editable (android.text.Editable)5 TextWatcher (android.text.TextWatcher)5 EditText (android.widget.EditText)5