Stay at top in the Nodes Dialog.

- Add a method to the Nodes Dialog in the Settings, so that the list of nodes always stays at the top and shows the best nodes.
This commit is contained in:
Severiano Jaramillo 2019-08-29 12:15:31 -05:00
parent 3c0d2091d8
commit 232d81baa8

View file

@ -10,9 +10,11 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.navigation.Navigation import androidx.navigation.Navigation
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.list.customListAdapter import com.afollestad.materialdialogs.list.customListAdapter
import com.afollestad.materialdialogs.list.getRecyclerView
import com.afollestad.materialdialogs.list.listItemsSingleChoice import com.afollestad.materialdialogs.list.listItemsSingleChoice
import com.crashlytics.android.Crashlytics import com.crashlytics.android.Crashlytics
import com.jakewharton.rxbinding3.widget.textChanges import com.jakewharton.rxbinding3.widget.textChanges
@ -66,6 +68,9 @@ class ImportBrainkeyFragment : BaseAccountFragment() {
/** 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
// NodesDialog's RecyclerView LayoutManager used to always keep showing the first node of the list.
private var mNodesDialogLinearLayoutManager: LinearLayoutManager? = null
/** Handler that will be used to make recurrent calls to get the latest BitShares block number*/ /** Handler that will be used to make recurrent calls to get the latest BitShares block number*/
private val mHandler = Handler() private val mHandler = Handler()
@ -144,6 +149,8 @@ class ImportBrainkeyFragment : BaseAccountFragment() {
.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
@ -164,6 +171,8 @@ class ImportBrainkeyFragment : BaseAccountFragment() {
} }
} }
mNodesDialogLinearLayoutManager = (mNodesDialog?.getRecyclerView()?.layoutManager as LinearLayoutManager)
// Registering a recurrent task used to poll for dynamic global properties requests // Registering a recurrent task used to poll for dynamic global properties requests
mHandler.post(mRequestDynamicGlobalPropertiesTask) mHandler.post(mRequestDynamicGlobalPropertiesTask)
} }