Search in sources :

Example 1 with NoteAttachmentState

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

the class NoteAttachmentDetailPage method provideComponent.

@Override
public void provideComponent(Provider provider) {
    mSvProvider = provider.get(StatefulViewProvider.class);
    mExecutorService = mSvProvider.get(ExecutorService.class);
    mRxDisposer = mSvProvider.get(RxDisposer.class);
    mFileHelper = mSvProvider.get(FileHelper.class);
    mLogger = mSvProvider.get(ILogger.class);
    mNewNoteAttachmentFileCmd = mSvProvider.get(NewNoteAttachmentFileCmd.class);
    mDeleteNoteAttachmentFileCmd = mSvProvider.get(DeleteNoteAttachmentFileCmd.class);
    boolean isUpdate = isUpdate();
    if (isUpdate) {
        mNewNoteAttachmentCmd = mSvProvider.get(UpdateNoteAttachmentCmd.class);
    } else {
        mNewNoteAttachmentCmd = mSvProvider.get(NewNoteAttachmentCmd.class);
    }
    if (mAppBarSV == null) {
        mAppBarSV = new AppBarSV(R.menu.page_note_attachment_detail);
    }
    if (mNoteAttachmentState == null) {
        if (isUpdate) {
            mNoteAttachmentState = getNoteAttachmentState();
        } else {
            mNoteAttachmentState = new NoteAttachmentState();
            if (shouldSave()) {
                mNoteAttachmentState.setNoteId(getNoteId());
            }
        }
    }
    mNameTextWatcher = 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 name = editable.toString();
            mNoteAttachmentState.setName(name);
            mNewNoteAttachmentCmd.valid(mNoteAttachmentState);
        }
    };
    mNoteAttachmentFileRecyclerViewAdapter = new NoteAttachmentFileRecyclerViewAdapter(mNoteAttachmentState, this, mNavigator, this);
}
Also used : NoteAttachmentState(m.co.rh.id.a_medic_log.base.state.NoteAttachmentState) AppBarSV(m.co.rh.id.a_medic_log.app.ui.component.AppBarSV) DeleteNoteAttachmentFileCmd(m.co.rh.id.a_medic_log.app.provider.command.DeleteNoteAttachmentFileCmd) NewNoteAttachmentFileCmd(m.co.rh.id.a_medic_log.app.provider.command.NewNoteAttachmentFileCmd) StatefulViewProvider(m.co.rh.id.a_medic_log.app.provider.StatefulViewProvider) RxDisposer(m.co.rh.id.a_medic_log.app.rx.RxDisposer) NoteAttachmentFileRecyclerViewAdapter(m.co.rh.id.a_medic_log.app.ui.component.note.attachment.NoteAttachmentFileRecyclerViewAdapter) FileHelper(m.co.rh.id.a_medic_log.base.provider.FileHelper) UpdateNoteAttachmentCmd(m.co.rh.id.a_medic_log.app.provider.command.UpdateNoteAttachmentCmd) NewNoteAttachmentCmd(m.co.rh.id.a_medic_log.app.provider.command.NewNoteAttachmentCmd) ExecutorService(java.util.concurrent.ExecutorService) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) ILogger(m.co.rh.id.alogger.ILogger)

Example 2 with NoteAttachmentState

use of m.co.rh.id.a_medic_log.base.state.NoteAttachmentState 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 3 with NoteAttachmentState

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

the class NoteAttachmentItemSV method onClick.

@Override
public void onClick(View view) {
    int id = view.getId();
    if (id == R.id.button_edit) {
        if (mNoteAttachmentItemOnEditClick != null) {
            mNoteAttachmentItemOnEditClick.noteAttachment_onEditClick(mNoteAttachmentStateSubject.getValue());
        }
    } else if (id == R.id.button_delete) {
        if (mNoteAttachmentItemOnDeleteClick != null) {
            mNoteAttachmentItemOnDeleteClick.noteAttachment_onDeleteClick(mNoteAttachmentStateSubject.getValue());
        }
    } else if (id == R.id.button_share) {
        Activity activity = mNavigator.getActivity();
        NoteAttachmentState noteAttachmentState = mNoteAttachmentStateSubject.getValue();
        String text = noteAttachmentState.getName();
        ArrayList<NoteAttachmentFile> attachmentFiles = noteAttachmentState.getNoteAttachmentFiles();
        ArrayList<Uri> imageUris = new ArrayList<>();
        if (!attachmentFiles.isEmpty()) {
            for (NoteAttachmentFile noteAttachmentFile : attachmentFiles) {
                Uri fileUri = FileProvider.getUriForFile(activity, Constants.FILE_PROVIDER_AUTHORITY, mFileHelper.getNoteAttachmentImage(noteAttachmentFile.fileName));
                imageUris.add(fileUri);
            }
        }
        Intent sendIntent = new Intent();
        sendIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
        sendIntent.putExtra(Intent.EXTRA_TEXT, text);
        sendIntent.setType("image/*");
        sendIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUris);
        Intent shareIntent = Intent.createChooser(sendIntent, null);
        activity.startActivity(shareIntent);
    }
}
Also used : NoteAttachmentState(m.co.rh.id.a_medic_log.base.state.NoteAttachmentState) ArrayList(java.util.ArrayList) Activity(android.app.Activity) NoteAttachmentFile(m.co.rh.id.a_medic_log.base.entity.NoteAttachmentFile) Intent(android.content.Intent) Uri(android.net.Uri)

Example 4 with NoteAttachmentState

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

the class NoteAttachmentItemSV method createView.

@Override
protected View createView(Activity activity, ViewGroup container) {
    ViewGroup rootLayout = (ViewGroup) activity.getLayoutInflater().inflate(R.layout.item_note_attachment, container, false);
    rootLayout.setOnClickListener(this);
    Button buttonShare = rootLayout.findViewById(R.id.button_share);
    Button buttonEdit = rootLayout.findViewById(R.id.button_edit);
    Button buttonDelete = rootLayout.findViewById(R.id.button_delete);
    buttonEdit.setOnClickListener(this);
    buttonDelete.setOnClickListener(this);
    buttonShare.setOnClickListener(this);
    TextView nameText = rootLayout.findViewById(R.id.text_name);
    RecyclerView noteAttachmentFileRecyclerView = rootLayout.findViewById(R.id.recyclerView_note_attachment_file);
    mRxDisposer.add("createView_onNoteAttachmentChanged", mNoteAttachmentStateSubject.getSubject().observeOn(AndroidSchedulers.mainThread()).subscribe(noteAttachmentState -> {
        int size = noteAttachmentState.getNoteAttachmentFiles().size();
        nameText.setText(noteAttachmentState.getName() + " (" + size + ") ");
        if (mNoteAttachmentFileRecyclerViewAdapter != null) {
            noteAttachmentFileRecyclerView.setAdapter(null);
            mNoteAttachmentFileRecyclerViewAdapter.dispose(activity);
        }
        if (!noteAttachmentState.getNoteAttachmentFiles().isEmpty()) {
            mNoteAttachmentFileRecyclerViewAdapter = new NoteAttachmentFileRecyclerViewAdapter(getNoteAttachmentState(), null, true, mNavigator, this);
            noteAttachmentFileRecyclerView.setAdapter(mNoteAttachmentFileRecyclerViewAdapter);
            noteAttachmentFileRecyclerView.setVisibility(View.VISIBLE);
        } else {
            noteAttachmentFileRecyclerView.setVisibility(View.GONE);
        }
    }));
    return rootLayout;
}
Also used : FileHelper(m.co.rh.id.a_medic_log.base.provider.FileHelper) SerialBehaviorSubject(m.co.rh.id.a_medic_log.base.rx.SerialBehaviorSubject) StatefulView(m.co.rh.id.anavigator.StatefulView) NoteAttachmentFile(m.co.rh.id.a_medic_log.base.entity.NoteAttachmentFile) Provider(m.co.rh.id.aprovider.Provider) NoteAttachmentState(m.co.rh.id.a_medic_log.base.state.NoteAttachmentState) Uri(android.net.Uri) Intent(android.content.Intent) ViewGroup(android.view.ViewGroup) ArrayList(java.util.ArrayList) 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) Constants(m.co.rh.id.a_medic_log.app.constants.Constants) RxDisposer(m.co.rh.id.a_medic_log.app.rx.RxDisposer) FileProvider(androidx.core.content.FileProvider) View(android.view.View) Button(android.widget.Button) R(m.co.rh.id.a_medic_log.R) RequireNavigator(m.co.rh.id.anavigator.component.RequireNavigator) RecyclerView(androidx.recyclerview.widget.RecyclerView) INavigator(m.co.rh.id.anavigator.component.INavigator) Activity(android.app.Activity) Button(android.widget.Button) ViewGroup(android.view.ViewGroup) TextView(android.widget.TextView) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 5 with NoteAttachmentState

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

the class NoteAttachmentRecyclerViewAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
    if (holder instanceof ItemViewHolder) {
        ArrayList<NoteAttachmentState> itemArrayList = mNoteState.getNoteAttachmentStates();
        NoteAttachmentState item = itemArrayList.get(position);
        ItemViewHolder itemViewHolder = (ItemViewHolder) holder;
        itemViewHolder.setItem(item);
    }
}
Also used : NoteAttachmentState(m.co.rh.id.a_medic_log.base.state.NoteAttachmentState)

Aggregations

NoteAttachmentState (m.co.rh.id.a_medic_log.base.state.NoteAttachmentState)6 ArrayList (java.util.ArrayList)3 NoteAttachmentFile (m.co.rh.id.a_medic_log.base.entity.NoteAttachmentFile)3 Activity (android.app.Activity)2 Intent (android.content.Intent)2 Uri (android.net.Uri)2 StatefulViewProvider (m.co.rh.id.a_medic_log.app.provider.StatefulViewProvider)2 RxDisposer (m.co.rh.id.a_medic_log.app.rx.RxDisposer)2 NoteAttachment (m.co.rh.id.a_medic_log.base.entity.NoteAttachment)2 FileHelper (m.co.rh.id.a_medic_log.base.provider.FileHelper)2 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 Button (android.widget.Button)1 TextView (android.widget.TextView)1 FileProvider (androidx.core.content.FileProvider)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 Transaction (androidx.room.Transaction)1 AndroidSchedulers (io.reactivex.rxjava3.android.schedulers.AndroidSchedulers)1