Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

overview: show rescan progress when rescanning #414

Merged
merged 2 commits into from
Dec 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions app/src/main/java/com/dcrandroid/activities/WalletSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,27 @@ class WalletSettings : BaseActivity() {
change_spending_pass.setOnClickListener {
ChangePassUtil(this, walletID).begin()
}

rescan_blockchain.setOnClickListener {
if (multiWallet!!.isSyncing) {
SnackBar.showError(this, R.string.err_sync_in_progress)
} else if (!multiWallet!!.isSynced) {
SnackBar.showError(this, R.string.not_connected)
} else if (multiWallet!!.isRescanning) {
SnackBar.showError(this, R.string.err_rescan_in_progress)
} else {
InfoDialog(this)
.setDialogTitle(getString(R.string.rescan_blockchain))
.setMessage(getString(R.string.rescan_blockchain_warning))
.setPositiveButton(getString(R.string.yes), DialogInterface.OnClickListener { _, _ ->
multiWallet!!.rescanBlocks(walletID)
SnackBar.showText(this, R.string.rescan_progress_notification)
})
.setNegativeButton(getString(R.string.no))
.show()
}

}

remove_wallet.setOnClickListener {
if (multiWallet!!.isSyncing || multiWallet!!.isSynced) {
Expand Down
62 changes: 60 additions & 2 deletions app/src/main/java/com/dcrandroid/util/SyncLayoutUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import kotlinx.android.synthetic.main.synced_unsynced_layout.view.*
import kotlinx.android.synthetic.main.syncing_layout.view.*
import kotlinx.coroutines.*

class SyncLayoutUtil(private val syncLayout: LinearLayout, restartSyncProcess: () -> Unit, scrollToBottom: () -> Unit) : SyncProgressListener {
class SyncLayoutUtil(private val syncLayout: LinearLayout, restartSyncProcess: () -> Unit, scrollToBottom: () -> Unit) : SyncProgressListener, BlocksRescanProgressListener {

private val context: Context
get() = syncLayout.context
Expand All @@ -51,6 +51,8 @@ class SyncLayoutUtil(private val syncLayout: LinearLayout, restartSyncProcess: (
multiWallet.removeSyncProgressListener(this.javaClass.name)
multiWallet.addSyncProgressListener(this, this.javaClass.name)

multiWallet.setBlocksRescanProgressListener(this)

if (multiWallet.isSyncing) {
displaySyncingLayout()
multiWallet.publishLastSyncProgress(this.javaClass.name)
Expand All @@ -71,7 +73,13 @@ class SyncLayoutUtil(private val syncLayout: LinearLayout, restartSyncProcess: (
syncLayout.syncing_cancel_layout.setOnClickListener {
GlobalScope.launch(Dispatchers.Main) {
it.isEnabled = false
launch(Dispatchers.Default) { multiWallet.cancelSync() }
launch(Dispatchers.Default) {
if (multiWallet.isSyncing) {
multiWallet.cancelSync()
} else if (multiWallet.isRescanning) {
multiWallet.cancelRescan()
}
}
it.isEnabled = true
}
}
Expand Down Expand Up @@ -224,6 +232,12 @@ class SyncLayoutUtil(private val syncLayout: LinearLayout, restartSyncProcess: (

syncLayout.tv_online_offline_status.setText(R.string.online)
syncLayout.view_online_offline_status.setBackgroundResource(R.drawable.online_dot)

syncLayout.syncing_layout.syncing_layout_status.text = if (multiWallet.isRescanning) {
context.getString(R.string.rescanning_blocks_ellipsis)
} else {
context.getString(R.string.syncing_state)
}
}

private fun showSyncVerboseExtras() {
Expand Down Expand Up @@ -371,9 +385,53 @@ class SyncLayoutUtil(private val syncLayout: LinearLayout, restartSyncProcess: (
syncLayout.connected_peers.text = HtmlCompat.fromHtml(context.getString(R.string.connected_peers, multiWallet.connectedPeers()), 0)
} else if (multiWallet.isSyncing) {
syncLayout.tv_syncing_layout_connected_peer.text = numberOfConnectedPeers.toString()
} else if (multiWallet.isRescanning) {
syncLayout.tv_steps_title.setText(R.string.connected_peers_count)
syncLayout.tv_steps.text = multiWallet.connectedPeers().toString()
}
}
}

override fun debug(debugInfo: DebugInfo?) {}

override fun onBlocksRescanStarted(walletID: Long) {
displaySyncingLayout()
}

override fun onBlocksRescanEnded(walletID: Long, e: java.lang.Exception?) {
displaySyncedUnsynced()
}

override fun onBlocksRescanProgress(report: HeadersRescanProgressReport) {
GlobalScope.launch(Dispatchers.Main) {
// connected peers
syncLayout.tv_steps.setText(R.string.connected_peers_count)
syncLayout.tv_steps_title.text = multiWallet.connectedPeers().toString()

syncLayout.syncing_layout_connected_peers_row.hide()

showSyncVerboseExtras()

// blocks scanned
syncLayout.tv_block_header_fetched.setText(R.string.scanned_blocks)
syncLayout.tv_fetch_discover_scan_count.text = report.currentRescanHeight.toString()

// scan progress
syncLayout.tv_progress.setText(R.string.syncing_progress)
syncLayout.tv_days.text = context.getString(R.string.blocks_left,
report.totalHeadersToScan - report.currentRescanHeight)

if (multiWallet.openedWalletsCount() > 1) {
syncLayout.syncing_layout_wallet_name.show()

val wallet = multiWallet.walletWithID(report.walletID)
syncLayout.tv_syncing_layout_wallet_name.text = wallet.name
} else {
syncLayout.syncing_layout_wallet_name.hide()
}
}

publishSyncProgress(report.generalSyncProgress)
displaySyncingLayoutIfNotShowing()
}
}
21 changes: 21 additions & 0 deletions app/src/main/res/layout/activity_debug.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,27 @@

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/check_statistics"
android:padding="@dimen/margin_padding_size_16"
android:focusable="true"
android:clickable="true"
android:background="@drawable/ripple"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@id/pref_title"
android:includeFontPadding="false"
android:text="@string/check_statistics"
android:textColor="@color/darkBlueTextColor"
android:fontFamily="@font/source_sans_pro"
android:textSize="@dimen/edit_text_size_16" />

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
Expand Down
144 changes: 94 additions & 50 deletions app/src/main/res/layout/activity_wallet_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,61 +21,60 @@
android:background="@color/colorBackground"
android:theme="@style/AppTheme.AppBarOverlay">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingStart="@dimen/margin_padding_size_16"
android:paddingEnd="0dp"
android:orientation="horizontal"
android:gravity="center_vertical">

<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:padding="@dimen/margin_padding_size_8"
android:background="@drawable/circular_transparent_ripple"
android:focusable="true"
android:clickable="true"
android:id="@+id/go_back"
app:srcCompat="@drawable/ic_back" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingStart="@dimen/margin_padding_size_16"
android:paddingEnd="0dp"
android:orientation="horizontal"
android:gravity="center_vertical">

<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:padding="@dimen/margin_padding_size_8"
android:background="@drawable/circular_transparent_ripple"
android:focusable="true"
android:clickable="true"
android:id="@+id/go_back"
app:srcCompat="@drawable/ic_back" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="@dimen/margin_padding_size_8"
android:gravity="center_vertical"
android:orientation="vertical"
>
android:layout_marginStart="@dimen/margin_padding_size_8"
android:gravity="center_vertical"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/settings"
android:textSize="@dimen/edit_text_size_20"
android:textColor="@color/darkBlueTextColor"
android:includeFontPadding="false"
app:fontFamily="@font/source_sans_pro" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tv_subtitle"
tools:text="@string/_default"
android:textSize="@dimen/edit_text_size_14"
android:textColor="@color/blueGraySecondTextColor"
android:includeFontPadding="false"
app:fontFamily="@font/source_sans_pro" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/settings"
android:textSize="@dimen/edit_text_size_20"
android:textColor="@color/darkBlueTextColor"
android:includeFontPadding="false"
app:fontFamily="@font/source_sans_pro" />

</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tv_subtitle"
tools:text="@string/_default"
android:textSize="@dimen/edit_text_size_14"
android:textColor="@color/blueGraySecondTextColor"
android:includeFontPadding="false"
app:fontFamily="@font/source_sans_pro" />

</LinearLayout>

</LinearLayout>

</com.google.android.material.appbar.AppBarLayout>

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/wallet_settings_scroll_view" >
android:id="@+id/wallet_settings_scroll_view">

<LinearLayout
android:layout_width="match_parent"
Expand All @@ -92,7 +91,7 @@
android:orientation="vertical"
android:paddingTop="@dimen/margin_padding_size_16"
android:paddingBottom="@dimen/margin_padding_size_8"
android:background="@drawable/card_bg" >
android:background="@drawable/card_bg">

<TextView
android:layout_width="wrap_content"
Expand Down Expand Up @@ -125,7 +124,7 @@
android:text="@string/change_spending_pin_password"
android:textColor="@color/darkBlueTextColor"
android:fontFamily="@font/source_sans_pro"
android:textSize="@dimen/edit_text_size_16"/>
android:textSize="@dimen/edit_text_size_16" />

</LinearLayout>

Expand Down Expand Up @@ -154,7 +153,7 @@
android:text="@string/use_fingerprint"
android:textColor="@color/darkBlueTextColor"
android:fontFamily="@font/source_sans_pro"
android:textSize="@dimen/edit_text_size_16"/>
android:textSize="@dimen/edit_text_size_16" />

</LinearLayout>

Expand All @@ -176,7 +175,7 @@
android:orientation="vertical"
android:paddingTop="@dimen/margin_padding_size_16"
android:paddingBottom="@dimen/margin_padding_size_8"
android:background="@drawable/card_bg" >
android:background="@drawable/card_bg">

<TextView
android:layout_width="wrap_content"
Expand Down Expand Up @@ -207,7 +206,7 @@
android:text="@string/incoming_transactions"
android:textColor="@color/darkBlueTextColor"
android:fontFamily="@font/source_sans_pro"
android:textSize="@dimen/edit_text_size_16"/>
android:textSize="@dimen/edit_text_size_16" />

<TextView
android:layout_width="wrap_content"
Expand All @@ -218,7 +217,52 @@
android:text="@string/none"
android:textColor="@color/blueGraySecondTextColor"
android:fontFamily="@font/source_sans_pro"
android:textSize="@dimen/edit_text_size_14"/>
android:textSize="@dimen/edit_text_size_14" />

</LinearLayout>

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/margin_padding_size_4"
android:elevation="4dp"
android:orientation="vertical"
android:paddingTop="@dimen/margin_padding_size_16"
android:paddingBottom="@dimen/margin_padding_size_8"
android:background="@drawable/card_bg">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:includeFontPadding="false"
android:text="@string/debug"
android:textSize="@dimen/edit_text_size_14"
android:fontFamily="@font/source_sans_pro"
android:layout_marginStart="@dimen/margin_padding_size_16"
android:textColor="@color/darkerBlueGrayTextColor" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/rescan_blockchain"
android:layout_marginTop="@dimen/margin_padding_size_8"
android:padding="@dimen/margin_padding_size_16"
android:focusable="true"
android:clickable="true"
android:background="@drawable/ripple"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@id/pref_title"
android:includeFontPadding="false"
android:text="@string/rescan_blockchain"
android:textColor="@color/darkBlueTextColor"
android:fontFamily="@font/source_sans_pro"
android:textSize="@dimen/edit_text_size_16" />

</LinearLayout>

Expand All @@ -232,7 +276,7 @@
android:orientation="vertical"
android:paddingTop="@dimen/margin_padding_size_8"
android:paddingBottom="@dimen/margin_padding_size_8"
android:background="@drawable/card_bg" >
android:background="@drawable/card_bg">

<LinearLayout
android:layout_width="match_parent"
Expand All @@ -252,7 +296,7 @@
android:text="@string/remove_wallet"
android:textColor="@color/orangeTextColor"
android:fontFamily="@font/source_sans_pro"
android:textSize="@dimen/edit_text_size_16"/>
android:textSize="@dimen/edit_text_size_16" />

</LinearLayout>

Expand Down
Loading