Search in sources :

Example 6 with RideForJson

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

the class MyRidesAdapter method configureMyActiveRides.

private void configureMyActiveRides(int position, final MyRidesAdapter.ViewHolder holder) {
    final RideForJson rideOffer = (RideForJson) rides.get(position);
    int color = Util.getColorbyZone(rideOffer.getZone());
    holder.location_tv.setTextColor(color);
    holder.photo_iv.setBorderColor(color);
    String profilePicUrl = rideOffer.getDriver().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);
    }
    String timeText;
    if (rideOffer.isGoing())
        timeText = activity.getResources().getString(R.string.arrivingAt, Util.formatTime(rideOffer.getTime()));
    else
        timeText = activity.getResources().getString(R.string.leavingAt, Util.formatTime(rideOffer.getTime()));
    holder.time_tv.setText(timeText);
    holder.date_tv.setText(Util.formatBadDateWithoutYear(rideOffer.getDate()));
    holder.name_tv.setText(rideOffer.getDriver().getName());
    String location;
    if (rideOffer.isGoing())
        location = rideOffer.getNeighborhood() + " ➜ " + rideOffer.getHub();
    else
        location = rideOffer.getHub() + " ➜ " + rideOffer.getNeighborhood();
    holder.location_tv.setText(location);
    holder.layout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            NewChatMsgIndicator.deleteAll(NewChatMsgIndicator.class, "db_id = ?", rideOffer.getDbId() + "");
            holder.newMsgIndicator_iv.setVisibility(View.INVISIBLE);
            Intent intent = new Intent(activity, ActiveRideAct.class);
            intent.putExtra("ride", rideOffer);
            activity.startActivity(intent);
            activity.overridePendingTransition(R.anim.anim_right_slide_in, R.anim.anim_left_slide_out);
        }
    });
    boolean found = false;
    for (NewChatMsgIndicator newChatMsgIndicator : newChatMsgIndicatorList) {
        if (newChatMsgIndicator.getDbId() == rideOffer.getDbId()) {
            holder.newMsgIndicator_iv.setVisibility(View.VISIBLE);
            found = true;
            break;
        }
    }
    if (!found)
        holder.newMsgIndicator_iv.setVisibility(View.INVISIBLE);
}
Also used : ActiveRideAct(br.ufrj.caronae.acts.ActiveRideAct) RideForJson(br.ufrj.caronae.models.modelsforjson.RideForJson) NewChatMsgIndicator(br.ufrj.caronae.models.NewChatMsgIndicator) RoundedTransformation(br.ufrj.caronae.RoundedTransformation) 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)

Example 7 with RideForJson

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

the class RideOfferAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final RideOfferAdapter.ViewHolder viewHolder, int position) {
    if (!(mixedList == null || mixedList.size() == 0)) {
        if (mixedList.get(position).getClass().equals(RideForJson.class)) {
            final RideForJson rideOffer = (RideForJson) mixedList.get(position);
            int color = Util.getColorbyZone(rideOffer.getZone());
            viewHolder.location_tv.setTextColor(color);
            viewHolder.time_tv.setTextColor(color);
            viewHolder.name_tv.setTextColor(color);
            viewHolder.date_tv.setTextColor(color);
            viewHolder.photo_iv.setBorderColor(color);
            String profilePicUrl = rideOffer.getDriver().getProfilePicUrl();
            if (profilePicUrl != null && !profilePicUrl.isEmpty()) {
                Picasso.with(context).load(profilePicUrl).placeholder(R.drawable.user_pic).error(R.drawable.user_pic).transform(new RoundedTransformation()).into(viewHolder.photo_iv);
            } else {
                viewHolder.photo_iv.setImageResource(R.drawable.user_pic);
            }
            String timeText;
            if (rideOffer.isGoing())
                timeText = context.getResources().getString(R.string.arrivingAt, Util.formatTime(rideOffer.getTime()));
            else
                timeText = context.getResources().getString(R.string.leavingAt, Util.formatTime(rideOffer.getTime()));
            viewHolder.time_tv.setText(timeText);
            viewHolder.date_tv.setText(Util.formatBadDateWithoutYear(rideOffer.getDate()));
            String name = rideOffer.getDriver().getName();
            try {
                String[] split = name.split(" ");
                String shortName = split[0] + " " + split[split.length - 1];
                viewHolder.name_tv.setText(shortName);
            } catch (Exception e) {
                viewHolder.name_tv.setText(name);
            }
            String location;
            if (rideOffer.isGoing())
                location = rideOffer.getNeighborhood() + " ➜ " + rideOffer.getHub();
            else
                location = rideOffer.getHub() + " ➜ " + rideOffer.getNeighborhood();
            viewHolder.location_tv.setText(location);
            List<RideRequestSent> rideRequests = RideRequestSent.find(RideRequestSent.class, "db_id = ?", rideOffer.getDbId() + "");
            boolean requested = false;
            if (rideRequests != null && !rideRequests.isEmpty())
                requested = true;
            viewHolder.requestIndicator_iv.setVisibility(requested ? View.VISIBLE : View.INVISIBLE);
            final boolean finalRequested = requested;
            viewHolder.parentLayout.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    Intent intent = new Intent(context, RideOfferAct.class);
                    intent.putExtra("ride", rideOffer);
                    intent.putExtra("requested", finalRequested);
                    context.startActivity(intent);
                }
            });
        } else {
            viewHolder.header_text.setText(getDateText((RideForJson) mixedList.get(position + 1)));
        }
    }
}
Also used : RideOfferAct(br.ufrj.caronae.acts.RideOfferAct) RideForJson(br.ufrj.caronae.models.modelsforjson.RideForJson) Intent(android.content.Intent) ImageView(android.widget.ImageView) CircleImageView(de.hdodenhof.circleimageview.CircleImageView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) RideRequestSent(br.ufrj.caronae.models.RideRequestSent) RoundedTransformation(br.ufrj.caronae.RoundedTransformation)

Example 8 with RideForJson

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

the class MyRidesListFrag method getActiveRides.

private void getActiveRides() {
    getActivity().runOnUiThread(new Runnable() {

        @Override
        public void run() {
            CaronaeAPI.service(getContext()).getMyActiveRides().enqueue(new Callback<List<RideForJson>>() {

                @Override
                public void onResponse(Call<List<RideForJson>> call, Response<List<RideForJson>> response) {
                    if (response.isSuccessful()) {
                        List<RideForJson> rideWithUsersList = response.body();
                        if (rideWithUsersList == null || rideWithUsersList.isEmpty()) {
                            MyRidesFrag.hideProgressBar();
                            myRidesList.setAdapter(new MyActiveRidesAdapter(new ArrayList<RideForJson>(), (MainAct) getActivity()));
                            myRidesList.setHasFixedSize(true);
                            myRidesList.setLayoutManager(new LinearLayoutManager(getActivity()));
                            new LoadRides().execute();
                            return;
                        }
                        ActiveRide.deleteAll(ActiveRide.class);
                        // subscribe to ride id topic
                        for (RideForJson rideWithUsers : rideWithUsersList) {
                            int rideId = rideWithUsers.getId().intValue();
                            rideWithUsers.setDbId(rideId);
                            FirebaseTopicsHandler.subscribeFirebaseTopic(rideId + "");
                            new ActiveRide(rideWithUsers.getDbId(), rideWithUsers.isGoing(), rideWithUsers.getDate()).save();
                        }
                        Collections.sort(rideWithUsersList, new RideOfferComparatorByDateAndTime());
                        addAllActiveRidesToList(rideWithUsersList);
                        MyRidesFrag.hideProgressBar();
                    } else {
                        Util.treatResponseFromServer(response);
                        MyRidesFrag.hideProgressBar();
                        norides_tv.setVisibility(View.VISIBLE);
                        Util.toast(R.string.frag_myactiverides_errorGetActiveRides);
                        Log.e("getMyActiveRides", response.message());
                    }
                    new LoadRides().execute();
                }

                @Override
                public void onFailure(Call<List<RideForJson>> call, Throwable t) {
                    MyRidesFrag.hideProgressBar();
                    norides_tv.setVisibility(View.VISIBLE);
                    Util.toast(R.string.frag_myactiverides_errorGetActiveRides);
                    new LoadRides().execute();
                    Log.e("getMyActiveRides", t.getMessage());
                }
            });
        }
    });
}
Also used : Call(retrofit2.Call) RideForJson(br.ufrj.caronae.models.modelsforjson.RideForJson) MyActiveRidesAdapter(br.ufrj.caronae.adapters.MyActiveRidesAdapter) ArrayList(java.util.ArrayList) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Response(retrofit2.Response) Callback(retrofit2.Callback) RideOfferComparatorByDateAndTime(br.ufrj.caronae.comparators.RideOfferComparatorByDateAndTime) MainAct(br.ufrj.caronae.acts.MainAct) ActiveRide(br.ufrj.caronae.models.ActiveRide)

Example 9 with RideForJson

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

the class RideSearchFrag method searchBt.

@OnClick(R.id.search_bt)
public void searchBt() {
    String location = location_et.getText().toString();
    if (location.isEmpty()) {
        Util.toast(getString(R.string.frag_rideSearch_locationEmpty));
        return;
    } else {
        if (location.contains("+")) {
            location = neighborhoods;
        }
    }
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy", Locale.US);
    String etDateString = date_et.getText().toString();
    Date todayDate = new Date();
    String todayString = simpleDateFormat.format(todayDate);
    try {
        todayDate = simpleDateFormat.parse(todayString);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    if (etDateString.isEmpty()) {
        date_et.setText(todayString);
        etDateString = todayString;
    } else {
        try {
            Date etDate = simpleDateFormat.parse(etDateString);
            if (etDate.before(todayDate)) {
                Util.toast(getString(R.string.frag_rideoffersearch_pastdate));
                return;
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
    String time = time_et.getText().toString();
    if (time.isEmpty()) {
        SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("HH:mm", Locale.US);
        String format = simpleDateFormat1.format(new Date());
        time_et.setText(format);
        time = format;
    }
    String center = center_et.getText().toString();
    if (center.equals(Util.getFundaoCenters()[0]) || center.equals("Cidade Universitária"))
        center = "";
    String campus = campi;
    boolean go = radioGroup.getCheckedRadioButtonId() == R.id.go_rb;
    RideSearchFiltersForJson rideSearchFilters = new RideSearchFiltersForJson(location, etDateString, time, center, campus, go, location_et.getText().toString());
    String lastRideSearchFilters = new Gson().toJson(rideSearchFilters);
    SharedPref.saveLastRideSearchFiltersPref(lastRideSearchFilters);
    rideSearchFilters.setDate(Util.formatBadDateWithYear(etDateString));
    Log.e("INPUT", "location: " + location);
    Log.e("INPUT", "data: " + etDateString);
    Log.e("INPUT", "hora: " + time);
    Log.e("INPUT", "center: " + center);
    Log.e("INPUT", "campus: " + campus);
    Log.e("INPUT", "locationResumeField: " + location_et.getText().toString());
    final ProgressDialog pd = ProgressDialog.show(getActivity(), "", getContext().getString(R.string.wait), true, true);
    CaronaeAPI.service(getContext()).listFiltered(rideSearchFilters).enqueue(new Callback<List<RideForJson>>() {

        @Override
        public void onResponse(Call<List<RideForJson>> call, Response<List<RideForJson>> response) {
            if (response.isSuccessful()) {
                List<RideForJson> rideOffers = response.body();
                if (rideOffers != null && !rideOffers.isEmpty()) {
                    Util.expandOrCollapse(lay, false);
                    anotherSearch_bt.setVisibility(View.VISIBLE);
                    Collections.sort(rideOffers, new RideOfferComparatorByDateAndTime());
                    for (RideForJson rideOffer : rideOffers) {
                        rideOffer.setDbId(rideOffer.getId().intValue());
                    }
                    adapter.makeList(rideOffers);
                } else {
                    Util.treatResponseFromServer(response);
                    Util.toast(R.string.frag_rideSearch_noRideFound);
                    adapter.makeList(new ArrayList<RideForJson>());
                }
                pd.dismiss();
            } else {
                pd.dismiss();
                Util.toast(R.string.frag_rideSearch_errorListFiltered);
                Log.e("listFiltered", response.message());
            }
        }

        @Override
        public void onFailure(Call<List<RideForJson>> call, Throwable t) {
            pd.dismiss();
            Util.toast(R.string.frag_rideSearch_errorListFiltered);
            Log.e("listFiltered", t.getMessage());
        }
    });
}
Also used : RideForJson(br.ufrj.caronae.models.modelsforjson.RideForJson) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) ProgressDialog(android.app.ProgressDialog) Date(java.util.Date) RideOfferComparatorByDateAndTime(br.ufrj.caronae.comparators.RideOfferComparatorByDateAndTime) ArrayList(java.util.ArrayList) List(java.util.List) ParseException(java.text.ParseException) RideSearchFiltersForJson(br.ufrj.caronae.models.modelsforjson.RideSearchFiltersForJson) SimpleDateFormat(java.text.SimpleDateFormat) OnClick(butterknife.OnClick)

Example 10 with RideForJson

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

the class RidesHistoryFrag method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_rides_history, container, false);
    ButterKnife.bind(this, view);
    final ProgressDialog pd = ProgressDialog.show(getActivity(), "", getContext().getString(R.string.wait), true, true);
    CaronaeAPI.service(getContext()).getRidesHistory().enqueue(new Callback<List<RideHistoryForJson>>() {

        @Override
        public void onResponse(Call<List<RideHistoryForJson>> call, Response<List<RideHistoryForJson>> response) {
            if (response.isSuccessful()) {
                List<RideHistoryForJson> historyRides = response.body();
                if (historyRides == null || historyRides.isEmpty()) {
                    norides_tv.setVisibility(View.VISIBLE);
                    pd.dismiss();
                    return;
                }
                for (RideForJson rideHistory : historyRides) {
                    rideHistory.setDbId(rideHistory.getId().intValue());
                    rideHistory.setTime(Util.formatTime(rideHistory.getTime()));
                    rideHistory.setDate(Util.formatBadDateWithYear(rideHistory.getDate()));
                }
                Collections.sort(historyRides, new RideComparatorByDateAndTimeReverse());
                myRidesList.setAdapter(new RidesHistoryAdapter(historyRides, (MainAct) getActivity()));
                myRidesList.setHasFixedSize(true);
                myRidesList.setLayoutManager(new LinearLayoutManager(getActivity()));
                pd.dismiss();
            } else {
                Util.treatResponseFromServer(response);
                norides_tv.setVisibility(View.VISIBLE);
                pd.dismiss();
                Util.toast(R.string.frag_rideshistory_errorGetRides);
                Log.e("getRidesHistory", response.message());
            }
        }

        @Override
        public void onFailure(Call<List<RideHistoryForJson>> call, Throwable t) {
            norides_tv.setVisibility(View.VISIBLE);
            pd.dismiss();
            Util.toast(R.string.frag_rideshistory_errorGetRides);
            Log.e("getRidesHistory", t.getMessage());
        }
    });
    return view;
}
Also used : RideForJson(br.ufrj.caronae.models.modelsforjson.RideForJson) RidesHistoryAdapter(br.ufrj.caronae.adapters.RidesHistoryAdapter) List(java.util.List) ProgressDialog(android.app.ProgressDialog) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) BindView(butterknife.BindView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) RideComparatorByDateAndTimeReverse(br.ufrj.caronae.comparators.RideComparatorByDateAndTimeReverse)

Aggregations

RideForJson (br.ufrj.caronae.models.modelsforjson.RideForJson)13 View (android.view.View)7 Intent (android.content.Intent)6 RecyclerView (android.support.v7.widget.RecyclerView)6 ArrayList (java.util.ArrayList)6 List (java.util.List)6 TextView (android.widget.TextView)5 ProgressDialog (android.app.ProgressDialog)4 ImageView (android.widget.ImageView)4 RideOfferComparatorByDateAndTime (br.ufrj.caronae.comparators.RideOfferComparatorByDateAndTime)4 Gson (com.google.gson.Gson)4 CircleImageView (de.hdodenhof.circleimageview.CircleImageView)4 Date (java.util.Date)4 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)3 RoundedTransformation (br.ufrj.caronae.RoundedTransformation)3 BindView (butterknife.BindView)3 SimpleDateFormat (java.text.SimpleDateFormat)3 ActiveRideAct (br.ufrj.caronae.acts.ActiveRideAct)2 ChatAssets (br.ufrj.caronae.models.ChatAssets)2 NewChatMsgIndicator (br.ufrj.caronae.models.NewChatMsgIndicator)2