Android Open Source - rss List View Feeds






From Project

Back to project page rss.

License

The source code is released under:

GNU General Public License

If you think the Android project rss listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.// w  w w  .ja  v  a  2s  .  com
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

package com.poloure.simplerss.ui;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.AbsListView;
import android.widget.Adapter;
import android.widget.ListView;

import com.poloure.simplerss.AsyncNavigationAdapter;
import com.poloure.simplerss.FeedItem;
import com.poloure.simplerss.FeedsActivity;
import com.poloure.simplerss.adapters.AdapterFeedItems;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public
class ListViewFeeds extends ListView implements AbsListView.OnScrollListener
{
    public
    ListViewFeeds(Context context, AttributeSet attributeSet)
    {
        super(context, attributeSet);
        setOnScrollListener(this);
    }

    /**
     * Finds the item lowest in the list that is unread and sets the ListView selection
     * to this position. If no items are unread, sets the selection to 0.
     *
     * @param readItemTimes a Collection of longs that correspond to the unix times that the
     *                      FeedItems were made.
     *
     * @see com.poloure.simplerss.FeedItem
     */
    public
    void setSelectionOldestUnread(final Collection<Long> readItemTimes)
    {
        AdapterFeedItems listAdapter = getAdapter();
        final int pos = getPositionOfLastItemOnlyInB(readItemTimes, listAdapter.getKeyList());

        // If all items are read, set the selection to 0, else the position.
        // Must be post because this function is called very early during making the ListView.
        clearFocus();
        post(new Runnable()
        {

            @Override
            public
            void run()
            {

                setSelection(-1 == pos ? 0 : pos);
            }
        });
    }

    @Override
    public
    AdapterFeedItems getAdapter()
    {
        return (AdapterFeedItems) super.getAdapter();
    }

    /**
     * Finds the last item of B that is not in A.
     *
     * @param a Collection to remove all of its elements from b.
     * @param b List that we want the last item of.
     *
     * @return -1 if B is a subset of A, else position in b of last member of B exclusive of A.
     */
    private static
    int getPositionOfLastItemOnlyInB(Collection<Long> a, List<Long> b)
    {
        // Create a copy of the B list.
        List<Long> times = new ArrayList<Long>(b);

        // Removes all the items from B that are in both collections.
        times.removeAll(a);

        // If B is a subset of A, return -1.
        if(times.isEmpty())
        {
            return -1;
        }

        // Get the last item of the new List.
        int last = times.size() - 1;
        long l = times.get(last);

        // Return the position of the last item of the new List in B.
        return b.indexOf(l);
    }

    @Override
    public
    void onScrollStateChanged(AbsListView view, int scrollState)
    {
        FeedsActivity activity = (FeedsActivity) view.getContext();

        if(SCROLL_STATE_TOUCH_SCROLL == scrollState || SCROLL_STATE_IDLE == scrollState)
        {
            Adapter adapter = view.getAdapter();
            int first = view.getFirstVisiblePosition();
            int last = view.getLastVisiblePosition();

            for(int i = 0; last - first >= i; i++)
            {
                View viewItem = view.getChildAt(i);

                if(null != viewItem && viewItem.isShown() && 0 <= viewItem.getTop())
                {
                    FeedItem item = (FeedItem) adapter.getItem(first + i);
                    activity.readItem(item.m_time);
                }
            }
        }
        if(SCROLL_STATE_IDLE == scrollState)
        {
            AsyncNavigationAdapter.run(activity);
        }
    }

    @Override
    public
    void onScroll(AbsListView v, int fir, int visible, int total)
    {
    }
}




Java Source Code List

com.poloure.simplerss.AsyncCheckFeed.java
com.poloure.simplerss.AsyncLoadImage.java
com.poloure.simplerss.AsyncManageAdapter.java
com.poloure.simplerss.AsyncNavigationAdapter.java
com.poloure.simplerss.AsyncNewTagAdapters.java
com.poloure.simplerss.Constants.java
com.poloure.simplerss.DialogConfirm.java
com.poloure.simplerss.DialogEditFeed.java
com.poloure.simplerss.FeedItem.java
com.poloure.simplerss.FeedsActivity.java
com.poloure.simplerss.FragmentFeeds.java
com.poloure.simplerss.FragmentNavigationDrawer.java
com.poloure.simplerss.FragmentSettings.java
com.poloure.simplerss.IndexItem.java
com.poloure.simplerss.ListFragmentFavourites.java
com.poloure.simplerss.ListFragmentManage.java
com.poloure.simplerss.ListFragmentTag.java
com.poloure.simplerss.ObjectIO.java
com.poloure.simplerss.PagerAdapterTags.java
com.poloure.simplerss.RssLogger.java
com.poloure.simplerss.ServiceUpdate.java
com.poloure.simplerss.Utilities.java
com.poloure.simplerss.ViewFeedItem.java
com.poloure.simplerss.ViewNavItem.java
com.poloure.simplerss.ViewPagerDelegate.java
com.poloure.simplerss.adapters.AdapterFeedItems.java
com.poloure.simplerss.adapters.AdapterManageItems.java
com.poloure.simplerss.adapters.AdapterNavigationDrawer.java
com.poloure.simplerss.adapters.LinkedMapAdapter.java
com.poloure.simplerss.asynctasks.AsyncTaskSaveImage.java
com.poloure.simplerss.fragments.FragmentWebView.java
com.poloure.simplerss.listeners.MultiModeListenerFavourites.java
com.poloure.simplerss.listeners.MultiModeListenerManage.java
com.poloure.simplerss.listeners.MultiModeListener.java
com.poloure.simplerss.ui.ListViewFeeds.java