Beispiel #1
0
        // constructor
        public RecyclerViewEndlessScrollListener(LinearLayoutManager layoutManager, NewsRecyclerAdapter adapter)
        {
            LayoutManager       = layoutManager;
            RecyclerViewAdapter = adapter;

            TriggerThreshold = 1;
        }
Beispiel #2
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            // Swipe refresh layout.
            swipeRefreshLayout = (SwipeRefreshLayout)inflater.Inflate(Resource.Layout.NewsFragment, container, false);

            // Recycler view & setup.
            recyclerView = swipeRefreshLayout.FindViewById <RecyclerView>(Resource.Id.newsfragment_recyclerview);
            LinearLayoutManager linearLayoutManager = new LinearLayoutManager(Activity);

            recyclerView.SetLayoutManager(linearLayoutManager);

            // Prepare adapter (an empty one).
            currentAdapter                  = new NewsRecyclerAdapter(Activity);
            currentAdapter.ItemClick       += (o, e) => OnNewsClick(e.ItemPosition);
            currentAdapter.Error           += OnError;
            currentAdapter.ConnectionError += OnConnectionError;
            currentAdapter.NoData          += OnNoData;
            currentAdapter.Loading         += OnLoading;
            currentAdapter.Loaded          += OnLoaded;


            recyclerView.SetAdapter(currentAdapter);

            // Apply scroll listener to recyclerview.
            endlessScrollListener = new RecyclerViewEndlessScrollListener(linearLayoutManager, currentAdapter);
            endlessScrollListener.ThresholdReached += async(o, e) => await currentAdapter.LoadMore();

            endlessScrollListener.Scroll += HandleScroll;

            recyclerView.AddOnScrollListener(endlessScrollListener);

            // swipe refresh layout events setup
            swipeRefreshLayout.Refresh += async(o, e) => await currentAdapter.RefreshNews();

            return(swipeRefreshLayout);
        }