Skip to content

Commit

Permalink
Fix codinguser#891 - When editing transactions, new lines are replace…
Browse files Browse the repository at this point in the history
…d with spaces.

When the description TextView loses focus and before the transaction is saved, all new lines are replaced with spaces.
  • Loading branch information
Thumas committed Jun 20, 2021
1 parent 4a97b14 commit 6fab9b1
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -845,6 +863,8 @@ private void saveNewTransaction() {
return;
}

sanitizeDescription();

Transaction transaction = extractTransactionFromView();
if (mEditMode) { //if editing an existing transaction
transaction.setUID(mTransaction.getUID());
Expand Down

0 comments on commit 6fab9b1

Please sign in to comment.