Search in sources :

Example 1 with InfoListAdapter

use of org.schabi.newpipe.info_list.InfoListAdapter in project NewPipe by TeamNewPipe.

the class ChannelActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ThemeHelper.setTheme(this, true);
    setContentView(R.layout.activity_channel);
    rootView = findViewById(android.R.id.content);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowTitleEnabled(true);
    infoListAdapter = new InfoListAdapter(this, rootView);
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.channel_streams_view);
    final LinearLayoutManager layoutManager = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(layoutManager);
    header = getLayoutInflater().inflate(R.layout.channel_header, recyclerView, false);
    infoListAdapter.setHeader(header);
    infoListAdapter.setFooter(getLayoutInflater().inflate(R.layout.pignate_footer, recyclerView, false));
    recyclerView.setAdapter(infoListAdapter);
    infoListAdapter.setOnStreamInfoItemSelectedListener(new InfoItemBuilder.OnInfoItemSelectedListener() {

        @Override
        public void selected(String url, int serviceId) {
            NavStack.getInstance().openDetailActivity(ChannelActivity.this, url, serviceId);
        }
    });
    // detect if list has ben scrolled to the bottom
    recyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            int pastVisiblesItems, visibleItemCount, totalItemCount;
            super.onScrolled(recyclerView, dx, dy);
            if (//check for scroll down
            dy > 0) {
                visibleItemCount = layoutManager.getChildCount();
                totalItemCount = layoutManager.getItemCount();
                pastVisiblesItems = layoutManager.findFirstVisibleItemPosition();
                if ((visibleItemCount + pastVisiblesItems) >= totalItemCount && !isLoading && hasNextPage) {
                    pageNumber++;
                    requestData(true);
                }
            }
        }
    });
    subS = getString(R.string.subscriber);
    progressBar = (ProgressBar) findViewById(R.id.progressBar);
    channelBanner = (ImageView) header.findViewById(R.id.channel_banner_image);
    avatarView = (ImageView) header.findViewById(R.id.channel_avatar_view);
    titleView = (TextView) header.findViewById(R.id.channel_title_view);
    subscirberView = (TextView) header.findViewById(R.id.channel_subscriber_view);
    subscriberButton = (Button) header.findViewById(R.id.channel_subscribe_button);
    subscriberLayout = header.findViewById(R.id.channel_subscriber_layout);
    if (savedInstanceState == null) {
        handleIntent(getIntent());
    } else {
        channelUrl = savedInstanceState.getString(NavStack.URL);
        serviceId = savedInstanceState.getInt(NavStack.SERVICE_ID);
        NavStack.getInstance().restoreSavedInstanceState(savedInstanceState);
        handleIntent(getIntent());
    }
}
Also used : InfoItemBuilder(org.schabi.newpipe.info_list.InfoItemBuilder) InfoListAdapter(org.schabi.newpipe.info_list.InfoListAdapter) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Example 2 with InfoListAdapter

use of org.schabi.newpipe.info_list.InfoListAdapter in project NewPipe by TeamNewPipe.

the class SearchInfoItemFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_searchinfoitem, container, false);
    Context context = view.getContext();
    loadingIndicator = (ProgressBar) view.findViewById(R.id.progressBar);
    RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.list);
    streamInfoListLayoutManager = new LinearLayoutManager(context);
    recyclerView.setLayoutManager(streamInfoListLayoutManager);
    infoListAdapter = new InfoListAdapter(getActivity(), getActivity().findViewById(android.R.id.content));
    infoListAdapter.setFooter(inflater.inflate(R.layout.pignate_footer, recyclerView, false));
    infoListAdapter.showFooter(false);
    infoListAdapter.setOnStreamInfoItemSelectedListener(new InfoItemBuilder.OnInfoItemSelectedListener() {

        @Override
        public void selected(String url, int serviceId) {
            NavStack.getInstance().openDetailActivity(getContext(), url, serviceId);
        }
    });
    infoListAdapter.setOnChannelInfoItemSelectedListener(new InfoItemBuilder.OnInfoItemSelectedListener() {

        @Override
        public void selected(String url, int serviceId) {
            NavStack.getInstance().openChannelActivity(getContext(), url, serviceId);
        }
    });
    recyclerView.setAdapter(infoListAdapter);
    recyclerView.clearOnScrollListeners();
    recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            int pastVisiblesItems, visibleItemCount, totalItemCount;
            super.onScrolled(recyclerView, dx, dy);
            if (//check for scroll down
            dy > 0) {
                visibleItemCount = streamInfoListLayoutManager.getChildCount();
                totalItemCount = streamInfoListLayoutManager.getItemCount();
                pastVisiblesItems = streamInfoListLayoutManager.findFirstVisibleItemPosition();
                if ((visibleItemCount + pastVisiblesItems) >= totalItemCount && !isLoading) {
                    pageNumber++;
                    search(searchQuery, pageNumber);
                }
            }
        }
    });
    return view;
}
Also used : Context(android.content.Context) InfoItemBuilder(org.schabi.newpipe.info_list.InfoItemBuilder) RecyclerView(android.support.v7.widget.RecyclerView) InfoListAdapter(org.schabi.newpipe.info_list.InfoListAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SearchView(android.support.v7.widget.SearchView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView)

Aggregations

LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 RecyclerView (android.support.v7.widget.RecyclerView)2 InfoItemBuilder (org.schabi.newpipe.info_list.InfoItemBuilder)2 InfoListAdapter (org.schabi.newpipe.info_list.InfoListAdapter)2 Context (android.content.Context)1 SearchView (android.support.v7.widget.SearchView)1 View (android.view.View)1