Search in sources :

Example 1 with RideOfferAdapter

use of br.ufrj.caronae.adapters.RideOfferAdapter in project caronae-android by caronae.

the class AllRidesListFrag method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_all_rides_list, container, false);
    ButterKnife.bind(this, view);
    Bundle bundle = getArguments();
    ArrayList<RideForJson> rideOffers = bundle.getParcelableArrayList("rides");
    pageIdentifier = bundle.getInt("ID");
    refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            pageCounter = FIRST_PAGE_TO_LOAD;
            for (int counter = FIRST_PAGE_TO_LOAD; counter <= pageCounter; counter++) {
                refreshRideList(counter);
            }
        }
    });
    adapter = new RideOfferAdapter(new ArrayList<RideForJson>(), getContext(), getActivity().getFragmentManager());
    mLayoutManager = new LinearLayoutManager(getContext());
    rvRides.setLayoutManager(mLayoutManager);
    scrollListener = new EndlessRecyclerViewScrollListener(mLayoutManager) {

        @Override
        public void onLoadMore(int page, int totalItemsCount, RecyclerView view) {
            loadOneMorePage();
        }
    };
    rvRides.addOnScrollListener(scrollListener);
    rvRides.setAdapter(adapter);
    if (!(rideOffers == null || rideOffers.isEmpty())) {
        adapter.makeList(rideOffers);
    }
    App.getBus().register(this);
    // After setting layout manager, adapter, etc...
    float offsetBottonPx = getResources().getDimension(R.dimen.recycler_view_botton_offset);
    float offsetTopPx = getResources().getDimension(R.dimen.recycler_view_top_offset);
    Util.OffsetDecoration OffsetDecoration = new Util.OffsetDecoration((int) offsetBottonPx, (int) offsetTopPx);
    rvRides.addItemDecoration(OffsetDecoration);
    animateListFadeIn();
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(App.getInst());
    sharedPreferences.registerOnSharedPreferenceChangeListener(new SharedPreferences.OnSharedPreferenceChangeListener() {

        @Override
        public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
            if (key.equals(SharedPref.RIDE_FILTER_PREF_KEY)) {
                pageCounter = FIRST_PAGE_TO_LOAD;
                refreshRideList(pageCounter);
            }
        }
    });
    return view;
}
Also used : RideOfferAdapter(br.ufrj.caronae.adapters.RideOfferAdapter) RideForJson(br.ufrj.caronae.models.modelsforjson.RideForJson) SharedPreferences(android.content.SharedPreferences) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) Util(br.ufrj.caronae.Util) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) BindView(butterknife.BindView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) EndlessRecyclerViewScrollListener(br.ufrj.caronae.EndlessRecyclerViewScrollListener) RecyclerView(android.support.v7.widget.RecyclerView)

Example 2 with RideOfferAdapter

use of br.ufrj.caronae.adapters.RideOfferAdapter in project caronae-android by caronae.

the class RideSearchFrag method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_ride_search, container, false);
    ButterKnife.bind(this, view);
    adapter = new RideOfferAdapter(new ArrayList<RideForJson>(), getActivity(), getActivity().getFragmentManager());
    rvRides.setAdapter(adapter);
    rvRides.setHasFixedSize(true);
    rvRides.setLayoutManager(new LinearLayoutManager(getActivity()));
    String lastRideSearchFilters = SharedPref.getLastRideSearchFiltersPref();
    if (!lastRideSearchFilters.equals(SharedPref.MISSING_PREF)) {
        loadLastFilters(lastRideSearchFilters);
    }
    App.getBus().register(this);
    return view;
}
Also used : RideOfferAdapter(br.ufrj.caronae.adapters.RideOfferAdapter) ArrayList(java.util.ArrayList) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) BindView(butterknife.BindView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView)

Aggregations

LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2 RideOfferAdapter (br.ufrj.caronae.adapters.RideOfferAdapter)2 BindView (butterknife.BindView)2 ArrayList (java.util.ArrayList)2 SharedPreferences (android.content.SharedPreferences)1 Bundle (android.os.Bundle)1 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)1 TextView (android.widget.TextView)1 EndlessRecyclerViewScrollListener (br.ufrj.caronae.EndlessRecyclerViewScrollListener)1 Util (br.ufrj.caronae.Util)1 RideForJson (br.ufrj.caronae.models.modelsforjson.RideForJson)1