Search in sources :

Example 1 with SuggestionAdapter

use of m.co.rh.id.a_medic_log.app.ui.component.adapter.SuggestionAdapter in project a-medic-log by rh-id.

the class MedicineIntakeDetailPage method createView.

@Override
protected View createView(Activity activity, ViewGroup container) {
    View rootLayout = activity.getLayoutInflater().inflate(R.layout.page_medicine_intake_detail, container, false);
    ViewGroup containerAppBar = rootLayout.findViewById(R.id.container_app_bar);
    containerAppBar.addView(mAppBarSv.buildView(activity, container));
    EditText inputTakenDateTime = rootLayout.findViewById(R.id.input_text_taken_date_time);
    inputTakenDateTime.setOnClickListener(this);
    inputTakenDateTime.addTextChangedListener(mTakenDateTimeTextWatcher);
    mSuggestionAdapter = new SuggestionAdapter(activity, android.R.layout.select_dialog_item, mSuggestionQuery);
    AutoCompleteTextView inputDescription = rootLayout.findViewById(R.id.input_text_description);
    inputDescription.addTextChangedListener(mDescriptionTextWatcher);
    inputDescription.setThreshold(1);
    inputDescription.setAdapter(mSuggestionAdapter);
    mRxDisposer.add("createView_onMedicineIntakeUpdated", mMedicineIntakeSubject.getSubject().observeOn(AndroidSchedulers.mainThread()).subscribe(medicineReminder -> {
        if (medicineReminder.takenDateTime != null) {
            inputTakenDateTime.setText(mDateFormat.format(medicineReminder.takenDateTime));
        } else {
            inputTakenDateTime.setText(null);
        }
        inputDescription.setText(medicineReminder.description);
    }));
    mRxDisposer.add("createView_onTakenDateTimeValidated", mNewMedicineIntakeCmd.getTakenDateTimeValid().observeOn(AndroidSchedulers.mainThread()).subscribe(s -> {
        if (s != null && !s.isEmpty()) {
            inputDescription.setError(s);
        } else {
            inputDescription.setError(null);
        }
    }));
    mRxDisposer.add("createView_onInputDescriptionValidated", mNewMedicineIntakeCmd.getDescriptionValid().observeOn(AndroidSchedulers.mainThread()).subscribe(s -> {
        if (s != null && !s.isEmpty()) {
            inputDescription.setError(s);
        } else {
            inputDescription.setError(null);
        }
    }));
    return rootLayout;
}
Also used : EditText(android.widget.EditText) Context(android.content.Context) Date(java.util.Date) MedicineIntake(m.co.rh.id.a_medic_log.base.entity.MedicineIntake) ILogger(m.co.rh.id.alogger.ILogger) SimpleDateFormat(java.text.SimpleDateFormat) AppBarSV(m.co.rh.id.a_medic_log.app.ui.component.AppBarSV) Function(java.util.function.Function) UpdateMedicineIntakeCmd(m.co.rh.id.a_medic_log.app.provider.command.UpdateMedicineIntakeCmd) Editable(android.text.Editable) MenuItem(android.view.MenuItem) NavInject(m.co.rh.id.anavigator.annotation.NavInject) NavRoute(m.co.rh.id.anavigator.NavRoute) SuggestionAdapter(m.co.rh.id.a_medic_log.app.ui.component.adapter.SuggestionAdapter) View(android.view.View) RequireNavigator(m.co.rh.id.anavigator.component.RequireNavigator) INavigator(m.co.rh.id.anavigator.component.INavigator) QueryMedicineCmd(m.co.rh.id.a_medic_log.app.provider.command.QueryMedicineCmd) 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) Collection(java.util.Collection) RequireNavRoute(m.co.rh.id.anavigator.component.RequireNavRoute) NavExtDialogConfig(m.co.rh.id.anavigator.extension.dialog.ui.NavExtDialogConfig) ViewGroup(android.view.ViewGroup) AutoCompleteTextView(android.widget.AutoCompleteTextView) Serializable(java.io.Serializable) ArrayAdapter(android.widget.ArrayAdapter) AndroidSchedulers(io.reactivex.rxjava3.android.schedulers.AndroidSchedulers) 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) Toolbar(androidx.appcompat.widget.Toolbar) R(m.co.rh.id.a_medic_log.R) NewMedicineIntakeCmd(m.co.rh.id.a_medic_log.app.provider.command.NewMedicineIntakeCmd) Activity(android.app.Activity) EditText(android.widget.EditText) TextWatcher(android.text.TextWatcher) ViewGroup(android.view.ViewGroup) SuggestionAdapter(m.co.rh.id.a_medic_log.app.ui.component.adapter.SuggestionAdapter) View(android.view.View) StatefulView(m.co.rh.id.anavigator.StatefulView) AutoCompleteTextView(android.widget.AutoCompleteTextView) AutoCompleteTextView(android.widget.AutoCompleteTextView)

Example 2 with SuggestionAdapter

use of m.co.rh.id.a_medic_log.app.ui.component.adapter.SuggestionAdapter in project a-medic-log by rh-id.

the class MedicineDetailPage method createView.

@Override
protected View createView(Activity activity, ViewGroup container) {
    View rootLayout = activity.getLayoutInflater().inflate(R.layout.page_medicine_detail, container, false);
    ViewGroup containerAppBar = rootLayout.findViewById(R.id.container_app_bar);
    containerAppBar.addView(mAppBarSv.buildView(activity, container));
    mSuggestionAdapter = new SuggestionAdapter(activity, android.R.layout.select_dialog_item, mSuggestionQuery);
    AutoCompleteTextView inputName = rootLayout.findViewById(R.id.input_text_name);
    inputName.addTextChangedListener(mNameTextWatcher);
    inputName.setThreshold(1);
    inputName.setAdapter(mSuggestionAdapter);
    EditText inputDescription = rootLayout.findViewById(R.id.input_text_description);
    inputDescription.addTextChangedListener(mDescriptionTextWatcher);
    Button addMedicineReminderButton = rootLayout.findViewById(R.id.button_add_medicine_reminder);
    addMedicineReminderButton.setOnClickListener(this);
    RecyclerView medicineReminderRecyclerView = rootLayout.findViewById(R.id.recyclerView_medicine_reminder);
    medicineReminderRecyclerView.addItemDecoration(new DividerItemDecoration(activity, DividerItemDecoration.VERTICAL));
    medicineReminderRecyclerView.setAdapter(mMedicineReminderRecyclerViewAdapter);
    mRxDisposer.add("createView_onMedicineChanged", mMedicineState.getMedicineFlow().observeOn(AndroidSchedulers.mainThread()).subscribe(medicine -> {
        inputName.setText(medicine.name);
        inputDescription.setText(medicine.description);
    }));
    mRxDisposer.add("createView_onInputNameValidated", mNewMedicineCmd.getNameValid().observeOn(AndroidSchedulers.mainThread()).subscribe(s -> {
        if (s != null && !s.isEmpty()) {
            inputName.setError(s);
        } else {
            inputName.setError(null);
        }
    }));
    mRxDisposer.add("createView_onMedicineReminderListChanged", mMedicineState.getMedicineReminderListFlow().observeOn(AndroidSchedulers.mainThread()).subscribe(medicineReminders -> mMedicineReminderRecyclerViewAdapter.notifyItemRefreshed()));
    mRxDisposer.add("createView_onMedicineReminderAdded", mMedicineReminderChangeNotifier.getAddedMedicineReminder().observeOn(Schedulers.from(mExecutorService)).subscribe(medicineReminder -> {
        if (isUpdate() && shouldSave()) {
            mMedicineState.addMedicineReminder(medicineReminder);
        }
    }));
    mRxDisposer.add("createView_onMedicineReminderUpdated", mMedicineReminderChangeNotifier.getUpdatedMedicineReminder().observeOn(Schedulers.from(mExecutorService)).subscribe(updateMedicineReminderEvent -> {
        if (isUpdate() && shouldSave()) {
            mMedicineState.updateMedicineReminder(updateMedicineReminderEvent.getAfter());
        }
    }));
    mRxDisposer.add("createView_onMedicineReminderDeleted", mMedicineReminderChangeNotifier.getDeletedMedicineReminder().observeOn(Schedulers.from(mExecutorService)).subscribe(medicineReminder -> {
        if (isUpdate() && shouldSave()) {
            mMedicineState.deleteMedicineReminder(medicineReminder);
        }
    }));
    return rootLayout;
}
Also used : EditText(android.widget.EditText) DividerItemDecoration(androidx.recyclerview.widget.DividerItemDecoration) Context(android.content.Context) NewMedicineCmd(m.co.rh.id.a_medic_log.app.provider.command.NewMedicineCmd) MedicineReminderChangeNotifier(m.co.rh.id.a_medic_log.app.provider.notifier.MedicineReminderChangeNotifier) ILogger(m.co.rh.id.alogger.ILogger) AppBarSV(m.co.rh.id.a_medic_log.app.ui.component.AppBarSV) Function(java.util.function.Function) Editable(android.text.Editable) MedicineReminder(m.co.rh.id.a_medic_log.base.entity.MedicineReminder) 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) SuggestionAdapter(m.co.rh.id.a_medic_log.app.ui.component.adapter.SuggestionAdapter) View(android.view.View) Button(android.widget.Button) RequireNavigator(m.co.rh.id.anavigator.component.RequireNavigator) UpdateMedicineReminderCmd(m.co.rh.id.a_medic_log.app.provider.command.UpdateMedicineReminderCmd) RecyclerView(androidx.recyclerview.widget.RecyclerView) INavigator(m.co.rh.id.anavigator.component.INavigator) QueryMedicineCmd(m.co.rh.id.a_medic_log.app.provider.command.QueryMedicineCmd) ExecutorService(java.util.concurrent.ExecutorService) DeleteMedicineReminderCmd(m.co.rh.id.a_medic_log.app.provider.command.DeleteMedicineReminderCmd) MedicineReminderRecyclerViewAdapter(m.co.rh.id.a_medic_log.app.ui.component.medicine.reminder.MedicineReminderRecyclerViewAdapter) UpdateMedicineCmd(m.co.rh.id.a_medic_log.app.provider.command.UpdateMedicineCmd) StatefulView(m.co.rh.id.anavigator.StatefulView) Provider(m.co.rh.id.aprovider.Provider) MedicineState(m.co.rh.id.a_medic_log.base.state.MedicineState) Collection(java.util.Collection) RequireNavRoute(m.co.rh.id.anavigator.component.RequireNavRoute) Routes(m.co.rh.id.a_medic_log.app.constants.Routes) MedicineReminderItemSV(m.co.rh.id.a_medic_log.app.ui.component.medicine.reminder.MedicineReminderItemSV) NavExtDialogConfig(m.co.rh.id.anavigator.extension.dialog.ui.NavExtDialogConfig) ViewGroup(android.view.ViewGroup) AutoCompleteTextView(android.widget.AutoCompleteTextView) Serializable(java.io.Serializable) ArrayAdapter(android.widget.ArrayAdapter) AndroidSchedulers(io.reactivex.rxjava3.android.schedulers.AndroidSchedulers) 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) Toolbar(androidx.appcompat.widget.Toolbar) R(m.co.rh.id.a_medic_log.R) Activity(android.app.Activity) EditText(android.widget.EditText) TextWatcher(android.text.TextWatcher) Button(android.widget.Button) ViewGroup(android.view.ViewGroup) SuggestionAdapter(m.co.rh.id.a_medic_log.app.ui.component.adapter.SuggestionAdapter) RecyclerView(androidx.recyclerview.widget.RecyclerView) DividerItemDecoration(androidx.recyclerview.widget.DividerItemDecoration) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) StatefulView(m.co.rh.id.anavigator.StatefulView) AutoCompleteTextView(android.widget.AutoCompleteTextView) AutoCompleteTextView(android.widget.AutoCompleteTextView)

Example 3 with SuggestionAdapter

use of m.co.rh.id.a_medic_log.app.ui.component.adapter.SuggestionAdapter in project a-medic-log by rh-id.

the class NoteTagDetailSVDialog method createView.

@Override
protected View createView(Activity activity, ViewGroup container) {
    View rootLayout = activity.getLayoutInflater().inflate(R.layout.dialog_note_tag_detail, container, false);
    AutoCompleteTextView tagTextInput = rootLayout.findViewById(R.id.input_text_tag);
    tagTextInput.addTextChangedListener(mTagTextWatcher);
    tagTextInput.setThreshold(1);
    tagTextInput.setAdapter(new SuggestionAdapter(activity, android.R.layout.select_dialog_item, mSuggestionQuery));
    Button okButton = rootLayout.findViewById(R.id.button_ok);
    okButton.setOnClickListener(this);
    Button cancelButton = rootLayout.findViewById(R.id.button_cancel);
    cancelButton.setOnClickListener(this);
    mRxDisposer.add("createView_onTagValid", mNewNoteTagCmd.getTagValid().observeOn(AndroidSchedulers.mainThread()).subscribe(s -> {
        if (!s.isEmpty()) {
            tagTextInput.setError(s);
        } else {
            tagTextInput.setError(null);
        }
    }));
    return rootLayout;
}
Also used : Context(android.content.Context) ILogger(m.co.rh.id.alogger.ILogger) QueryNoteCmd(m.co.rh.id.a_medic_log.app.provider.command.QueryNoteCmd) Function(java.util.function.Function) Editable(android.text.Editable) NavRoute(m.co.rh.id.anavigator.NavRoute) SuggestionAdapter(m.co.rh.id.a_medic_log.app.ui.component.adapter.SuggestionAdapter) View(android.view.View) Button(android.widget.Button) StatefulViewDialog(m.co.rh.id.anavigator.StatefulViewDialog) NewNoteTagCmd(m.co.rh.id.a_medic_log.app.provider.command.NewNoteTagCmd) SerialBehaviorSubject(m.co.rh.id.a_medic_log.base.rx.SerialBehaviorSubject) Provider(m.co.rh.id.aprovider.Provider) Collection(java.util.Collection) RequireNavRoute(m.co.rh.id.anavigator.component.RequireNavRoute) ViewGroup(android.view.ViewGroup) AutoCompleteTextView(android.widget.AutoCompleteTextView) Serializable(java.io.Serializable) AndroidSchedulers(io.reactivex.rxjava3.android.schedulers.AndroidSchedulers) 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) R(m.co.rh.id.a_medic_log.R) NoteTag(m.co.rh.id.a_medic_log.base.entity.NoteTag) Activity(android.app.Activity) TextWatcher(android.text.TextWatcher) Button(android.widget.Button) SuggestionAdapter(m.co.rh.id.a_medic_log.app.ui.component.adapter.SuggestionAdapter) View(android.view.View) AutoCompleteTextView(android.widget.AutoCompleteTextView) AutoCompleteTextView(android.widget.AutoCompleteTextView)

Aggregations

Activity (android.app.Activity)3 Context (android.content.Context)3 Editable (android.text.Editable)3 TextWatcher (android.text.TextWatcher)3 View (android.view.View)3 ViewGroup (android.view.ViewGroup)3 AutoCompleteTextView (android.widget.AutoCompleteTextView)3 AndroidSchedulers (io.reactivex.rxjava3.android.schedulers.AndroidSchedulers)3 Serializable (java.io.Serializable)3 Collection (java.util.Collection)3 Function (java.util.function.Function)3 R (m.co.rh.id.a_medic_log.R)3 StatefulViewProvider (m.co.rh.id.a_medic_log.app.provider.StatefulViewProvider)3 RxDisposer (m.co.rh.id.a_medic_log.app.rx.RxDisposer)3 SuggestionAdapter (m.co.rh.id.a_medic_log.app.ui.component.adapter.SuggestionAdapter)3 ILogger (m.co.rh.id.alogger.ILogger)3 NavRoute (m.co.rh.id.anavigator.NavRoute)3 RequireComponent (m.co.rh.id.anavigator.component.RequireComponent)3 RequireNavRoute (m.co.rh.id.anavigator.component.RequireNavRoute)3 Provider (m.co.rh.id.aprovider.Provider)3