app/src/main/java/com/smedic/tubtub/fragments/SearchFragment.java
private void addListeners() {

        videosFoundListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> av, View v, int pos,
                                    long id) {
                //check network connectivity
                if (!networkConf.isNetworkAvailable()) {
                    networkConf.createNetErrorDialog();
                    return;
                }

                Toast.makeText(getContext(), "Playing: " + searchResultsList.get(pos).getTitle(), Toast.LENGTH_SHORT).show();

                YouTubeSqlDb.getInstance().videos(YouTubeSqlDb.VIDEOS_TYPE.RECENTLY_WATCHED).create(searchResultsList.get(pos));

                Intent serviceIntent = new Intent(getContext(), BackgroundAudioService.class);
                serviceIntent.setAction(BackgroundAudioService.ACTION_PLAY);
                serviceIntent.putExtra(Config.YOUTUBE_TYPE, Config.YOUTUBE_MEDIA_TYPE_VIDEO);
                serviceIntent.putExtra(Config.YOUTUBE_TYPE_VIDEO, searchResultsList.get(pos));
                getActivity().startService(serviceIntent);
            }
        });

        videosFoundListView.setOnScrollListener(new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {

            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

                //if specified number of videos is added, do not load more
                if (totalItemCount < Config.NUMBER_OF_VIDEOS_RETURNED) {
                    if (view.getAdapter() != null && ((firstVisibleItem + visibleItemCount) >= totalItemCount) && totalItemCount != mPrevTotalItemCount) {
                        mPrevTotalItemCount = totalItemCount;
                        addMoreData();
                    }
                }
            }
        });
    }
/**
     * Adds listener for item list selection and starts BackgroundAudioService
     */
Adds listener for item list selection and starts BackgroundAudioService
Adds listener for item list selection and starts BackgroundAudioService
private void addListeners() {
        videosFoundListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> av, View v, int pos,
                                    long id) {
                if (!networkConf.isNetworkAvailable()) {
                    networkConf.createNetErrorDialog();
                    return;
                }
                Toast.makeText(getContext(), "Playing: " + searchResultsList.get(pos).getTitle(), Toast.LENGTH_SHORT).show();
                YouTubeSqlDb.getInstance().videos(YouTubeSqlDb.VIDEOS_TYPE.RECENTLY_WATCHED).create(searchResultsList.get(pos));
                Intent serviceIntent = new Intent(getContext(), BackgroundAudioService.class);
                serviceIntent.setAction(BackgroundAudioService.ACTION_PLAY);
                serviceIntent.putExtra(Config.YOUTUBE_TYPE, Config.YOUTUBE_MEDIA_TYPE_VIDEO);
                serviceIntent.putExtra(Config.YOUTUBE_TYPE_VIDEO, searchResultsList.get(pos));
                getActivity().startService(serviceIntent);
            }
        });
        videosFoundListView.setOnScrollListener(new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {
            }
            @Override
            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
                if (totalItemCount < Config.NUMBER_OF_VIDEOS_RETURNED) {
                    if (view.getAdapter() != null && ((firstVisibleItem + visibleItemCount) >= totalItemCount) && totalItemCount != mPrevTotalItemCount) {
                        mPrevTotalItemCount = totalItemCount;
                        addMoreData();
                    }
                }
            }
        });
    }
private void addListeners ( ) { videosFoundListView . setOnItemClickListener ( new AdapterView . OnItemClickListener ( ) { @ Override public void onItemClick ( AdapterView < ? > av , View v , int pos , long id ) { if ( ! networkConf . isNetworkAvailable ( ) ) { networkConf . createNetErrorDialog ( ) ; return ; } Toast . makeText ( getContext ( ) , "Playing: " + searchResultsList . get ( pos ) . getTitle ( ) , Toast . LENGTH_SHORT ) . show ( ) ; YouTubeSqlDb . getInstance ( ) . videos ( YouTubeSqlDb . VIDEOS_TYPE . RECENTLY_WATCHED ) . create ( searchResultsList . get ( pos ) ) ; Intent serviceIntent = new Intent ( getContext ( ) , BackgroundAudioService . class ) ; serviceIntent . setAction ( BackgroundAudioService . ACTION_PLAY ) ; serviceIntent . putExtra ( Config . YOUTUBE_TYPE , Config . YOUTUBE_MEDIA_TYPE_VIDEO ) ; serviceIntent . putExtra ( Config . YOUTUBE_TYPE_VIDEO , searchResultsList . get ( pos ) ) ; getActivity ( ) . startService ( serviceIntent ) ; } } ) ; videosFoundListView . setOnScrollListener ( new AbsListView . OnScrollListener ( ) { @ Override public void onScrollStateChanged ( AbsListView view , int scrollState ) { } @ Override public void onScroll ( AbsListView view , int firstVisibleItem , int visibleItemCount , int totalItemCount ) { if ( totalItemCount < Config . NUMBER_OF_VIDEOS_RETURNED ) { if ( view . getAdapter ( ) != null && ( ( firstVisibleItem + visibleItemCount ) >= totalItemCount ) && totalItemCount != mPrevTotalItemCount ) { mPrevTotalItemCount = totalItemCount ; addMoreData ( ) ; } } } } ) ; }
Adds listener for item list selection and starts BackgroundAudioService
Adds listener for item list selection and starts BackgroundAudioService
//check network connectivity //if specified number of videos is added, do not load more