Format outbound transactions.

This commit is contained in:
Kevin Gorham 2020-01-02 18:53:06 -05:00
parent b53992534a
commit ce09ed7bd2
No known key found for this signature in database
GPG Key ID: CCA55602DF49FC38
7 changed files with 64 additions and 24 deletions

View File

@ -12,7 +12,7 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/ZcashTheme">
<activity android:name=".ui.MainActivity">
<activity android:name=".ui.MainActivity" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />

View File

@ -5,7 +5,6 @@ import android.view.ViewGroup
import androidx.paging.PagedListAdapter
import androidx.recyclerview.widget.DiffUtil
import cash.z.ecc.android.R
import cash.z.wallet.sdk.demoapp.demos.listtransactions.TransactionViewHolder
import cash.z.wallet.sdk.entity.ConfirmedTransaction
class TransactionAdapter<T : ConfirmedTransaction> :

View File

@ -1,23 +1,61 @@
package cash.z.wallet.sdk.demoapp.demos.listtransactions
package cash.z.ecc.android.ui.detail
import android.view.View
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import cash.z.ecc.android.R
import cash.z.ecc.android.ext.toAppColor
import cash.z.wallet.sdk.entity.ConfirmedTransaction
import cash.z.wallet.sdk.ext.abbreviatedAddress
import cash.z.wallet.sdk.ext.convertZatoshiToZecString
import java.text.SimpleDateFormat
import java.util.*
class TransactionViewHolder<T : ConfirmedTransaction>(itemView: View) : RecyclerView.ViewHolder(itemView) {
private val indicator = itemView.findViewById<View>(R.id.indicator)
private val amountText = itemView.findViewById<TextView>(R.id.text_transaction_amount)
private val timeText = itemView.findViewById<TextView>(R.id.text_transaction_timestamp)
private val topText = itemView.findViewById<TextView>(R.id.text_transaction_top)
private val bottomText = itemView.findViewById<TextView>(R.id.text_transaction_bottom)
private val formatter = SimpleDateFormat("M/d h:mma", Locale.getDefault())
fun bindTo(transaction: T?) {
amountText.text = transaction?.value.convertZatoshiToZecString()
timeText.text =
if (transaction == null || transaction?.blockTimeInSeconds == 0L) "Pending"
else formatter.format(transaction.blockTimeInSeconds * 1000L)
var lineOne: String = ""
var lineTwo: String = ""
var amount: String = ""
var amountColor: Int = 0
var indicatorColor: Int = 0
transaction?.apply {
amount = value.convertZatoshiToZecString()
// TODO: these might be good extension functions
val timestamp = formatter.format(blockTimeInSeconds * 1000L)
val isMined = blockTimeInSeconds != 0L
when {
!toAddress.isNullOrEmpty() -> {
lineOne = "You paid ${toAddress?.abbreviatedAddress()}"
lineTwo = if (isMined) "Sent $timestamp" else "Pending confirmation"
amount = "- $amount"
amountColor = R.color.zcashRed
indicatorColor = R.color.colorPrimary
}
raw == null || raw?.isEmpty() == true -> {
lineOne = "Unknown paid you"
lineTwo = "Received $timestamp"
amount = "+ $amount"
amountColor = R.color.zcashGreen
indicatorColor = R.color.zcashGreen
}
else -> {
lineOne = "Unknown"
lineTwo = "Unknown"
}
}
}
topText.text = lineOne
bottomText.text = lineTwo
amountText.text = amount
amountText.setTextColor(amountColor.toAppColor())
indicator.setBackgroundColor(indicatorColor.toAppColor())
}
}

View File

@ -54,7 +54,7 @@ class WalletDetailFragment : BaseFragment<FragmentDetailBinding>() {
LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false)
adapter = TransactionAdapter()
resumedScope.launch {
mainActivity?.synchronizer?.receivedTransactions?.collect { onTransactionsUpdated(it) }
mainActivity?.synchronizer?.clearedTransactions?.collect { onTransactionsUpdated(it) }
}
binding.recyclerTransactions.adapter = adapter
}

View File

@ -1,5 +1,5 @@
<vector android:height="24dp"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF66BB6A" android:pathData="M20,5.41L18.59,4 7,15.59V9H5v10h10v-2H8.41z"/>
<path android:fillColor="@color/zcashGreen" android:pathData="M20,5.41L18.59,4 7,15.59V9H5v10h10v-2H8.41z"/>
</vector>

View File

@ -14,30 +14,30 @@
android:layout_marginTop="4dp"
tools:ignore="RtlSymmetry">
<ImageView
android:id="@+id/image_transaction_type"
android:layout_width="40dp"
android:layout_height="40dp"
app:srcCompat="@drawable/ic_receive"
app:layout_constraintBottom_toBottomOf="parent"
<View
android:id="@+id/indicator"
android:layout_width="4dp"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintBottom_toBottomOf="parent"
android:background="@color/zcashGreen"/>
<TextView
android:id="@+id/text_transaction_timestamp"
android:id="@+id/text_transaction_top"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginStart="16dp"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@id/text_transaction_address"
app:layout_constraintStart_toEndOf="@id/image_transaction_type"
app:layout_constraintBottom_toTopOf="@id/text_transaction_bottom"
app:layout_constraintStart_toEndOf="@id/indicator"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed"
tools:text="8/23 3:24pm" />
<TextView
android:id="@+id/text_transaction_address"
android:id="@+id/text_transaction_bottom"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="12sp"
@ -45,8 +45,8 @@
android:maxLines="1"
android:ellipsize="end"
app:layout_constraintEnd_toStartOf="@id/text_transaction_amount"
app:layout_constraintStart_toStartOf="@id/text_transaction_timestamp"
app:layout_constraintTop_toBottomOf="@id/text_transaction_timestamp"
app:layout_constraintStart_toStartOf="@id/text_transaction_top"
app:layout_constraintTop_toBottomOf="@id/text_transaction_top"
app:layout_constraintBottom_toBottomOf="parent"
android:text="funds received" />

View File

@ -38,6 +38,9 @@
<color name="zcashBlack_dark">#171717</color>
<color name="zcashBlack_0">#00000000</color>
<color name="zcashGreen">#66BB6A</color>
<color name="zcashRed">#BB666A</color>
<!-- yellows -->
<color name="zcashYellow_light">#FFD649</color>
<color name="zcashYellow">#FFB727</color>