Sort Balances alphabetically by symbol and place the asset symbol to the left and the balance amount to the right.

This commit is contained in:
Severiano Jaramillo 2018-12-18 07:55:04 -06:00
parent 720b4f7b1e
commit dc7decfb77
2 changed files with 21 additions and 9 deletions

View file

@ -48,7 +48,8 @@ class BalancesAdapter(private val context: Context) :
})
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val tvBalance: TextView = itemView.findViewById(R.id.tvBalance)
val tvSymbol: TextView = itemView.findViewById(R.id.tvSymbol)
val tvAmount: TextView = itemView.findViewById(R.id.tvAmount)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BalancesAdapter.ViewHolder {
@ -62,10 +63,10 @@ class BalancesAdapter(private val context: Context) :
override fun onBindViewHolder(viewHolder: ViewHolder, position: Int) {
val balance = mSortedList.get(position)
val amount = balance.amount.toDouble() / Math.pow(10.0, balance.precision.toDouble())
viewHolder.tvSymbol.text = balance.symbol
viewHolder.tvBalance.text =
String.format("%." + Math.min(balance.precision, 8) + "f %s", amount, balance.symbol)
val amount = balance.amount.toDouble() / Math.pow(10.0, balance.precision.toDouble())
viewHolder.tvAmount.text = String.format("%." + Math.min(balance.precision, 8) + "f", amount)
}
fun add(balance: BalanceDetail) {

View file

@ -1,10 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView
android:id="@+id/tvBalance"
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="4dp"
android:paddingBottom="4dp"
tools:text="123.45 BTS"/>
android:paddingBottom="4dp">
<TextView
android:id="@+id/tvSymbol"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="123.45"/>
<TextView
android:id="@+id/tvAmount"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
tools:text="BTS"
android:textAlignment="viewEnd"/>
</LinearLayout>