Search in sources :

Example 1 with MedicineState

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

the class NoteDetailPage method confirmDeleteMedicine.

private void confirmDeleteMedicine(MedicineState medicineState) {
    Context context = mSvProvider.getContext();
    mRxDisposer.add("confirmDeleteMedicine_deleteMedicineCmd", mSvProvider.get(DeleteMedicineCmd.class).execute(medicineState).observeOn(AndroidSchedulers.mainThread()).subscribe((note, throwable) -> {
        String errorMessage = context.getString(R.string.error_failed_to_delete_medicine);
        String successMessage = context.getString(R.string.success_deleting_medicine);
        if (throwable != null) {
            mLogger.e(TAG, errorMessage, throwable);
        } else {
            mLogger.i(TAG, successMessage);
            mMedicineRecyclerViewAdapter.notifyItemDeleted(medicineState);
        }
    }));
}
Also used : Context(android.content.Context) DividerItemDecoration(androidx.recyclerview.widget.DividerItemDecoration) Chip(com.google.android.material.chip.Chip) Date(java.util.Date) NoteState(m.co.rh.id.a_medic_log.base.state.NoteState) ILogger(m.co.rh.id.alogger.ILogger) AppBarSV(m.co.rh.id.a_medic_log.app.ui.component.AppBarSV) NoteAttachmentItemSV(m.co.rh.id.a_medic_log.app.ui.component.note.attachment.NoteAttachmentItemSV) MedicineRecyclerViewAdapter(m.co.rh.id.a_medic_log.app.ui.component.medicine.MedicineRecyclerViewAdapter) UiUtils(m.co.rh.id.a_medic_log.app.util.UiUtils) View(android.view.View) Button(android.widget.Button) RecyclerView(androidx.recyclerview.widget.RecyclerView) NoteAttachmentRecyclerViewAdapter(m.co.rh.id.a_medic_log.app.ui.component.note.attachment.NoteAttachmentRecyclerViewAdapter) SerialBehaviorSubject(m.co.rh.id.a_medic_log.base.rx.SerialBehaviorSubject) StatefulView(m.co.rh.id.anavigator.StatefulView) MedicineState(m.co.rh.id.a_medic_log.base.state.MedicineState) DeleteNoteTagCmd(m.co.rh.id.a_medic_log.app.provider.command.DeleteNoteTagCmd) NoteAttachmentFileChangeNotifier(m.co.rh.id.a_medic_log.app.provider.notifier.NoteAttachmentFileChangeNotifier) 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) DeleteMedicineCmd(m.co.rh.id.a_medic_log.app.provider.command.DeleteMedicineCmd) Toolbar(androidx.appcompat.widget.Toolbar) NoteTag(m.co.rh.id.a_medic_log.base.entity.NoteTag) TextWatcher(android.text.TextWatcher) Context(android.content.Context) MedicineItemSV(m.co.rh.id.a_medic_log.app.ui.component.medicine.MedicineItemSV) NewNoteCmd(m.co.rh.id.a_medic_log.app.provider.command.NewNoteCmd) NoteAttachmentState(m.co.rh.id.a_medic_log.base.state.NoteAttachmentState) MedicineReminderChangeNotifier(m.co.rh.id.a_medic_log.app.provider.notifier.MedicineReminderChangeNotifier) ChipGroup(com.google.android.material.chip.ChipGroup) QueryNoteCmd(m.co.rh.id.a_medic_log.app.provider.command.QueryNoteCmd) Editable(android.text.Editable) TreeSet(java.util.TreeSet) 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) CompositeDisposable(io.reactivex.rxjava3.disposables.CompositeDisposable) RequireNavigator(m.co.rh.id.anavigator.component.RequireNavigator) INavigator(m.co.rh.id.anavigator.component.INavigator) ExecutorService(java.util.concurrent.ExecutorService) Provider(m.co.rh.id.aprovider.Provider) RequireNavRoute(m.co.rh.id.anavigator.component.RequireNavRoute) Routes(m.co.rh.id.a_medic_log.app.constants.Routes) UpdateNoteCmd(m.co.rh.id.a_medic_log.app.provider.command.UpdateNoteCmd) NavExtDialogConfig(m.co.rh.id.anavigator.extension.dialog.ui.NavExtDialogConfig) RequireComponent(m.co.rh.id.anavigator.component.RequireComponent) DeleteNoteAttachmentCmd(m.co.rh.id.a_medic_log.app.provider.command.DeleteNoteAttachmentCmd) RxDisposer(m.co.rh.id.a_medic_log.app.rx.RxDisposer) R(m.co.rh.id.a_medic_log.R) Activity(android.app.Activity) EditText(android.widget.EditText)

Example 2 with MedicineState

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

the class NoteDetailPage method medicineItem_onEditClick.

@Override
public void medicineItem_onEditClick(MedicineState medicineState) {
    MedicineDetailPage.Args args;
    MedicineState medicineStateArgs = medicineState.clone();
    if (isUpdate()) {
        args = MedicineDetailPage.Args.forUpdate(medicineStateArgs);
    } else {
        args = MedicineDetailPage.Args.forEdit(medicineStateArgs);
    }
    mNavigator.push(Routes.MEDICINE_DETAIL_PAGE, args, (navigator, navRoute, activity, currentView) -> {
        MedicineDetailPage.Result result = MedicineDetailPage.Result.of(navRoute);
        if (result != null) {
            updateMedicineState(result.getMedicineState());
        }
    });
}
Also used : MedicineState(m.co.rh.id.a_medic_log.base.state.MedicineState)

Example 3 with MedicineState

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

the class MedicineDetailPage method onEnableSwitchClick.

@Override
public void onEnableSwitchClick(MedicineReminder medicineReminder) {
    // save only if this is update medicine AND save flag enabled
    if (isUpdate() && shouldSave()) {
        Context context = mSvProvider.getContext();
        UpdateMedicineReminderCmd updateMedicineReminderCmd = mSvProvider.get(UpdateMedicineReminderCmd.class);
        if (updateMedicineReminderCmd.valid(medicineReminder)) {
            mRxDisposer.add("onEnableSwitchClick_saveMedicineReminder", updateMedicineReminderCmd.execute(medicineReminder).observeOn(AndroidSchedulers.mainThread()).subscribe((medicineState, throwable) -> {
                String errorMessage = context.getString(R.string.error_failed_to_update_medicine_reminder);
                String successMessage = context.getString(R.string.success_updating_medicine_reminder);
                if (throwable != null) {
                    mSvProvider.get(ILogger.class).e(TAG, errorMessage, throwable);
                } else {
                    mSvProvider.get(ILogger.class).i(TAG, successMessage);
                }
            }));
        } else {
            String error = updateMedicineReminderCmd.getValidationError();
            mSvProvider.get(ILogger.class).i(TAG, error);
        }
        mSvProvider.get(UpdateMedicineReminderCmd.class).execute(medicineReminder);
    } else {
        mMedicineReminderRecyclerViewAdapter.notifyItemUpdated(medicineReminder);
    }
}
Also used : Context(android.content.Context) 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) UpdateMedicineReminderCmd(m.co.rh.id.a_medic_log.app.provider.command.UpdateMedicineReminderCmd) ILogger(m.co.rh.id.alogger.ILogger)

Example 4 with MedicineState

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

the class MedicineDetailPage method onMenuItemClick.

@Override
public boolean onMenuItemClick(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.menu_save) {
        if (shouldSave()) {
            boolean isUpdate = isUpdate();
            Context context = mSvProvider.getContext();
            if (mNewMedicineCmd.valid(mMedicineState)) {
                mRxDisposer.add("onMenuItemClick_saveNewMedicine", mNewMedicineCmd.execute(mMedicineState).observeOn(AndroidSchedulers.mainThread()).subscribe((medicineState, throwable) -> {
                    String errorMessage;
                    String successMessage;
                    if (isUpdate) {
                        errorMessage = context.getString(R.string.error_failed_to_update_medicine);
                        successMessage = context.getString(R.string.success_updating_medicine);
                    } else {
                        errorMessage = context.getString(R.string.error_failed_to_add_medicine);
                        successMessage = context.getString(R.string.success_adding_medicine);
                    }
                    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(mMedicineState));
                    }
                }));
            } else {
                String error = mNewMedicineCmd.getValidationError();
                mSvProvider.get(ILogger.class).i(TAG, error);
            }
        } else {
            mNavigator.pop(Result.with(mMedicineState));
        }
        return true;
    }
    return false;
}
Also used : Context(android.content.Context) 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) ILogger(m.co.rh.id.alogger.ILogger)

Example 5 with MedicineState

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

the class NoteDaoTest method insertUpdateDelete_noteState.

@Test
public void insertUpdateDelete_noteState() {
    NoteDao noteDao = mAppDatabase.noteDao();
    MedicineDao medicineDao = mAppDatabase.medicineDao();
    String noteContent = "test note";
    String noteTagTag = "sample tag";
    String medicineName = "test medicine name";
    String medicineIntakeDesc = "test medicine intake";
    String medicineReminderMessage = "test medicine reminder message";
    NoteState noteState = new NoteState();
    Note note = new Note();
    note.content = noteContent;
    noteState.updateNote(note);
    NoteTag noteTag = new NoteTag();
    noteTag.tag = noteTagTag;
    noteState.updateNoteTagSet(Collections.singletonList(noteTag));
    List<MedicineState> medicineStateList = new ArrayList<>();
    MedicineState medicineState = new MedicineState();
    Medicine medicine = new Medicine();
    medicine.name = medicineName;
    medicineState.updateMedicine(medicine);
    MedicineReminder medicineReminder = new MedicineReminder();
    medicineReminder.message = medicineReminderMessage;
    medicineState.updateMedicineReminderList(Collections.singletonList(medicineReminder));
    medicineStateList.add(medicineState);
    noteState.updateMedicineStates(medicineStateList);
    // INSERT NOTE
    noteDao.insertNote(noteState);
    assertEquals(1, noteDao.countNote());
    assertEquals(1, noteDao.countNoteTag());
    assertEquals(1, medicineDao.countMedicine());
    assertEquals(1, medicineDao.countMedicineReminder());
    assertEquals(0, medicineDao.countMedicineIntake());
    Note noteFromInsert = noteDao.findNoteById(noteState.getNoteId());
    assertEquals(noteContent, noteFromInsert.content);
    List<NoteTag> noteTagListFromInsert = noteDao.findNoteTagsByNoteId(noteState.getNoteId());
    assertEquals(1, noteTagListFromInsert.size());
    assertEquals(noteTagTag, noteTagListFromInsert.get(0).tag);
    List<Medicine> medicineListFromInsert = noteDao.findMedicinesByNoteId(noteState.getNoteId());
    assertEquals(1, medicineListFromInsert.size());
    assertEquals(medicineName, medicineListFromInsert.get(0).name);
    List<MedicineReminder> medicineReminderListFromInsert = medicineDao.findMedicineRemindersByMedicineId(medicineListFromInsert.get(0).id);
    assertEquals(1, medicineReminderListFromInsert.size());
    assertEquals(medicineReminderMessage, medicineReminderListFromInsert.get(0).message);
    // try insert medicine intake
    MedicineIntake medicineIntake = new MedicineIntake();
    medicineIntake.medicineId = medicineListFromInsert.get(0).id;
    medicineIntake.description = medicineIntakeDesc;
    medicineDao.insert(medicineIntake);
    // after that update note
    String noteContentUpdate = noteContent + " updated ";
    noteState.getNote().content = noteContentUpdate;
    // UPDATE NOTE
    noteDao.updateNote(noteState);
    assertEquals(1, noteDao.countNote());
    assertEquals(1, noteDao.countNoteTag());
    assertEquals(1, medicineDao.countMedicine());
    assertEquals(1, medicineDao.countMedicineReminder());
    assertEquals(1, medicineDao.countMedicineIntake());
    Note noteFromUpdate = noteDao.findNoteById(noteState.getNoteId());
    assertEquals(noteContentUpdate, noteFromUpdate.content);
    List<NoteTag> noteTagListFromUpdate = noteDao.findNoteTagsByNoteId(noteState.getNoteId());
    assertEquals(1, noteTagListFromUpdate.size());
    assertEquals(noteTagTag, noteTagListFromUpdate.get(0).tag);
    List<Medicine> medicineListFromUpdate = noteDao.findMedicinesByNoteId(noteState.getNoteId());
    assertEquals(1, medicineListFromUpdate.size());
    assertEquals(medicineName, medicineListFromUpdate.get(0).name);
    List<MedicineReminder> medicineReminderListFromUpdate = medicineDao.findMedicineRemindersByMedicineId(medicineListFromUpdate.get(0).id);
    assertEquals(1, medicineReminderListFromUpdate.size());
    assertEquals(medicineReminderMessage, medicineReminderListFromUpdate.get(0).message);
    // ensure medicine intake not deleted when updating note state
    MedicineIntake updateNoteMedicineIntake = medicineDao.findLastMedicineIntake(medicineIntake.medicineId);
    assertNotNull(updateNoteMedicineIntake);
    assertEquals(medicineIntakeDesc, updateNoteMedicineIntake.description);
    // DELETE NOTE
    noteDao.deleteNote(noteState);
    assertEquals(0, noteDao.countNote());
    assertEquals(0, noteDao.countNoteTag());
    assertEquals(0, medicineDao.countMedicine());
    assertEquals(0, medicineDao.countMedicineReminder());
    assertEquals(0, medicineDao.countMedicineIntake());
}
Also used : MedicineState(m.co.rh.id.a_medic_log.base.state.MedicineState) ArrayList(java.util.ArrayList) NoteTag(m.co.rh.id.a_medic_log.base.entity.NoteTag) NoteState(m.co.rh.id.a_medic_log.base.state.NoteState) Medicine(m.co.rh.id.a_medic_log.base.entity.Medicine) Note(m.co.rh.id.a_medic_log.base.entity.Note) MedicineIntake(m.co.rh.id.a_medic_log.base.entity.MedicineIntake) MedicineReminder(m.co.rh.id.a_medic_log.base.entity.MedicineReminder) Test(org.junit.Test)

Aggregations

MedicineState (m.co.rh.id.a_medic_log.base.state.MedicineState)10 MedicineReminder (m.co.rh.id.a_medic_log.base.entity.MedicineReminder)7 Activity (android.app.Activity)4 MenuItem (android.view.MenuItem)4 View (android.view.View)4 ViewGroup (android.view.ViewGroup)4 Button (android.widget.Button)4 AndroidSchedulers (io.reactivex.rxjava3.android.schedulers.AndroidSchedulers)4 Schedulers (io.reactivex.rxjava3.schedulers.Schedulers)4 ExecutorService (java.util.concurrent.ExecutorService)4 R (m.co.rh.id.a_medic_log.R)4 StatefulViewProvider (m.co.rh.id.a_medic_log.app.provider.StatefulViewProvider)4 RxDisposer (m.co.rh.id.a_medic_log.app.rx.RxDisposer)4 Medicine (m.co.rh.id.a_medic_log.base.entity.Medicine)4 StatefulView (m.co.rh.id.anavigator.StatefulView)4 RequireComponent (m.co.rh.id.anavigator.component.RequireComponent)4 Provider (m.co.rh.id.aprovider.Provider)4 Context (android.content.Context)3 Editable (android.text.Editable)3 TextWatcher (android.text.TextWatcher)3