mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2025-02-17 09:37:50 +01:00
Fix crash when reading from a broken SCID database
This commit is contained in:
parent
f99e24efda
commit
4cfbc0da6c
|
@ -49,12 +49,10 @@ import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.AdapterView;
|
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import android.widget.AdapterView.OnItemClickListener;
|
|
||||||
|
|
||||||
public class LoadScid extends ListActivity {
|
public class LoadScid extends ListActivity {
|
||||||
private static final class GameInfo {
|
private static final class GameInfo {
|
||||||
|
@ -294,28 +292,34 @@ public class LoadScid extends ListActivity {
|
||||||
|
|
||||||
gamesInFile.clear();
|
gamesInFile.clear();
|
||||||
if (cursor != null) {
|
if (cursor != null) {
|
||||||
int noGames = cursor.getCount();
|
try {
|
||||||
gamesInFile.ensureCapacity(noGames);
|
int noGames = cursor.getCount();
|
||||||
int percent = -1;
|
gamesInFile.ensureCapacity(noGames);
|
||||||
if (cursor.moveToFirst()) {
|
int percent = -1;
|
||||||
addGameInfo(cursor);
|
if (cursor.moveToFirst()) {
|
||||||
int gameNo = 1;
|
|
||||||
while (cursor.moveToNext()) {
|
|
||||||
if (Thread.currentThread().isInterrupted()) {
|
|
||||||
setResult(RESULT_CANCELED);
|
|
||||||
finish();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
addGameInfo(cursor);
|
addGameInfo(cursor);
|
||||||
gameNo++;
|
int gameNo = 1;
|
||||||
final int newPercent = gameNo * 100 / noGames;
|
while (cursor.moveToNext()) {
|
||||||
if (newPercent > percent) {
|
if (Thread.currentThread().isInterrupted()) {
|
||||||
percent = newPercent;
|
setResult(RESULT_CANCELED);
|
||||||
if (progress != null) {
|
finish();
|
||||||
runOnUiThread(() -> progress.setProgress(newPercent));
|
return false;
|
||||||
|
}
|
||||||
|
addGameInfo(cursor);
|
||||||
|
gameNo++;
|
||||||
|
final int newPercent = gameNo * 100 / noGames;
|
||||||
|
if (newPercent > percent) {
|
||||||
|
percent = newPercent;
|
||||||
|
if (progress != null) {
|
||||||
|
runOnUiThread(() -> progress.setProgress(newPercent));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (IllegalArgumentException ignore) {
|
||||||
|
setResult(RESULT_CANCELED);
|
||||||
|
finish();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cacheValid = true;
|
cacheValid = true;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user