Search in sources :

Example 11 with User

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

the class MyRidesAdapter method configureMyOfferRide.

private void configureMyOfferRide(int position, final MyRidesAdapter.ViewHolder holder) {
    final Ride ride = (Ride) rides.get(position);
    int color = Util.getColorbyZone(ride.getZone());
    holder.location_tv.setTextColor(color);
    if (ride.isGoing())
        holder.time_tv.setText(activity.getString(R.string.arrivingAt, Util.formatBadHour(ride.getTime())));
    else
        holder.time_tv.setText(activity.getString(R.string.leavingAt, Util.formatBadHour(ride.getTime())));
    if (ride.getDate().contains("-")) {
        ride.setDate(Util.formatBadDateWithYear(ride.getDate()));
    }
    holder.date_tv.setText(Util.formatGoodDateWithoutYear(ride.getDate()));
    holder.slots_tv.setText(activity.getString(R.string.Xslots, ride.getSlots(), (Integer.parseInt(ride.getSlots()) > 1 ? "s" : "")));
    String location;
    if (ride.isGoing())
        location = ride.getNeighborhood() + " ➜ " + ride.getHub();
    else
        location = ride.getHub() + " ➜ " + ride.getNeighborhood();
    holder.location_tv.setText(location);
    String s = activity.getString(R.string.repeats);
    if (ride.isRoutine()) {
        s += ride.getWeekDays().contains("7") ? activity.getString(R.string.sunday) : "";
        s += ride.getWeekDays().contains("1") ? activity.getString(R.string.monday) : "";
        s += ride.getWeekDays().contains("2") ? activity.getString(R.string.tuesday) : "";
        s += ride.getWeekDays().contains("3") ? activity.getString(R.string.wednesday) : "";
        s += ride.getWeekDays().contains("4") ? activity.getString(R.string.thursday) : "";
        s += ride.getWeekDays().contains("5") ? activity.getString(R.string.friday) : "";
        s += ride.getWeekDays().contains("6") ? activity.getString(R.string.saturday) : "";
        s = s.substring(0, s.length() - 1);
    } else {
        s = activity.getString(R.string.notRoutine);
    }
    holder.routine_tv.setText(s);
    holder.delete_bt.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (ride.isRoutine()) {
                Dialog.Builder builder = new SimpleDialog.Builder(R.style.SimpleDialogLight) {

                    @Override
                    protected void onBuildDone(Dialog dialog) {
                        dialog.layoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                    }

                    @Override
                    public void onPositiveActionClicked(DialogFragment fragment) {
                        RadioGroup radioGroup = (RadioGroup) fragment.getDialog().findViewById(R.id.radioGroup);
                        int checkedRadioButton = radioGroup.getCheckedRadioButtonId();
                        switch(checkedRadioButton) {
                            case R.id.all_rb:
                                deleteAllRidesFromRoutine();
                                break;
                            case R.id.single_rb:
                                deleteSingleRide();
                                break;
                        }
                        super.onPositiveActionClicked(fragment);
                    }

                    @Override
                    public void onNegativeActionClicked(DialogFragment fragment) {
                        super.onNegativeActionClicked(fragment);
                    }
                };
                builder.title(activity.getString(R.string.attention)).positiveAction(activity.getString(R.string.ok)).negativeAction(activity.getString(R.string.cancel)).contentView(R.layout.delete_routine_dialog);
                DialogFragment fragment = DialogFragment.newInstance(builder);
                fragment.show(activity.getSupportFragmentManager(), null);
            } else {
                deleteSingleRide();
            }
        }

        private void deleteAllRidesFromRoutine() {
            Dialog.Builder builder = new SimpleDialog.Builder(R.style.SimpleDialogLight) {

                @Override
                public void onPositiveActionClicked(DialogFragment fragment) {
                    final ProgressDialog pd = ProgressDialog.show(activity, "", activity.getString(R.string.wait), true, true);
                    final String routineId = ride.getRoutineId();
                    CaronaeAPI.service(activity.getApplicationContext()).deleteAllRidesFromRoutine(routineId).enqueue(new Callback<ResponseBody>() {

                        @Override
                        public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                            if (response.isSuccessful()) {
                                pd.dismiss();
                                Util.toast(R.string.ridesDeleted);
                                if (routineId != null) {
                                    Iterator<Object> it = rides.iterator();
                                    while (it.hasNext()) {
                                        Object object = it.next();
                                        if (object.getClass() == Ride.class) {
                                            Ride ride2 = (Ride) object;
                                            if (ride2.getRoutineId().equals(routineId))
                                                it.remove();
                                        }
                                    }
                                }
                                notifyDataSetChanged();
                                Ride.deleteAll(Ride.class, "routine_id = ?", routineId);
                            } else {
                                Util.treatResponseFromServer(response);
                                pd.dismiss();
                                Util.toast(activity.getString(R.string.errorDeleteRide));
                                Log.e("deleteAllFromRoutine", response.message());
                            }
                        }

                        @Override
                        public void onFailure(Call<ResponseBody> call, Throwable t) {
                            pd.dismiss();
                            Util.toast(activity.getString(R.string.errorDeleteRide));
                            Log.e("deleteAllFromRoutine", t.getMessage());
                        }
                    });
                    super.onPositiveActionClicked(fragment);
                }

                @Override
                public void onNegativeActionClicked(DialogFragment fragment) {
                    super.onNegativeActionClicked(fragment);
                }
            };
            ((SimpleDialog.Builder) builder).message(activity.getString(R.string.warnDeleteRidesCouldBeActive)).title(activity.getString(R.string.attention)).positiveAction(activity.getString(R.string.ok)).negativeAction(activity.getString(R.string.cancel));
            DialogFragment fragment = DialogFragment.newInstance(builder);
            fragment.show(activity.getSupportFragmentManager(), null);
        }

        private void deleteSingleRide() {
            Dialog.Builder builder = new SimpleDialog.Builder(R.style.SimpleDialogLight) {

                @Override
                public void onPositiveActionClicked(DialogFragment fragment) {
                    final ProgressDialog pd = ProgressDialog.show(activity, "", activity.getString(R.string.wait), true, true);
                    CaronaeAPI.service(activity.getApplicationContext()).deleteRide(ride.getDbId() + "").enqueue(new Callback<ResponseBody>() {

                        @Override
                        public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                            if (response.isSuccessful()) {
                                pd.dismiss();
                                Util.toast(R.string.rideDeleted);
                                rides.remove(ride);
                                notifyItemRemoved(holder.getAdapterPosition());
                                for (int rideCounter = 0; rideCounter < rides.size(); rideCounter++) {
                                    if (rides.get(rideCounter).getClass() == RideForJson.class) {
                                        RideForJson rideForJson = (RideForJson) rides.get(rideCounter);
                                        if (rideForJson.getId() == ride.getId()) {
                                            rides.remove(rideForJson);
                                            notifyItemRemoved(rideCounter);
                                        }
                                    }
                                }
                                ride.delete();
                            } else {
                                Util.treatResponseFromServer(response);
                                pd.dismiss();
                                Util.toast(activity.getString(R.string.errorDeleteRide));
                                Log.e("deleteRide", response.message());
                            }
                        }

                        @Override
                        public void onFailure(Call<ResponseBody> call, Throwable t) {
                            pd.dismiss();
                            Util.toast(activity.getString(R.string.errorDeleteRide));
                            Log.e("deleteRide", t.getMessage());
                        }
                    });
                    super.onPositiveActionClicked(fragment);
                }

                @Override
                public void onNegativeActionClicked(DialogFragment fragment) {
                    super.onNegativeActionClicked(fragment);
                }
            };
            ((SimpleDialog.Builder) builder).message(activity.getString(R.string.warnDeleteRideCouldBeActive)).title(activity.getString(R.string.attention)).positiveAction(activity.getString(R.string.ok)).negativeAction(activity.getString(R.string.cancel));
            DialogFragment fragment = DialogFragment.newInstance(builder);
            fragment.show(activity.getSupportFragmentManager(), null);
        }
    });
    final int colorToSend = color;
    final boolean[] isOpen = { false, false };
    holder.myRideLayout.setShowMode(SwipeLayout.ShowMode.LayDown);
    holder.delete_bt.setBackgroundColor(color);
    holder.myRideLayout.addSwipeListener(new SwipeLayout.SwipeListener() {

        @Override
        public void onStartOpen(SwipeLayout layout) {
            isOpen[0] = true;
            isOpen[1] = true;
        }

        @Override
        public void onOpen(SwipeLayout layout) {
        }

        @Override
        public void onStartClose(SwipeLayout layout) {
        }

        @Override
        public void onClose(SwipeLayout layout) {
            isOpen[1] = false;
        }

        @Override
        public void onUpdate(SwipeLayout layout, int leftOffset, int topOffset) {
        }

        @Override
        public void onHandRelease(SwipeLayout layout, float xvel, float yvel) {
        }
    });
    holder.share_bt.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("text/plain");
            intent.putExtra(Intent.EXTRA_TEXT, Util.getTextToShareRide(ride));
            intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Check out this site!");
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            activity.startActivity(intent.createChooser(intent, "Compartilhar Carona"));
        }
    });
    holder.myRideLayout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (!isOpen[0]) {
                final ProgressDialog pd = ProgressDialog.show(activity, "", activity.getResources().getString(R.string.wait), true, true);
                RideRequestReceived.deleteAll(RideRequestReceived.class, "db_id = ?", ride.getDbId() + "");
                holder.newRequest_iv.setVisibility(View.INVISIBLE);
                CaronaeAPI.service(activity.getApplicationContext()).getRequesters(ride.getDbId() + "").enqueue(new Callback<List<User>>() {

                    @Override
                    public void onResponse(Call<List<User>> call, Response<List<User>> response) {
                        if (response.isSuccessful()) {
                            pd.dismiss();
                            List<User> users = response.body();
                            if (users.isEmpty()) {
                                Util.toast(R.string.noRequesters);
                            } else {
                                Intent intent = new Intent(activity, RequestersListAct.class);
                                intent.putParcelableArrayListExtra("users", (ArrayList<User>) users);
                                intent.putExtra("rideId", ride.getDbId());
                                intent.putExtra("color", colorToSend);
                                activity.startActivity(intent);
                            }
                        } else {
                            Util.treatResponseFromServer(response);
                            pd.dismiss();
                            Util.toast(R.string.errorGetRequesters);
                            Log.e("getRequesters", response.message());
                        }
                    }

                    @Override
                    public void onFailure(Call<List<User>> call, Throwable t) {
                        pd.dismiss();
                        Util.toast(R.string.errorGetRequesters);
                        Log.e("getRequesters", t.getMessage());
                    }
                });
            } else if (isOpen[0] && !isOpen[1]) {
                isOpen[0] = false;
            }
        }
    });
    boolean found = false;
    for (RideRequestReceived requestReceived : rideRequestReceivedList) {
        if (requestReceived.getDbId() == ride.getDbId()) {
            holder.newRequest_iv.setVisibility(View.VISIBLE);
            found = true;
            break;
        }
    }
    if (!found) {
        CaronaeAPI.service(activity.getApplicationContext()).getRequesters(ride.getDbId() + "").enqueue(new Callback<List<User>>() {

            @Override
            public void onResponse(Call<List<User>> call, Response<List<User>> response) {
                if (response.isSuccessful()) {
                    List<User> requesters = response.body();
                    if (requesters.isEmpty()) {
                        holder.newRequest_iv.setVisibility(View.INVISIBLE);
                    } else {
                        holder.newRequest_iv.setVisibility(View.VISIBLE);
                        new RideRequestReceived(Integer.valueOf(ride.getDbId())).save();
                    }
                } else {
                    Util.toast(R.string.errorGetRequesters);
                    Log.e("getRequesters", response.message());
                }
            }

            @Override
            public void onFailure(Call<List<User>> call, Throwable t) {
                Util.toast(R.string.errorGetRequesters);
                Log.e("getRequesters", t.getMessage());
            }
        });
    }
}
Also used : User(br.ufrj.caronae.models.User) RadioGroup(android.widget.RadioGroup) DialogFragment(com.rey.material.app.DialogFragment) ProgressDialog(android.app.ProgressDialog) SimpleDialog(com.rey.material.app.SimpleDialog) ProgressDialog(android.app.ProgressDialog) SimpleDialog(com.rey.material.app.SimpleDialog) Dialog(com.rey.material.app.Dialog) SwipeLayout(com.daimajia.swipe.SwipeLayout) RideRequestReceived(br.ufrj.caronae.models.RideRequestReceived) ArrayList(java.util.ArrayList) List(java.util.List) Call(retrofit2.Call) RideForJson(br.ufrj.caronae.models.modelsforjson.RideForJson) Intent(android.content.Intent) ImageView(android.widget.ImageView) CircleImageView(de.hdodenhof.circleimageview.CircleImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) Response(retrofit2.Response) Callback(retrofit2.Callback) Ride(br.ufrj.caronae.models.Ride)

Example 12 with User

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

the class RequestersAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final RequestersAdapter.ViewHolder holder, final int position) {
    final User user = users.get(position);
    holder.name_tv.setText(user.getName());
    holder.course_tv.setText(user.getCourse());
    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);
    } else {
        holder.photo_iv.setImageResource(R.drawable.user_pic);
    }
    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));
            intent.putExtra("from", "requesters");
            activity.startActivity(intent);
        }
    });
    holder.accept_bt.setTextColor(color);
    holder.accept_bt.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            final ProgressDialog pd = ProgressDialog.show(activity, "", activity.getString(R.string.wait), true, true);
            CaronaeAPI.service(activity.getApplicationContext()).answerJoinRequest(String.valueOf(rideId), new JoinRequestIDsForJson(user.getDbId(), true)).enqueue(new Callback<ResponseBody>() {

                @Override
                public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                    if (response.isSuccessful()) {
                        pd.dismiss();
                        Util.toast(R.string.requestAccepted);
                        users.remove(user);
                        notifyItemRemoved(holder.getAdapterPosition());
                        if (users.isEmpty())
                            activity.finish();
                        FirebaseTopicsHandler.subscribeFirebaseTopic(rideId + "");
                    } else {
                        Util.treatResponseFromServer(response);
                        pd.dismiss();
                        Log.e("answerJoinRequest", response.message());
                        Util.toast(R.string.errorAnsweRequest);
                    }
                }

                @Override
                public void onFailure(Call<ResponseBody> call, Throwable t) {
                    pd.dismiss();
                    Log.e("answerJoinRequest", t.getMessage());
                    Util.toast(R.string.errorAnsweRequest);
                }
            });
        }
    });
    holder.reject_bt.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            final ProgressDialog pd = ProgressDialog.show(activity, "", activity.getString(R.string.wait), true, true);
            CaronaeAPI.service(activity.getApplicationContext()).answerJoinRequest(String.valueOf(rideId), new JoinRequestIDsForJson(user.getDbId(), false)).enqueue(new Callback<ResponseBody>() {

                @Override
                public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                    if (response.isSuccessful()) {
                        pd.dismiss();
                        Util.toast(R.string.requestRejected);
                        users.remove(user);
                        notifyItemRemoved(holder.getAdapterPosition());
                    } else {
                        Util.treatResponseFromServer(response);
                        pd.dismiss();
                        Log.e("answerJoinRequest", response.message());
                    }
                }

                @Override
                public void onFailure(Call<ResponseBody> call, Throwable t) {
                    pd.dismiss();
                    Log.e("answerJoinRequest", t.getMessage());
                }
            });
        }
    });
}
Also used : Call(retrofit2.Call) User(br.ufrj.caronae.models.User) Gson(com.google.gson.Gson) Intent(android.content.Intent) ProgressDialog(android.app.ProgressDialog) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) JoinRequestIDsForJson(br.ufrj.caronae.models.modelsforjson.JoinRequestIDsForJson) Response(retrofit2.Response) ProfileAct(br.ufrj.caronae.acts.ProfileAct) Callback(retrofit2.Callback) RoundedTransformation(br.ufrj.caronae.RoundedTransformation)

Example 13 with User

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

the class RidesHistoryAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final RidesHistoryAdapter.ViewHolder holder, int position) {
    final RideHistoryForJson historyRide = historyRides.get(position);
    int color = 0, bgRes = 0;
    if (historyRide.getZone().equals("Centro")) {
        color = ContextCompat.getColor(activity, R.color.zone_centro);
        bgRes = R.drawable.bg_bt_raise_zone_centro;
    }
    if (historyRide.getZone().equals("Zona Sul")) {
        color = ContextCompat.getColor(activity, R.color.zone_sul);
        bgRes = R.drawable.bg_bt_raise_zone_sul;
    }
    if (historyRide.getZone().equals("Zona Oeste")) {
        color = ContextCompat.getColor(activity, R.color.zone_oeste);
        bgRes = R.drawable.bg_bt_raise_zone_oeste;
    }
    if (historyRide.getZone().equals("Zona Norte")) {
        color = ContextCompat.getColor(activity, R.color.zone_norte);
        bgRes = R.drawable.bg_bt_raise_zone_norte;
    }
    if (historyRide.getZone().equals("Baixada")) {
        color = ContextCompat.getColor(activity, R.color.zone_baixada);
        bgRes = R.drawable.bg_bt_raise_zone_baixada;
    }
    if (historyRide.getZone().equals("Grande Niterói")) {
        color = ContextCompat.getColor(activity, R.color.zone_niteroi);
        bgRes = R.drawable.bg_bt_raise_zone_niteroi;
    }
    if (historyRide.getZone().equals("Outros")) {
        color = ContextCompat.getColor(activity, R.color.zone_outros);
        bgRes = R.drawable.bg_bt_raise_zone_outros;
    }
    if (historyRide.isGoing())
        holder.time_tv.setText(activity.getString(R.string.arrivedAt, historyRide.getTime() + " | "));
    else
        holder.time_tv.setText(activity.getString(R.string.leftAt, historyRide.getTime() + " | "));
    holder.time_tv.setTextColor(color);
    holder.date_tv.setText(Util.formatDateRemoveYear(historyRide.getDate()));
    holder.date_tv.setTextColor(color);
    holder.name_tv.setTextColor(color);
    String location;
    if (historyRide.isGoing()) {
        location = historyRide.getNeighborhood() + " ➜ " + historyRide.getHub();
    } else {
        location = historyRide.getHub() + " ➜ " + historyRide.getNeighborhood();
    }
    holder.location_tv.setText(location);
    holder.location_tv.setTextColor(color);
    User driver = historyRide.getDriver();
    if (driver != null) {
        holder.name_tv.setText(driver.getName());
        String driverPic = driver.getProfilePicUrl();
        if (driverPic != null && !driverPic.isEmpty()) {
            Picasso.with(activity).load(driverPic).placeholder(R.drawable.user_pic).error(R.drawable.user_pic).transform(new RoundedTransformation()).into(holder.photo_iv);
        } else {
            holder.photo_iv.setImageResource(R.drawable.user_pic);
        }
    }
}
Also used : RideHistoryForJson(br.ufrj.caronae.models.modelsforjson.RideHistoryForJson) User(br.ufrj.caronae.models.User) RoundedTransformation(br.ufrj.caronae.RoundedTransformation)

Aggregations

User (br.ufrj.caronae.models.User)13 View (android.view.View)8 ImageView (android.widget.ImageView)8 TextView (android.widget.TextView)8 RoundedTransformation (br.ufrj.caronae.RoundedTransformation)8 Intent (android.content.Intent)5 RecyclerView (android.support.v7.widget.RecyclerView)5 BindView (butterknife.BindView)5 Gson (com.google.gson.Gson)5 Call (retrofit2.Call)5 Callback (retrofit2.Callback)5 Response (retrofit2.Response)5 ProgressDialog (android.app.ProgressDialog)4 SimpleDialog (com.rey.material.app.SimpleDialog)4 ActionBar (android.support.v7.app.ActionBar)3 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)3 Toolbar (android.support.v7.widget.Toolbar)3 DialogFragment (com.rey.material.app.DialogFragment)3 List (java.util.List)3 ScrollView (android.widget.ScrollView)2