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