From cc0c376e3f9f12bc657a92165bf486e97de2d5bd Mon Sep 17 00:00:00 2001 From: Harshad Srinivasan Date: Sun, 21 Mar 2021 21:16:26 -0700 Subject: [PATCH 1/4] Back with empty file is ok --- .../net/gsantner/markor/activity/DocumentEditFragment.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/net/gsantner/markor/activity/DocumentEditFragment.java b/app/src/main/java/net/gsantner/markor/activity/DocumentEditFragment.java index a342619693..c83af6d48f 100644 --- a/app/src/main/java/net/gsantner/markor/activity/DocumentEditFragment.java +++ b/app/src/main/java/net/gsantner/markor/activity/DocumentEditFragment.java @@ -421,8 +421,10 @@ public boolean onOptionsItemSelected(final MenuItem item) { return true; } case android.R.id.home: { - if (saveDocument() && getActivity() != null) { - getActivity().onBackPressed(); + saveDocument(); + final Activity activity = getActivity(); + if (activity != null) { + activity.onBackPressed(); } return true; } From ddbb838085a5c11478f9ce9f5d924f78f17477a3 Mon Sep 17 00:00:00 2001 From: Harshad Srinivasan Date: Tue, 23 Mar 2021 09:58:10 -0700 Subject: [PATCH 2/4] Added explicit length test --- .../net/gsantner/markor/activity/DocumentEditFragment.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/java/net/gsantner/markor/activity/DocumentEditFragment.java b/app/src/main/java/net/gsantner/markor/activity/DocumentEditFragment.java index c83af6d48f..14bffb77b1 100644 --- a/app/src/main/java/net/gsantner/markor/activity/DocumentEditFragment.java +++ b/app/src/main/java/net/gsantner/markor/activity/DocumentEditFragment.java @@ -421,9 +421,8 @@ public boolean onOptionsItemSelected(final MenuItem item) { return true; } case android.R.id.home: { - saveDocument(); final Activity activity = getActivity(); - if (activity != null) { + if ((saveDocument() || _hlEditor.length() == 0) && activity != null) { activity.onBackPressed(); } return true; From 1f662abaa737f6b11b659b96f399bae47ac0ab7a Mon Sep 17 00:00:00 2001 From: Harshad Srinivasan Date: Tue, 23 Mar 2021 10:08:29 -0700 Subject: [PATCH 3/4] Added trim --- .../java/net/gsantner/markor/activity/DocumentEditFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/net/gsantner/markor/activity/DocumentEditFragment.java b/app/src/main/java/net/gsantner/markor/activity/DocumentEditFragment.java index 14bffb77b1..0f47a46ee4 100644 --- a/app/src/main/java/net/gsantner/markor/activity/DocumentEditFragment.java +++ b/app/src/main/java/net/gsantner/markor/activity/DocumentEditFragment.java @@ -422,7 +422,7 @@ public boolean onOptionsItemSelected(final MenuItem item) { } case android.R.id.home: { final Activity activity = getActivity(); - if ((saveDocument() || _hlEditor.length() == 0) && activity != null) { + if ((saveDocument() || _hlEditor.toString().trim().length() == 0) && activity != null) { activity.onBackPressed(); } return true; From ef88960e46025280d39d72107d84f2d4e5555a56 Mon Sep 17 00:00:00 2001 From: Gregor Santner Date: Wed, 24 Mar 2021 00:39:11 +0100 Subject: [PATCH 4/4] Optimization for big texts --- .../net/gsantner/markor/activity/DocumentEditFragment.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/net/gsantner/markor/activity/DocumentEditFragment.java b/app/src/main/java/net/gsantner/markor/activity/DocumentEditFragment.java index 0f47a46ee4..3f01bb06ba 100644 --- a/app/src/main/java/net/gsantner/markor/activity/DocumentEditFragment.java +++ b/app/src/main/java/net/gsantner/markor/activity/DocumentEditFragment.java @@ -14,7 +14,6 @@ import android.appwidget.AppWidgetManager; import android.content.ComponentName; import android.content.Context; -import android.graphics.Bitmap; import android.graphics.Color; import android.graphics.Typeface; import android.graphics.drawable.Drawable; @@ -24,6 +23,7 @@ import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; +import android.text.TextUtils; import android.util.TypedValue; import android.view.Gravity; import android.view.Menu; @@ -422,7 +422,7 @@ public boolean onOptionsItemSelected(final MenuItem item) { } case android.R.id.home: { final Activity activity = getActivity(); - if ((saveDocument() || _hlEditor.toString().trim().length() == 0) && activity != null) { + if ((saveDocument() || (_hlEditor.length() < 10 && TextUtils.getTrimmedLength(_hlEditor.getEditableText()) == 0)) && activity != null) { activity.onBackPressed(); } return true;