diff --git a/app/build.gradle b/app/build.gradle index e08cdaa..8e45d2f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -115,7 +115,7 @@ dependencies { implementation 'org.bitcoinj:bitcoinj-core:0.14.3' implementation 'com.moldedbits.r2d2:r2d2:1.0.1' implementation 'me.dm7.barcodescanner:zxing:1.9.8' - implementation 'com.afollestad.material-dialogs:core:2.0.0' + implementation 'com.afollestad.material-dialogs:core:3.1.0' implementation 'com.andrognito.patternlockview:patternlockview:1.0.0' // Android Debug Database debugImplementation 'com.amitshekhar.android:debug-db:1.0.6' diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/CreateAccountFragment.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/CreateAccountFragment.kt index e7e8567..4e253e2 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/CreateAccountFragment.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/CreateAccountFragment.kt @@ -272,11 +272,11 @@ class CreateAccountFragment : BaseAccountFragment() { override fun onFailure(call: Call, t: Throwable) { // the network call was a failure context?.let { context -> - MaterialDialog(context) - .title(R.string.title_error) - .message(cy.agorise.bitsybitshareswallet.R.string.error__faucet) - .negativeButton(android.R.string.ok) - .show() + MaterialDialog(context).show { + title(R.string.title_error) + message(R.string.error__faucet) + negativeButton(android.R.string.ok) + } } setStateError() diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/ImportBrainkeyFragment.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/ImportBrainkeyFragment.kt index 0863a86..d443d86 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/ImportBrainkeyFragment.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/ImportBrainkeyFragment.kt @@ -29,10 +29,7 @@ import cy.agorise.graphenej.api.calls.GetKeyReferences import cy.agorise.graphenej.models.AccountProperties import cy.agorise.graphenej.models.DynamicGlobalProperties import cy.agorise.graphenej.models.JsonRpcResponse -import cy.agorise.graphenej.network.FullNode -import io.reactivex.Observer import io.reactivex.android.schedulers.AndroidSchedulers -import io.reactivex.disposables.Disposable import kotlinx.android.synthetic.main.fragment_import_brainkey.* import org.bitcoinj.core.ECKey import java.text.NumberFormat @@ -67,7 +64,7 @@ class ImportBrainkeyFragment : BaseAccountFragment() { private var mNodesDialog: MaterialDialog? = null /** Adapter that holds the FullNode list used in the Bitshares nodes modal */ - private var mNodesAdapter: FullNodesAdapter? = null + private var nodesAdapter: FullNodesAdapter? = null /** Handler that will be used to make recurrent calls to get the latest BitShares block number*/ private val mHandler = Handler() @@ -129,29 +126,46 @@ class ImportBrainkeyFragment : BaseAccountFragment() { Navigation.createNavigateOnClickListener(R.id.create_account_action) ) - tvNetworkStatus.setOnClickListener { v -> - if (mNetworkService != null) { - // PublishSubject used to announce full node latencies updates - val fullNodePublishSubject = mNetworkService!!.nodeLatencyObservable - fullNodePublishSubject?.observeOn(AndroidSchedulers.mainThread())?.subscribe(nodeLatencyObserver) + tvNetworkStatus.setOnClickListener { v -> showNodesDialog(v) } + } - val fullNodes = mNetworkService!!.nodes + private fun showNodesDialog(v: View) { + if (mNetworkService != null) { + val fullNodes = mNetworkService!!.nodes - mNodesAdapter = FullNodesAdapter(v.context) - mNodesAdapter?.add(fullNodes) + nodesAdapter = FullNodesAdapter(v.context) + nodesAdapter?.add(fullNodes) - mNodesDialog = MaterialDialog(v.context) - .title(text = String.format("%s v%s", getString(R.string.app_name), BuildConfig.VERSION_NAME)) - .message(text = getString(R.string.title__bitshares_nodes_dialog, "-------")) - .customListAdapter(mNodesAdapter as FullNodesAdapter) - .negativeButton(android.R.string.ok) - .onDismiss { mHandler.removeCallbacks(mRequestDynamicGlobalPropertiesTask) } + // PublishSubject used to announce full node latencies updates + val fullNodePublishSubject = mNetworkService!!.nodeLatencyObservable ?: return - mNodesDialog?.show() + val nodesDisposable = fullNodePublishSubject + .subscribeOn(AndroidSchedulers.mainThread()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe( + { fullNode -> + if (!fullNode.isRemoved) + nodesAdapter?.add(fullNode) + else + nodesAdapter?.remove(fullNode) + }, { + Log.e(TAG, "nodeLatencyObserver.onError.Msg: " + it.message) + } + ) - // Registering a recurrent task used to poll for dynamic global properties requests - mHandler.post(mRequestDynamicGlobalPropertiesTask) + mNodesDialog = MaterialDialog(v.context).show { + title(text = String.format("%s v%s", getString(R.string.app_name), BuildConfig.VERSION_NAME)) + message(text = getString(R.string.title__bitshares_nodes_dialog, "-------")) + customListAdapter(nodesAdapter as FullNodesAdapter) + negativeButton(android.R.string.ok) + onDismiss { + mHandler.removeCallbacks(mRequestDynamicGlobalPropertiesTask) + nodesDisposable.dispose() + } } + + // Registering a recurrent task used to poll for dynamic global properties requests + mHandler.post(mRequestDynamicGlobalPropertiesTask) } } @@ -345,28 +359,6 @@ class ImportBrainkeyFragment : BaseAccountFragment() { } } - /** - * Observer used to be notified about node latency measurement updates. - */ - private val nodeLatencyObserver = object : Observer { - override fun onSubscribe(d: Disposable) { - mDisposables.add(d) - } - - override fun onNext(fullNode: FullNode) { - if (!fullNode.isRemoved) - mNodesAdapter?.add(fullNode) - else - mNodesAdapter?.remove(fullNode) - } - - override fun onError(e: Throwable) { - Log.e(TAG, "nodeLatencyObserver.onError.Msg: " + e.message) - } - - override fun onComplete() {} - } - /** * Task used to obtain frequent updates on the global dynamic properties object */ diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/SettingsFragment.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/SettingsFragment.kt index 0dcd9d6..580e4f7 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/SettingsFragment.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/SettingsFragment.kt @@ -170,17 +170,16 @@ class SettingsFragment : ConnectedFragment(), BaseSecurityLockDialog.OnPINPatter } ) - mNodesDialog = MaterialDialog(v.context) - .title(text = String.format("%s v%s", getString(R.string.app_name), BuildConfig.VERSION_NAME)) - .message(text = getString(R.string.title__bitshares_nodes_dialog, "-------")) - .customListAdapter(nodesAdapter as FullNodesAdapter) - .negativeButton(android.R.string.ok) - .onDismiss { + mNodesDialog = MaterialDialog(v.context).show { + title(text = String.format("%s v%s", getString(R.string.app_name), BuildConfig.VERSION_NAME)) + message(text = getString(R.string.title__bitshares_nodes_dialog, "-------")) + customListAdapter(nodesAdapter as FullNodesAdapter) + negativeButton(android.R.string.ok) + onDismiss { mHandler.removeCallbacks(mRequestDynamicGlobalPropertiesTask) nodesDisposable.dispose() } - - mNodesDialog?.show() + } // Registering a recurrent task used to poll for dynamic global properties requests mHandler.post(mRequestDynamicGlobalPropertiesTask)