Update material-dialogs library.

- Updated the material-dialogs library, and its usages to reflect the new code style 100% focused on Kotlin.
This commit is contained in:
Severiano Jaramillo 2019-08-29 12:09:34 -05:00
parent a42736b738
commit 3c0d2091d8
4 changed files with 48 additions and 57 deletions

View file

@ -115,7 +115,7 @@ dependencies {
implementation 'org.bitcoinj:bitcoinj-core:0.14.3' implementation 'org.bitcoinj:bitcoinj-core:0.14.3'
implementation 'com.moldedbits.r2d2:r2d2:1.0.1' implementation 'com.moldedbits.r2d2:r2d2:1.0.1'
implementation 'me.dm7.barcodescanner:zxing:1.9.8' 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' implementation 'com.andrognito.patternlockview:patternlockview:1.0.0'
// Android Debug Database // Android Debug Database
debugImplementation 'com.amitshekhar.android:debug-db:1.0.6' debugImplementation 'com.amitshekhar.android:debug-db:1.0.6'

View file

@ -272,11 +272,11 @@ class CreateAccountFragment : BaseAccountFragment() {
override fun onFailure(call: Call<FaucetResponse>, t: Throwable) { override fun onFailure(call: Call<FaucetResponse>, t: Throwable) {
// the network call was a failure // the network call was a failure
context?.let { context -> context?.let { context ->
MaterialDialog(context) MaterialDialog(context).show {
.title(R.string.title_error) title(R.string.title_error)
.message(cy.agorise.bitsybitshareswallet.R.string.error__faucet) message(R.string.error__faucet)
.negativeButton(android.R.string.ok) negativeButton(android.R.string.ok)
.show() }
} }
setStateError() setStateError()

View file

@ -29,10 +29,7 @@ import cy.agorise.graphenej.api.calls.GetKeyReferences
import cy.agorise.graphenej.models.AccountProperties import cy.agorise.graphenej.models.AccountProperties
import cy.agorise.graphenej.models.DynamicGlobalProperties import cy.agorise.graphenej.models.DynamicGlobalProperties
import cy.agorise.graphenej.models.JsonRpcResponse 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.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import kotlinx.android.synthetic.main.fragment_import_brainkey.* import kotlinx.android.synthetic.main.fragment_import_brainkey.*
import org.bitcoinj.core.ECKey import org.bitcoinj.core.ECKey
import java.text.NumberFormat import java.text.NumberFormat
@ -67,7 +64,7 @@ class ImportBrainkeyFragment : BaseAccountFragment() {
private var mNodesDialog: MaterialDialog? = null private var mNodesDialog: MaterialDialog? = 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 mNodesAdapter: FullNodesAdapter? = null private var nodesAdapter: FullNodesAdapter? = 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()
@ -129,29 +126,46 @@ class ImportBrainkeyFragment : BaseAccountFragment() {
Navigation.createNavigateOnClickListener(R.id.create_account_action) Navigation.createNavigateOnClickListener(R.id.create_account_action)
) )
tvNetworkStatus.setOnClickListener { v -> tvNetworkStatus.setOnClickListener { v -> showNodesDialog(v) }
if (mNetworkService != null) { }
// PublishSubject used to announce full node latencies updates
val fullNodePublishSubject = mNetworkService!!.nodeLatencyObservable
fullNodePublishSubject?.observeOn(AndroidSchedulers.mainThread())?.subscribe(nodeLatencyObserver)
val fullNodes = mNetworkService!!.nodes private fun showNodesDialog(v: View) {
if (mNetworkService != null) {
val fullNodes = mNetworkService!!.nodes
mNodesAdapter = FullNodesAdapter(v.context) nodesAdapter = FullNodesAdapter(v.context)
mNodesAdapter?.add(fullNodes) nodesAdapter?.add(fullNodes)
mNodesDialog = MaterialDialog(v.context) // PublishSubject used to announce full node latencies updates
.title(text = String.format("%s v%s", getString(R.string.app_name), BuildConfig.VERSION_NAME)) val fullNodePublishSubject = mNetworkService!!.nodeLatencyObservable ?: return
.message(text = getString(R.string.title__bitshares_nodes_dialog, "-------"))
.customListAdapter(mNodesAdapter as FullNodesAdapter)
.negativeButton(android.R.string.ok)
.onDismiss { mHandler.removeCallbacks(mRequestDynamicGlobalPropertiesTask) }
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 mNodesDialog = MaterialDialog(v.context).show {
mHandler.post(mRequestDynamicGlobalPropertiesTask) 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<FullNode> {
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 * Task used to obtain frequent updates on the global dynamic properties object
*/ */

View file

@ -170,17 +170,16 @@ class SettingsFragment : ConnectedFragment(), BaseSecurityLockDialog.OnPINPatter
} }
) )
mNodesDialog = MaterialDialog(v.context) 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)
.negativeButton(android.R.string.ok) negativeButton(android.R.string.ok)
.onDismiss { onDismiss {
mHandler.removeCallbacks(mRequestDynamicGlobalPropertiesTask) mHandler.removeCallbacks(mRequestDynamicGlobalPropertiesTask)
nodesDisposable.dispose() nodesDisposable.dispose()
} }
}
mNodesDialog?.show()
// 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)