Search in sources :

Example 6 with MedicineReminder

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

the class MedicineDao method updateMedicine.

@Transaction
public void updateMedicine(Medicine medicine, ArrayList<MedicineReminder> medicineReminders) {
    update(medicine);
    long medsId = medicine.id;
    if (medicineReminders != null && !medicineReminders.isEmpty()) {
        for (MedicineReminder medicineReminder : medicineReminders) {
            medicineReminder.medicineId = medsId;
            if (medicineReminder.id == null) {
                insertMedicineReminder(medicineReminder);
            } else {
                update(medicineReminder);
            }
        }
    }
}
Also used : MedicineReminder(m.co.rh.id.a_medic_log.base.entity.MedicineReminder) Transaction(androidx.room.Transaction)

Example 7 with MedicineReminder

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

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

the class MedicineState method readObject.

@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    Medicine medicine = (Medicine) in.readObject();
    ArrayList<MedicineReminder> medicineReminders = (ArrayList<MedicineReminder>) in.readObject();
    mMedicineSubject = BehaviorSubject.createDefault(medicine);
    mMedicineReminderListSubject = BehaviorSubject.createDefault(medicineReminders);
}
Also used : Medicine(m.co.rh.id.a_medic_log.base.entity.Medicine) ArrayList(java.util.ArrayList) MedicineReminder(m.co.rh.id.a_medic_log.base.entity.MedicineReminder)

Example 9 with MedicineReminder

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

the class MedicineState method clone.

@Override
public MedicineState clone() {
    MedicineState medicineState = new MedicineState();
    Medicine medicine = mMedicineSubject.getValue();
    if (medicine != null) {
        medicine = medicine.clone();
    }
    medicineState.updateMedicine(medicine);
    ArrayList<MedicineReminder> medicineReminders = mMedicineReminderListSubject.getValue();
    if (medicineReminders != null) {
        ArrayList<MedicineReminder> clonedList = new ArrayList<>(medicineReminders.size());
        for (MedicineReminder medicineReminder : medicineReminders) {
            clonedList.add(medicineReminder.clone());
        }
        medicineReminders = clonedList;
    } else {
        medicineReminders = new ArrayList<>();
    }
    medicineState.updateMedicineReminderList(medicineReminders);
    return medicineState;
}
Also used : Medicine(m.co.rh.id.a_medic_log.base.entity.Medicine) ArrayList(java.util.ArrayList) MedicineReminder(m.co.rh.id.a_medic_log.base.entity.MedicineReminder)

Example 10 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 createView.

@Override
protected View createView(Activity activity, ViewGroup container) {
    View rootLayout = activity.getLayoutInflater().inflate(R.layout.item_medicine_reminder, container, false);
    rootLayout.findViewById(R.id.root_layout).setOnClickListener(this);
    TextView startDateText = rootLayout.findViewById(R.id.text_start_date);
    TextView messageText = rootLayout.findViewById(R.id.text_message);
    SwitchCompat enabledButton = rootLayout.findViewById(R.id.button_enabled);
    enabledButton.setOnClickListener(this);
    Button deleteButton = rootLayout.findViewById(R.id.button_delete);
    deleteButton.setOnClickListener(this);
    mSvProvider.get(RxDisposer.class).add("createView_onMedicineReminderChanged", mMedicineReminderSubject.getSubject().observeOn(AndroidSchedulers.mainThread()).subscribe(medicineReminder -> {
        startDateText.setText(mDateFormat.format(medicineReminder.startDateTime));
        messageText.setText(medicineReminder.message);
        enabledButton.setChecked(medicineReminder.reminderEnabled);
    }));
    return rootLayout;
}
Also used : SerialBehaviorSubject(m.co.rh.id.a_medic_log.base.rx.SerialBehaviorSubject) StatefulView(m.co.rh.id.anavigator.StatefulView) SwitchCompat(androidx.appcompat.widget.SwitchCompat) Provider(m.co.rh.id.aprovider.Provider) SimpleDateFormat(java.text.SimpleDateFormat) ViewGroup(android.view.ViewGroup) MedicineReminder(m.co.rh.id.a_medic_log.base.entity.MedicineReminder) 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) View(android.view.View) Button(android.widget.Button) R(m.co.rh.id.a_medic_log.R) Activity(android.app.Activity) DateFormat(java.text.DateFormat) Button(android.widget.Button) TextView(android.widget.TextView) StatefulView(m.co.rh.id.anavigator.StatefulView) TextView(android.widget.TextView) View(android.view.View) RxDisposer(m.co.rh.id.a_medic_log.app.rx.RxDisposer) SwitchCompat(androidx.appcompat.widget.SwitchCompat)

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