<commit_before>package com.newsblur.fragment;

import android.database.Cursor;
import android.support.v4.app.Fragment;
import android.support.v4.content.Loader;
import android.util.Log;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.ListView;
import android.widget.TextView;

import com.newsblur.R;
import com.newsblur.activity.ItemsList;
import com.newsblur.database.StoryItemsAdapter;
import com.newsblur.util.StoryOrder;

public abstract class ItemListFragment extends Fragment implements OnScrollListener {

    protected int currentPage = 0;
    protected boolean requestedPage;
	protected StoryItemsAdapter adapter;
    private boolean firstSyncDone = false;
	
	public abstract void hasUpdated();
	public abstract void changeState(final int state);
	public abstract void setStoryOrder(StoryOrder storyOrder);


    public void resetPagination() {
        this.currentPage = 0;
    }

    public void syncDone() {
        this.firstSyncDone = true;
    }

    private void finishLoadingScreen() {
        View v = this.getView();
        if (v == null) return; // we might have beat construction?

        ListView itemList = (ListView) v.findViewById(R.id.itemlistfragment_list);
        if (itemList == null) {
            Log.w(this.getClass().getName(), "ItemListFragment does not have the expected ListView.");
            return;
        }

        TextView emptyView = (TextView) itemList.getEmptyView();
        emptyView.setText(R.string.empty_list_view_no_stories);
    }

	@Override
	public synchronized void onScroll(AbsListView view, int firstVisible, int visibleCount, int totalCount) {
		if (totalCount != 0 && (firstVisible + visibleCount + 1 >= totalCount) && !requestedPage) {
			currentPage += 1;
			requestedPage = true;
			triggerRefresh(currentPage);
		}
	}

	@Override
	public void onScrollStateChanged(AbsListView view, int scrollState) { }

	protected void triggerRefresh(int page) {
        ((ItemsList) getActivity()).triggerRefresh(page);
    }

    // all child classes need this callback, so implement it here
	public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
		if (cursor != null) {
            if (cursor.getCount() == 0) {
                currentPage += 1;<commit_msg>Even smoother story list preloading.<commit_after>package com.newsblur.fragment;

import android.database.Cursor;
import android.support.v4.app.Fragment;
import android.support.v4.content.Loader;
import android.util.Log;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.ListView;
import android.widget.TextView;

import com.newsblur.R;
import com.newsblur.activity.ItemsList;
import com.newsblur.database.StoryItemsAdapter;
import com.newsblur.util.StoryOrder;

public abstract class ItemListFragment extends Fragment implements OnScrollListener {

    protected int currentPage = 0;
    protected boolean requestedPage;
	protected StoryItemsAdapter adapter;
    private boolean firstSyncDone = false;
	
	public abstract void hasUpdated();
	public abstract void changeState(final int state);
	public abstract void setStoryOrder(StoryOrder storyOrder);


    public void resetPagination() {
        this.currentPage = 0;
    }

    public void syncDone() {
        this.firstSyncDone = true;
    }

    private void finishLoadingScreen() {
        View v = this.getView();
        if (v == null) return; // we might have beat construction?

        ListView itemList = (ListView) v.findViewById(R.id.itemlistfragment_list);
        if (itemList == null) {
            Log.w(this.getClass().getName(), "ItemListFragment does not have the expected ListView.");
            return;
        }

        TextView emptyView = (TextView) itemList.getEmptyView();
        emptyView.setText(R.string.empty_list_view_no_stories);
    }

	@Override
	public synchronized void onScroll(AbsListView view, int firstVisible, int visibleCount, int totalCount) {
        // load an extra page worth of stories past the viewport
		if (totalCount != 0 && (firstVisible + visibleCount + visibleCount - 1  >= totalCount) && !requestedPage) {
			currentPage += 1;
			requestedPage = true;
			triggerRefresh(currentPage);
		}
	}

	@Override
	public void onScrollStateChanged(AbsListView view, int scrollState) { }

	protected void triggerRefresh(int page) {
        ((ItemsList) getActivity()).triggerRefresh(page);
    }

    // all child classes need this callback, so implement it here
	public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
		if (cursor != null) {
            if (cursor.getCount() == 0) {
                currentPage += 1;
{'fraction_non_alphanumeric': 0.094331641285956, 'fraction_numerical': 0.0038071065989847717, 'mean_word_length': 3.6961271102284012, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4443154', 'n_tokens_mistral': 1360, 'n_tokens_neox': 1263, 'n_words': 360}