aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/org/rssin/android/NavigationDrawerAllFeedsFragment.java
blob: b7a0d73176cc7f82f6c3b1cc0a7f3e2da831dbb0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package org.rssin.android;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.android.volley.VolleyError;

import org.rssin.listener.FallibleListener;
import org.rssin.rssin.FeedLoaderAndSorter;
import org.rssin.rssin.R;
import org.rssin.rssin.SortedFeedItemContainer;

import java.util.List;

/**
 * @author Jos.
 */

public class NavigationDrawerAllFeedsFragment extends Fragment {
    /**
     * Returns a new instance of this fragment for the given section
     * number.
     */
    public static NavigationDrawerAllFeedsFragment newInstance() {
        NavigationDrawerAllFeedsFragment fragment = new NavigationDrawerAllFeedsFragment();
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        final View rootView = inflater.inflate(R.layout.fragment_home_screen, container, false);
        final RecyclerView mRecyclerView = (RecyclerView) rootView.findViewById(R.id.unified_inbox_feeditems);
        final Context context = mRecyclerView.getContext();
        RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(context);
        mRecyclerView.setLayoutManager(mLayoutManager);

        /**
         * @todo Load feeds in separate thread so that the UI is immediately available
         *
         * @todo Now, feed items are only returned after *all* feeds have been loaded. With many
         * filters that may take a while, so it would be preferable to return intermediate
         * results. We could do this for example with {@link org.rssin.listener.RealtimeListener}
         */
        FeedLoaderAndSorter loaderAndSorter = new FeedLoaderAndSorter(FeedsList.getInstance().getFeeds());
        loaderAndSorter.getFilteredFeedItems(context, new VolleyFetcher(context), new FallibleListener<List<SortedFeedItemContainer>, VolleyError>() {
            @Override
            public void onReceive(List<SortedFeedItemContainer> data) {
                FeedItemAdapter feedItemAdapter = new FeedItemAdapter(data);
                mRecyclerView.setAdapter(feedItemAdapter);
                mRecyclerView.setHasFixedSize(true);
            }

            @Override
            public void onError(VolleyError error) {
                Frontend.error(context, R.string.error_net_load);
            }
        });

        return rootView;
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
    }
}