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;
}
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;
}
Aggregations