Add date field to TransferDetails model and correctly format and display it in the Transactions list.

This commit is contained in:
Severiano Jaramillo 2018-12-21 23:33:58 -06:00
parent a96f3d0b77
commit 7fb1d4ff86
4 changed files with 27 additions and 15 deletions

View file

@ -17,6 +17,7 @@ import cy.agorise.bitsybitshareswallet.utils.Constants
import java.math.RoundingMode
import java.text.DecimalFormat
import java.text.DecimalFormatSymbols
import java.text.SimpleDateFormat
import java.util.*
class TransfersDetailsAdapter(private val context: Context) :
@ -59,6 +60,15 @@ class TransfersDetailsAdapter(private val context: Context) :
}
})
private val dateFormat: SimpleDateFormat
private val timeFormat: SimpleDateFormat
init {
val locale = context.resources.configuration.locale
dateFormat = SimpleDateFormat("dd MMM", locale)
timeFormat = SimpleDateFormat("HH:mm:ss z", locale)
}
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val rootView: ConstraintLayout = itemView.findViewById(R.id.rootView)
val vPaymentDirection: View = itemView.findViewById(R.id.vPaymentDirection)
@ -91,8 +101,11 @@ class TransfersDetailsAdapter(private val context: Context) :
viewHolder.tvFrom.text = transferDetail.from ?: ""
viewHolder.tvTo.text = transferDetail.to ?: ""
viewHolder.tvDate.text = "02 Oct"
viewHolder.tvTime.text = "15:01:18 CET"
// Format date and time
val date = Date(transferDetail.date * 1000)
viewHolder.tvDate.text = dateFormat.format(date)
viewHolder.tvTime.text = timeFormat.format(date)
// Show the crypto amount correctly formatted
// TODO lift the DecimalFormat declaration to other place to make things more efficient

View file

@ -5,7 +5,7 @@ data class TransferDetail(
val from: String?,
val to: String?,
val direction: Boolean, // True -> Received, False -> Sent
// val date: Long,
val date: Long,
val cryptoAmount: Long,
val cryptoPrecision: Int,
val cryptoSymbol: String

View file

@ -7,6 +7,6 @@ import androidx.room.Query
@Dao
interface TransferDetailDao {
@Query("SELECT transfers.id, (SELECT name FROM user_accounts WHERE user_accounts.id=transfers.source) AS `from`, (SELECT name FROM user_accounts WHERE user_accounts.id=transfers.destination) AS `to`, (CASE WHEN destination=:userId THEN 1 ELSE 0 END) AS `direction`, transfers.transfer_amount AS `cryptoAmount`, assets.precision AS `cryptoPrecision`, assets.symbol AS cryptoSymbol FROM transfers INNER JOIN assets WHERE transfers.transfer_asset_id = assets.id")
@Query("SELECT transfers.id, (SELECT name FROM user_accounts WHERE user_accounts.id=transfers.source) AS `from`, (SELECT name FROM user_accounts WHERE user_accounts.id=transfers.destination) AS `to`, (CASE WHEN destination=:userId THEN 1 ELSE 0 END) AS `direction`, transfers.timestamp AS `date`, transfers.transfer_amount AS `cryptoAmount`, assets.precision AS `cryptoPrecision`, assets.symbol AS cryptoSymbol FROM transfers INNER JOIN assets WHERE transfers.transfer_asset_id = assets.id")
fun getAll(userId: String): LiveData<List<TransferDetail>>
}

View file

@ -38,15 +38,19 @@
more than one account, please select which account you wish to import
</string>
<!-- Main Activity -->
<string name="title_activity_main">MainActivity</string>
<!-- Home -->
<string name="title_transactions">Transactions</string>
<string name="title_merchants">Merchants</string>
<string name="title_receive">Receive</string>
<string name="title_balances">Balances</string>
<string name="title_merchants">Merchants</string>
<string name="title_send">Send</string>
<string name="title_net_worth">Net Worth</string>
<string name="text__coming_soon">Coming soon</string>
<!-- Balances -->
<string name="title_transactions">Transactions</string>
<!-- Transactions -->
<string name="title_search">Search</string>
<string name="title_filter">Filter</string>
<string name="title_export">Export</string>
<!-- Send & Receive Transaction -->
<string name="text__to">To</string>
@ -57,6 +61,7 @@
<string name="template__please_pay">Please Pay: %1$s %2$s</string>
<string name="template__to">To: %1$s</string>
<string name="msg__invoice_subject">BiTSy invoice from %1$s</string>
<string name="title_share">Share</string>
<string name="text__share_with">Share with</string>
<!-- Settings -->
@ -77,11 +82,5 @@
https://github.com/Agorise
</string>
<string name="title__bitshares_nodes_dialog">Block: %1$s</string>
<string name="text__coming_soon">Coming soon</string>
<string name="title_net_worth">Net Worth</string>
<string name="title_search">Search</string>
<string name="title_filter">Filter</string>
<string name="title_export">Export</string>
<string name="title_share">Share</string>
</resources>