Search in sources :

Example 1 with UserShowContactPatchRequest

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);
        }
    });
}
Also used : User(app.insti.api.model.User) UserShowContactPatchRequest(app.insti.api.request.UserShowContactPatchRequest) RetrofitInterface(app.insti.api.RetrofitInterface)

Aggregations

RetrofitInterface (app.insti.api.RetrofitInterface)1 User (app.insti.api.model.User)1 UserShowContactPatchRequest (app.insti.api.request.UserShowContactPatchRequest)1