Keep nodes dialog scrolled to the top.

- Added a custom LinearLayoutManager to the NodesDialog's adapter, so that it can be forced to be kept scrolled up to the top.
This commit is contained in:
Severiano Jaramillo 2019-12-31 13:54:52 -06:00
parent 680f2a616d
commit 25087fd483

View file

@ -11,6 +11,7 @@ import android.view.ViewGroup
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.collection.LongSparseArray import androidx.collection.LongSparseArray
import androidx.lifecycle.ViewModelProviders import androidx.lifecycle.ViewModelProviders
import androidx.recyclerview.widget.LinearLayoutManager
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.callbacks.onDismiss import com.afollestad.materialdialogs.callbacks.onDismiss
import com.afollestad.materialdialogs.customview.customView import com.afollestad.materialdialogs.customview.customView
@ -67,6 +68,9 @@ class SettingsFragment : ConnectedFragment(), BaseSecurityLockDialog.OnPINPatter
// Dialog displaying the list of nodes and their latencies // Dialog displaying the list of nodes and their latencies
private var mNodesDialog: MaterialDialog? = null private var mNodesDialog: MaterialDialog? = null
// NodesDialog's RecyclerView LayoutManager used to always keep showing the first node of the list.
private var mNodesDialogLinearLayoutManager: LinearLayoutManager? = null
/** Adapter that holds the FullNode list used in the Bitshares nodes modal */ /** Adapter that holds the FullNode list used in the Bitshares nodes modal */
private var nodesAdapter: FullNodesAdapter? = null private var nodesAdapter: FullNodesAdapter? = null
@ -165,13 +169,15 @@ class SettingsFragment : ConnectedFragment(), BaseSecurityLockDialog.OnPINPatter
nodesAdapter?.add(fullNodes) nodesAdapter?.add(fullNodes)
// PublishSubject used to announce full node latencies updates // PublishSubject used to announce full node latencies updates
val fullNodePublishSubject = mNetworkService!!.nodeLatencyObservable ?: return val fullNodePublishSubject = mNetworkService?.nodeLatencyObservable ?: return
val nodesDisposable = fullNodePublishSubject val nodesDisposable = fullNodePublishSubject
.subscribeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe( .subscribe(
{ fullNode -> { fullNode ->
mNodesDialogLinearLayoutManager?.scrollToPositionWithOffset(0, 0)
if (!fullNode.isRemoved) if (!fullNode.isRemoved)
nodesAdapter?.add(fullNode) nodesAdapter?.add(fullNode)
else else
@ -181,10 +187,12 @@ class SettingsFragment : ConnectedFragment(), BaseSecurityLockDialog.OnPINPatter
} }
) )
mNodesDialogLinearLayoutManager = LinearLayoutManager(v.context)
mNodesDialog = MaterialDialog(v.context).show { mNodesDialog = MaterialDialog(v.context).show {
title(text = String.format("%s v%s", getString(R.string.app_name), BuildConfig.VERSION_NAME)) title(text = String.format("%s v%s", getString(R.string.app_name), BuildConfig.VERSION_NAME))
message(text = getString(R.string.title__bitshares_nodes_dialog, "-------")) message(text = getString(R.string.title__bitshares_nodes_dialog, "-------"))
customListAdapter(nodesAdapter as FullNodesAdapter) customListAdapter(nodesAdapter as FullNodesAdapter, mNodesDialogLinearLayoutManager)
negativeButton(android.R.string.ok) negativeButton(android.R.string.ok)
onDismiss { onDismiss {
mHandler.removeCallbacks(mRequestDynamicGlobalPropertiesTask) mHandler.removeCallbacks(mRequestDynamicGlobalPropertiesTask)