mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2024-11-23 11:31:33 +01:00
DroidFish: Fixed race condition when canceling a progress dialog.
This commit is contained in:
parent
1141efca4f
commit
76d79ef7a8
|
@ -73,6 +73,7 @@ public class EditPGN extends ListActivity {
|
|||
long lastModTime = -1;
|
||||
|
||||
Thread workThread = null;
|
||||
boolean canceled = false;
|
||||
|
||||
boolean loadGame; // True when loading game, false when saving
|
||||
String pgnToSave;
|
||||
|
@ -101,6 +102,7 @@ public class EditPGN extends ListActivity {
|
|||
Intent i = getIntent();
|
||||
String action = i.getAction();
|
||||
String fileName = i.getStringExtra("org.petero.droidfish.pathname");
|
||||
canceled = false;
|
||||
if (action.equals("org.petero.droidfish.loadFile")) {
|
||||
pgnFile = new PGNFile(fileName);
|
||||
loadGame = true;
|
||||
|
@ -112,8 +114,13 @@ public class EditPGN extends ListActivity {
|
|||
return;
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
if (canceled) {
|
||||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
} else {
|
||||
lpgn.showList();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -168,7 +175,10 @@ public class EditPGN extends ListActivity {
|
|||
return;
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
if (gamesInFile.size() == 0) {
|
||||
if (canceled) {
|
||||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
} else if (gamesInFile.size() == 0) {
|
||||
pgnFile.appendPGN(pgnToSave, getApplicationContext());
|
||||
finish();
|
||||
} else {
|
||||
|
@ -327,6 +337,7 @@ public class EditPGN extends ListActivity {
|
|||
progress.setOnCancelListener(new OnCancelListener() {
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
canceled = true;
|
||||
Thread thr = workThread;
|
||||
if (thr != null)
|
||||
thr.interrupt();
|
||||
|
@ -417,7 +428,6 @@ public class EditPGN extends ListActivity {
|
|||
long modTime = new File(fileName).lastModified();
|
||||
if (cacheValid && (modTime == lastModTime) && fileName.equals(lastFileName))
|
||||
return true;
|
||||
pgnFile = new PGNFile(fileName);
|
||||
Pair<GameInfoResult, ArrayList<GameInfo>> p = pgnFile.getGameInfo(this, progress);
|
||||
if (p.first != GameInfoResult.OK) {
|
||||
gamesInFile = new ArrayList<GameInfo>();
|
||||
|
|
|
@ -73,6 +73,7 @@ public class LoadFEN extends ListActivity {
|
|||
|
||||
private Thread workThread = null;
|
||||
private CountDownLatch progressLatch = null;
|
||||
private boolean canceled = false;
|
||||
|
||||
private ChessBoardPlay cb;
|
||||
private Button okButton;
|
||||
|
@ -117,8 +118,13 @@ public class LoadFEN extends ListActivity {
|
|||
return;
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
if (canceled) {
|
||||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
} else {
|
||||
lfen.showList();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -298,7 +304,9 @@ public class LoadFEN extends ListActivity {
|
|||
super.onCancel(dialog);
|
||||
Activity a = getActivity();
|
||||
if (a instanceof LoadFEN) {
|
||||
Thread thr = ((LoadFEN)a).workThread;
|
||||
LoadFEN lf = (LoadFEN)a;
|
||||
lf.canceled = true;
|
||||
Thread thr = lf.workThread;
|
||||
if (thr != null)
|
||||
thr.interrupt();
|
||||
}
|
||||
|
|
|
@ -78,6 +78,7 @@ public class LoadScid extends ListActivity {
|
|||
|
||||
private Thread workThread = null;
|
||||
private CountDownLatch progressLatch = null;
|
||||
private boolean canceled = false;
|
||||
|
||||
private boolean resultSentBack = false;
|
||||
|
||||
|
@ -131,6 +132,7 @@ public class LoadScid extends ListActivity {
|
|||
String action = i.getAction();
|
||||
fileName = i.getStringExtra("org.petero.droidfish.pathname");
|
||||
resultSentBack = false;
|
||||
canceled = false;
|
||||
if (action.equals("org.petero.droidfish.loadScid")) {
|
||||
progressLatch = new CountDownLatch(1);
|
||||
showProgressDialog();
|
||||
|
@ -149,8 +151,13 @@ public class LoadScid extends ListActivity {
|
|||
return;
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
if (canceled) {
|
||||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
} else {
|
||||
lpgn.showList();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -267,7 +274,9 @@ public class LoadScid extends ListActivity {
|
|||
super.onCancel(dialog);
|
||||
Activity a = getActivity();
|
||||
if (a instanceof LoadScid) {
|
||||
Thread thr = ((LoadScid)a).workThread;
|
||||
LoadScid ls = (LoadScid)a;
|
||||
ls.canceled = true;
|
||||
Thread thr = ls.workThread;
|
||||
if (thr != null)
|
||||
thr.interrupt();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user