Add direction to TransferDetail and use it to display the correct left bar color and direction arrow in the Transactions list..
This commit is contained in:
parent
de75c12197
commit
70ebea75b0
6 changed files with 22 additions and 9 deletions
|
@ -1,6 +1,7 @@
|
||||||
package cy.agorise.bitsybitshareswallet.adapters
|
package cy.agorise.bitsybitshareswallet.adapters
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.preference.PreferenceManager
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
@ -12,10 +13,14 @@ import androidx.recyclerview.widget.RecyclerView
|
||||||
import androidx.recyclerview.widget.SortedList
|
import androidx.recyclerview.widget.SortedList
|
||||||
import cy.agorise.bitsybitshareswallet.R
|
import cy.agorise.bitsybitshareswallet.R
|
||||||
import cy.agorise.bitsybitshareswallet.database.joins.TransferDetail
|
import cy.agorise.bitsybitshareswallet.database.joins.TransferDetail
|
||||||
|
import cy.agorise.bitsybitshareswallet.utils.Constants
|
||||||
|
|
||||||
class TransfersAdapter(private val context: Context) :
|
class TransfersAdapter(private val context: Context) :
|
||||||
RecyclerView.Adapter<TransfersAdapter.ViewHolder>() {
|
RecyclerView.Adapter<TransfersAdapter.ViewHolder>() {
|
||||||
|
|
||||||
|
val userId = PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
|
.getString(Constants.KEY_CURRENT_ACCOUNT_ID, "")!!
|
||||||
|
|
||||||
private val mComparator =
|
private val mComparator =
|
||||||
Comparator<TransferDetail> { a, b -> a.id.compareTo(b.id) }
|
Comparator<TransferDetail> { a, b -> a.id.compareTo(b.id) }
|
||||||
|
|
||||||
|
@ -75,8 +80,16 @@ class TransfersAdapter(private val context: Context) :
|
||||||
override fun onBindViewHolder(viewHolder: ViewHolder, position: Int) {
|
override fun onBindViewHolder(viewHolder: ViewHolder, position: Int) {
|
||||||
val transferDetail = mSortedList.get(position)
|
val transferDetail = mSortedList.get(position)
|
||||||
|
|
||||||
|
viewHolder.vPaymentDirection.setBackgroundColor(context.resources.getColor(
|
||||||
|
if(transferDetail.direction) R.color.colorReceive else R.color.colorSend
|
||||||
|
))
|
||||||
|
|
||||||
viewHolder.tvFrom.text = transferDetail.from
|
viewHolder.tvFrom.text = transferDetail.from
|
||||||
viewHolder.tvTo.text = transferDetail.to
|
viewHolder.tvTo.text = transferDetail.to
|
||||||
|
|
||||||
|
viewHolder.ivDirectionArrow.setImageDrawable(context.getDrawable(
|
||||||
|
if(transferDetail.direction) R.drawable.ic_arrow_receive else R.drawable.ic_arrow_send
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun add(transferDetail: TransferDetail) {
|
fun add(transferDetail: TransferDetail) {
|
||||||
|
|
|
@ -3,8 +3,8 @@ package cy.agorise.bitsybitshareswallet.database.joins
|
||||||
data class TransferDetail(
|
data class TransferDetail(
|
||||||
val id: String,
|
val id: String,
|
||||||
val from: String,
|
val from: String,
|
||||||
val to: String
|
val to: String,
|
||||||
// val direction: Boolean, // True -> Received, False -> Sent
|
val direction: Boolean // True -> Received, False -> Sent
|
||||||
// val date: Long,
|
// val date: Long,
|
||||||
// val cryptoAmount: Long,
|
// val cryptoAmount: Long,
|
||||||
// val cryptoPrecision: Int,
|
// val cryptoPrecision: Int,
|
||||||
|
|
|
@ -7,6 +7,6 @@ import androidx.room.Query
|
||||||
@Dao
|
@Dao
|
||||||
interface TransferDetailDao {
|
interface TransferDetailDao {
|
||||||
|
|
||||||
@Query("SELECT id, IFNULL((SELECT name FROM user_accounts WHERE user_accounts.id=transfers.source), '') AS `from`, IFNULL((SELECT name FROM user_accounts WHERE user_accounts.id=transfers.destination), '') AS `to` FROM transfers")
|
@Query("SELECT id, IFNULL((SELECT name FROM user_accounts WHERE user_accounts.id=transfers.source), '') AS `from`, IFNULL((SELECT name FROM user_accounts WHERE user_accounts.id=transfers.destination), '') AS `to`, (CASE WHEN destination=:userId THEN 1 ELSE 0 END) AS `direction` FROM transfers")
|
||||||
fun getAll(): LiveData<List<TransferDetail>>
|
fun getAll(userId: String): LiveData<List<TransferDetail>>
|
||||||
}
|
}
|
|
@ -67,7 +67,7 @@ class BalancesFragment : Fragment() {
|
||||||
rvTransactions.adapter = transfersAdapter
|
rvTransactions.adapter = transfersAdapter
|
||||||
rvTransactions.layoutManager = LinearLayoutManager(context)
|
rvTransactions.layoutManager = LinearLayoutManager(context)
|
||||||
|
|
||||||
mTransferDetailViewModel.getAll().observe(this, Observer<List<TransferDetail>> { transfersDetails ->
|
mTransferDetailViewModel.getAll(userId).observe(this, Observer<List<TransferDetail>> { transfersDetails ->
|
||||||
transfersAdapter.replaceAll(transfersDetails)
|
transfersAdapter.replaceAll(transfersDetails)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,8 @@ class TransferDetailRepository internal constructor(context: Context) {
|
||||||
mTransferDetailDao = db!!.transferDetailDao()
|
mTransferDetailDao = db!!.transferDetailDao()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getAll(): LiveData<List<TransferDetail>> {
|
fun getAll(userId: String): LiveData<List<TransferDetail>> {
|
||||||
return mTransferDetailDao.getAll()
|
return mTransferDetailDao.getAll(userId)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -9,7 +9,7 @@ import cy.agorise.bitsybitshareswallet.repositories.TransferDetailRepository
|
||||||
class TransferDetailViewModel(application: Application) : AndroidViewModel(application) {
|
class TransferDetailViewModel(application: Application) : AndroidViewModel(application) {
|
||||||
private var mRepository = TransferDetailRepository(application)
|
private var mRepository = TransferDetailRepository(application)
|
||||||
|
|
||||||
internal fun getAll(): LiveData<List<TransferDetail>> {
|
internal fun getAll(userId: String): LiveData<List<TransferDetail>> {
|
||||||
return mRepository.getAll()
|
return mRepository.getAll(userId)
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue