Search in sources :

Example 1 with UrlForJson

use of br.ufrj.caronae.models.modelsforjson.UrlForJson in project caronae-android by caronae.

the class MyProfileFrag method userPic.

@OnClick(R.id.user_pic)
public void userPic() {
    SimpleDialog.Builder builder = new SimpleDialog.Builder(R.style.SimpleDialogLight) {

        @Override
        public void onPositiveActionClicked(DialogFragment fragment) {
            final User user = App.getUser();
            if (getSelectedValue().toString().equals(getString(R.string.frag_myprofile_facePicChoice))) {
                Profile profile = Profile.getCurrentProfile();
                if (profile != null) {
                    String faceId = profile.getId();
                    String profilePicUrl = "https://graph.facebook.com/" + faceId + "/picture?type=large";
                    // if (user.getProfilePicUrl() == null || !user.getProfilePicUrl().equals(profilePicUrl)) {
                    user.setProfilePicUrl(profilePicUrl);
                    Picasso.with(getContext()).load(profilePicUrl).error(R.drawable.auth_bg).transform(new RoundedTransformation()).into(user_pic);
                    saveProfilePicUrl(profilePicUrl);
                // }
                } else {
                    Util.toast(R.string.frag_myprofile_facePickChoiceNotOnFace);
                }
            } else {
                CaronaeAPI.service(getContext()).getIntranetPhotoUrl().enqueue(new Callback<UrlForJson>() {

                    @Override
                    public void onResponse(Call<UrlForJson> call, Response<UrlForJson> response) {
                        if (response.isSuccessful()) {
                            UrlForJson urlForJson = response.body();
                            if (urlForJson == null)
                                return;
                            String profilePicUrl = urlForJson.getUrl();
                            if (profilePicUrl != null && !profilePicUrl.isEmpty()) {
                                user.setProfilePicUrl(profilePicUrl);
                                Picasso.with(getContext()).load(profilePicUrl).error(R.drawable.user_pic).transform(new RoundedTransformation()).into(user_pic);
                                saveProfilePicUrl(profilePicUrl);
                            }
                        } else {
                            Util.treatResponseFromServer(response);
                            Util.toast(R.string.frag_myprofile_errorGetIntranetPhoto);
                            Log.e("getIntranetPhotoUrl", response.message());
                        }
                    }

                    @Override
                    public void onFailure(Call<UrlForJson> call, Throwable t) {
                        Util.toast(R.string.frag_myprofile_errorGetIntranetPhoto);
                        Log.e("getIntranetPhotoUrl", t.getMessage());
                    }
                });
            }
            super.onPositiveActionClicked(fragment);
        }

        @Override
        public void onNegativeActionClicked(DialogFragment fragment) {
            super.onNegativeActionClicked(fragment);
        }
    };
    builder.items(new String[] { getString(R.string.frag_myprofile_facePicChoice) }, 0).title("Usar foto do Facebook?").positiveAction(getString(R.string.ok)).negativeAction(getString(R.string.cancel));
    DialogFragment fragment = DialogFragment.newInstance(builder);
    fragment.show(getFragmentManager(), null);
}
Also used : UrlForJson(br.ufrj.caronae.models.modelsforjson.UrlForJson) User(br.ufrj.caronae.models.User) DialogFragment(com.rey.material.app.DialogFragment) CaretString(com.redmadrobot.inputmask.model.CaretString) Profile(com.facebook.Profile) SimpleDialog(com.rey.material.app.SimpleDialog) RoundedTransformation(br.ufrj.caronae.RoundedTransformation) OnClick(butterknife.OnClick)

Aggregations

RoundedTransformation (br.ufrj.caronae.RoundedTransformation)1 User (br.ufrj.caronae.models.User)1 UrlForJson (br.ufrj.caronae.models.modelsforjson.UrlForJson)1 OnClick (butterknife.OnClick)1 Profile (com.facebook.Profile)1 CaretString (com.redmadrobot.inputmask.model.CaretString)1 DialogFragment (com.rey.material.app.DialogFragment)1 SimpleDialog (com.rey.material.app.SimpleDialog)1