<commit_before>package retrobox.utils;

import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
import xtvapps.core.NetworkProgressListener;
import xtvapps.core.Utils;

public class InfoProgressListener extends NetworkProgressListener {
	private final static int DETAIL_TIME = 250;
	
	public static boolean operationIsCancelled = false;
	
	String infoTemplate;
	String lastInfoTemplate = "";
	private TextView textViewInfo;
	private TextView textViewProgress;
	private ProgressBar progressView;
	
	private long lastUpdateTime = 0;
	
	public InfoProgressListener(TextView textViewInfo, TextView textViewProgress, ProgressBar progressView) {
		this.textViewInfo     = textViewInfo;
		this.textViewProgress = textViewProgress;
		this.progressView      = progressView;
	}
	
	public void setInfoTemplate(String infoTemplate) {
		this.infoTemplate = infoTemplate;
	}
	
	private void updateInfo(int progress, int total) {
		String info = new String(infoTemplate); 
		if (info.endsWith("{size}")) {
			String sizeInfo  = "";
			info = info.replace("{size}", "");
			if (total == 0) {
				sizeInfo = "";
			} else {
				sizeInfo = Utils.size2humanDetailed(progress) + " / " + Utils.size2humanDetailed(total);
				if (textViewProgress == null) {
					info += "    ( " + sizeInfo + " )";
				}
			}
			if (textViewProgress!=null) textViewProgress.setText(sizeInfo);
		} else if (info.endsWith("{count}")) {
			String countInfo = "";
			info = info.replace("{count}", "");
			if (total == 0) {
				countInfo = "";
			} else {
				countInfo = (progress+1) + " / " + total;
				if (textViewProgress == null) {
					info += "  ( " + countInfo + " )";	
				}
			}
			if (textViewProgress!=null) textViewProgress.setText(countInfo);
		}
		textViewInfo.setText(info);
		progressView.setProgress(progress);
		progressView.setMax(total);
		textViewInfo.setVisibility(View.VISIBLE);
		progressView.setVisibility(View.VISIBLE);
	}
	
	@Override
	public boolean updateProgress(final int progress, final int max) {
		if (!lastInfoTemplate.equals(infoTemplate) || System.currentTimeMillis() - lastUpdateTime > DETAIL_TIME) {
			lastUpdateTime = System.currentTimeMillis();
			lastInfoTemplate = infoTemplate;
			progressView.post(new Runnable() {<commit_msg>Add reset method to InfoProgressListener<commit_after>package retrobox.utils;

import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
import xtvapps.core.NetworkProgressListener;
import xtvapps.core.Utils;

public class InfoProgressListener extends NetworkProgressListener {
	private final static int DETAIL_TIME = 250;
	
	public static boolean operationIsCancelled = false;
	
	String infoTemplate;
	String lastInfoTemplate = "";
	private TextView textViewInfo;
	private TextView textViewProgress;
	private ProgressBar progressView;
	
	private long lastUpdateTime = 0;
	
	public InfoProgressListener(TextView textViewInfo, TextView textViewProgress, ProgressBar progressView) {
		this.textViewInfo     = textViewInfo;
		this.textViewProgress = textViewProgress;
		this.progressView      = progressView;
	}
	
	public void setInfoTemplate(String infoTemplate) {
		this.infoTemplate = infoTemplate;
	}
	
	private void updateInfo(int progress, int total) {
		String info = new String(infoTemplate); 
		if (info.endsWith("{size}")) {
			String sizeInfo  = "";
			info = info.replace("{size}", "");
			if (total == 0) {
				sizeInfo = "";
			} else {
				sizeInfo = Utils.size2humanDetailed(progress) + " / " + Utils.size2humanDetailed(total);
				if (textViewProgress == null) {
					info += "    ( " + sizeInfo + " )";
				}
			}
			if (textViewProgress!=null) textViewProgress.setText(sizeInfo);
		} else if (info.endsWith("{count}")) {
			String countInfo = "";
			info = info.replace("{count}", "");
			if (total == 0) {
				countInfo = "";
			} else {
				countInfo = (progress+1) + " / " + total;
				if (textViewProgress == null) {
					info += "  ( " + countInfo + " )";	
				}
			}
			if (textViewProgress!=null) textViewProgress.setText(countInfo);
		}
		textViewInfo.setText(info);
		progressView.setProgress(progress);
		progressView.setMax(total);
	}
	
	public void reset() {
		textViewInfo.setText("");
		if (textViewProgress!=null) textViewProgress.setText("");
		
		progressView.setProgress(0);
		progressView.setMax(0);
	}
	
	@Override
	public boolean updateProgress(final int progress, final int max) {
		if (!lastInfoTemplate.equals(infoTemplate) || System.currentTimeMillis() - lastUpdateTime > DETAIL_TIME) {
			lastUpdateTime = System.currentTimeMillis();
			lastInfoTemplate = infoTemplate;
			progressView.post(new Runnable() {
{'fraction_non_alphanumeric': 0.11992263056092843, 'fraction_numerical': 0.004298302170642596, 'mean_word_length': 4.282633371169126, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1213976', 'n_tokens_mistral': 1591, 'n_tokens_neox': 1391, 'n_words': 299}