add indicator

This commit is contained in:
Eljo 2020-12-19 21:38:25 +01:00
parent dc972f2528
commit 3725624eaa
2 changed files with 33 additions and 6 deletions

View File

@ -2,6 +2,7 @@ package cash.z.ecc.android.sdk.demoapp.demos.getbalance
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import cash.z.ecc.android.bip39.Mnemonics import cash.z.ecc.android.bip39.Mnemonics
import cash.z.ecc.android.bip39.toSeed import cash.z.ecc.android.bip39.toSeed
@ -62,6 +63,8 @@ class GetBalanceFragment : BaseDemoFragment<FragmentGetBalanceBinding>() {
private fun monitorChanges() { private fun monitorChanges() {
synchronizer.status.collectWith(lifecycleScope, ::onStatus) synchronizer.status.collectWith(lifecycleScope, ::onStatus)
synchronizer.progress.collectWith(lifecycleScope, ::onProgress)
synchronizer.processorInfo.collectWith(lifecycleScope, ::onProcessorInfoUpdated)
synchronizer.balances.collectWith(lifecycleScope, ::onBalance) synchronizer.balances.collectWith(lifecycleScope, ::onBalance)
} }
@ -75,7 +78,7 @@ class GetBalanceFragment : BaseDemoFragment<FragmentGetBalanceBinding>() {
private fun onStatus(status: Synchronizer.Status) { private fun onStatus(status: Synchronizer.Status) {
binding.textBalance.text = "Status: $status" binding.textStatus.text = "Status: $status"
if (CompactBlockProcessor.WalletBalance().none()) { if (CompactBlockProcessor.WalletBalance().none()) {
binding.textBalance.text = "Calculating balance..." binding.textBalance.text = "Calculating balance..."
} else { } else {
@ -83,6 +86,12 @@ class GetBalanceFragment : BaseDemoFragment<FragmentGetBalanceBinding>() {
} }
} }
private fun onProgress(i: Int) {
if (i < 100) {
binding.textStatus.text = "Downloading blocks...$i%"
}
}
/** /**
* Extension function which checks if the balance has been updated or its -1 * Extension function which checks if the balance has been updated or its -1
*/ */
@ -91,4 +100,8 @@ class GetBalanceFragment : BaseDemoFragment<FragmentGetBalanceBinding>() {
&& synchronizer.latestBalance.availableZatoshi == -1L) return true && synchronizer.latestBalance.availableZatoshi == -1L) return true
return false return false
} }
private fun onProcessorInfoUpdated(info: CompactBlockProcessor.ProcessorInfo) {
if (info.isScanning) binding.textStatus.text = "Scanning blocks...${info.scanProgress}%"
}
} }

View File

@ -1,17 +1,31 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<TextView
android:id="@+id/text_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Initializing wallet..."
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView <TextView
android:id="@+id/text_balance" android:id="@+id/text_balance"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Balance"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="@+id/text_status"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintHorizontal_bias="0.492"
app:layout_constraintTop_toTopOf="parent"/> app:layout_constraintStart_toStartOf="@+id/text_status"
app:layout_constraintTop_toBottomOf="@+id/text_status"
app:layout_constraintVertical_bias="0.0" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>