package net.elprespufferfish.rssreader;

import android.support.v4.view.ViewPager;

/**
 * Handles marking articles as read
 */
public class ArticleReadListener implements ViewPager.OnPageChangeListener {

    private final ArticlePagerAdapter articlePagerAdapter;
    private int lastPosition = 0;

    public ArticleReadListener(ArticlePagerAdapter articlePagerAdapter) {
        this.articlePagerAdapter = articlePagerAdapter;
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        // unused
    }

    @Override
    public void onPageSelected(int position) {
        ArticleFragment articleFragment = (ArticleFragment) articlePagerAdapter.getItem(lastPosition);
        Article article = articleFragment.getArguments().getParcelable(ArticleFragment.ARTICLE_KEY);
        Feeds.getInstance().markArticleRead(article);

        lastPosition = position;
    }

    @Override
    public void onPageScrollStateChanged(int state) {
        // unused
    }

}

@@ -261,42 +261,8 @@
 ter;
-%0A    private int lastPosition = 0;
 %0A%0A  
@@ -679,21 +679,17 @@
 getItem(
-lastP
+p
 osition)
@@ -848,42 +848,8 @@
 le);
-%0A%0A        lastPosition = position;
 %0A   

Mark article read as it comes into view, rather than when it leaves