From c287ffe31351570557e77192eab3dcbdfc5e612f Mon Sep 17 00:00:00 2001 From: Konrad Renner Date: Thu, 11 Jul 2019 08:47:36 +0200 Subject: [PATCH] fixed issues #197 and #198 --- CHANGELOG.md | 8 ++- app/build.gradle | 4 +- .../android/fragment/DetailFragment.java | 69 +++++++++++++++++-- .../android/widget/StickyNoteWidget.java | 3 + 4 files changed, 77 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 930c797..5efd058 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/). You can also have a look on the GitHub release page: https://github.com/konradrenner/kolabnotes-android/releases +## [3.2.1] - 2019-07-11 +### Fixed +- GitHub issue 197 +- GitHub issue 198 + ## [3.2.0] - 2018-11-06 ### Added - Polish translation thx to Waldemar Stoczkowski! @@ -95,7 +100,8 @@ You can also have a look on the GitHub release page: https://github.com/konradre ### Fixed - First stable release, support for all major features of the Kolab notes format -[Unreleased]: https://github.com/konradrenner/kolabnotes-android/compare/3.2.0...HEAD +[Unreleased]: https://github.com/konradrenner/kolabnotes-android/compare/3.2.1...HEAD +[3.2.1]: https://github.com/konradrenner/kolabnotes-android/compare/3.2.0...3.2.1 [3.2.0]: https://github.com/konradrenner/kolabnotes-android/compare/3.1.3...3.2.0 [3.1.3]: https://github.com/konradrenner/kolabnotes-android/compare/3.1.2...3.1.3 [3.1.2]: https://github.com/konradrenner/kolabnotes-android/compare/3.1.1...3.1.2 diff --git a/app/build.gradle b/app/build.gradle index 96122e3..1fe3ea2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,8 +8,8 @@ android { applicationId "org.kore.kolabnotes.android" minSdkVersion 16 targetSdkVersion 26 - versionCode 99 - versionName "3.2.0" + versionCode 100 + versionName "3.2.1" //Running test testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" diff --git a/app/src/main/java/org/kore/kolabnotes/android/fragment/DetailFragment.java b/app/src/main/java/org/kore/kolabnotes/android/fragment/DetailFragment.java index 2caa5ba..8616429 100644 --- a/app/src/main/java/org/kore/kolabnotes/android/fragment/DetailFragment.java +++ b/app/src/main/java/org/kore/kolabnotes/android/fragment/DetailFragment.java @@ -32,6 +32,8 @@ import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.webkit.WebView; +import android.webkit.WebViewClient; import android.widget.ArrayAdapter; import android.widget.EditText; import android.widget.RadioButton; @@ -132,6 +134,9 @@ public class DetailFragment extends Fragment implements OnAccountSwitchedListene private String uuidForCreation; + // the onPause methode of the activity is always called, when the fragment is finished. This applies also to "back" action, where it is not necessary to store the note (because when selected back, the user don't wants to store the note) + private boolean saveNotRequiredAnymore = false; + //This map contains inline images in its base form, sadly the android webview destroys the correct form private Map base64Images = new HashMap<>(); @@ -1199,7 +1204,9 @@ public void onClick(DialogInterface dialog, int which) { @Override public void save() { - saveNote(false); + if(!saveNotRequiredAnymore){ + saveNote(false); + } } void saveNote(boolean closeWhenSaved){ @@ -1491,7 +1498,7 @@ public void onClick(DialogInterface dialog, int which) { }else{ goBack(); } - } else if (editor.getHtml() != null || !TextUtils.isEmpty( + } else if (/* GitHub issue 197 */(editor != null && editor.getHtml() != null) || !TextUtils.isEmpty( ((EditText) activity.findViewById(R.id.detail_summary)).getText().toString())) { AlertDialog.Builder builder = new AlertDialog.Builder(activity); @@ -1503,6 +1510,12 @@ public void onClick(DialogInterface dialog, int which) { if(isNewNote){ final ActiveAccount activeAccount = activeAccountRepository.getActiveAccount(); new AttachmentRepository(activity).deleteForNote(activeAccount.getAccount(), activeAccount.getRootFolder(), getUUIDForCreation()); + + // If the activity was paused, the note got stored in the meantime + if(note != null) { + noteRepository.delete(activeAccount.getAccount(), activeAccount.getRootFolder(), note); + noteTagRepository.delete(activeAccount.getAccount(), activeAccount.getRootFolder(), note.getIdentification().getUid()); + } } goBack(); } @@ -1560,8 +1573,54 @@ private void printNote() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { PrintManager printManager = (PrintManager) activity.getSystemService(Context.PRINT_SERVICE); String jobName = getString(R.string.app_name) + " Document"; - PrintDocumentAdapter printAdapter = editor.createPrintDocumentAdapter(); - PrintJob printJob = printManager.print(jobName, printAdapter, new PrintAttributes.Builder().build()); + + // GitHub issue 197 + if(editor != null){ + PrintDocumentAdapter printAdapter = editor.createPrintDocumentAdapter(); + printManager.print(jobName, printAdapter, new PrintAttributes.Builder().build()); + }else if(editText != null){ + printEditText(jobName); + }else{ + Toast.makeText(activity, R.string.empty_note_description, Toast.LENGTH_LONG).show(); + } + + } + } + + private void printEditText(final String jobName) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + // Create a WebView object specifically for printing + WebView webView = new WebView(getActivity()); + webView.setWebViewClient(new WebViewClient() { + + public boolean shouldOverrideUrlLoading(WebView view, String url) { + return false; + } + + @Override + public void onPageFinished(WebView view, String url) { + Log.i("printEditText", "page finished loading " + url); + createWebPrintJob(view, jobName); + } + }); + + String htmlDocument = Html.toHtml(editText.getText()); + webView.loadDataWithBaseURL(null, htmlDocument, "text/HTML", "UTF-8", null); + } + } + + private void createWebPrintJob(WebView webView, String jobName) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + // Get a PrintManager instance + PrintManager printManager = (PrintManager) getActivity() + .getSystemService(Context.PRINT_SERVICE); + + // Get a print adapter instance + PrintDocumentAdapter printAdapter = webView.createPrintDocumentAdapter(); + + // Create a print job with name and adapter instance + PrintJob printJob = printManager.print(jobName, printAdapter, + new PrintAttributes.Builder().build()); } } @@ -1581,6 +1640,8 @@ private void goBack(){ Intent returnIntent = new Intent(); returnIntent.putExtra("selectedNotebookName",givenNotebook); + saveNotRequiredAnymore = true; + ((OnFragmentCallback)activity).fragmentFinished(returnIntent, OnFragmentCallback.ResultCode.BACK); } } diff --git a/app/src/main/java/org/kore/kolabnotes/android/widget/StickyNoteWidget.java b/app/src/main/java/org/kore/kolabnotes/android/widget/StickyNoteWidget.java index fe43ccf..92bf099 100644 --- a/app/src/main/java/org/kore/kolabnotes/android/widget/StickyNoteWidget.java +++ b/app/src/main/java/org/kore/kolabnotes/android/widget/StickyNoteWidget.java @@ -83,6 +83,9 @@ static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, if(note == null){ views.setTextViewText(R.id.sticky_note_summary, context.getResources().getString(R.string.note_not_found)); + //GitHub issue 198 + views.setOnClickPendingIntent(R.id.sticky_note_summary, null); + views.setTextViewText(R.id.sticky_note_description, ""); }else {