/** * called when the presenter and view are ready. getView() will not be null * * @param savedInstanceState This bundle is only passed on rotation not passed on navigating * back */ @Override protected void onLoad(Bundle savedInstanceState) { Timber.v("onLoad"); ButterKnife.bind(this, getView()); userRepo .getMe() .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe( new Action1<User>() { @Override public void call(User user) { String firstName = user.getData().attributes().getFirstName(); String lastName = user.getData().attributes().getLastName(); // String email = user.getData().attributes().getEmail(); firstNameEditText.setText(firstName); lastNameEditText.setText(lastName); // emailEditText.setText(email); photoEditView.load(user.getData().attributes(), userPhoto); } }, new Action1<Throwable>() { @Override public void call(Throwable throwable) { Timber.e(throwable, "Unable to retrieve profile"); Crashlytics.logException(throwable); ProfileEditView view = getView(); if (view != null) { ToastService.get(view) .bern(view.getContext().getString(R.string.error_retrieving_profile)); } else { Timber.w("getView() null, can not notify user of failed profile retrieval."); } } }); photoEditView.setPhotoChangeListener( new PhotoEditView.PhotoChangeListener() { @Override public void onPhotoChanged(Bitmap bitmap, String base64PhotoData) { userPhoto = bitmap; Presenter.this.base64PhotoData = base64PhotoData; } }); getView() .postDelayed( new Runnable() { @Override public void run() { photoEditView.toggleAvatarWidget(true); } }, 300); }
@OnClick(R.id.submit_profile) void onSaveProfileClicked(final View v) { Timber.v("Attempting to save profile"); String firstName = firstNameEditText.getText().toString(); String lastName = lastNameEditText.getText().toString(); // String email = emailEditText.getText().toString(); UserSpec spec = new UserSpec(); final User user = new User(); user.getData().attributes().firstName(firstName); user.getData().attributes().lastName(lastName); user.getData().attributes().base64PhotoData(base64PhotoData); // user.getData().attributes().email(email); spec.create(new CreateUserRequest()); spec.update(user); userRepo .update(spec) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe( new Action1<User>() { @Override public void call(User user) { Timber.v("Profile saved"); ProfileEditView view = getView(); if (view != null) { ToastService.get(view) .bern(view.getContext().getString(R.string.profile_saved)); FTBApplication.getEventBus().post(new LoginEvent(LoginEvent.LOGIN, user)); Flow.get(view.getContext()).set(new HomeScreen()); } else { Timber.w("getView() null, cannot notify user of successful profile save"); } } }, new Action1<Throwable>() { @Override public void call(Throwable throwable) { Timber.e(throwable, "Unable to save profile"); Crashlytics.logException(throwable); ProfileEditView view = getView(); if (view != null) { ToastService.get(view) .bern(view.getContext().getString(R.string.error_saving_profile)); } else { Timber.w("getView() null, cannot notify user of failed profile save"); } } }); }