Search in sources :

Example 1 with MainAct

use of br.ufrj.caronae.acts.MainAct in project caronae-android by caronae.

the class AllRidesFrag method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_all_rides, container, false);
    ButterKnife.bind(this, view);
    context = getContext();
    setHasOptionsMenu(true);
    coordinatorLayout = (CoordinatorLayout) view.findViewById(R.id.all_rides_coordinator);
    listAllRides(1);
    if (((MainAct) getActivity()).filterText.getText().equals("")) {
        ((MainAct) getActivity()).hideFilterCard(context);
    }
    return view;
}
Also used : MainAct(br.ufrj.caronae.acts.MainAct) BindView(butterknife.BindView) View(android.view.View)

Example 2 with MainAct

use of br.ufrj.caronae.acts.MainAct 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 3 with MainAct

use of br.ufrj.caronae.acts.MainAct in project caronae-android by caronae.

the class MyRidesListFrag method updateAdapter.

private void updateAdapter() {
    adapter = new MyRidesAdapter(allRides, (MainAct) getActivity());
    myRidesList.setAdapter(adapter);
    myRidesList.setLayoutManager(new LinearLayoutManager(getActivity()));
}
Also used : MyRidesAdapter(br.ufrj.caronae.adapters.MyRidesAdapter) MainAct(br.ufrj.caronae.acts.MainAct) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Aggregations

MainAct (br.ufrj.caronae.acts.MainAct)3 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 View (android.view.View)1 MyActiveRidesAdapter (br.ufrj.caronae.adapters.MyActiveRidesAdapter)1 MyRidesAdapter (br.ufrj.caronae.adapters.MyRidesAdapter)1 RideOfferComparatorByDateAndTime (br.ufrj.caronae.comparators.RideOfferComparatorByDateAndTime)1 ActiveRide (br.ufrj.caronae.models.ActiveRide)1 RideForJson (br.ufrj.caronae.models.modelsforjson.RideForJson)1 BindView (butterknife.BindView)1 ArrayList (java.util.ArrayList)1 Call (retrofit2.Call)1 Callback (retrofit2.Callback)1 Response (retrofit2.Response)1