Search in sources :

Example 1 with NoteTag

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

the class NoteTagDetailSVDialog method provideComponent.

@Override
public void provideComponent(Provider provider) {
    mSvProvider = provider.get(StatefulViewProvider.class);
    mLogger = mSvProvider.get(ILogger.class);
    mRxDisposer = mSvProvider.get(RxDisposer.class);
    mQueryNoteCmd = mSvProvider.get(QueryNoteCmd.class);
    mNewNoteTagCmd = mSvProvider.get(NewNoteTagCmd.class);
    if (mNoteTag == null) {
        NoteTag noteTag = new NoteTag();
        if (shouldSave()) {
            noteTag.noteId = getNoteId();
        }
        mNoteTag = new SerialBehaviorSubject<>(noteTag);
    }
    mTagTextWatcher = new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        // Leave blank
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        // Leave blank
        }

        @Override
        public void afterTextChanged(Editable editable) {
            String tag = editable.toString();
            NoteTag noteTag = mNoteTag.getValue();
            noteTag.tag = tag;
            mNewNoteTagCmd.valid(noteTag);
        }
    };
    mSuggestionQuery = s -> mQueryNoteCmd.searchNoteTag(s).blockingGet();
}
Also used : StatefulViewProvider(m.co.rh.id.a_medic_log.app.provider.StatefulViewProvider) NoteTag(m.co.rh.id.a_medic_log.base.entity.NoteTag) NewNoteTagCmd(m.co.rh.id.a_medic_log.app.provider.command.NewNoteTagCmd) RxDisposer(m.co.rh.id.a_medic_log.app.rx.RxDisposer) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) ILogger(m.co.rh.id.alogger.ILogger) QueryNoteCmd(m.co.rh.id.a_medic_log.app.provider.command.QueryNoteCmd)

Example 2 with NoteTag

use of m.co.rh.id.a_medic_log.base.entity.NoteTag 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 NoteTag

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

the class NoteDao method insertNote.

@Transaction
public void insertNote(NoteState noteState) {
    Note note = noteState.getNote();
    Set<NoteTag> noteTags = noteState.getNoteTagSet();
    List<NoteAttachmentState> noteAttachmentStates = noteState.getNoteAttachmentStates();
    List<MedicineState> medicineStates = noteState.getMedicineList();
    long noteId = insert(note);
    note.id = noteId;
    if (noteTags != null && !noteTags.isEmpty()) {
        for (NoteTag noteTag : noteTags) {
            noteTag.noteId = noteId;
            noteTag.id = insert(noteTag);
        }
    }
    if (noteAttachmentStates != null && !noteAttachmentStates.isEmpty()) {
        for (NoteAttachmentState noteAttachmentState : noteAttachmentStates) {
            NoteAttachment noteAttachment = noteAttachmentState.getNoteAttachment();
            noteAttachment.noteId = noteId;
            insertNoteAttachment(noteAttachmentState);
        }
    }
    if (medicineStates != null && !medicineStates.isEmpty()) {
        for (MedicineState medicineState : medicineStates) {
            Medicine medicine = medicineState.getMedicine();
            medicine.noteId = noteId;
            long medicineId = insert(medicine);
            medicine.id = medicineId;
            List<MedicineReminder> medicineReminders = medicineState.getMedicineReminderList();
            if (medicineReminders != null && !medicineReminders.isEmpty()) {
                for (MedicineReminder medicineReminder : medicineReminders) {
                    medicineReminder.medicineId = medicineId;
                    medicineReminder.id = insert(medicineReminder);
                }
            }
        }
    }
}
Also used : NoteAttachmentState(m.co.rh.id.a_medic_log.base.state.NoteAttachmentState) NoteAttachment(m.co.rh.id.a_medic_log.base.entity.NoteAttachment) Medicine(m.co.rh.id.a_medic_log.base.entity.Medicine) MedicineState(m.co.rh.id.a_medic_log.base.state.MedicineState) Note(m.co.rh.id.a_medic_log.base.entity.Note) NoteTag(m.co.rh.id.a_medic_log.base.entity.NoteTag) MedicineReminder(m.co.rh.id.a_medic_log.base.entity.MedicineReminder) Transaction(androidx.room.Transaction)

Example 4 with NoteTag

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

the class NoteState method clone.

@Override
public NoteState clone() {
    NoteState noteState = new NoteState();
    Note note = mNoteSubject.getValue();
    if (note != null) {
        note = note.clone();
    }
    noteState.updateNote(note);
    TreeSet<NoteTag> noteTags = mNoteTagSetSubject.getValue();
    if (noteTags != null && !noteTags.isEmpty()) {
        TreeSet<NoteTag> noteTagsClone = new TreeSet<>();
        for (NoteTag noteTag : noteTags) {
            noteTagsClone.add(noteTag.clone());
        }
        noteTags = noteTagsClone;
    } else {
        noteTags = new TreeSet<>();
    }
    noteState.updateNoteTagSet(noteTags);
    ArrayList<MedicineState> medicineStates = mMedicineListSubject.getValue();
    if (medicineStates != null && !medicineStates.isEmpty()) {
        ArrayList<MedicineState> medicineStatesClone = new ArrayList<>(medicineStates.size());
        for (MedicineState medicineState : medicineStates) {
            medicineStatesClone.add(medicineState.clone());
        }
        medicineStates = medicineStatesClone;
    } else {
        medicineStates = new ArrayList<>();
    }
    noteState.updateMedicineStates(medicineStates);
    return noteState;
}
Also used : TreeSet(java.util.TreeSet) Note(m.co.rh.id.a_medic_log.base.entity.Note) ArrayList(java.util.ArrayList) NoteTag(m.co.rh.id.a_medic_log.base.entity.NoteTag)

Example 5 with NoteTag

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

the class PagedNoteItemsCmd method searchNoteTag.

private Future<List<Note>> searchNoteTag(String search) {
    return mExecutorService.submit(() -> {
        List<NoteTag> noteTagList = mNoteDao.searchNoteTag(search);
        List<Note> noteList = new ArrayList<>();
        Set<Long> noteIds = new LinkedHashSet<>();
        if (!noteTagList.isEmpty()) {
            for (NoteTag noteTag : noteTagList) {
                noteIds.add(noteTag.noteId);
            }
            if (!noteIds.isEmpty()) {
                List<Note> notes = mNoteDao.findNoteByIds(noteIds);
                noteList.addAll(notes);
            }
        }
        return noteList;
    });
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Note(m.co.rh.id.a_medic_log.base.entity.Note) ArrayList(java.util.ArrayList) NoteTag(m.co.rh.id.a_medic_log.base.entity.NoteTag)

Aggregations

NoteTag (m.co.rh.id.a_medic_log.base.entity.NoteTag)7 Note (m.co.rh.id.a_medic_log.base.entity.Note)4 ArrayList (java.util.ArrayList)3 TreeSet (java.util.TreeSet)3 StatefulViewProvider (m.co.rh.id.a_medic_log.app.provider.StatefulViewProvider)3 QueryNoteCmd (m.co.rh.id.a_medic_log.app.provider.command.QueryNoteCmd)3 RxDisposer (m.co.rh.id.a_medic_log.app.rx.RxDisposer)3 ILogger (m.co.rh.id.alogger.ILogger)3 Activity (android.app.Activity)2 Context (android.content.Context)2 Editable (android.text.Editable)2 TextWatcher (android.text.TextWatcher)2 View (android.view.View)2 ViewGroup (android.view.ViewGroup)2 Button (android.widget.Button)2 TextView (android.widget.TextView)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