Search in sources :

Example 1 with FacebookFriendForJson

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

Aggregations

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 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 RoundedTransformation (br.ufrj.caronae.RoundedTransformation)1 RidersAdapter (br.ufrj.caronae.adapters.RidersAdapter)1 User (br.ufrj.caronae.models.User)1 FacebookFriendForJson (br.ufrj.caronae.models.modelsforjson.FacebookFriendForJson)1 HistoryRideCountForJson (br.ufrj.caronae.models.modelsforjson.HistoryRideCountForJson)1 BindView (butterknife.BindView)1 AccessToken (com.facebook.AccessToken)1 Gson (com.google.gson.Gson)1