Fix: wallet history now correctly scrolls to the top.

Previously, it would chop off the last transaction which happens to be what users are most interested in seeing. This was happening because the scroll was being called before the list contents were fully loaded from the database so we were scrolling to the top of an empty list.
This commit is contained in:
Kevin Gorham 2020-08-01 02:53:01 -04:00
parent 3a336396a0
commit a9bc645cb1
No known key found for this signature in database
GPG Key ID: CCA55602DF49FC38
1 changed files with 27 additions and 7 deletions

View File

@ -60,19 +60,39 @@ class WalletDetailFragment : BaseFragment<FragmentDetailBinding>() {
}
private fun initTransactionUI() {
binding.recyclerTransactions.layoutManager =
LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false)
binding.recyclerTransactions.addItemDecoration(TransactionsFooter(binding.recyclerTransactions.context))
adapter = TransactionAdapter()
binding.recyclerTransactions.apply {
layoutManager =
LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false)
addItemDecoration(TransactionsFooter(binding.recyclerTransactions.context))
adapter = this@WalletDetailFragment.adapter
scrollToTop()
}
viewModel.transactions.collectWith(resumedScope) { onTransactionsUpdated(it) }
binding.recyclerTransactions.adapter = adapter
binding.recyclerTransactions.smoothScrollToPosition(0)
}
private fun onTransactionsUpdated(transactions: PagedList<ConfirmedTransaction>) {
twig("got a new paged list of transactions")
binding.groupEmptyViews.goneIf(transactions.size > 0)
adapter.submitList(transactions)
transactions.size.let { newCount ->
binding.groupEmptyViews.goneIf(newCount > 0)
val preSize = adapter.itemCount
adapter.submitList(transactions)
// don't rescroll while the user is looking at the list, unless it's initialization
// using 4 here because there might be headers or other things that make 0 a bad pick
// 4 is about how many can fit before scrolling becomes necessary on many screens
if (preSize < 4 && newCount > preSize) {
scrollToTop()
}
}
}
private fun scrollToTop() {
twig("scrolling to the top")
binding.recyclerTransactions.apply {
postDelayed({
smoothScrollToPosition(0)
}, 5L)
}
}
// TODO: maybe implement this for better fade behavior. Or do an actual scroll behavior instead, yeah do that. Or an item decoration.