]> git.ktnx.net Git - mobile-ledger.git/commitdiff
hint account name wrapping after the colon to help long accounts
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 8 May 2021 20:20:03 +0000 (23:20 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 8 May 2021 20:20:03 +0000 (23:20 +0300)
app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionRowHolder.java
app/src/main/java/net/ktnx/mobileledger/utils/Misc.java
app/src/main/res/layout/transaction_list_row_accounts_table_row.xml

index 2edf59cb9e1db2abb6c7150af8bd5f3d8dd3b904..876430f5de06e4c1b4b25a9061a5f9d74abfe94b 100644 (file)
@@ -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();
index 349a04a5d9866e416cbb0c29216dc852281f255d..67dc0958686a9722f15b3f797d3634740c531dbc 100644 (file)
@@ -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();
+    }
 }
index 5dbed6054eb006f6ba5320d80f4dd990153334c6..ceea9acfe2845f048561f72c3e5148be28e8a95a 100644 (file)
             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:"
             />
 
         <TextView