Skip to content

Commit

Permalink
Tweaks to launching; file paths -> canonical
Browse files Browse the repository at this point in the history
  • Loading branch information
harshad1 committed Sep 4, 2024
1 parent 3738d2b commit 372d7b5
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 43 deletions.
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
<intent-filter>
Expand Down Expand Up @@ -167,7 +167,7 @@
</activity>
<activity
android:name=".activity.openeditor.OpenFromShortcutOrWidgetActivity"
android:launchMode="singleTop"
android:launchMode="standard"
android:theme="@android:style/Theme.NoDisplay" />
<activity
android:name=".activity.DocumentActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private static void launch(
intent.putExtra(Document.EXTRA_DO_PREVIEW, doPreview);
}

if (Build.VERSION.SDK_INT >= 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);
}

Expand Down
27 changes: 7 additions & 20 deletions app/src/main/java/net/gsantner/markor/activity/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down
41 changes: 21 additions & 20 deletions app/src/main/java/net/gsantner/markor/model/AppSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand Down Expand Up @@ -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<String> 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);
Expand All @@ -358,7 +359,7 @@ public void setFavouriteFiles(final Collection<File> files) {
final Set<String> 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));
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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<String> getPopularDocumentsSorted() {
Expand Down Expand Up @@ -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<String> recent = getRecentDocuments();
if (recent.contains(file.getAbsolutePath())) {
recent.remove(file.getAbsolutePath());
if (recent.contains(Document.getPath(file))) {
recent.remove(Document.getPath(file));
setRecentDocuments(recent);
}
}
Expand All @@ -837,11 +838,11 @@ public ArrayList<String> 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() {
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 372d7b5

Please sign in to comment.