use of br.ufrj.caronae.models.User in project caronae-android by caronae.
the class MyProfileFrag method saveProfileBtn.
@OnClick(R.id.save_profile_btn)
public void saveProfileBtn() {
if (App.getUser() == null)
return;
final User editedUser = new User();
prepEditedUser(editedUser);
if (!App.getUser().sameFieldsState(editedUser)) {
int validation = fieldsValidated();
if (validation == 0) {
CaronaeAPI.service(getContext()).updateUser(String.valueOf(App.getUser().getDbId()), editedUser).enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
if (response.isSuccessful()) {
User user = App.getUser();
if (user == null)
return;
user.setUser(editedUser);
SharedPref.saveUser(user);
Util.toast(R.string.frag_myprofile_updated);
} else {
Util.treatResponseFromServer(response);
Log.e("updateUser", response.message());
Util.toast(R.string.frag_myprofile_errorUpdated);
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
Log.e("updateUser", t.getMessage());
Util.toast(R.string.frag_myprofile_errorUpdated);
}
});
} else if (validation == 1) {
Util.toast(getString(R.string.frag_myprofile_invalidFieldsTelephone));
} else if (validation == 2) {
Util.toast(getString(R.string.frag_myprofile_invalidFieldsEmail));
} else if (validation == 3) {
Util.toast(getString(R.string.frag_myprofile_invalidFieldsPlate));
}
} else {
Util.toast(getString(R.string.frag_myprofile_SameFieldsState));
}
}
use of br.ufrj.caronae.models.User 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;
}
use of br.ufrj.caronae.models.User in project caronae-android by caronae.
the class FalaeFrag method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_falae, container, false);
ButterKnife.bind(this, view);
User user = App.getUser();
name_tv.setText(user.getName());
profile_tv.setText(user.getProfile());
course_tv.setText(user.getCourse());
String profilePicUrl = user.getProfilePicUrl();
if (profilePicUrl != null && !profilePicUrl.isEmpty())
Picasso.with(getContext()).load(profilePicUrl).placeholder(R.drawable.user_pic).error(R.drawable.user_pic).transform(new RoundedTransformation()).into(user_pic_iv);
return view;
}
use of br.ufrj.caronae.models.User in project caronae-android by caronae.
the class MainAct method onStart.
@Override
protected void onStart() {
super.onStart();
User user = App.getUser();
Fragment fragment;
boolean goToMyRides = getIntent().getBooleanExtra(SharedPref.MY_RIDE_LIST_KEY, false);
if (user.getEmail() == null || user.getEmail().isEmpty() || user.getPhoneNumber() == null || user.getPhoneNumber().isEmpty() || user.getLocation() == null || user.getLocation().isEmpty()) {
fragment = new MyProfileFrag();
Util.toast(getString(R.string.act_main_profileIncomplete));
} else if (goToMyRides) {
fragment = new MyRidesFrag();
backstack.add(new AllRidesFrag().getClass());
} else {
fragment = new AllRidesFrag();
}
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.flContent, fragment).commit();
backstack.add(fragment.getClass());
}
use of br.ufrj.caronae.models.User in project caronae-android by caronae.
the class ActiveRideAct method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_active_ride);
ButterKnife.bind(this);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
final ActionBar ab = getSupportActionBar();
if (ab != null) {
ab.setDisplayHomeAsUpEnabled(true);
}
rideWithUsers = getIntent().getExtras().getParcelable("ride");
if (rideWithUsers == null) {
Util.toast(getString(R.string.act_activeride_rideNUll));
finish();
return;
}
final User driver = rideWithUsers.getDriver();
final boolean isDriver = driver.getDbId() == App.getUser().getDbId();
int color = 0, colorPressed = 0, bgRes = 0;
if (rideWithUsers.getZone().equals("Centro")) {
color = ContextCompat.getColor(this, R.color.zone_centro);
colorPressed = ContextCompat.getColor(this, R.color.light_zone_centro_transparency);
bgRes = R.drawable.bg_bt_raise_zone_centro;
}
if (rideWithUsers.getZone().equals("Zona Sul")) {
color = ContextCompat.getColor(this, R.color.zone_sul);
colorPressed = ContextCompat.getColor(this, R.color.light_zone_sul_transparency);
bgRes = R.drawable.bg_bt_raise_zone_sul;
}
if (rideWithUsers.getZone().equals("Zona Oeste")) {
color = ContextCompat.getColor(this, R.color.zone_oeste);
colorPressed = ContextCompat.getColor(this, R.color.light_zone_oeste_transparency);
bgRes = R.drawable.bg_bt_raise_zone_oeste;
}
if (rideWithUsers.getZone().equals("Zona Norte")) {
color = ContextCompat.getColor(this, R.color.zone_norte);
colorPressed = ContextCompat.getColor(this, R.color.light_zone_norte_transparency);
bgRes = R.drawable.bg_bt_raise_zone_norte;
}
if (rideWithUsers.getZone().equals("Baixada")) {
color = ContextCompat.getColor(this, R.color.zone_baixada);
colorPressed = ContextCompat.getColor(this, R.color.light_zone_baixada_transparency);
bgRes = R.drawable.bg_bt_raise_zone_baixada;
}
if (rideWithUsers.getZone().equals("Grande Niterói")) {
color = ContextCompat.getColor(this, R.color.zone_niteroi);
colorPressed = ContextCompat.getColor(this, R.color.light_zone_niteroi_transparency);
bgRes = R.drawable.bg_bt_raise_zone_niteroi;
}
if (rideWithUsers.getZone().equals("Outros")) {
color = ContextCompat.getColor(this, R.color.zone_outros);
colorPressed = ContextCompat.getColor(this, R.color.light_gray);
bgRes = R.drawable.bg_bt_raise_zone_outros;
}
lay1.setBackgroundColor(color);
toolbar.setBackgroundColor(color);
chat_bt.setColorNormal(color);
chat_bt.setColorPressed(colorPressed);
finish_bt.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).load(R.drawable.user_pic).into(user_pic);
} else {
Picasso.with(this).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(ActiveRideAct.this, ProfileAct.class);
intent.putExtra("user", new Gson().toJson(driver));
intent.putExtra("from", "activeRides");
startActivity(intent);
}
}
});
location_tv.setText(location);
name_tv.setText(driver.getName());
profile_tv.setText(driver.getProfile());
if (rideWithUsers.getRoute().equals("")) {
way_tv.setVisibility(View.GONE);
way_text_tv.setVisibility(View.GONE);
} else {
way_tv.setText(rideWithUsers.getRoute());
}
if (rideWithUsers.getPlace().equals("")) {
place_text_tv.setVisibility(View.GONE);
place_tv.setVisibility(View.GONE);
} else {
place_tv.setText(rideWithUsers.getPlace());
}
phoneNumber_tv.setText(driver.getPhoneNumber());
course_tv.setText(driver.getCourse());
if (rideWithUsers.isGoing())
time_tv.setText(getString(R.string.arrivingAt, Util.formatTime(rideWithUsers.getTime())));
else
time_tv.setText(getString(R.string.leavingAt, Util.formatTime(rideWithUsers.getTime())));
time_tv.setTextColor(color);
date_tv.setText(Util.formatBadDateWithoutYear(rideWithUsers.getDate()));
date_tv.setTextColor(color);
carModel_tv.setText(driver.getCarModel());
carColor_tv.setText(driver.getCarColor());
carPlate_tv.setText(driver.getCarPlate());
if (rideWithUsers.getDescription().equals("")) {
description_text_tv.setVisibility(View.GONE);
description_tv.setVisibility(View.GONE);
} else {
description_tv.setText(rideWithUsers.getDescription());
}
ridersList.setAdapter(new RidersAdapter(rideWithUsers.getRiders(), this));
ridersList.setHasFixedSize(true);
ridersList.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
final int finalColor = color, finalBgRes = bgRes;
chat_bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
List<ChatAssets> l = ChatAssets.find(ChatAssets.class, "ride_id = ?", rideWithUsers.getDbId() + "");
if (l == null || l.isEmpty())
new ChatAssets(rideWithUsers.getDbId() + "", location, finalColor, finalBgRes, Util.formatBadDateWithoutYear(rideWithUsers.getDate()), Util.formatTime(rideWithUsers.getTime())).save();
Intent intent = new Intent(ActiveRideAct.this, ChatAct.class);
intent.putExtra("rideId", rideWithUsers.getDbId() + "");
startActivity(intent);
}
});
rideId2 = rideWithUsers.getDbId() + "";
final String rideId = rideId2;
if (isDriver) {
leave_bt.setText(R.string.act_activeride_quitBtn);
seeProfile_iv.setVisibility(View.GONE);
}
leave_bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Dialog.Builder builder = new SimpleDialog.Builder(R.style.SimpleDialogLight) {
@Override
public void onPositiveActionClicked(DialogFragment fragment) {
final ProgressDialog pd = ProgressDialog.show(ActiveRideAct.this, "", getString(R.string.wait), true, true);
CaronaeAPI.service(getApplicationContext()).leaveRide(rideId).enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
if (response.isSuccessful()) {
pd.dismiss();
if (isDriver)
Util.toast(getString(R.string.act_activeride_cancelledRide));
else
Util.toast(getString(R.string.act_activeride_quitRide));
FirebaseTopicsHandler.unsubscribeFirebaseTopic(rideId + "");
List<Ride> rides = Ride.find(Ride.class, "db_id = ?", rideId);
if (rides != null && !rides.isEmpty())
rides.get(0).delete();
ActiveRide.deleteAll(ActiveRide.class, "db_id = ?", rideId);
SharedPref.saveRemoveRideFromList(rideId);
finish();
} else {
Util.treatResponseFromServer(response);
pd.dismiss();
Util.toast(R.string.errorRideDeleted);
Log.e("leaveRide", response.message());
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
pd.dismiss();
Util.toast(R.string.errorRideDeleted);
Log.e("leaveRide", t.getMessage());
}
});
super.onPositiveActionClicked(fragment);
}
@Override
public void onNegativeActionClicked(DialogFragment fragment) {
super.onNegativeActionClicked(fragment);
}
};
String title;
if (isDriver) {
title = getString(R.string.act_activeRide_sureWantToCancel);
((SimpleDialog.Builder) builder).message(getString(R.string.act_activeRide_cancelRideMsg)).title(title).positiveAction(getString(R.string.ok)).negativeAction(getString(R.string.cancel));
} else {
title = getString(R.string.act_activeRide_sureWantToQuit);
builder.title(title).positiveAction(getString(R.string.ok)).negativeAction(getString(R.string.cancel));
}
DialogFragment fragment = DialogFragment.newInstance(builder);
fragment.show(getSupportFragmentManager(), null);
}
});
if (!isDriver) {
finish_bt.setVisibility(View.GONE);
}
finish_bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Dialog.Builder builder = new SimpleDialog.Builder(R.style.SimpleDialogLight) {
@Override
public void onPositiveActionClicked(DialogFragment fragment) {
final ProgressDialog pd = ProgressDialog.show(ActiveRideAct.this, "", getString(R.string.wait), true, true);
CaronaeAPI.service(getApplicationContext()).finishRide(rideId).enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
if (response.isSuccessful()) {
pd.dismiss();
Util.toast(R.string.rideFinished);
FirebaseTopicsHandler.unsubscribeFirebaseTopic(rideId + "");
List<Ride> rides = Ride.find(Ride.class, "db_id = ?", rideId);
if (rides != null && !rides.isEmpty())
rides.get(0).delete();
ActiveRide.deleteAll(ActiveRide.class, "db_id = ?", rideId);
SharedPref.saveRemoveRideFromList(rideId);
finish();
} else {
Util.treatResponseFromServer(response);
pd.dismiss();
if (response.code() == 403) {
Util.toast(R.string.finishFutureRide);
} else {
Util.toast(R.string.errorFinishRide);
Log.e("finish_bt", response.message());
}
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
pd.dismiss();
Util.toast(R.string.errorFinishRide);
Log.e("finish_bt", t.getMessage());
}
});
super.onPositiveActionClicked(fragment);
}
@Override
public void onNegativeActionClicked(DialogFragment fragment) {
super.onNegativeActionClicked(fragment);
}
};
builder.title(getString(R.string.act_activeride_sureWantToFinish)).positiveAction(getString(R.string.ok)).negativeAction(getString(R.string.cancel));
DialogFragment fragment = DialogFragment.newInstance(builder);
fragment.show(getSupportFragmentManager(), null);
}
});
phoneNumber_tv.setOnClickListener((View v) -> {
actionNumberTouch(0, driver);
});
phoneNumber_tv.setOnLongClickListener((View v) -> {
actionNumberTouch(1, driver);
return true;
});
App.getBus().register(this);
notVisible = false;
scheduledToClose = false;
configureShareBt();
}
Aggregations