Search in sources :

Example 1 with IdForJson

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;
}
Also used : Call(retrofit2.Call) InputFilter(android.text.InputFilter) User(br.ufrj.caronae.models.User) LoginResult(com.facebook.login.LoginResult) CaretString(com.redmadrobot.inputmask.model.CaretString) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) Profile(com.facebook.Profile) Response(retrofit2.Response) FacebookCallback(com.facebook.FacebookCallback) Callback(retrofit2.Callback) FacebookException(com.facebook.FacebookException) IdForJson(br.ufrj.caronae.models.modelsforjson.IdForJson) HistoryRideCountForJson(br.ufrj.caronae.models.modelsforjson.HistoryRideCountForJson) CompoundButton(android.widget.CompoundButton)

Aggregations

InputFilter (android.text.InputFilter)1 View (android.view.View)1 CompoundButton (android.widget.CompoundButton)1 ImageView (android.widget.ImageView)1 ScrollView (android.widget.ScrollView)1 TextView (android.widget.TextView)1 User (br.ufrj.caronae.models.User)1 HistoryRideCountForJson (br.ufrj.caronae.models.modelsforjson.HistoryRideCountForJson)1 IdForJson (br.ufrj.caronae.models.modelsforjson.IdForJson)1 BindView (butterknife.BindView)1 FacebookCallback (com.facebook.FacebookCallback)1 FacebookException (com.facebook.FacebookException)1 Profile (com.facebook.Profile)1 LoginResult (com.facebook.login.LoginResult)1 CaretString (com.redmadrobot.inputmask.model.CaretString)1 Call (retrofit2.Call)1 Callback (retrofit2.Callback)1 Response (retrofit2.Response)1