Android Open Source - RssReader Rss Article Pager 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  w w  .  ja  va  2 s.  c  o 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.lang.ref.WeakReference;

import org.m2x.rssreader.fragment.RssArticleFragment;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.util.SparseArray;
import android.view.ViewGroup;

public class RssArticlePagerAdapter extends FragmentStatePagerAdapter {  

  private long[] mRssEntryIds;
  private SparseArray<WeakReference<Fragment>> mRegisterdFragments = 
      new SparseArray<WeakReference<Fragment>>();
  
  public RssArticlePagerAdapter(FragmentManager fm, long[] rssEntryIds) {
    super(fm);
    mRssEntryIds = rssEntryIds;
  }
  
  @Override
  public int getCount() {
    return mRssEntryIds.length;
  }

  @Override
  public Fragment getItem(int position) {
    return RssArticleFragment.newInstance(mRssEntryIds[position]);
  }
    
    @Override
    public Object instantiateItem(ViewGroup container, int position){
      Fragment fragment = (Fragment) super.instantiateItem(container, position);
        WeakReference<Fragment> rFragment = new WeakReference<Fragment>(fragment);
        mRegisterdFragments.put(position, rFragment);
        return fragment;
    }
        
  @Override
  public void destroyItem(ViewGroup container, int position, Object object) {
    mRegisterdFragments.remove(position);
      super.destroyItem(container, position, object);
  }

    public Fragment getRegisteredFragment(int position) {
      WeakReference<Fragment> fragment = mRegisterdFragments.get(position);
        if (fragment != null)
          return fragment.get();
        
        return null;
    }   
}




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