use of app.insti.api.request.UserShowContactPatchRequest in project IITB-App by wncc.
the class SettingsFragment method toggleShowContact.
private void toggleShowContact(final SwitchPreferenceCompat showContactPref, Object option) {
final boolean isChecked = (boolean) option;
showContactPref.setEnabled(false);
RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
retrofitInterface.patchUserMe(Utils.getSessionIDHeader(), new UserShowContactPatchRequest(isChecked)).enqueue(new Callback<User>() {
@Override
public void onResponse(Call<User> call, Response<User> response) {
if (getActivity() == null || getView() == null)
return;
if (response.isSuccessful()) {
showContactPref.setChecked(response.body().getShowContactNumber());
showContactPref.setEnabled(true);
Utils.currentUserCache = response.body();
} else {
showContactPref.setChecked(!isChecked);
showContactPref.setEnabled(true);
}
}
@Override
public void onFailure(Call<User> call, Throwable t) {
if (getActivity() == null || getView() == null)
return;
showContactPref.setChecked(!isChecked);
showContactPref.setEnabled(true);
}
});
}
Aggregations