Search in sources :

Example 1 with NoteAttachment

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

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

the class NewNoteAttachmentCmd method valid.

public boolean valid(NoteAttachmentState noteAttachmentState) {
    boolean isValid = false;
    if (noteAttachmentState != null) {
        NoteAttachment noteAttachment = noteAttachmentState.getNoteAttachment();
        boolean nameValid;
        if (noteAttachment.name != null && !noteAttachment.name.isEmpty()) {
            nameValid = true;
            mNameValidSubject.onNext("");
        } else {
            nameValid = false;
            mNameValidSubject.onNext(mAppContext.getString(R.string.name_is_required));
        }
        isValid = nameValid;
    }
    return isValid;
}
Also used : NoteAttachment(m.co.rh.id.a_medic_log.base.entity.NoteAttachment)

Example 3 with NoteAttachment

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

the class QueryNoteCmd method queryNoteAttachmentStateList.

private void queryNoteAttachmentStateList(NoteState noteState) {
    Long noteId = noteState.getNoteId();
    List<NoteAttachment> noteAttachments = mNoteDao.findNoteAttachmentsByNoteId(noteId);
    if (!noteAttachments.isEmpty()) {
        List<NoteAttachmentState> noteAttachmentStates = new ArrayList<>();
        for (NoteAttachment noteAttachment : noteAttachments) {
            List<NoteAttachmentFile> noteAttachmentFiles = mNoteDao.findNoteAttachmentFilesByAttachmentId(noteAttachment.id);
            NoteAttachmentState noteAttachmentState = new NoteAttachmentState();
            noteAttachmentState.updateNoteAttachment(noteAttachment);
            noteAttachmentState.updateNoteAttachmentFileList(noteAttachmentFiles);
            noteAttachmentStates.add(noteAttachmentState);
        }
        noteState.updateNoteAttachments(noteAttachmentStates);
    }
}
Also used : NoteAttachment(m.co.rh.id.a_medic_log.base.entity.NoteAttachment) NoteAttachmentState(m.co.rh.id.a_medic_log.base.state.NoteAttachmentState) ArrayList(java.util.ArrayList) NoteAttachmentFile(m.co.rh.id.a_medic_log.base.entity.NoteAttachmentFile)

Example 4 with NoteAttachment

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

the class NoteDao method deleteNote.

@Transaction
public void deleteNote(NoteState noteState) {
    Note note = noteState.getNote();
    delete(note);
    long noteId = note.id;
    deleteNoteTagByNoteId(noteId);
    List<NoteAttachment> noteAttachments = findNoteAttachmentsByNoteId(noteId);
    if (noteAttachments != null && !noteAttachments.isEmpty()) {
        deleteNoteAttachmentsByNoteId(noteId);
        for (NoteAttachment noteAttachment : noteAttachments) {
            deleteNoteAttachmentFilesByAttachmentId(noteAttachment.id);
        }
    }
    List<Medicine> medicines = findMedicinesByNoteId(noteId);
    if (medicines != null && !medicines.isEmpty()) {
        deleteMedicinesByNoteId(noteId);
        for (Medicine medicine : medicines) {
            long medicineId = medicine.id;
            deleteMedicineReminderByMedicineId(medicineId);
            deleteMedicineIntakeByMedicineId(medicineId);
        }
    }
}
Also used : NoteAttachment(m.co.rh.id.a_medic_log.base.entity.NoteAttachment) Medicine(m.co.rh.id.a_medic_log.base.entity.Medicine) Note(m.co.rh.id.a_medic_log.base.entity.Note) Transaction(androidx.room.Transaction)

Example 5 with NoteAttachment

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

the class NoteDao method deleteNoteAttachment.

@Transaction
public void deleteNoteAttachment(NoteAttachmentState noteAttachmentState) {
    NoteAttachment noteAttachment = noteAttachmentState.getNoteAttachment();
    Long noteAttachmentId = noteAttachment.id;
    if (noteAttachmentId != null) {
        deleteNoteAttachmentFilesByAttachmentId(noteAttachmentId);
        delete(noteAttachment);
    }
}
Also used : NoteAttachment(m.co.rh.id.a_medic_log.base.entity.NoteAttachment) Transaction(androidx.room.Transaction)

Aggregations

NoteAttachment (m.co.rh.id.a_medic_log.base.entity.NoteAttachment)7 Transaction (androidx.room.Transaction)4 NoteAttachmentFile (m.co.rh.id.a_medic_log.base.entity.NoteAttachmentFile)3 ArrayList (java.util.ArrayList)2 Medicine (m.co.rh.id.a_medic_log.base.entity.Medicine)2 Note (m.co.rh.id.a_medic_log.base.entity.Note)2 NoteAttachmentState (m.co.rh.id.a_medic_log.base.state.NoteAttachmentState)2 MedicineReminder (m.co.rh.id.a_medic_log.base.entity.MedicineReminder)1 NoteTag (m.co.rh.id.a_medic_log.base.entity.NoteTag)1 MedicineState (m.co.rh.id.a_medic_log.base.state.MedicineState)1