From e2b6593a80d5e510989d1a4cb2da9ecafe17cdc5 Mon Sep 17 00:00:00 2001 From: William Brawner Date: Mon, 15 Feb 2021 13:50:37 -0700 Subject: [PATCH] Show description in transaction list --- .../transactions/TransactionListFragment.kt | 7 ++++ .../main/res/layout/list_item_transaction.xml | 38 ++++++++++++++----- .../budget/common/transaction/Transaction.kt | 2 +- 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/android/src/main/java/com/wbrawner/budget/ui/transactions/TransactionListFragment.kt b/android/src/main/java/com/wbrawner/budget/ui/transactions/TransactionListFragment.kt index 14048c2..da714e9 100644 --- a/android/src/main/java/com/wbrawner/budget/ui/transactions/TransactionListFragment.kt +++ b/android/src/main/java/com/wbrawner/budget/ui/transactions/TransactionListFragment.kt @@ -82,6 +82,7 @@ const val TRANSACTION_VIEW = R.layout.list_item_transaction class TransactionViewHolder(itemView: View, val navController: NavController) : BindableAdapter.CoroutineViewHolder(itemView) { private val name: TextView = itemView.findViewById(R.id.transaction_title) + private val description: TextView = itemView.findViewById(R.id.transaction_description) private val date: TextView = itemView.findViewById(R.id.transaction_date) private val amount: TextView = itemView.findViewById(R.id.transaction_amount) @@ -89,6 +90,12 @@ class TransactionViewHolder(itemView: View, val navController: NavController) : override fun onBind(item: BindableData) { val transaction = item.data name.text = transaction.title + if (transaction.description.isNullOrBlank()) { + description.visibility = View.GONE + } else { + description.visibility = View.VISIBLE + description.text = transaction.description + } date.text = SimpleDateFormat.getDateInstance(SimpleDateFormat.SHORT).format(transaction.date) amount.text = String.format("${'$'}%.02f", transaction.amount / 100.0f) val context = itemView.context diff --git a/android/src/main/res/layout/list_item_transaction.xml b/android/src/main/res/layout/list_item_transaction.xml index 7cb72af..7be9fcd 100644 --- a/android/src/main/res/layout/list_item_transaction.xml +++ b/android/src/main/res/layout/list_item_transaction.xml @@ -1,6 +1,7 @@ @@ -11,30 +12,46 @@ android:layout_height="wrap_content" android:textColor="@color/colorTextPrimary" android:textSize="18sp" - app:layout_constraintHorizontal_bias="0" - app:layout_constraintVertical_chainStyle="packed" app:layout_constraintBottom_toTopOf="@+id/transaction_date" app:layout_constraintEnd_toStartOf="@+id/barrier" + app:layout_constraintHorizontal_bias="0" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toTopOf="parent" /> + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintVertical_chainStyle="packed" + tools:text="Starbucks" /> + + + app:layout_constraintTop_toBottomOf="@+id/transaction_description" + app:layout_constraintVertical_chainStyle="packed" + tools:text="12/12/12" /> + android:layout_height="wrap_content" + app:barrierDirection="start" + app:constraint_referenced_ids="transaction_amount" /> + app:layout_constraintTop_toTopOf="parent" + tools:text="$4.68" /> \ No newline at end of file diff --git a/common/src/main/java/com/wbrawner/budget/common/transaction/Transaction.kt b/common/src/main/java/com/wbrawner/budget/common/transaction/Transaction.kt index c96a24c..54bf3f0 100644 --- a/common/src/main/java/com/wbrawner/budget/common/transaction/Transaction.kt +++ b/common/src/main/java/com/wbrawner/budget/common/transaction/Transaction.kt @@ -7,7 +7,7 @@ data class Transaction( override val id: String? = null, val title: String, val date: Date, - val description: String, + val description: String? = null, val amount: Long, val categoryId: String? = null, val budgetId: String,