Search in sources :

Example 6 with NoteTag

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

the class NoteItemSV method createView.

@Override
protected View createView(Activity activity, ViewGroup container) {
    ViewGroup rootLayout = (ViewGroup) activity.getLayoutInflater().inflate(R.layout.item_note, container, false);
    rootLayout.setOnClickListener(this);
    Button buttonEdit = rootLayout.findViewById(R.id.button_edit);
    Button buttonDelete = rootLayout.findViewById(R.id.button_delete);
    buttonEdit.setOnClickListener(this);
    buttonDelete.setOnClickListener(this);
    TextView textEntryDate = rootLayout.findViewById(R.id.text_entry_date);
    TextView textContent = rootLayout.findViewById(R.id.text_content);
    ChipGroup noteTagChipGroup = rootLayout.findViewById(R.id.chip_group_note_tag);
    mRxDisposer.add("crateView_onNoteTagSetChanged", mNoteTagSetSubject.getSubject().observeOn(AndroidSchedulers.mainThread()).subscribe(noteTags -> {
        noteTagChipGroup.removeAllViews();
        if (!noteTags.isEmpty()) {
            for (NoteTag noteTag : noteTags) {
                Chip chip = new Chip(activity);
                chip.setText(noteTag.tag);
                chip.setClickable(false);
                noteTagChipGroup.addView(chip);
            }
            noteTagChipGroup.setVisibility(View.VISIBLE);
        } else {
            noteTagChipGroup.setVisibility(View.GONE);
        }
    }));
    mRxDisposer.add("createView_onNoteChanged", mNoteSubject.getSubject().observeOn(AndroidSchedulers.mainThread()).subscribe(note -> {
        textEntryDate.setText(mDateFormat.format(note.entryDateTime));
        textContent.setText(note.content);
        if (note.id != null) {
            refreshNoteTagSet(note.id);
        }
    }));
    mRxDisposer.add("createView_onNoteTagAdded", mNoteTagChangeNotifier.getAddedNoteTag().observeOn(AndroidSchedulers.mainThread()).subscribe(noteTag -> {
        Note note = mNoteSubject.getValue();
        if (noteTag.noteId.equals(note.id)) {
            TreeSet<NoteTag> noteTagTreeSet = mNoteTagSetSubject.getValue();
            if (noteTagTreeSet.add(noteTag)) {
                mNoteTagSetSubject.onNext(noteTagTreeSet);
            }
        }
    }));
    mRxDisposer.add("createView_onNoteTagDeleted", mNoteTagChangeNotifier.getDeletedNoteTag().observeOn(AndroidSchedulers.mainThread()).subscribe(noteTag -> {
        Note note = mNoteSubject.getValue();
        if (noteTag.noteId.equals(note.id)) {
            TreeSet<NoteTag> noteTagTreeSet = mNoteTagSetSubject.getValue();
            if (noteTagTreeSet.remove(noteTag)) {
                mNoteTagSetSubject.onNext(noteTagTreeSet);
            }
        }
    }));
    return rootLayout;
}
Also used : Context(android.content.Context) Chip(com.google.android.material.chip.Chip) ILogger(m.co.rh.id.alogger.ILogger) ChipGroup(com.google.android.material.chip.ChipGroup) SimpleDateFormat(java.text.SimpleDateFormat) NoteTagChangeNotifier(m.co.rh.id.a_medic_log.app.provider.notifier.NoteTagChangeNotifier) QueryNoteCmd(m.co.rh.id.a_medic_log.app.provider.command.QueryNoteCmd) TreeSet(java.util.TreeSet) NavInject(m.co.rh.id.anavigator.annotation.NavInject) CompositeDisposable(io.reactivex.rxjava3.disposables.CompositeDisposable) Note(m.co.rh.id.a_medic_log.base.entity.Note) View(android.view.View) Button(android.widget.Button) INavigator(m.co.rh.id.anavigator.component.INavigator) DateFormat(java.text.DateFormat) SerialBehaviorSubject(m.co.rh.id.a_medic_log.base.rx.SerialBehaviorSubject) StatefulView(m.co.rh.id.anavigator.StatefulView) Provider(m.co.rh.id.aprovider.Provider) Routes(m.co.rh.id.a_medic_log.app.constants.Routes) NavExtDialogConfig(m.co.rh.id.anavigator.extension.dialog.ui.NavExtDialogConfig) ViewGroup(android.view.ViewGroup) 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) NoteDetailPage(m.co.rh.id.a_medic_log.app.ui.page.NoteDetailPage) R(m.co.rh.id.a_medic_log.R) NoteTag(m.co.rh.id.a_medic_log.base.entity.NoteTag) Activity(android.app.Activity) DeleteNoteCmd(m.co.rh.id.a_medic_log.app.provider.command.DeleteNoteCmd) Button(android.widget.Button) ViewGroup(android.view.ViewGroup) TreeSet(java.util.TreeSet) Note(m.co.rh.id.a_medic_log.base.entity.Note) NoteTag(m.co.rh.id.a_medic_log.base.entity.NoteTag) TextView(android.widget.TextView) Chip(com.google.android.material.chip.Chip) ChipGroup(com.google.android.material.chip.ChipGroup)

Example 7 with NoteTag

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

the class NoteDetailPage method createView.

@Override
protected View createView(Activity activity, ViewGroup container) {
    ViewGroup rootLayout = (ViewGroup) activity.getLayoutInflater().inflate(R.layout.page_note_detail, container, false);
    ViewGroup appBarContainer = rootLayout.findViewById(R.id.container_app_bar);
    appBarContainer.addView(mAppBarSv.buildView(activity, appBarContainer));
    EditText entryDateTimeInput = rootLayout.findViewById(R.id.input_text_entry_date_time);
    entryDateTimeInput.setOnClickListener(this);
    entryDateTimeInput.addTextChangedListener(mEntryDateTimeTextWatcher);
    Button clearEntryDateTimeInput = rootLayout.findViewById(R.id.button_clear_entry_date_time);
    clearEntryDateTimeInput.setOnClickListener(this);
    EditText contentInput = rootLayout.findViewById(R.id.input_text_content);
    contentInput.addTextChangedListener(mContentTextWatcher);
    Button expandNoteTag = rootLayout.findViewById(R.id.button_expand_note_tag);
    expandNoteTag.setOnClickListener(this);
    View noteTagTextContainer = rootLayout.findViewById(R.id.container_note_tag_text);
    noteTagTextContainer.setOnClickListener(this);
    TextView noteTagTitle = rootLayout.findViewById(R.id.text_note_tag_title);
    Button addNoteTagButton = rootLayout.findViewById(R.id.button_add_note_tag);
    addNoteTagButton.setOnClickListener(this);
    ChipGroup noteTagChipGroup = rootLayout.findViewById(R.id.chip_group_note_tag);
    // medicine
    Button shareMedicineButton = rootLayout.findViewById(R.id.button_share_medicine);
    shareMedicineButton.setOnClickListener(this);
    Button addMedicineButton = rootLayout.findViewById(R.id.button_add_medicine);
    addMedicineButton.setOnClickListener(this);
    Button expandMedicine = rootLayout.findViewById(R.id.button_expand_medicine);
    expandMedicine.setOnClickListener(this);
    View medicineTextContainer = rootLayout.findViewById(R.id.container_medicine_text);
    medicineTextContainer.setOnClickListener(this);
    TextView medicineTitle = rootLayout.findViewById(R.id.text_medicine_title);
    RecyclerView medicineRecyclerView = rootLayout.findViewById(R.id.recyclerView_medicine);
    medicineRecyclerView.addItemDecoration(new DividerItemDecoration(activity, DividerItemDecoration.VERTICAL));
    medicineRecyclerView.setAdapter(mMedicineRecyclerViewAdapter);
    // attachment
    Button addAttachmentButton = rootLayout.findViewById(R.id.button_add_attachment);
    addAttachmentButton.setOnClickListener(this);
    Button expandAttachment = rootLayout.findViewById(R.id.button_expand_attachment);
    expandAttachment.setOnClickListener(this);
    View attachmentTextContainer = rootLayout.findViewById(R.id.container_attachment_text);
    attachmentTextContainer.setOnClickListener(this);
    TextView attachmentTitle = rootLayout.findViewById(R.id.text_attachment_title);
    RecyclerView attachmentRecyclerView = rootLayout.findViewById(R.id.recyclerView_attachment);
    attachmentRecyclerView.addItemDecoration(new DividerItemDecoration(activity, DividerItemDecoration.VERTICAL));
    attachmentRecyclerView.setAdapter(mNoteAttachmentRecyclerViewAdapter);
    mRxDisposer.add("createView_onNoteChanged", mNoteState.getNoteFlow().observeOn(AndroidSchedulers.mainThread()).subscribe(note -> {
        entryDateTimeInput.setText(mNoteState.getNoteEntryDateTimeDisplay());
        contentInput.setText(mNoteState.getNoteContent());
    }));
    mRxDisposer.add("createView_onNoteTagChanged", mNoteState.getNoteTagSetFlow().observeOn(AndroidSchedulers.mainThread()).subscribe(noteTags -> {
        noteTagTitle.setText(activity.getString(R.string.title_tag, noteTags.size()));
        noteTagChipGroup.removeAllViews();
        if (!noteTags.isEmpty()) {
            boolean isUpdate = isUpdate();
            for (NoteTag noteTag : noteTags) {
                Chip chip = new Chip(activity);
                chip.setText(noteTag.tag);
                chip.setOnCloseIconClickListener(view -> {
                    noteTagChipGroup.removeView(chip);
                    chip.setOnCloseIconClickListener(null);
                    TreeSet<NoteTag> noteTagSet = mNoteState.getNoteTagSet();
                    noteTagSet.remove(noteTag);
                    noteTagTitle.setText(activity.getString(R.string.title_tag, noteTagSet.size()));
                    if (isUpdate && noteTag.id != null) {
                        Context context = activity.getApplicationContext();
                        mCompositeDisposable.add(mDeleteNoteTagCmd.execute(noteTag).observeOn(AndroidSchedulers.mainThread()).subscribe((deletedNoteTag, throwable) -> {
                            String errorMessage = context.getString(R.string.error_failed_to_delete_note_tag);
                            String successMessage = context.getString(R.string.success_deleting_note_tag);
                            if (throwable != null) {
                                mLogger.e(TAG, errorMessage, throwable);
                            } else {
                                mLogger.i(TAG, successMessage);
                            }
                        }));
                    }
                });
                chip.setCloseIconVisible(true);
                noteTagChipGroup.addView(chip);
            }
        }
    }));
    mRxDisposer.add("createView_onNoteTagShow", mNoteTagShow.getSubject().observeOn(AndroidSchedulers.mainThread()).subscribe(aBoolean -> {
        if (aBoolean) {
            noteTagChipGroup.setVisibility(View.VISIBLE);
        } else {
            noteTagChipGroup.setVisibility(View.GONE);
        }
        expandNoteTag.setActivated(aBoolean);
    }));
    mRxDisposer.add("createView_onMedicineListShow", mMedicineListShow.getSubject().observeOn(AndroidSchedulers.mainThread()).subscribe(aBoolean -> {
        if (aBoolean) {
            medicineRecyclerView.setVisibility(View.VISIBLE);
        } else {
            medicineRecyclerView.setVisibility(View.GONE);
        }
        expandMedicine.setActivated(aBoolean);
    }));
    mRxDisposer.add("createView_onMedicineChanged", mNoteState.getMedicineListFlow().observeOn(AndroidSchedulers.mainThread()).subscribe(medicineStates -> {
        int size = medicineStates.size();
        medicineTitle.setText(activity.getString(R.string.title_medicine, size));
        if (size > 0) {
            shareMedicineButton.setVisibility(View.VISIBLE);
        } else {
            shareMedicineButton.setVisibility(View.GONE);
        }
        mMedicineRecyclerViewAdapter.notifyItemRefreshed();
    }));
    mRxDisposer.add("createView_onAttachmentChanged", mNoteState.getNoteAttachmentStatesFlow().observeOn(AndroidSchedulers.mainThread()).subscribe(noteAttachmentStates -> {
        attachmentTitle.setText(activity.getString(R.string.title_attachment, noteAttachmentStates.size()));
        mNoteAttachmentRecyclerViewAdapter.notifyItemRefreshed();
    }));
    mRxDisposer.add("createView_onAttachmentShow", mAttachmentShow.getSubject().observeOn(AndroidSchedulers.mainThread()).subscribe(aBoolean -> {
        if (aBoolean) {
            attachmentRecyclerView.setVisibility(View.VISIBLE);
        } else {
            attachmentRecyclerView.setVisibility(View.GONE);
        }
        expandAttachment.setActivated(aBoolean);
    }));
    mRxDisposer.add("createView_onEntryDateTimeValidation", mNewNoteCmd.getEntryDateTimeValid().observeOn(AndroidSchedulers.mainThread()).subscribe(error -> {
        if (error != null && !error.isEmpty()) {
            entryDateTimeInput.setError(error);
        } else {
            entryDateTimeInput.setError(null);
        }
    }));
    mRxDisposer.add("createView_onContentValidation", mNewNoteCmd.getContentValid().observeOn(AndroidSchedulers.mainThread()).subscribe(error -> {
        if (error != null && !error.isEmpty()) {
            contentInput.setError(error);
        } else {
            contentInput.setError(null);
        }
    }));
    mRxDisposer.add("createView_onNoteAttachmentFileAdded", mNoteAttachmentFileChangeNotifier.getAddedNoteAttachmentFile().observeOn(Schedulers.from(mExecutorService)).subscribe(noteAttachmentFile -> {
        if (isUpdate()) {
            mQueryNoteCmd.queryNoteAttachmentInfo(mNoteState);
        }
    }));
    mRxDisposer.add("createView_onNoteAttachmentFileDeleted", mNoteAttachmentFileChangeNotifier.getDeletedNoteAttachmentFile().observeOn(Schedulers.from(mExecutorService)).subscribe(noteAttachmentFile -> {
        if (isUpdate()) {
            mQueryNoteCmd.queryNoteAttachmentInfo(mNoteState);
        }
    }));
    mRxDisposer.add("createView_onMedicineReminderAdded", mMedicineReminderChangeNotifier.getAddedMedicineReminder().observeOn(Schedulers.from(mExecutorService)).subscribe(medicineReminder -> {
        if (isUpdate()) {
            mQueryNoteCmd.queryMedicineInfo(mNoteState);
        }
    }));
    mRxDisposer.add("createView_onMedicineReminderUpdated", mMedicineReminderChangeNotifier.getUpdatedMedicineReminder().observeOn(Schedulers.from(mExecutorService)).subscribe(medicineReminder -> {
        if (isUpdate()) {
            mQueryNoteCmd.queryMedicineInfo(mNoteState);
        }
    }));
    mRxDisposer.add("createView_onMedicineReminderDeleted", mMedicineReminderChangeNotifier.getDeletedMedicineReminder().observeOn(Schedulers.from(mExecutorService)).subscribe(medicineReminder -> {
        if (isUpdate()) {
            mQueryNoteCmd.queryMedicineInfo(mNoteState);
        }
    }));
    return rootLayout;
}
Also used : EditText(android.widget.EditText) 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) Context(android.content.Context) ViewGroup(android.view.ViewGroup) NoteTag(m.co.rh.id.a_medic_log.base.entity.NoteTag) DividerItemDecoration(androidx.recyclerview.widget.DividerItemDecoration) Chip(com.google.android.material.chip.Chip) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) StatefulView(m.co.rh.id.anavigator.StatefulView) TextView(android.widget.TextView) Button(android.widget.Button) TreeSet(java.util.TreeSet) TextView(android.widget.TextView) RecyclerView(androidx.recyclerview.widget.RecyclerView) ChipGroup(com.google.android.material.chip.ChipGroup)

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