diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ce51fec55..7f5d71a89 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -62,7 +62,7 @@ android:name=".activity.MainActivity" android:exported="true" android:label="@string/app_name" - android:launchMode="singleInstance" + android:launchMode="standard" android:taskAffinity=".activity.MainActivity" android:windowSoftInputMode="stateUnchanged|adjustResize"> @@ -167,7 +167,7 @@ = Build.VERSION_CODES.LOLLIPOP && as.isMultiWindowEnabled() && !(activity instanceof DocumentActivity)) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && as.isMultiWindowEnabled()) { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT | Intent.FLAG_ACTIVITY_MULTIPLE_TASK); } diff --git a/app/src/main/java/net/gsantner/markor/activity/MainActivity.java b/app/src/main/java/net/gsantner/markor/activity/MainActivity.java index 22bc86f43..bbcca5bc6 100644 --- a/app/src/main/java/net/gsantner/markor/activity/MainActivity.java +++ b/app/src/main/java/net/gsantner/markor/activity/MainActivity.java @@ -62,7 +62,6 @@ public class MainActivity extends MarkorBaseActivity implements GsFileBrowserFra private MoreFragment _more; private FloatingActionButton _fab; - private boolean _doubleBackToExitPressedOnce; private MarkorContextUtils _cu; private File _quickSwitchPrevFolder = null; @@ -327,32 +326,20 @@ private void newItemCallback(final File file) { @Override public void onBackPressed() { - // Exit confirmed with 2xBack - if (_doubleBackToExitPressedOnce) { - super.onBackPressed(); - _appSettings.setFileBrowserLastBrowsedFolder(_notebook.getCurrentFolder()); - return; - } - // Check if fragment handled back press final GsFragmentBase frag = getPosFragment(getCurrentPos()); - if (frag != null && frag.onBackPressed()) { - return; + if (frag == null || !frag.onBackPressed()) { + super.onBackPressed(); } - - // Confirm exit with back / snack bar - _doubleBackToExitPressedOnce = true; - _cu.showSnackBar(this, R.string.press_back_again_to_exit, false, R.string.exit, view -> finish()); - new Handler().postDelayed(() -> _doubleBackToExitPressedOnce = false, 2000); } public String getFileBrowserTitle() { - final File file = _appSettings.getFileBrowserLastBrowsedFolder(); - String title = getString(R.string.app_name); - if (!_appSettings.getNotebookDirectory().getAbsolutePath().equals(file.getAbsolutePath())) { - title = "> " + file.getName(); + final File file = _notebook.getCurrentFolder(); + if (file != null && !_appSettings.getNotebookDirectory().equals(file)) { + return "> " + file.getName(); + } else { + return getString(R.string.app_name); } - return title; } public int tabIdToPos(final int id) { diff --git a/app/src/main/java/net/gsantner/markor/model/AppSettings.java b/app/src/main/java/net/gsantner/markor/model/AppSettings.java index 4e4c87506..e07d02a73 100644 --- a/app/src/main/java/net/gsantner/markor/model/AppSettings.java +++ b/app/src/main/java/net/gsantner/markor/model/AppSettings.java @@ -87,7 +87,7 @@ public boolean isPreferViewMode() { } public void setNotebookDirectory(final File file) { - setString(R.string.pref_key__notebook_directory, file.getAbsolutePath()); + setString(R.string.pref_key__notebook_directory, Document.getPath(file)); } public File getNotebookDirectory() { @@ -106,7 +106,7 @@ public File getQuickNoteFile() { } public void setQuickNoteFile(final File file) { - setString(R.string.pref_key__quicknote_filepath, file.getAbsolutePath()); + setString(R.string.pref_key__quicknote_filepath, Document.getPath(file)); } public File getDefaultQuickNoteFile() { @@ -118,7 +118,7 @@ public File getTodoFile() { } public void setTodoFile(final File file) { - setString(R.string.pref_key__todo_filepath, file.getAbsolutePath()); + setString(R.string.pref_key__todo_filepath, Document.getPath(file)); } public File getDefaultTodoFile() { @@ -132,7 +132,7 @@ public File getSnippetsDirectory() { } public void setSnippetDirectory(final File folder) { - setString(R.string.pref_key__snippet_directory_path, folder.getAbsolutePath()); + setString(R.string.pref_key__snippet_directory_path, Document.getPath(folder)); } public String getFontFamily() { @@ -340,15 +340,16 @@ public void addRecentFile(final File file) { if (!listFileInRecents(file)) { return; } + final String path = Document.getPath(file); if (!file.equals(getTodoFile()) && !file.equals(getQuickNoteFile())) { ArrayList recent = getRecentDocuments(); - recent.add(0, file.getAbsolutePath()); - recent.remove(getTodoFile().getAbsolutePath()); - recent.remove(getQuickNoteFile().getAbsolutePath()); + recent.add(0, path); + recent.remove(Document.getPath(getTodoFile())); + recent.remove(Document.getPath(getQuickNoteFile())); recent.remove(""); recent.remove(null); - setInt(file.getAbsolutePath(), getInt(file.getAbsolutePath(), 0, _prefCache) + 1, _prefCache); + setInt(path, getInt(path, 0, _prefCache) + 1, _prefCache); setRecentDocuments(recent); } ShortcutUtils.setShortcuts(_context); @@ -358,7 +359,7 @@ public void setFavouriteFiles(final Collection files) { final Set set = new LinkedHashSet<>(); for (final File f : files) { if (f != null && (f.exists() || GsFileBrowserListAdapter.isVirtualFolder(f))) { - set.add(f.getAbsolutePath()); + set.add(Document.getPath(f)); } } setStringList(R.string.pref_key__favourite_files, GsCollectionUtils.map(set, p -> p)); @@ -422,8 +423,8 @@ public void setLastViewPosition(File file, int scrollX, int scrollY) { return; } if (!file.equals(getTodoFile()) && !file.equals(getQuickNoteFile())) { - setInt(PREF_PREFIX_VIEW_SCROLL_X + file.getAbsolutePath(), scrollX, _prefCache); - setInt(PREF_PREFIX_VIEW_SCROLL_Y + file.getAbsolutePath(), scrollY, _prefCache); + setInt(PREF_PREFIX_VIEW_SCROLL_X + Document.getPath(file), scrollX, _prefCache); + setInt(PREF_PREFIX_VIEW_SCROLL_Y + Document.getPath(file), scrollY, _prefCache); } } @@ -550,14 +551,14 @@ public int getLastViewPositionX(File file) { if (file == null || !file.exists()) { return -1; } - return getInt(PREF_PREFIX_VIEW_SCROLL_X + file.getAbsolutePath(), -3, _prefCache); + return getInt(PREF_PREFIX_VIEW_SCROLL_X + Document.getPath(file), -3, _prefCache); } public int getLastViewPositionY(File file) { if (file == null || !file.exists()) { return -1; } - return getInt(PREF_PREFIX_VIEW_SCROLL_Y + file.getAbsolutePath(), -3, _prefCache); + return getInt(PREF_PREFIX_VIEW_SCROLL_Y + Document.getPath(file), -3, _prefCache); } private List getPopularDocumentsSorted() { @@ -813,16 +814,16 @@ public int getTabWidth() { } public boolean listFileInRecents(File file) { - return getBool(file.getAbsolutePath() + "_list_in_recents", true); + return getBool(Document.getPath(file) + "_list_in_recents", true); } public void setListFileInRecents(File file, boolean value) { - setBool(file.getAbsolutePath() + "_list_in_recents", value); + setBool(Document.getPath(file) + "_list_in_recents", value); if (!value) { ArrayList recent = getRecentDocuments(); - if (recent.contains(file.getAbsolutePath())) { - recent.remove(file.getAbsolutePath()); + if (recent.contains(Document.getPath(file))) { + recent.remove(Document.getPath(file)); setRecentDocuments(recent); } } @@ -837,11 +838,11 @@ public ArrayList getFilesTaggedWith(String tag) { }*/ public int getRating(File file) { - return getInt(file.getAbsolutePath() + "_rating", 0); + return getInt(Document.getPath(file) + "_rating", 0); } public void setRating(File file, int value) { - setInt(file.getAbsolutePath() + "_rating", value); + setInt(Document.getPath(file) + "_rating", value); } public boolean isEditorLineBreakingEnabled() { @@ -931,7 +932,7 @@ public void setNewFileDialogLastUsedType(final int format) { } public void setFileBrowserLastBrowsedFolder(File f) { - setString(R.string.pref_key__file_browser_last_browsed_folder, f.getAbsolutePath()); + setString(R.string.pref_key__file_browser_last_browsed_folder, Document.getPath(f)); } public File getFileBrowserLastBrowsedFolder() {