<commit_before>package com.nostra13.universalimageloader.core.assist;

import java.util.concurrent.atomic.AtomicBoolean;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.GridView;
import android.widget.ListView;

/**
 * Listener-helper for {@linkplain AbsListView list views} ({@link ListView}, {@link GridView}) which makes some
 * {@link #LOADING_DELAY_ON_FLING delay} before starting image loading during fast list scrolling (fling). It prevents
 * redundant loadings.<br />
 * Set it to your list view's {@link AbsListView#setOnScrollListener(OnScrollListener) setOnScrollListener(...)} and
 * later get options (using {@linkplain #getOptions()}) for
 * {@link ImageLoader#displayImage(String, android.widget.ImageView, DisplayImageOptions) ImageLoader.displayImage(...)}
 * calls.
 * 
 * @author <NAME> (nostra13[at]gmail[dot]com)
 */
public class OnScrollSmartOptions implements OnScrollListener {

	/** {@value} */
	public static final int LOADING_DELAY_ON_FLING = 100; // ms

	private final DisplayImageOptions options;
	private final DisplayImageOptions flingOptions;
	private final OnScrollListener externalListener;

	private final AtomicBoolean isFlingScrolling;

	/**
	 * @param displayOptions
	 *            {@linkplain DisplayImageOptions Display options} you want to use for displaying images in you
	 *            {@linkplain AbsListView list view}
	 */
	public OnScrollSmartOptions(DisplayImageOptions displayOptions) {
		this(displayOptions, null);
	}

	/**
	 * @param displayOptions
	 *            {@linkplain DisplayImageOptions Display options} you want to use for displaying images in you
	 *            {@linkplain AbsListView list view}
	 * @param customListener
	 *            Your custom {@link OnScrollListener} for {@linkplain AbsListView list view} which also will be get
	 *            scroll events
	 */
	public OnScrollSmartOptions(DisplayImageOptions displayOptions, OnScrollListener customListener) {
		options = displayOptions;
		externalListener = customListener;

		flingOptions = new DisplayImageOptions.Builder()
			.cloneFrom(options)
			.delayBeforeLoading(LOADING_DELAY_ON_FLING)
			.build();
		isFlingScrolling = new AtomicBoolean(false);
	}

	@Override
	public void onScrollStateChanged(AbsListView view, int scrollState) {
		switch (scrollState) {
			case OnScrollListener.SCROLL_STATE_IDLE:
			case OnScrollListener.SCROLL_STATE_TOUCH_SCROLL:
				isFlingScrolling.set(false);
				break;
			case OnScrollListener.SCROLL_STATE_FLING:
				isFlingScrolling.set(true);
				break;
		}
		if (externalListener != null) {
			externalListener.onScrollStateChanged(view, scrollState);
		}
	}

	@Override
	public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
		if (externalListener != null) {
			externalListener.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount);
		}
	}

	/**
	 * Returns appropriate {@linkplain DisplayImageOptions display options} depending on {@linkplain AbsListView list
	 * view's} current scrolling state
	 */
	public DisplayImageOptions getOptions() {
		return isFlingScrolling.get() ? flingOptions : options;
	}
}
<commit_msg>Issue #103 - Refactored OnScrollSmartOptions<commit_after>package com.nostra13.universalimageloader.core.assist;

import java.util.concurrent.atomic.AtomicInteger;

import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.GridView;
import android.widget.ListView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

/**
 * Listener-helper for {@linkplain AbsListView list views} ({@link ListView}, {@link GridView}) which makes some
 * {@link #LOADING_DELAY_ON_FLING delay} before starting image loading during touch scrolling and/or fast list scrolling
 * (fling). It prevents redundant loadings.<br />
 * Set it to your list view's {@link AbsListView#setOnScrollListener(OnScrollListener) setOnScrollListener(...)} and
 * later get options (using {@linkplain #getOptions()}) for
 * {@link ImageLoader#displayImage(String, android.widget.ImageView, DisplayImageOptions) ImageLoader.displayImage(...)}
 * calls.
 * 
 * @author <NAME> (nostra13[at]gmail[dot]com)
 */
public class OnScrollSmartOptions implements OnScrollListener {

	/** {@value} */
	public static final int LOADING_DELAY_ON_TOUCH_SCROLL = 0; // ms
	/** {@value} */
	public static final int LOADING_DELAY_ON_FLING = 300; // ms

	private final DisplayImageOptions options;
	private final DisplayImageOptions scrollOptions;
	private final DisplayImageOptions flingOptions;
	private final OnScrollListener externalListener;

	private final AtomicInteger scrollState;

	/**
	 * Constructor<br />
	 * Delay before loading for touch scrolling - {@value #LOADING_DELAY_ON_TOUCH_SCROLL} ms<br />
	 * Delay before loading for fling scrolling - {@value #LOADING_DELAY_ON_FLING} ms
	 * 
	 * @param displayOptions
	 *            {@linkplain DisplayImageOptions Display options} you want to use for displaying images in you
	 *            {@linkplain AbsListView list view}
	 */
	public OnScrollSmartOptions(DisplayImageOptions displayOptions) {
		this(displayOptions, LOADING_DELAY_ON_TOUCH_SCROLL, LOADING_DELAY_ON_FLING);
	}

	/**
	 * Constructor
	 * 
	 * @param displayOptions
	 *            {@linkplain DisplayImageOptions Display options} you want to use for displaying images in you
	 *            {@linkplain AbsListView list view}
	 * @param loadingDelayOnScroll
	 *            Delay (in milliseconds) before starting loading during scrolling
	 * @param loadingDelayOnFling
	 *            Delay (in milliseconds) before starting loading during fast scrolling (fling)
	 */
	public OnScrollSmartOptions(DisplayImageOptions displayOptions, int loadingDelayOnScroll, int loadingDelayOnFling) {
		this(displayOptions, loadingDelayOnScroll, loadingDelayOnFling, null);
	}

	/**
	 * Constructor
	 * 
	 * @param displayOptions
	 *            {@linkplain DisplayImageOptions Display options} you want to use for displaying images in you
	 *            {@linkplain AbsListView list view}
	 * @param loadingDelayOnScroll
	 *            Delay (in milliseconds) before starting loading during touch scrolling
	 * @param loadingDelayOnFling
	 *            Delay (in milliseconds) before starting loading during fast scrolling (fling)
	 * @param customListener
	 *            Your custom {@link OnScrollListener} for {@linkplain AbsListView list view} which also will be get
	 *            scroll events
	 */
	public OnScrollSmartOptions(DisplayImageOptions displayOptions, int loadingDelayOnScroll, int loadingDelayOnFling, OnScrollListener customListener) {
		options = displayOptions;
		scrollOptions = new DisplayImageOptions.Builder()
			.cloneFrom(options)
			.delayBeforeLoading(loadingDelayOnScroll)
			.build();
		flingOptions = new DisplayImageOptions.Builder()
			.cloneFrom(options)
			.delayBeforeLoading(loadingDelayOnFling)
			.build();
		externalListener = customListener;

		scrollState = new AtomicInteger(OnScrollListener.SCROLL_STATE_IDLE);
	}

	@Override
	public void onScrollStateChanged(AbsListView view, int scrollState) {
		this.scrollState.set(scrollState);
		if (externalListener != null) {
			externalListener.onScrollStateChanged(view, scrollState);
		}
	}

	@Override
	public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
		if (externalListener != null) {
			externalListener.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount);
		}
	}

	/**
	 * Returns appropriate {@linkplain DisplayImageOptions display options} depending on {@linkplain AbsListView list
	 * view's} current scrolling state
	 */
	public DisplayImageOptions getOptions() {
		switch (scrollState.get()) {
			case OnScrollListener.SCROLL_STATE_IDLE:
				return options;
			case OnScrollListener.SCROLL_STATE_TOUCH_SCROLL:
				return scrollOptions;
			case OnScrollListener.SCROLL_STATE_FLING:
				return flingOptions;
			default:
				return options;
		}
	}
}

{'fraction_non_alphanumeric': 0.08228895720028376, 'fraction_numerical': 0.0030740127689761173, 'mean_word_length': 4.0865904990980155, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '5017266', 'n_tokens_mistral': 2553, 'n_tokens_neox': 2248, 'n_words': 613}