]> git.ktnx.net Git - mobile-ledger.git/commitdiff
initial (buggy) implementation showing account comments in transaction list
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 5 Jan 2020 21:07:52 +0000 (23:07 +0200)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 5 Jan 2020 21:07:52 +0000 (23:07 +0200)
app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListAdapter.java
app/src/main/res/layout/transaction_list_row.xml
app/src/main/res/layout/transaction_list_row_accounts_table_row.xml [new file with mode: 0644]

index 13983309e3830f2aeeaedf135b90c868a2d89ba1..d8e2c7b0df8aa303d89498fd1627b77d7598b97b 100644 (file)
@@ -163,35 +163,16 @@ public class TransactionListAdapter extends RecyclerView.Adapter<TransactionRowH
                     int rowIndex = step.getAccountPosition();
                     Context ctx = holder.row.getContext();
                     LinearLayout row = (LinearLayout) holder.tableAccounts.getChildAt(rowIndex);
-                    TextView accName, accAmount;
                     if (row == null) {
-                        row = new LinearLayout(ctx);
-                        row.setLayoutParams(new LinearLayout.LayoutParams(
-                                LinearLayout.LayoutParams.MATCH_PARENT,
-                                LinearLayout.LayoutParams.WRAP_CONTENT));
-                        row.setGravity(Gravity.CENTER_VERTICAL);
-                        row.setOrientation(LinearLayout.HORIZONTAL);
-                        row.setPaddingRelative(dp2px(ctx, 8), 0, 0, 0);
-                        accName = new AppCompatTextView(ctx);
-                        accName.setLayoutParams(new LinearLayout.LayoutParams(0,
-                                LinearLayout.LayoutParams.WRAP_CONTENT, 5f));
-                        accName.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_START);
-                        row.addView(accName);
-                        accAmount = new AppCompatTextView(ctx);
-                        LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(
-                                LinearLayout.LayoutParams.WRAP_CONTENT,
-                                LinearLayout.LayoutParams.WRAP_CONTENT);
-                        llp.setMarginEnd(0);
-                        accAmount.setLayoutParams(llp);
-                        accAmount.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_END);
-                        accAmount.setMinWidth(dp2px(ctx, 60));
-                        row.addView(accAmount);
-                        holder.tableAccounts.addView(row);
-                    }
-                    else {
-                        accName = (TextView) row.getChildAt(0);
-                        accAmount = (TextView) row.getChildAt(1);
+                        LayoutInflater inflater = ((Activity) ctx).getLayoutInflater();
+                        row = (LinearLayout) inflater.inflate(
+                                R.layout.transaction_list_row_accounts_table_row,
+                                holder.tableAccounts);
                     }
+                    TextView accName = row.findViewById(R.id.transaction_list_acc_row_acc_name);
+                    TextView accComment =
+                            row.findViewById(R.id.transaction_list_acc_row_acc_comment);
+                    TextView accAmount = row.findViewById(R.id.transaction_list_acc_row_acc_amount);
                     LedgerTransactionAccount acc = step.getAccount();
 
 
@@ -215,6 +196,15 @@ public class TransactionListAdapter extends RecyclerView.Adapter<TransactionRowH
                         accAmount.setTextColor(Colors.defaultTextColor);
                         accName.setText(acc.getAccountName());
                     }
+
+                    String comment = acc.getComment();
+                    if (comment != null && !comment.isEmpty()) {
+                        accComment.setText(comment);
+                        accComment.setVisibility(View.VISIBLE);
+                    }
+                    else {
+                        accComment.setVisibility(View.GONE);
+                    }
                     accAmount.setText(acc.toString());
 
                     break;
index 5e398e7dcb80cf64a0c58f014a40dae1cd63e659..66cca2b866a6b2aa3fe4023ea4543f6dfbadd903 100644 (file)
@@ -28,7 +28,7 @@
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_margin="8dp"
-        android:visibility="gone"
+        android:visibility="visible"
         app:cardCornerRadius="16dp"
         app:cardElevation="4dp"
         app:cardUseCompatPadding="false"
@@ -70,8 +70,8 @@
                 android:id="@+id/transaction_row_header_border"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
-                android:background="@drawable/dashed_border_1dp"
                 android:alpha="0.3"
+                android:background="@drawable/dashed_border_1dp"
                 android:minHeight="2dp"
                 android:orientation="horizontal"
                 app:layout_constraintEnd_toEndOf="parent"
                 app:layout_constraintStart_toStartOf="parent"
                 app:layout_constraintTop_toBottomOf="@+id/transaction_row_header_border">
 
-                <LinearLayout
-                    android:layout_width="match_parent"
-                    android:layout_height="wrap_content"
-                    android:gravity="center_vertical"
-                    android:orientation="horizontal"
-                    android:paddingStart="8dp"
-                    android:paddingEnd="0dp">
-
-                    <TextView
-                        android:layout_width="0dp"
-                        android:layout_height="wrap_content"
-                        android:layout_weight="5"
-                        android:text="---"
-                        android:textAlignment="viewStart"
-                        tools:ignore="HardcodedText" />
-
-                    <TextView
-                        android:layout_width="wrap_content"
-                        android:layout_height="wrap_content"
-                        android:layout_marginEnd="0dp"
-                        android:minWidth="60dp"
-                        android:text="€ --,--"
-                        android:textAlignment="viewEnd"
-                        tools:ignore="HardcodedText" />
-                </LinearLayout>
-
-                <LinearLayout
-                    android:layout_width="match_parent"
-                    android:layout_height="wrap_content"
-                    android:gravity="center_vertical"
-                    android:orientation="horizontal"
-                    android:paddingStart="8dp"
-                    android:paddingEnd="0dp">
-
-                    <TextView
-                        android:layout_width="0dp"
-                        android:layout_height="wrap_content"
-                        android:layout_weight="5"
-                        android:text="---"
-                        android:textAlignment="viewStart"
-                        tools:ignore="HardcodedText" />
-
-                    <TextView
-                        android:layout_width="wrap_content"
-                        android:layout_height="wrap_content"
-                        android:layout_marginEnd="0dp"
-                        android:minWidth="60dp"
-                        android:text="---,--"
-                        android:textAlignment="viewEnd"
-                        tools:ignore="HardcodedText" />
-                </LinearLayout>
+                <include layout="@layout/transaction_list_row_accounts_table_row"/>
+                <include layout="@layout/transaction_list_row_accounts_table_row"/>
+
             </LinearLayout>
 
         </androidx.constraintlayout.widget.ConstraintLayout>
             android:layout_height="16dp"
             android:layout_marginStart="8dp"
             android:layout_marginEnd="8dp"
-            android:background="@drawable/dashed_border_1dp"
             android:alpha="0.3"
+            android:background="@drawable/dashed_border_1dp"
             app:layout_constraintBottom_toBottomOf="parent"
             app:layout_constraintEnd_toStartOf="@id/transaction_delimiter_date"
             app:layout_constraintStart_toEndOf="@id/transaction_delimiter_month"
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
new file mode 100644 (file)
index 0000000..228660e
--- /dev/null
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+  ~ Copyright © 2020 Damyan Ivanov.
+  ~ This file is part of MoLe.
+  ~ MoLe is free software: you can distribute it and/or modify it
+  ~ under the term of the GNU General Public License as published by
+  ~ the Free Software Foundation, either version 3 of the License, or
+  ~ (at your opinion), any later version.
+  ~
+  ~ MoLe is distributed in the hope that it will be useful,
+  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
+  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+  ~ GNU General Public License terms for details.
+  ~
+  ~ You should have received a copy of the GNU General Public License
+  ~ along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+  -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:gravity="center_vertical"
+    android:orientation="horizontal"
+    android:paddingStart="8dp"
+    android:paddingEnd="0dp">
+
+    <LinearLayout
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        android:layout_weight="5"
+        android:orientation="vertical">
+
+        <TextView
+            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:textAlignment="viewStart"
+            tools:ignore="HardcodedText" />
+
+        <TextView
+            android:id="@+id/transaction_list_acc_row_acc_comment"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:alpha="0.75"
+            android:text="account comment"
+            android:textAlignment="viewStart"
+            android:textStyle="italic"
+            tools:ignore="HardcodedText" />
+    </LinearLayout>
+
+    <TextView
+        android:id="@+id/transaction_list_acc_row_acc_amount"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_gravity="top"
+        android:layout_marginEnd="0dp"
+        android:minWidth="60dp"
+        android:text="---,--"
+        android:textAlignment="viewEnd"
+        tools:ignore="HardcodedText" />
+</LinearLayout>