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