mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2024-11-27 06:10:28 +01:00
New file action "load deleted game"
The new action "load deleted game" loads a recently deleted game from the autosave file, without affecting the "last used file" and "current position in last used file" properties.
This commit is contained in:
parent
683a238bff
commit
65537e70f8
|
@ -2310,6 +2310,7 @@ public class DroidFish extends Activity
|
|||
final int LOAD_POS = 2;
|
||||
final int LOAD_SCID_GAME = 3;
|
||||
final int SAVE_GAME = 4;
|
||||
final int LOAD_DELETED_GAME = 5;
|
||||
|
||||
setAutoMode(AutoMode.OFF);
|
||||
List<String> lst = new ArrayList<>();
|
||||
|
@ -2322,6 +2323,9 @@ public class DroidFish extends Activity
|
|||
if (hasScidProvider()) {
|
||||
lst.add(getString(R.string.load_scid_game)); actions.add(LOAD_SCID_GAME);
|
||||
}
|
||||
if (storageAvailable() && (new File(getAutoSaveFile())).exists()) {
|
||||
lst.add(getString(R.string.load_del_game)); actions.add(LOAD_DELETED_GAME);
|
||||
}
|
||||
lst.add(getString(R.string.save_game)); actions.add(SAVE_GAME);
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(R.string.load_save_menu);
|
||||
|
@ -2345,6 +2349,9 @@ public class DroidFish extends Activity
|
|||
case LOAD_SCID_GAME:
|
||||
selectScidFile();
|
||||
break;
|
||||
case LOAD_DELETED_GAME:
|
||||
loadPGNFromFile(getAutoSaveFile(), false);
|
||||
break;
|
||||
}
|
||||
});
|
||||
return builder.create();
|
||||
|
@ -3515,13 +3522,21 @@ public class DroidFish extends Activity
|
|||
|
||||
/** Load a PGN game from a file. */
|
||||
private void loadPGNFromFile(String pathName) {
|
||||
loadPGNFromFile(pathName, true);
|
||||
}
|
||||
|
||||
/** Load a PGN game from a file. */
|
||||
private void loadPGNFromFile(String pathName, boolean updateCurrFile) {
|
||||
if (updateCurrFile) {
|
||||
Editor editor = settings.edit();
|
||||
editor.putString("currentPGNFile", pathName);
|
||||
editor.putInt("currFT", FT_PGN);
|
||||
editor.apply();
|
||||
}
|
||||
Intent i = new Intent(DroidFish.this, EditPGNLoad.class);
|
||||
i.setAction("org.petero.droidfish.loadFile");
|
||||
i.putExtra("org.petero.droidfish.pathname", pathName);
|
||||
i.putExtra("org.petero.droidfish.updateDefFilePos", updateCurrFile);
|
||||
setEditPGNBackup(i, pathName);
|
||||
startActivityForResult(i, RESULT_LOAD_PGN);
|
||||
}
|
||||
|
|
|
@ -69,6 +69,7 @@ public abstract class EditPGN extends AppCompatActivity {
|
|||
|
||||
private SharedPreferences settings;
|
||||
private long defaultFilePos = 0;
|
||||
private boolean updateDefaultFilePos;
|
||||
private long currentFilePos = 0;
|
||||
private String lastSearchString = "";
|
||||
private String lastFileName = "";
|
||||
|
@ -111,6 +112,7 @@ public abstract class EditPGN extends AppCompatActivity {
|
|||
String action = i.getAction();
|
||||
String fileName = i.getStringExtra("org.petero.droidfish.pathname");
|
||||
backup = i.getBooleanExtra("org.petero.droidfish.backup", false);
|
||||
updateDefaultFilePos = i.getBooleanExtra("org.petero.droidfish.updateDefFilePos", true);
|
||||
canceled = false;
|
||||
if ("org.petero.droidfish.loadFile".equals(action)) {
|
||||
pgnFile = new PGNFile(fileName);
|
||||
|
@ -159,7 +161,7 @@ public abstract class EditPGN extends AppCompatActivity {
|
|||
finish();
|
||||
} else {
|
||||
GameInfo gi = gamesInFile.get(loadItem);
|
||||
defaultFilePos = gi.startPos;
|
||||
setDefaultFilePos(gi.startPos);
|
||||
sendBackResult(gi);
|
||||
}
|
||||
});
|
||||
|
@ -283,7 +285,7 @@ public abstract class EditPGN extends AppCompatActivity {
|
|||
if (selectedGi == null)
|
||||
return;
|
||||
if (loadGame) {
|
||||
defaultFilePos = selectedGi.startPos;
|
||||
setDefaultFilePos(selectedGi.startPos);
|
||||
sendBackResult(selectedGi);
|
||||
} else {
|
||||
reShowDialog(SAVE_GAME_DIALOG);
|
||||
|
@ -430,18 +432,27 @@ public abstract class EditPGN extends AppCompatActivity {
|
|||
}
|
||||
}
|
||||
|
||||
private void setDefaultFilePos(long pos) {
|
||||
if (updateDefaultFilePos)
|
||||
defaultFilePos = pos;
|
||||
}
|
||||
|
||||
private boolean readFile() {
|
||||
String fileName = pgnFile.getName();
|
||||
if (!fileName.equals(lastFileName))
|
||||
defaultFilePos = 0;
|
||||
setDefaultFilePos(0);
|
||||
long modTime = new File(fileName).lastModified();
|
||||
if (cacheValid && (modTime == lastModTime) && fileName.equals(lastFileName))
|
||||
return true;
|
||||
try {
|
||||
gamesInFile = pgnFile.getGameInfo(this, progress);
|
||||
if (updateDefaultFilePos) {
|
||||
cacheValid = true;
|
||||
lastModTime = modTime;
|
||||
lastFileName = fileName;
|
||||
} else {
|
||||
cacheValid = false;
|
||||
}
|
||||
return true;
|
||||
} catch (PGNFile.CancelException ignore) {
|
||||
} catch (PGNFile.NotPgnFile ex) {
|
||||
|
|
|
@ -39,6 +39,7 @@ If you are running on battery power, it is recommended that you change settings
|
|||
<string name="load_game">Load game from PGN file</string>
|
||||
<string name="load_position">Load position from file</string>
|
||||
<string name="load_scid_game">Load game from Scid file</string>
|
||||
<string name="load_del_game">Load deleted game</string>
|
||||
<string name="save_game">Save game to PGN file</string>
|
||||
<string name="get_fen">Retrieve Position</string>
|
||||
<string name="repeat_last_move">Repeat last move</string>
|
||||
|
|
Loading…
Reference in New Issue
Block a user