diff --git a/DroidFish/src/org/petero/droidfish/activities/EditPGN.java b/DroidFish/src/org/petero/droidfish/activities/EditPGN.java index 7893312..03a8e6c 100644 --- a/DroidFish/src/org/petero/droidfish/activities/EditPGN.java +++ b/DroidFish/src/org/petero/droidfish/activities/EditPGN.java @@ -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,7 +114,12 @@ public class EditPGN extends ListActivity { return; runOnUiThread(new Runnable() { public void run() { - lpgn.showList(); + 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> p = pgnFile.getGameInfo(this, progress); if (p.first != GameInfoResult.OK) { gamesInFile = new ArrayList(); diff --git a/DroidFish/src/org/petero/droidfish/activities/LoadFEN.java b/DroidFish/src/org/petero/droidfish/activities/LoadFEN.java index d1d9178..aad3cb3 100644 --- a/DroidFish/src/org/petero/droidfish/activities/LoadFEN.java +++ b/DroidFish/src/org/petero/droidfish/activities/LoadFEN.java @@ -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,7 +118,12 @@ public class LoadFEN extends ListActivity { return; runOnUiThread(new Runnable() { public void run() { - lfen.showList(); + 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(); } diff --git a/DroidFish/src/org/petero/droidfish/activities/LoadScid.java b/DroidFish/src/org/petero/droidfish/activities/LoadScid.java index 6b76892..82d68dd 100644 --- a/DroidFish/src/org/petero/droidfish/activities/LoadScid.java +++ b/DroidFish/src/org/petero/droidfish/activities/LoadScid.java @@ -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,7 +151,12 @@ public class LoadScid extends ListActivity { return; runOnUiThread(new Runnable() { public void run() { - lpgn.showList(); + 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(); }