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);
}
}
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;
}
Aggregations