From 1fb6688fd48866ace7c8a3561f15a72fd795ec31 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Sat, 8 May 2021 23:20:03 +0300 Subject: [PATCH] hint account name wrapping after the colon to help long accounts --- .../TransactionRowHolder.java | 7 ++++--- .../net/ktnx/mobileledger/utils/Misc.java | 19 +++++++++++++++++++ ...ransaction_list_row_accounts_table_row.xml | 4 +++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionRowHolder.java b/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionRowHolder.java index 2edf59cb..876430f5 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionRowHolder.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionRowHolder.java @@ -94,8 +94,9 @@ class TransactionRowHolder extends TransactionRowHolderBase { accName.setTextColor(Colors.primary); accAmount.setTextColor(Colors.primary); - SpannableString ss = new SpannableString(acc.getAccountName()); - ss.setSpan(new StyleSpan(Typeface.BOLD), 0, boldAccountName.length(), + SpannableString ss = new SpannableString(Misc.addWrapHints(acc.getAccountName())); + ss.setSpan(new StyleSpan(Typeface.BOLD), 0, Misc.addWrapHints(boldAccountName) + .length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); accName.setText(ss); } @@ -104,7 +105,7 @@ class TransactionRowHolder extends TransactionRowHolderBase { .getDefaultColor(); accName.setTextColor(textColor); accAmount.setTextColor(textColor); - accName.setText(acc.getAccountName()); + accName.setText(Misc.addWrapHints(acc.getAccountName())); } String comment = acc.getComment(); diff --git a/app/src/main/java/net/ktnx/mobileledger/utils/Misc.java b/app/src/main/java/net/ktnx/mobileledger/utils/Misc.java index 349a04a5..67dc0958 100644 --- a/app/src/main/java/net/ktnx/mobileledger/utils/Misc.java +++ b/app/src/main/java/net/ktnx/mobileledger/utils/Misc.java @@ -31,6 +31,7 @@ import androidx.fragment.app.FragmentActivity; import org.jetbrains.annotations.Contract; public class Misc { + public static final char ZERO_WIDTH_SPACE = '\u200B'; public static boolean isZero(float f) { return (f < 0.005) && (f > -0.005); } @@ -107,4 +108,22 @@ public class Misc { public static void onMainThread(Runnable r) { new Handler(Looper.getMainLooper()).post(r); } + public static String addWrapHints(String input) { + if (input == null) + return null; + StringBuilder result = new StringBuilder(); + int lastPos = 0; + int pos = input.indexOf(':'); + + while (pos >= 0) { + result.append(input.substring(lastPos, pos + 1)) + .append(ZERO_WIDTH_SPACE); + lastPos = pos + 1; + pos = input.indexOf(':', lastPos + 1); + } + if (lastPos > 0) + result.append(input.substring(lastPos)); + + return result.toString(); + } } diff --git a/app/src/main/res/layout/transaction_list_row_accounts_table_row.xml b/app/src/main/res/layout/transaction_list_row_accounts_table_row.xml index 5dbed605..ceea9acf 100644 --- a/app/src/main/res/layout/transaction_list_row_accounts_table_row.xml +++ b/app/src/main/res/layout/transaction_list_row_accounts_table_row.xml @@ -40,10 +40,12 @@ android:id="@+id/transaction_list_acc_row_acc_name" android:layout_width="match_parent" android:layout_height="wrap_content" - android:text="another acc name" + android:breakStrategy="high_quality" android:textAlignment="viewStart" android:textAppearance="@android:style/TextAppearance.Material.Small" tools:ignore="HardcodedText" + android:hyphenationFrequency="full" + android:text="one:very:long:account:name:that:needs:to:wrap:to:more:tnan:one:line:two:would:be:nice:but:the:more:the:better:and:the:better:" />