use of br.ufrj.caronae.models.User 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.User in project caronae-android by caronae.
the class RequestersListAct method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_requesters_list);
ButterKnife.bind(this);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
final ActionBar ab = getSupportActionBar();
if (ab != null) {
ab.setDisplayHomeAsUpEnabled(true);
}
ArrayList<User> users = getIntent().getExtras().getParcelableArrayList("users");
int rideId = getIntent().getExtras().getInt("rideId");
int color = getIntent().getExtras().getInt("color");
requestersList.setAdapter(new RequestersAdapter(users, rideId, color, this));
requestersList.setHasFixedSize(true);
requestersList.setLayoutManager(new LinearLayoutManager(this));
}
use of br.ufrj.caronae.models.User in project caronae-android by caronae.
the class RideOfferAct method configureActivityWithRide.
private void configureActivityWithRide(final RideForJson rideWithUsers, boolean isFull) {
final boolean requested = getIntent().getBooleanExtra("requested", false);
if (rideWithUsers == null) {
Util.toast(getString(R.string.act_activeride_rideNUll));
finish();
}
AllRidesFrag.setPageThatWas(rideWithUsers.isGoing());
final User driver = rideWithUsers.getDriver();
final boolean isDriver = driver.getDbId() == App.getUser().getDbId();
int color = Util.getColorbyZone(rideWithUsers.getZone());
join_bt.setBackgroundColor(color);
location_dt.setTextColor(color);
final String location;
if (rideWithUsers.isGoing())
location = rideWithUsers.getNeighborhood() + " ➜ " + rideWithUsers.getHub();
else
location = rideWithUsers.getHub() + " ➜ " + rideWithUsers.getNeighborhood();
String profilePicUrl = driver.getProfilePicUrl();
if (profilePicUrl == null || profilePicUrl.isEmpty()) {
Picasso.with(this.getApplicationContext()).load(R.drawable.user_pic).into(user_pic);
} else {
Picasso.with(this.getApplicationContext()).load(profilePicUrl).placeholder(R.drawable.user_pic).error(R.drawable.user_pic).transform(new RoundedTransformation()).into(user_pic);
}
user_pic.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!isDriver) {
// dont allow user to open own profile
Intent intent = new Intent(getApplicationContext(), ProfileAct.class);
intent.putExtra("user", new Gson().toJson(driver));
intent.putExtra("from", "rideoffer");
startActivity(intent);
}
}
});
location_dt.setText(location);
name_dt.setText(driver.getName());
profile_dt.setText(driver.getProfile());
if (rideWithUsers.getRoute().equals("")) {
way_dt.setText("- - -");
} else {
way_dt.setText(rideWithUsers.getRoute());
}
if (rideWithUsers.getPlace().equals("")) {
place_dt.setText("- - -");
} else {
place_dt.setText(rideWithUsers.getPlace());
}
course_dt.setText(driver.getCourse());
if (rideWithUsers.isGoing())
time_dt.setText(getString(R.string.arrivingAt, Util.formatTime(rideWithUsers.getTime())));
else
time_dt.setText(getString(R.string.leavingAt, Util.formatTime(rideWithUsers.getTime())));
time_dt.setTextColor(color);
date_dt.setText(Util.formatBadDateWithoutYear(rideWithUsers.getDate()));
date_dt.setTextColor(color);
if (rideWithUsers.getDescription().equals("")) {
description_dt.setText("- - -");
} else {
description_dt.setText(rideWithUsers.getDescription());
}
if (isDriver) {
join_bt.setVisibility(View.GONE);
} else {
if (requested) {
join_bt.setVisibility(View.GONE);
requested_dt.setVisibility(View.VISIBLE);
} else {
if (isFull) {
join_bt.setText("CARONA CHEIA");
join_bt.setClickable(false);
} else {
join_bt.setClickable(true);
final Context context = this;
join_bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
List<ActiveRide> list = ActiveRide.find(ActiveRide.class, "date = ? and going = ?", rideWithUsers.getDate(), rideWithUsers.isGoing() ? "1" : "0");
if (list != null && !list.isEmpty()) {
Util.toast(getString(R.string.act_rideOffer_rideConflict));
return;
}
com.rey.material.app.Dialog.Builder builder = new SimpleDialog.Builder(R.style.SlideInDialog) {
@Override
protected void onBuildDone(com.rey.material.app.Dialog dialog) {
dialog.layoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
dialog.getWindow().getAttributes().windowAnimations = R.style.SlideInRightDialog;
}
@Override
public void onPositiveActionClicked(com.rey.material.app.DialogFragment fragment) {
final ProgressDialog pd = ProgressDialog.show(context, "", getString(R.string.wait), true, true);
CaronaeAPI.service(context).requestJoin(String.valueOf(rideWithUsers.getDbId())).enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
if (response.isSuccessful()) {
RideRequestSent rideRequest = new RideRequestSent(rideWithUsers.getDbId(), rideWithUsers.isGoing(), rideWithUsers.getDate());
rideRequest.save();
createChatAssets(rideWithUsers);
join_bt.startAnimation(getAnimationForSendButton());
requested_dt.startAnimation(getAnimationForResquestedText());
App.getBus().post(rideRequest);
pd.dismiss();
Util.snack(coordinatorLayout, getResources().getString(R.string.requestSent));
} else {
Util.treatResponseFromServer(response);
pd.dismiss();
Util.snack(coordinatorLayout, getResources().getString(R.string.errorRequestSent));
Log.e("requestJoin", response.message());
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
pd.dismiss();
Util.snack(coordinatorLayout, getResources().getString(R.string.requestSent));
Log.e("requestJoin", t.getMessage());
}
});
super.onPositiveActionClicked(fragment);
}
@Override
public void onNegativeActionClicked(com.rey.material.app.DialogFragment fragment) {
super.onNegativeActionClicked(fragment);
}
};
((SimpleDialog.Builder) builder).message(getString(R.string.act_rideOffer_requestWarn)).title(getString(R.string.attention)).positiveAction(getString(R.string.ok)).negativeAction(getString(R.string.cancel));
com.rey.material.app.DialogFragment fragment = com.rey.material.app.DialogFragment.newInstance(builder);
fragment.show(getSupportFragmentManager(), "a");
}
});
}
}
}
configureShareButton();
}
use of br.ufrj.caronae.models.User in project caronae-android by caronae.
the class RidersAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
final User user = users.get(position);
String profilePicUrl = user.getProfilePicUrl();
if (profilePicUrl != null && !profilePicUrl.isEmpty())
Picasso.with(activity).load(profilePicUrl).placeholder(R.drawable.user_pic).error(R.drawable.user_pic).transform(new RoundedTransformation()).into(holder.photo_iv);
holder.name_tv.setText(user.getName().split(" ")[0]);
if (user.getDbId() != App.getUser().getDbId()) {
// dont allow user to open own profile
holder.photo_iv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(activity, ProfileAct.class);
intent.putExtra("user", new Gson().toJson(user));
Class openScreenClass = activity.getClass();
String riders = openScreenClass == ActiveRideAct.class ? "activeRides" : openScreenClass.getSimpleName();
intent.putExtra("from", riders);
activity.startActivity(intent);
}
});
}
}
use of br.ufrj.caronae.models.User in project caronae-android by caronae.
the class MyProfileFrag method userPic.
@OnClick(R.id.user_pic)
public void userPic() {
SimpleDialog.Builder builder = new SimpleDialog.Builder(R.style.SimpleDialogLight) {
@Override
public void onPositiveActionClicked(DialogFragment fragment) {
final User user = App.getUser();
if (getSelectedValue().toString().equals(getString(R.string.frag_myprofile_facePicChoice))) {
Profile profile = Profile.getCurrentProfile();
if (profile != null) {
String faceId = profile.getId();
String profilePicUrl = "https://graph.facebook.com/" + faceId + "/picture?type=large";
// if (user.getProfilePicUrl() == null || !user.getProfilePicUrl().equals(profilePicUrl)) {
user.setProfilePicUrl(profilePicUrl);
Picasso.with(getContext()).load(profilePicUrl).error(R.drawable.auth_bg).transform(new RoundedTransformation()).into(user_pic);
saveProfilePicUrl(profilePicUrl);
// }
} else {
Util.toast(R.string.frag_myprofile_facePickChoiceNotOnFace);
}
} else {
CaronaeAPI.service(getContext()).getIntranetPhotoUrl().enqueue(new Callback<UrlForJson>() {
@Override
public void onResponse(Call<UrlForJson> call, Response<UrlForJson> response) {
if (response.isSuccessful()) {
UrlForJson urlForJson = response.body();
if (urlForJson == null)
return;
String profilePicUrl = urlForJson.getUrl();
if (profilePicUrl != null && !profilePicUrl.isEmpty()) {
user.setProfilePicUrl(profilePicUrl);
Picasso.with(getContext()).load(profilePicUrl).error(R.drawable.user_pic).transform(new RoundedTransformation()).into(user_pic);
saveProfilePicUrl(profilePicUrl);
}
} else {
Util.treatResponseFromServer(response);
Util.toast(R.string.frag_myprofile_errorGetIntranetPhoto);
Log.e("getIntranetPhotoUrl", response.message());
}
}
@Override
public void onFailure(Call<UrlForJson> call, Throwable t) {
Util.toast(R.string.frag_myprofile_errorGetIntranetPhoto);
Log.e("getIntranetPhotoUrl", t.getMessage());
}
});
}
super.onPositiveActionClicked(fragment);
}
@Override
public void onNegativeActionClicked(DialogFragment fragment) {
super.onNegativeActionClicked(fragment);
}
};
builder.items(new String[] { getString(R.string.frag_myprofile_facePicChoice) }, 0).title("Usar foto do Facebook?").positiveAction(getString(R.string.ok)).negativeAction(getString(R.string.cancel));
DialogFragment fragment = DialogFragment.newInstance(builder);
fragment.show(getFragmentManager(), null);
}
Aggregations