From 6fab9b1c6f0b28fcbaa99bba62aa358c7d996cef Mon Sep 17 00:00:00 2001 From: thomas Date: Sun, 20 Jun 2021 19:59:28 +0200 Subject: [PATCH] Fix #891 - When editing transactions, new lines are replaced with spaces. When the description TextView loses focus and before the transaction is saved, all new lines are replaced with spaces. --- .../transaction/TransactionFormFragment.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/app/src/main/java/org/gnucash/android/ui/transaction/TransactionFormFragment.java b/app/src/main/java/org/gnucash/android/ui/transaction/TransactionFormFragment.java index ad9f36e03..550f7c174 100644 --- a/app/src/main/java/org/gnucash/android/ui/transaction/TransactionFormFragment.java +++ b/app/src/main/java/org/gnucash/android/ui/transaction/TransactionFormFragment.java @@ -454,9 +454,27 @@ public void onItemClick(AdapterView adapterView, View view, int position, lon } }); + mDescriptionEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() { + @Override + public void onFocusChange(View view, boolean hasFocus) { + if (!hasFocus && view instanceof AutoCompleteTextView) { + TransactionFormFragment.this.sanitizeDescription(); + } + } + }); + mDescriptionEditText.setAdapter(adapter); } + /** + * Removes new line characters from the description text field and replaces them with spaces. + */ + private void sanitizeDescription() { + String original = mDescriptionEditText.getText().toString(); + mDescriptionEditText.setText(original.replaceAll("\\r?\\n", " ")); + } + + /** * Initialize views in the fragment with information from a transaction. * This method is called if the fragment is used for editing a transaction @@ -845,6 +863,8 @@ private void saveNewTransaction() { return; } + sanitizeDescription(); + Transaction transaction = extractTransactionFromView(); if (mEditMode) { //if editing an existing transaction transaction.setUID(mTransaction.getUID());