Search in sources :

Example 1 with NoteState

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

the class NoteDetailPage method provideComponent.

@Override
public void provideComponent(Provider provider) {
    mExecutorService = provider.get(ExecutorService.class);
    mSvProvider = provider.get(StatefulViewProvider.class);
    mLogger = mSvProvider.get(ILogger.class);
    mRxDisposer = mSvProvider.get(RxDisposer.class);
    mMedicineReminderChangeNotifier = mSvProvider.get(MedicineReminderChangeNotifier.class);
    mNoteAttachmentFileChangeNotifier = mSvProvider.get(NoteAttachmentFileChangeNotifier.class);
    mQueryNoteCmd = mSvProvider.get(QueryNoteCmd.class);
    boolean isUpdate = isUpdate();
    if (isUpdate) {
        mNewNoteCmd = mSvProvider.get(UpdateNoteCmd.class);
    } else {
        mNewNoteCmd = mSvProvider.get(NewNoteCmd.class);
    }
    mDeleteNoteTagCmd = mSvProvider.get(DeleteNoteTagCmd.class);
    mDeleteNoteAttachmentCmd = mSvProvider.get(DeleteNoteAttachmentCmd.class);
    if (mNoteState == null) {
        mNoteState = new NoteState();
        if (isUpdate) {
            mNoteState.setNoteId(getNoteId());
            mRxDisposer.add("provideComponent_queryNoteInfo", mQueryNoteCmd.queryNoteInfo(mNoteState).subscribe((noteState, throwable) -> {
                if (throwable != null) {
                    mLogger.e(TAG, throwable.getMessage(), throwable);
                }
            }));
        } else {
            mNoteState.setNoteProfileId(getProfileId());
        }
    }
    if (mAppBarSv == null) {
        mAppBarSv = new AppBarSV(R.menu.page_note_detail);
    }
    if (isUpdate) {
        mAppBarSv.setTitle(mNavigator.getActivity().getString(R.string.title_update_note));
    } else {
        mAppBarSv.setTitle(mNavigator.getActivity().getString(R.string.title_add_note));
    }
    mAppBarSv.setMenuItemListener(this);
    initTextWatcher();
    mMedicineRecyclerViewAdapter = new MedicineRecyclerViewAdapter(mNoteState, this, this, this, this, mNavigator, this);
    mNoteAttachmentRecyclerViewAdapter = new NoteAttachmentRecyclerViewAdapter(mNoteState, this, this, mNavigator, this);
    mCompositeDisposable = new CompositeDisposable();
}
Also used : 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) NoteAttachmentRecyclerViewAdapter(m.co.rh.id.a_medic_log.app.ui.component.note.attachment.NoteAttachmentRecyclerViewAdapter) AppBarSV(m.co.rh.id.a_medic_log.app.ui.component.AppBarSV) UpdateNoteCmd(m.co.rh.id.a_medic_log.app.provider.command.UpdateNoteCmd) NewNoteCmd(m.co.rh.id.a_medic_log.app.provider.command.NewNoteCmd) StatefulViewProvider(m.co.rh.id.a_medic_log.app.provider.StatefulViewProvider) DeleteNoteTagCmd(m.co.rh.id.a_medic_log.app.provider.command.DeleteNoteTagCmd) NoteAttachmentFileChangeNotifier(m.co.rh.id.a_medic_log.app.provider.notifier.NoteAttachmentFileChangeNotifier) MedicineRecyclerViewAdapter(m.co.rh.id.a_medic_log.app.ui.component.medicine.MedicineRecyclerViewAdapter) RxDisposer(m.co.rh.id.a_medic_log.app.rx.RxDisposer) NoteState(m.co.rh.id.a_medic_log.base.state.NoteState) DeleteNoteAttachmentCmd(m.co.rh.id.a_medic_log.app.provider.command.DeleteNoteAttachmentCmd) ExecutorService(java.util.concurrent.ExecutorService) ILogger(m.co.rh.id.alogger.ILogger) MedicineReminderChangeNotifier(m.co.rh.id.a_medic_log.app.provider.notifier.MedicineReminderChangeNotifier) QueryNoteCmd(m.co.rh.id.a_medic_log.app.provider.command.QueryNoteCmd) CompositeDisposable(io.reactivex.rxjava3.disposables.CompositeDisposable)

Example 2 with NoteState

use of m.co.rh.id.a_medic_log.base.state.NoteState 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)

Example 3 with NoteState

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

the class NoteDetailPage method onMenuItemClick.

@Override
public boolean onMenuItemClick(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.menu_save) {
        if (mNewNoteCmd.valid(mNoteState)) {
            Context context = mSvProvider.getContext();
            boolean isUpdate = isUpdate();
            mSvProvider.get(RxDisposer.class).add("onMenuItemClick_newNoteCmd.execute", mNewNoteCmd.execute(mNoteState).subscribe((noteState, throwable) -> {
                String errorMessage;
                String successMessage;
                if (isUpdate) {
                    errorMessage = context.getString(R.string.error_failed_to_update_note);
                    successMessage = context.getString(R.string.success_updating_note);
                } else {
                    errorMessage = context.getString(R.string.error_failed_to_add_note);
                    successMessage = context.getString(R.string.success_adding_note);
                }
                if (throwable != null) {
                    mLogger.e(TAG, errorMessage, throwable);
                    mNavigator.pop();
                } else {
                    mLogger.i(TAG, successMessage);
                    mNavigator.pop(Result.withNote(noteState));
                }
            }));
        } else {
            String error = mNewNoteCmd.getValidationError();
            mLogger.i(TAG, error);
        }
    }
    return false;
}
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) RxDisposer(m.co.rh.id.a_medic_log.app.rx.RxDisposer)

Aggregations

Activity (android.app.Activity)2 Context (android.content.Context)2 Editable (android.text.Editable)2 TextWatcher (android.text.TextWatcher)2 MenuItem (android.view.MenuItem)2 View (android.view.View)2 ViewGroup (android.view.ViewGroup)2 Button (android.widget.Button)2 EditText (android.widget.EditText)2 TextView (android.widget.TextView)2 Toolbar (androidx.appcompat.widget.Toolbar)2 DividerItemDecoration (androidx.recyclerview.widget.DividerItemDecoration)2 RecyclerView (androidx.recyclerview.widget.RecyclerView)2 Chip (com.google.android.material.chip.Chip)2 ChipGroup (com.google.android.material.chip.ChipGroup)2 AndroidSchedulers (io.reactivex.rxjava3.android.schedulers.AndroidSchedulers)2 CompositeDisposable (io.reactivex.rxjava3.disposables.CompositeDisposable)2 Schedulers (io.reactivex.rxjava3.schedulers.Schedulers)2 Serializable (java.io.Serializable)2 Date (java.util.Date)2