Search in sources :

Example 1 with Provider

use of m.co.rh.id.aprovider.Provider in project a-medic-log by rh-id.

the class NoteDetailPage method noteAttachment_onDeleteClick.

@Override
public void noteAttachment_onDeleteClick(NoteAttachmentState noteAttachmentState) {
    if (isUpdate()) {
        Context context = mSvProvider.getContext();
        String title = context.getString(R.string.title_confirm);
        String content = context.getString(R.string.confirm_delete_attachment);
        NavExtDialogConfig navExtDialogConfig = mSvProvider.get(NavExtDialogConfig.class);
        mNavigator.push(navExtDialogConfig.route_confirmDialog(), navExtDialogConfig.args_confirmDialog(title, content), (navigator, navRoute, activity, currentView) -> {
            Provider provider = (Provider) navigator.getNavConfiguration().getRequiredComponent();
            Boolean result = provider.get(NavExtDialogConfig.class).result_confirmDialog(navRoute);
            if (result != null && result) {
                deleteNoteAttachment(noteAttachmentState);
            }
        });
    } else {
        mNoteAttachmentRecyclerViewAdapter.notifyItemDeleted(noteAttachmentState);
    }
}
Also used : Context(android.content.Context) NavExtDialogConfig(m.co.rh.id.anavigator.extension.dialog.ui.NavExtDialogConfig) StatefulViewProvider(m.co.rh.id.a_medic_log.app.provider.StatefulViewProvider) Provider(m.co.rh.id.aprovider.Provider)

Example 2 with Provider

use of m.co.rh.id.aprovider.Provider in project a-medic-log by rh-id.

the class NoteDetailPage method medicineItem_onDeleteClick.

@Override
public void medicineItem_onDeleteClick(MedicineState medicineState) {
    if (isUpdate()) {
        Context context = mSvProvider.getContext();
        String title = context.getString(R.string.title_confirm);
        String content = context.getString(R.string.confirm_delete_medicine, medicineState.getMedicineName());
        NavExtDialogConfig navExtDialogConfig = mSvProvider.get(NavExtDialogConfig.class);
        mNavigator.push(navExtDialogConfig.route_confirmDialog(), navExtDialogConfig.args_confirmDialog(title, content), (navigator, navRoute, activity, currentView) -> {
            Provider provider = (Provider) navigator.getNavConfiguration().getRequiredComponent();
            Boolean result = provider.get(NavExtDialogConfig.class).result_confirmDialog(navRoute);
            if (result != null && result) {
                confirmDeleteMedicine(medicineState);
            }
        });
    } else {
        mMedicineRecyclerViewAdapter.notifyItemDeleted(medicineState);
    }
}
Also used : Context(android.content.Context) NavExtDialogConfig(m.co.rh.id.anavigator.extension.dialog.ui.NavExtDialogConfig) StatefulViewProvider(m.co.rh.id.a_medic_log.app.provider.StatefulViewProvider) Provider(m.co.rh.id.aprovider.Provider)

Example 3 with Provider

use of m.co.rh.id.aprovider.Provider in project a-medic-log by rh-id.

the class NoteDetailPage method provideComponent.

@Override
public void provideComponent(Provider provider) {
    mExecutorService = provider.get(ExecutorService.class);
    mSvProvider = provider.get(StatefulViewProvider.class);
    mLogger = mSvProvider.get(ILogger.class);
    mRxDisposer = mSvProvider.get(RxDisposer.class);
    mMedicineReminderChangeNotifier = mSvProvider.get(MedicineReminderChangeNotifier.class);
    mNoteAttachmentFileChangeNotifier = mSvProvider.get(NoteAttachmentFileChangeNotifier.class);
    mQueryNoteCmd = mSvProvider.get(QueryNoteCmd.class);
    boolean isUpdate = isUpdate();
    if (isUpdate) {
        mNewNoteCmd = mSvProvider.get(UpdateNoteCmd.class);
    } else {
        mNewNoteCmd = mSvProvider.get(NewNoteCmd.class);
    }
    mDeleteNoteTagCmd = mSvProvider.get(DeleteNoteTagCmd.class);
    mDeleteNoteAttachmentCmd = mSvProvider.get(DeleteNoteAttachmentCmd.class);
    if (mNoteState == null) {
        mNoteState = new NoteState();
        if (isUpdate) {
            mNoteState.setNoteId(getNoteId());
            mRxDisposer.add("provideComponent_queryNoteInfo", mQueryNoteCmd.queryNoteInfo(mNoteState).subscribe((noteState, throwable) -> {
                if (throwable != null) {
                    mLogger.e(TAG, throwable.getMessage(), throwable);
                }
            }));
        } else {
            mNoteState.setNoteProfileId(getProfileId());
        }
    }
    if (mAppBarSv == null) {
        mAppBarSv = new AppBarSV(R.menu.page_note_detail);
    }
    if (isUpdate) {
        mAppBarSv.setTitle(mNavigator.getActivity().getString(R.string.title_update_note));
    } else {
        mAppBarSv.setTitle(mNavigator.getActivity().getString(R.string.title_add_note));
    }
    mAppBarSv.setMenuItemListener(this);
    initTextWatcher();
    mMedicineRecyclerViewAdapter = new MedicineRecyclerViewAdapter(mNoteState, this, this, this, this, mNavigator, this);
    mNoteAttachmentRecyclerViewAdapter = new NoteAttachmentRecyclerViewAdapter(mNoteState, this, this, mNavigator, this);
    mCompositeDisposable = new CompositeDisposable();
}
Also used : 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) NoteAttachmentRecyclerViewAdapter(m.co.rh.id.a_medic_log.app.ui.component.note.attachment.NoteAttachmentRecyclerViewAdapter) AppBarSV(m.co.rh.id.a_medic_log.app.ui.component.AppBarSV) UpdateNoteCmd(m.co.rh.id.a_medic_log.app.provider.command.UpdateNoteCmd) NewNoteCmd(m.co.rh.id.a_medic_log.app.provider.command.NewNoteCmd) StatefulViewProvider(m.co.rh.id.a_medic_log.app.provider.StatefulViewProvider) DeleteNoteTagCmd(m.co.rh.id.a_medic_log.app.provider.command.DeleteNoteTagCmd) NoteAttachmentFileChangeNotifier(m.co.rh.id.a_medic_log.app.provider.notifier.NoteAttachmentFileChangeNotifier) MedicineRecyclerViewAdapter(m.co.rh.id.a_medic_log.app.ui.component.medicine.MedicineRecyclerViewAdapter) RxDisposer(m.co.rh.id.a_medic_log.app.rx.RxDisposer) NoteState(m.co.rh.id.a_medic_log.base.state.NoteState) DeleteNoteAttachmentCmd(m.co.rh.id.a_medic_log.app.provider.command.DeleteNoteAttachmentCmd) ExecutorService(java.util.concurrent.ExecutorService) ILogger(m.co.rh.id.alogger.ILogger) MedicineReminderChangeNotifier(m.co.rh.id.a_medic_log.app.provider.notifier.MedicineReminderChangeNotifier) QueryNoteCmd(m.co.rh.id.a_medic_log.app.provider.command.QueryNoteCmd) CompositeDisposable(io.reactivex.rxjava3.disposables.CompositeDisposable)

Example 4 with Provider

use of m.co.rh.id.aprovider.Provider in project a-medic-log by rh-id.

the class MedicineIntakeDetailPage method onClick.

@Override
public void onClick(View view) {
    int id = view.getId();
    if (id == R.id.input_text_taken_date_time) {
        NavExtDialogConfig navExtDialogConfig = mSvProvider.get(NavExtDialogConfig.class);
        mNavigator.push(navExtDialogConfig.route_dateTimePickerDialog(), navExtDialogConfig.args_dateTimePickerDialog(true, mMedicineIntakeSubject.getValue().takenDateTime), (navigator, navRoute, activity, currentView) -> {
            Provider provider = (Provider) navigator.getNavConfiguration().getRequiredComponent();
            NavExtDialogConfig navExtDialogConfig1 = provider.get(NavExtDialogConfig.class);
            Date result = navExtDialogConfig1.result_dateTimePickerDialog(navRoute);
            if (result != null) {
                updateTakenDateTime(result);
            }
        });
    }
}
Also used : NavExtDialogConfig(m.co.rh.id.anavigator.extension.dialog.ui.NavExtDialogConfig) Date(java.util.Date) Provider(m.co.rh.id.aprovider.Provider) StatefulViewProvider(m.co.rh.id.a_medic_log.app.provider.StatefulViewProvider)

Example 5 with Provider

use of m.co.rh.id.aprovider.Provider in project a-medic-log by rh-id.

the class LogPage method createView.

@Override
protected View createView(Activity activity, ViewGroup container) {
    View view = activity.getLayoutInflater().inflate(R.layout.page_log, container, false);
    ViewGroup rootLayout = view.findViewById(R.id.root_layout);
    ViewGroup containerAppBar = view.findViewById(R.id.container_app_bar);
    mAppBarSV.setTitle(activity.getString(R.string.title_log_file));
    containerAppBar.addView(mAppBarSV.buildView(activity, rootLayout));
    ProgressBar progressBar = view.findViewById(R.id.progress_circular);
    View noRecord = view.findViewById(R.id.no_record);
    ScrollView scrollView = view.findViewById(R.id.scroll_view);
    TextView textView = view.findViewById(R.id.text_content);
    Provider provider = BaseApplication.of(activity).getProvider();
    if (mSvProvider != null) {
        mSvProvider.dispose();
    }
    mSvProvider = Provider.createProvider(activity.getApplicationContext(), new RxProviderModule());
    FileHelper fileHelper = provider.get(FileHelper.class);
    File logFile = fileHelper.getLogFile();
    FloatingActionButton fabClear = view.findViewById(R.id.fab_clear);
    FloatingActionButton fabShare = view.findViewById(R.id.fab_share);
    fabShare.setOnClickListener(v -> {
        try {
            UiUtils.shareFile(activity, logFile, activity.getString(R.string.share_log_file));
        } catch (Throwable e) {
            provider.get(ILogger.class).e(TAG, activity.getString(R.string.error_sharing_log_file), e);
        }
    });
    BehaviorSubject<File> subject = BehaviorSubject.createDefault(logFile);
    fabClear.setOnClickListener(view1 -> {
        fileHelper.clearLogFile();
        provider.get(ILogger.class).i(TAG, activity.getString(R.string.log_file_deleted));
        provider.get(Handler.class).post(() -> subject.onNext(logFile));
    });
    mSvProvider.get(RxDisposer.class).add("readLogFile", subject.observeOn(Schedulers.from(BaseApplication.of(activity).getProvider().get(ExecutorService.class))).map(file -> {
        if (!file.exists()) {
            return "";
        } else {
            StringBuilder stringBuilder = new StringBuilder();
            BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
            char[] buff = new char[2048];
            int b = bufferedReader.read(buff);
            while (b != -1) {
                stringBuilder.append(buff);
                b = bufferedReader.read(buff);
            }
            return stringBuilder.toString();
        }
    }).observeOn(AndroidSchedulers.mainThread()).subscribe(s -> {
        progressBar.setVisibility(View.GONE);
        textView.setText(s);
        if (s.isEmpty()) {
            noRecord.setVisibility(View.VISIBLE);
            scrollView.setVisibility(View.GONE);
            fabShare.setVisibility(View.GONE);
            fabClear.setVisibility(View.GONE);
        } else {
            noRecord.setVisibility(View.GONE);
            scrollView.setVisibility(View.VISIBLE);
            scrollView.post(() -> scrollView.fullScroll(View.FOCUS_DOWN));
            fabShare.setVisibility(View.VISIBLE);
            fabClear.setVisibility(View.VISIBLE);
        }
    }));
    return view;
}
Also used : FileHelper(m.co.rh.id.a_medic_log.base.provider.FileHelper) ProgressBar(android.widget.ProgressBar) ILogger(m.co.rh.id.alogger.ILogger) BehaviorSubject(io.reactivex.rxjava3.subjects.BehaviorSubject) AppBarSV(m.co.rh.id.a_medic_log.app.ui.component.AppBarSV) BaseApplication(m.co.rh.id.a_medic_log.base.BaseApplication) Schedulers(io.reactivex.rxjava3.schedulers.Schedulers) NavInject(m.co.rh.id.anavigator.annotation.NavInject) UiUtils(m.co.rh.id.a_medic_log.app.util.UiUtils) Handler(android.os.Handler) FloatingActionButton(com.google.android.material.floatingactionbutton.FloatingActionButton) View(android.view.View) RxProviderModule(m.co.rh.id.a_medic_log.app.provider.RxProviderModule) ExecutorService(java.util.concurrent.ExecutorService) StatefulView(m.co.rh.id.anavigator.StatefulView) Provider(m.co.rh.id.aprovider.Provider) ViewGroup(android.view.ViewGroup) File(java.io.File) AndroidSchedulers(io.reactivex.rxjava3.android.schedulers.AndroidSchedulers) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) RxDisposer(m.co.rh.id.a_medic_log.app.rx.RxDisposer) R(m.co.rh.id.a_medic_log.R) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) Activity(android.app.Activity) ViewGroup(android.view.ViewGroup) Handler(android.os.Handler) View(android.view.View) StatefulView(m.co.rh.id.anavigator.StatefulView) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) RxDisposer(m.co.rh.id.a_medic_log.app.rx.RxDisposer) Provider(m.co.rh.id.aprovider.Provider) FileHelper(m.co.rh.id.a_medic_log.base.provider.FileHelper) ScrollView(android.widget.ScrollView) RxProviderModule(m.co.rh.id.a_medic_log.app.provider.RxProviderModule) BufferedReader(java.io.BufferedReader) FloatingActionButton(com.google.android.material.floatingactionbutton.FloatingActionButton) TextView(android.widget.TextView) ILogger(m.co.rh.id.alogger.ILogger) FileReader(java.io.FileReader) ProgressBar(android.widget.ProgressBar) File(java.io.File)

Aggregations

Provider (m.co.rh.id.aprovider.Provider)14 StatefulViewProvider (m.co.rh.id.a_medic_log.app.provider.StatefulViewProvider)10 NavExtDialogConfig (m.co.rh.id.anavigator.extension.dialog.ui.NavExtDialogConfig)10 Context (android.content.Context)8 Activity (android.app.Activity)5 View (android.view.View)5 ViewGroup (android.view.ViewGroup)5 TextView (android.widget.TextView)5 AndroidSchedulers (io.reactivex.rxjava3.android.schedulers.AndroidSchedulers)5 R (m.co.rh.id.a_medic_log.R)5 RxDisposer (m.co.rh.id.a_medic_log.app.rx.RxDisposer)5 ILogger (m.co.rh.id.alogger.ILogger)5 StatefulView (m.co.rh.id.anavigator.StatefulView)5 NavInject (m.co.rh.id.anavigator.annotation.NavInject)5 Button (android.widget.Button)4 CompositeDisposable (io.reactivex.rxjava3.disposables.CompositeDisposable)4 Date (java.util.Date)4 Chip (com.google.android.material.chip.Chip)3 ChipGroup (com.google.android.material.chip.ChipGroup)3 Schedulers (io.reactivex.rxjava3.schedulers.Schedulers)3