Search in sources :

Example 1 with HistoryRideCountForJson

use of br.ufrj.caronae.models.modelsforjson.HistoryRideCountForJson in project caronae-android by caronae.

the class ProfileAct method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_profile);
    ButterKnife.bind(this);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    final ActionBar ab = getSupportActionBar();
    if (ab != null) {
        ab.setDisplayHomeAsUpEnabled(true);
    }
    String user2 = getIntent().getExtras().getString("user");
    user = new Gson().fromJson(user2, User.class);
    name_tv.setText(user.getName());
    profile_tv.setText(user.getProfile());
    course_tv.setText(user.getCourse());
    phone_tv.setText(user.getPhoneNumber());
    String profilePicUrl = user.getProfilePicUrl();
    if (profilePicUrl != null && !profilePicUrl.isEmpty())
        Picasso.with(this).load(profilePicUrl).placeholder(R.drawable.user_pic).error(R.drawable.user_pic).transform(new RoundedTransformation()).into(user_pic_iv);
    try {
        String date = user.getCreatedAt().split(" ")[0];
        date = Util.formatBadDateWithYear(date).substring(3);
        createdAt_tv.setText(date);
    } catch (Exception e) {
        e.printStackTrace();
    }
    CaronaeAPI.service(getApplicationContext()).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());
        }
    });
    try {
        AccessToken token = AccessToken.getCurrentAccessToken();
        if (token != null) {
            if (user.getFaceId() != null) {
                String name = user.getName().split(" ")[0];
                openProfile_tv.setText(getString(R.string.act_profile_openFbProfile, name));
                openProfile_tv.setVisibility(View.VISIBLE);
                CaronaeAPI.service(getApplicationContext()).getMutualFriends(token.getToken(), user.getFaceId()).enqueue(new Callback<FacebookFriendForJson>() {

                    @Override
                    public void onResponse(Call<FacebookFriendForJson> call, Response<FacebookFriendForJson> response) {
                        if (response.isSuccessful()) {
                            FacebookFriendForJson mutualFriends = response.body();
                            if (mutualFriends.getTotalCount() < 1)
                                return;
                            mutualFriends_lay.setVisibility(View.VISIBLE);
                            int totalCount = mutualFriends.getTotalCount();
                            String s = mutualFriends.getTotalCount() > 1 ? "s" : "";
                            int size = mutualFriends.getMutualFriends().size();
                            String s1 = mutualFriends.getMutualFriends().size() != 1 ? "m" : "";
                            mutualFriends_tv.setText(getString(R.string.act_profile_mutualFriends, totalCount, s, size, s1));
                            mutualFriendsList.setAdapter(new RidersAdapter(mutualFriends.getMutualFriends(), ProfileAct.this));
                            mutualFriendsList.setHasFixedSize(true);
                            mutualFriendsList.setLayoutManager(new LinearLayoutManager(ProfileAct.this, LinearLayoutManager.HORIZONTAL, false));
                        } else {
                            Util.treatResponseFromServer(response);
                            // Util.toast(getString(R.string.act_profile_errorMutualFriends));
                            Log.e("getMutualFriends", response.message());
                        }
                    }

                    @Override
                    public void onFailure(Call<FacebookFriendForJson> call, Throwable t) {
                        Log.e("getMutualFriends", t.getMessage());
                    }
                });
            } else {
                Log.i("profileact,facebook", "user face id is null");
            }
        }
    } catch (Exception e) {
        Log.e("profileact", e.getMessage());
    }
    String from = getIntent().getExtras().getString("from");
    if (from != null && (from.equals("activeRides"))) {
        // Controls the options that appears on app when user touch (short or long) on phone number
        phone_tv.setOnClickListener((View v) -> {
            actionNumberTouch(0);
        });
        phone_tv.setOnLongClickListener((View v) -> {
            actionNumberTouch(1);
            return true;
        });
    } else {
        phone_icon.setVisibility(View.INVISIBLE);
        phone_tv.setVisibility(View.INVISIBLE);
    }
}
Also used : FacebookFriendForJson(br.ufrj.caronae.models.modelsforjson.FacebookFriendForJson) User(br.ufrj.caronae.models.User) Gson(com.google.gson.Gson) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) AccessToken(com.facebook.AccessToken) RoundedTransformation(br.ufrj.caronae.RoundedTransformation) HistoryRideCountForJson(br.ufrj.caronae.models.modelsforjson.HistoryRideCountForJson) RidersAdapter(br.ufrj.caronae.adapters.RidersAdapter) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar)

Example 2 with HistoryRideCountForJson

use of br.ufrj.caronae.models.modelsforjson.HistoryRideCountForJson 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

View (android.view.View)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 User (br.ufrj.caronae.models.User)2 HistoryRideCountForJson (br.ufrj.caronae.models.modelsforjson.HistoryRideCountForJson)2 BindView (butterknife.BindView)2 ActionBar (android.support.v7.app.ActionBar)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 Toolbar (android.support.v7.widget.Toolbar)1 InputFilter (android.text.InputFilter)1 CompoundButton (android.widget.CompoundButton)1 ScrollView (android.widget.ScrollView)1 RoundedTransformation (br.ufrj.caronae.RoundedTransformation)1 RidersAdapter (br.ufrj.caronae.adapters.RidersAdapter)1 FacebookFriendForJson (br.ufrj.caronae.models.modelsforjson.FacebookFriendForJson)1 IdForJson (br.ufrj.caronae.models.modelsforjson.IdForJson)1 AccessToken (com.facebook.AccessToken)1 FacebookCallback (com.facebook.FacebookCallback)1 FacebookException (com.facebook.FacebookException)1