From 2d1af254a15b44c57aca023616bc6f29adb86f38 Mon Sep 17 00:00:00 2001 From: dgis Date: Fri, 6 Dec 2019 00:15:40 +0100 Subject: [PATCH] Ask to SaveAs just after creating a new calculator and improve the Save and SaveAs in certain situation. --- .../emulator/forty/eight/MainActivity.java | 27 +++++++++++++------ app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/pref_general.xml | 2 +- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/org/emulator/forty/eight/MainActivity.java b/app/src/main/java/org/emulator/forty/eight/MainActivity.java index ea56577..cb271c5 100644 --- a/app/src/main/java/org/emulator/forty/eight/MainActivity.java +++ b/app/src/main/java/org/emulator/forty/eight/MainActivity.java @@ -602,12 +602,14 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On } } - private void ensureDocumentSaved(Runnable continueCallback) { - ensureDocumentSaved(continueCallback, false); - } - private Runnable fileSaveAsCallback = null; + private void ensureDocumentSaved(Runnable continueCallback) { + ensureDocumentSaved(continueCallback, false, false); + } private void ensureDocumentSaved(Runnable continueCallback, boolean forceRequest) { + ensureDocumentSaved(continueCallback, forceRequest, false); + } + private void ensureDocumentSaved(Runnable continueCallback, boolean forceRequest, boolean simpleSave) { if(NativeLib.isDocumentAvailable()) { String currentFilename = NativeLib.getCurrentFilename(); boolean hasFilename = (currentFilename != null && currentFilename.length() > 0); @@ -629,7 +631,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On } }; - if(!forceRequest && hasFilename && sharedPreferences.getBoolean("settings_autosave", true)) { + if(simpleSave || (!forceRequest && hasFilename && sharedPreferences.getBoolean("settings_autosave", true))) { onClickListener.onClick(null, DialogInterface.BUTTON_POSITIVE); } else { new AlertDialog.Builder(this) @@ -646,7 +648,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On // By default Port1 is set setPort1Settings(true, true); - ensureDocumentSaved(() -> showKMLPicker(false)); + ensureDocumentSaved(() -> showKMLPicker(false) ); } private void newFileFromKML(String kmlScriptFilename) { @@ -655,11 +657,20 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On showCalculatorView(true); displayFilename(""); showKMLLog(); + suggestToSaveNewFile(); } else showKMLLogForce(); updateNavigationDrawerItems(); } + private void suggestToSaveNewFile() { + new AlertDialog.Builder(this) + .setMessage(getString(R.string.message_save_new_file)) + .setPositiveButton(android.R.string.yes, (dialog, which) -> OnFileSaveAs()) + .setNegativeButton(android.R.string.no, (dialog, which) -> {}) + .show(); + } + private void OnFileOpen() { ensureDocumentSaved(() -> { Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); @@ -670,7 +681,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On }); } private void OnFileSave() { - ensureDocumentSaved(null); + ensureDocumentSaved(null, false, true); } private void OnFileSaveAs() { Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); @@ -1228,7 +1239,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On } private void showKMLLog() { - if(sharedPreferences.getBoolean("settings_alwaysdisplog", true)) { + if(sharedPreferences.getBoolean("settings_alwaysdisplog", false)) { showKMLLogForce(); } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d299b75..17944e8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -71,6 +71,7 @@ I hope now you could open again the state file. State saved Do you want to save changes?\n(BACK to cancel) + Do you want to save this new state file?\n(To avoid losing the state of the machine) Yes No Ok diff --git a/app/src/main/res/xml/pref_general.xml b/app/src/main/res/xml/pref_general.xml index 757c3fe..88292c2 100644 --- a/app/src/main/res/xml/pref_general.xml +++ b/app/src/main/res/xml/pref_general.xml @@ -22,7 +22,7 @@ + android:defaultValue="false" />