<commit_before>package com.afollestad.silk.fragments;

import android.content.ContentResolver;
import android.os.Bundle;
import com.afollestad.silk.caching.SilkCursorItem;

import java.util.List;

/**
 * @author <NAME> (afollestad)
 */
public abstract class SilkCursorFeedFragment<ItemType extends SilkCursorItem> extends SilkCursorListFragment<ItemType> {

    protected boolean mInitialLoadOnResume;
    private boolean mBlockRefresh;

    @Override
    protected void onVisibilityChanged(boolean visible) {
        super.onVisibilityChanged(visible);
        if (visible && mInitialLoadOnResume)
            onInitialRefresh();
    }

    @Override
    public void onResume() {
        super.onResume();
        if (!isActuallyVisible() && mInitialLoadOnResume) {
            // If it is visible, then onVisibilityChanged() will handle it instead
            onInitialRefresh();
        }
    }

    protected void onPreLoad() {
        clearProvider();
    }

    protected void onPostLoad(List<ItemType> items) {
        ContentResolver resolver = getActivity().getContentResolver();
        for (ItemType item : items)
            resolver.insert(getLoaderUri(), item.getContentValues());
        onInitialRefresh();
    }

    protected abstract List<ItemType> refresh() throws Exception;

    protected abstract void onError(Exception e);

    @Override
    protected void onCursorEmpty() {
        super.onCursorEmpty();
        performRefresh(true);
    }

    public void performRefresh(boolean showProgress) {
        if (isLoading()) return;
        mBlockRefresh = false;
        setLoading(showProgress);
        onPreLoad();
        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    final List<ItemType> items = refresh();
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            mBlockRefresh = items.size() == 0;
                            onPostLoad(items);
                        }
                    });
                } catch (final Exception e) {
                    e.printStackTrace();
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            onError(e);
                            setLoadComplete(true);
                        }
                    });
                }
            }
        });
        t.setPriority(Thread.MAX_PRIORITY);
        t.start();
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        if (!mInitialLoadOnResume) onInitialRefresh();
    }
}<commit_msg>Fixes<commit_after>package com.afollestad.silk.fragments;

import android.content.ContentResolver;
import android.os.Bundle;
import com.afollestad.silk.caching.SilkCursorItem;

import java.util.List;

/**
 * @author <NAME> (afollestad)
 */
public abstract class SilkCursorFeedFragment<ItemType extends SilkCursorItem> extends SilkCursorListFragment<ItemType> {

    protected boolean mInitialLoadOnResume;
    private boolean mBlockRefresh;

    @Override
    protected void onVisibilityChanged(boolean visible) {
        super.onVisibilityChanged(visible);
        if (visible && mInitialLoadOnResume)
            onInitialRefresh();
    }

    @Override
    public void onResume() {
        super.onResume();
        if (!isActuallyVisible() && mInitialLoadOnResume) {
            // If it is visible, then onVisibilityChanged() will handle it instead
            onInitialRefresh();
        }
    }

    protected void onPreLoad() {
        clearProvider();
    }

    protected void onPostLoad(List<ItemType> items) {
        ContentResolver resolver = getActivity().getContentResolver();
        for (ItemType item : items)
            resolver.insert(getLoaderUri(), item.getContentValues());
        onInitialRefresh();
    }

    protected abstract List<ItemType> refresh() throws Exception;

    protected abstract void onError(Exception e);

    @Override
    protected void onCursorEmpty() {
        super.onCursorEmpty();
        performRefresh(true);
    }

    public void performRefresh(boolean showProgress) {
        if (isLoading() || mBlockRefresh) return;
        mBlockRefresh = false;
        setLoading(showProgress);
        onPreLoad();
        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    final List<ItemType> items = refresh();
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            mBlockRefresh = items.size() == 0;
                            onPostLoad(items);
                        }
                    });
                } catch (final Exception e) {
                    e.printStackTrace();
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            onError(e);
                            setLoadComplete(true);
                        }
                    });
                }
            }
        });
        t.setPriority(Thread.MAX_PRIORITY);
        t.start();
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        if (!mInitialLoadOnResume) onInitialRefresh();
    }
}
{'fraction_non_alphanumeric': 0.0891674127126231, 'fraction_numerical': 0.00035810205908683976, 'mean_word_length': 1.7777225261064147, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '6001009', 'n_tokens_mistral': 1405, 'n_tokens_neox': 1339, 'n_words': 301}