Search in sources :

Example 16 with MedicineReminder

use of m.co.rh.id.a_medic_log.base.entity.MedicineReminder in project a-medic-log by rh-id.

the class MedicineReminderItemSV method onClick.

@Override
public void onClick(View view) {
    int id = view.getId();
    MedicineReminder medicineReminder = mMedicineReminderSubject.getValue();
    if (id == R.id.root_layout) {
        if (mOnEditClick != null) {
            mOnEditClick.onEditClick(medicineReminder);
        }
    } else if (id == R.id.button_enabled) {
        medicineReminder.reminderEnabled = !medicineReminder.reminderEnabled;
        if (mOnEnableSwitchClick != null) {
            mOnEnableSwitchClick.onEnableSwitchClick(medicineReminder);
        }
    } else if (id == R.id.button_delete) {
        if (mOnDeleteClick != null) {
            mOnDeleteClick.onDeleteClick(medicineReminder);
        }
    }
}
Also used : MedicineReminder(m.co.rh.id.a_medic_log.base.entity.MedicineReminder)

Example 17 with MedicineReminder

use of m.co.rh.id.a_medic_log.base.entity.MedicineReminder in project a-medic-log by rh-id.

the class MedicineReminderRecyclerViewAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
    if (holder instanceof ItemViewHolder) {
        ArrayList<MedicineReminder> itemArrayList = mMedicineState.getMedicineReminderList();
        MedicineReminder item = itemArrayList.get(position);
        ItemViewHolder itemViewHolder = (ItemViewHolder) holder;
        itemViewHolder.setItem(item);
    }
}
Also used : MedicineReminder(m.co.rh.id.a_medic_log.base.entity.MedicineReminder)

Example 18 with MedicineReminder

use of m.co.rh.id.a_medic_log.base.entity.MedicineReminder in project a-medic-log by rh-id.

the class AppNotificationHandler method takeMedicine.

public void takeMedicine(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);
                    MedicineIntake medicineIntake = new MedicineIntake();
                    medicineIntake.medicineId = medicineReminder.medicineId;
                    medicineIntake.description = medicineReminder.message;
                    mNewMedicineIntakeCmd.get().execute(medicineIntake);
                    cancelNotificationSync(medicineReminder);
                }
            } catch (Exception e) {
                mLogger.get().d(TAG, "Failed to take medicine: " + e.getMessage(), e);
            } finally {
                mLock.unlock();
            }
        });
    }
}
Also used : Serializable(java.io.Serializable) MedicineIntake(m.co.rh.id.a_medic_log.base.entity.MedicineIntake) AndroidNotification(m.co.rh.id.a_medic_log.base.entity.AndroidNotification) MedicineReminder(m.co.rh.id.a_medic_log.base.entity.MedicineReminder)

Example 19 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 onMenuItemClick.

@Override
public boolean onMenuItemClick(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.menu_save) {
        MedicineReminder medicineReminder = mMedicineReminderSubject.getValue();
        if (shouldSave()) {
            boolean isUpdate = isUpdate();
            Context context = mSvProvider.getContext();
            if (mNewMedicineReminderCmd.valid(medicineReminder)) {
                mRxDisposer.add("onMenuItemClick_saveNewMedicineReminder", mNewMedicineReminderCmd.execute(medicineReminder).observeOn(AndroidSchedulers.mainThread()).subscribe((medicineState, throwable) -> {
                    String errorMessage;
                    String successMessage;
                    if (isUpdate) {
                        errorMessage = context.getString(R.string.error_failed_to_update_medicine_reminder);
                        successMessage = context.getString(R.string.success_updating_medicine_reminder);
                    } else {
                        errorMessage = context.getString(R.string.error_failed_to_add_medicine_reminder);
                        successMessage = context.getString(R.string.success_adding_medicine_reminder);
                    }
                    if (throwable != null) {
                        mSvProvider.get(ILogger.class).e(TAG, errorMessage, throwable);
                        mNavigator.pop();
                    } else {
                        mSvProvider.get(ILogger.class).i(TAG, successMessage);
                        mNavigator.pop(Result.with(medicineReminder));
                    }
                }));
            } else {
                String error = mNewMedicineReminderCmd.getValidationError();
                mSvProvider.get(ILogger.class).i(TAG, error);
            }
        } else {
            if (mNewMedicineReminderCmd.valid(medicineReminder)) {
                mNavigator.pop(Result.with(medicineReminder));
            } else {
                String error = mNewMedicineReminderCmd.getValidationError();
                mSvProvider.get(ILogger.class).i(TAG, error);
            }
        }
        return true;
    }
    return false;
}
Also used : Context(android.content.Context) 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) ILogger(m.co.rh.id.alogger.ILogger) MedicineReminder(m.co.rh.id.a_medic_log.base.entity.MedicineReminder)

Example 20 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 getMedicineReminder.

private MedicineReminder getMedicineReminder() {
    MedicineReminder medicineReminder;
    Args args = Args.of(mNavRoute);
    if (args != null && args.mMedicineReminder != null) {
        medicineReminder = args.mMedicineReminder;
    } else {
        medicineReminder = new MedicineReminder();
        medicineReminder.medicineId = getMedicineId();
    }
    return medicineReminder;
}
Also used : MedicineReminder(m.co.rh.id.a_medic_log.base.entity.MedicineReminder)

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