use of br.ufrj.caronae.models.modelsforjson.IdForJson in project caronae-android by caronae.
the class MyProfileFrag method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_my_profile, container, false);
ButterKnife.bind(this, view);
callbackManager = ((MainAct) getActivity()).getFbCallbackManager();
carOwner_sw.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
carOwnerSw();
}
});
carPlate_et.setFilters(new InputFilter[] { new InputFilter.AllCaps() });
loginButton.setReadPermissions("user_friends");
loginButton.setFragment(this);
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Log.i("face", "onSuccess = " + loginResult.toString());
Profile profile = Profile.getCurrentProfile();
if (profile != null) {
final String faceId = profile.getId();
CaronaeAPI.service(getContext()).saveFaceId(new IdForJson(faceId)).enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
if (response.isSuccessful()) {
Log.i("saveFaceId", "face id saved");
User user = App.getUser();
user.setFaceId(faceId);
SharedPref.saveUser(user);
} else {
Util.treatResponseFromServer(response);
Util.toast(R.string.frag_myprofile_errorSaveFaceId);
Log.e("saveFaceId", response.message());
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
Util.toast(R.string.frag_myprofile_errorSaveFaceId);
Log.e("saveFaceId", t.getMessage());
}
});
}
}
@Override
public void onCancel() {
Log.i("face", "onCancel");
}
@Override
public void onError(FacebookException exception) {
Util.toast(R.string.frag_myprofile_errorFaceLogin);
Log.e("face", "onError = " + exception.toString());
}
});
setFieldValidatorsListeners();
User user = App.getUser();
if (user != null) {
fillUserFields(user);
CaronaeAPI.service(getContext()).getRidesHistoryCount(user.getDbId() + "").enqueue(new Callback<HistoryRideCountForJson>() {
@Override
public void onResponse(Call<HistoryRideCountForJson> call, Response<HistoryRideCountForJson> response) {
if (response.isSuccessful()) {
HistoryRideCountForJson historyRideCountForJson = response.body();
ridesOffered_tv.setText(String.valueOf(historyRideCountForJson.getOfferedCount()));
ridesTaken_tv.setText(String.valueOf(historyRideCountForJson.getTakenCount()));
} else {
Util.treatResponseFromServer(response);
Util.toast(R.string.act_profile_errorCountRidesHistory);
Log.e("getRidesHistoryCount", response.message());
}
}
@Override
public void onFailure(Call<HistoryRideCountForJson> call, Throwable t) {
Util.toast(R.string.act_profile_errorCountRidesHistory);
Log.e("getRidesHistoryCount", t.getMessage());
}
});
}
setETFormat();
return view;
}
Aggregations