Android Open Source - RssReader Rss Item List Adapter






From Project

Back to project page RssReader.

License

The source code is released under:

GNU General Public License

If you think the Android project RssReader 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

/**
 * RssReader// w  ww  . j  a  va2  s .co  m
 *
 * Copyright (c) 2013-2014 teejoe
 *
 *     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.
 *
 *     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 org.m2x.rssreader.adapter;

import java.util.ArrayList;

import org.m2x.rssreader.R;
import org.m2x.rssreader.provider.FeedData.EntryColumns;
import org.m2x.rssreader.provider.FeedData.FeedColumns;
import org.m2x.rssreader.util.StringUtils;

import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

/**
 * The list adapter for the RSS item list.
 * @author teejoe(mtjm2x@gmail.com)
 */
public class RssItemListAdapter extends BaseAdapter {
  
  private final Context mContext;
  private Cursor mCursor;
  LayoutInflater mInflater;
  
  public RssItemListAdapter(Context context, Cursor cursor) {
    mContext = context;
    mCursor = cursor;
    mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  }

  @Override
    public boolean areAllItemsEnabled() {
        return true;
    }

    @Override
    public boolean isEnabled(int position) {
        return true;
    }
    
  @Override
  public int getCount() {
    if (mCursor != null) {
      return mCursor.getCount();
    }
    return 0;
  }

  @Override
  public Object getItem(int position) {
    return null;
  }

  @Override
  public long getItemId(int position) {
    return position;
  }

  static class ViewHolder {
    TextView channelName, updateTime, title;
    CheckBox hasRead;
  }
  
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder = new ViewHolder();
    if (convertView == null){
      convertView = mInflater.inflate(R.layout.rss_list_item, parent, false);
      holder = new ViewHolder();
      holder.channelName = (TextView)convertView.findViewById(R.id.channel_name);
      holder.updateTime = (TextView)convertView.findViewById(R.id.update_time);
      holder.hasRead = (CheckBox)convertView.findViewById(R.id.has_read);
      holder.title = (TextView)convertView.findViewById(R.id.title);
      
      convertView.setTag(holder);
    }
    else {
      holder = (ViewHolder)convertView.getTag();
    }
    
    if (mCursor != null && mCursor.moveToPosition(position)) {
      holder.channelName.setText(mCursor.getString(mCursor.getColumnIndex(
          EntryColumns.FEED_ID)));
      holder.updateTime.setText(StringUtils.getDateTimeString(mCursor.getLong(
          mCursor.getColumnIndex(EntryColumns.DATE))));
      holder.title.setText(mCursor.getString(mCursor.getColumnIndex(
          EntryColumns.TITLE)));
      holder.channelName.setText(mCursor.getString(mCursor.getColumnIndex(
          FeedColumns.NAME)));
      holder.hasRead.setChecked(mCursor.getInt(mCursor.getColumnIndex(
          EntryColumns.IS_READ)) == 1);
    }
    
    return convertView;
  }
  
  public void setCursor(Cursor cursor) {
    mCursor = cursor;
    notifyDataSetChanged();
  }
  
  /** Get the RSS entry ids. */
  public ArrayList<Long> getRssEntryIds() {
    if (mCursor.getCount() == 0) {
      return null;
    }
    
    ArrayList<Long> entryIds = new ArrayList<Long>();
    
    mCursor.moveToFirst();
    do {
      Long id = mCursor.getLong(mCursor.getColumnIndex(EntryColumns._ID));
      entryIds.add(id);
    } while (mCursor.moveToNext());
    
    return entryIds;
  }
}




Java Source Code List

org.m2x.rssreader.Constants.java
org.m2x.rssreader.MainApplication.java
org.m2x.rssreader.activity.AddChannelActivity.java
org.m2x.rssreader.activity.EditChannelActivity.java
org.m2x.rssreader.activity.MainActivity.java
org.m2x.rssreader.activity.PreferenceActivity.java
org.m2x.rssreader.activity.RssArticleActivity.java
org.m2x.rssreader.activity.RssItemListActivity.java
org.m2x.rssreader.adapter.ChannelListAdapter.java
org.m2x.rssreader.adapter.RssArticlePagerAdapter.java
org.m2x.rssreader.adapter.RssItemListAdapter.java
org.m2x.rssreader.fragment.ChannelListFragment.java
org.m2x.rssreader.fragment.RssArticleFragment.java
org.m2x.rssreader.fragment.RssItemListFragment.java
org.m2x.rssreader.provider.DatabaseHelper.java
org.m2x.rssreader.provider.FeedDataProvider.java
org.m2x.rssreader.provider.FeedData.java
org.m2x.rssreader.service.FetcherService.java
org.m2x.rssreader.service.RefreshService.java
org.m2x.rssreader.util.HtmlUtils.java
org.m2x.rssreader.util.NetworkUtils.java
org.m2x.rssreader.util.OPML.java
org.m2x.rssreader.util.PrefUtils.java
org.m2x.rssreader.util.RssAtomParser.java
org.m2x.rssreader.util.StringUtils.java
org.m2x.rssreader.util.UiUtils.java
org.m2x.rssreader.view.RssArticleView.java