Show description in transaction list
This commit is contained in:
parent
d8800838c5
commit
e2b6593a80
3 changed files with 36 additions and 11 deletions
|
@ -82,6 +82,7 @@ const val TRANSACTION_VIEW = R.layout.list_item_transaction
|
||||||
|
|
||||||
class TransactionViewHolder(itemView: View, val navController: NavController) : BindableAdapter.CoroutineViewHolder<Transaction>(itemView) {
|
class TransactionViewHolder(itemView: View, val navController: NavController) : BindableAdapter.CoroutineViewHolder<Transaction>(itemView) {
|
||||||
private val name: TextView = itemView.findViewById(R.id.transaction_title)
|
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 date: TextView = itemView.findViewById(R.id.transaction_date)
|
||||||
private val amount: TextView = itemView.findViewById(R.id.transaction_amount)
|
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<Transaction>) {
|
override fun onBind(item: BindableData<Transaction>) {
|
||||||
val transaction = item.data
|
val transaction = item.data
|
||||||
name.text = transaction.title
|
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)
|
date.text = SimpleDateFormat.getDateInstance(SimpleDateFormat.SHORT).format(transaction.date)
|
||||||
amount.text = String.format("${'$'}%.02f", transaction.amount / 100.0f)
|
amount.text = String.format("${'$'}%.02f", transaction.amount / 100.0f)
|
||||||
val context = itemView.context
|
val context = itemView.context
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:padding="16dp">
|
android:padding="16dp">
|
||||||
|
@ -11,30 +12,46 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textColor="@color/colorTextPrimary"
|
android:textColor="@color/colorTextPrimary"
|
||||||
android:textSize="18sp"
|
android:textSize="18sp"
|
||||||
app:layout_constraintHorizontal_bias="0"
|
|
||||||
app:layout_constraintVertical_chainStyle="packed"
|
|
||||||
app:layout_constraintBottom_toTopOf="@+id/transaction_date"
|
app:layout_constraintBottom_toTopOf="@+id/transaction_date"
|
||||||
app:layout_constraintEnd_toStartOf="@+id/barrier"
|
app:layout_constraintEnd_toStartOf="@+id/barrier"
|
||||||
|
app:layout_constraintHorizontal_bias="0"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintVertical_chainStyle="packed"
|
||||||
|
tools:text="Starbucks" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/transaction_description"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:ellipsize="end"
|
||||||
|
app:layout_constraintBottom_toTopOf="@+id/transaction_date"
|
||||||
|
app:layout_constraintEnd_toStartOf="@+id/transaction_amount"
|
||||||
|
app:layout_constraintHorizontal_bias="0"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/transaction_title"
|
||||||
|
app:layout_constraintVertical_chainStyle="packed"
|
||||||
|
tools:text="Grande decaf vanilla latte with a shot of peppermint" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/transaction_date"
|
android:id="@+id/transaction_date"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
app:layout_constraintHorizontal_bias="0"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintVertical_chainStyle="packed"
|
|
||||||
app:layout_constraintEnd_toStartOf="@+id/transaction_amount"
|
app:layout_constraintEnd_toStartOf="@+id/transaction_amount"
|
||||||
|
app:layout_constraintHorizontal_bias="0"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/transaction_title" />
|
app:layout_constraintTop_toBottomOf="@+id/transaction_description"
|
||||||
|
app:layout_constraintVertical_chainStyle="packed"
|
||||||
|
tools:text="12/12/12" />
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.Barrier
|
<androidx.constraintlayout.widget.Barrier
|
||||||
android:id="@+id/barrier"
|
android:id="@+id/barrier"
|
||||||
app:barrierDirection="start"
|
|
||||||
app:constraint_referenced_ids="transaction_amount"
|
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content"
|
||||||
|
app:barrierDirection="start"
|
||||||
|
app:constraint_referenced_ids="transaction_amount" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/transaction_amount"
|
android:id="@+id/transaction_amount"
|
||||||
|
@ -43,5 +60,6 @@
|
||||||
android:textSize="18sp"
|
android:textSize="18sp"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
tools:text="$4.68" />
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -7,7 +7,7 @@ data class Transaction(
|
||||||
override val id: String? = null,
|
override val id: String? = null,
|
||||||
val title: String,
|
val title: String,
|
||||||
val date: Date,
|
val date: Date,
|
||||||
val description: String,
|
val description: String? = null,
|
||||||
val amount: Long,
|
val amount: Long,
|
||||||
val categoryId: String? = null,
|
val categoryId: String? = null,
|
||||||
val budgetId: String,
|
val budgetId: String,
|
||||||
|
|
Loading…
Reference in a new issue