Skip to content

Commit

Permalink
Add rescan settings preference
Browse files Browse the repository at this point in the history
  • Loading branch information
cpacia committed Apr 6, 2019
1 parent e72069b commit 5796470
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/src/main/java/cash/bchd/android_neutrino/DialogPreference.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package cash.bchd.android_neutrino;

import android.content.Context;
import android.util.AttributeSet;

public class DialogPreference extends android.support.v7.preference.DialogPreference {
public DialogPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
}
26 changes: 26 additions & 0 deletions app/src/main/java/cash/bchd/android_neutrino/SettingsFragment.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package cash.bchd.android_neutrino;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import com.takisoft.fix.support.v7.preference.EditTextPreference;

import android.support.v7.app.AlertDialog;
import android.support.v7.preference.Preference;
import com.takisoft.fix.support.v7.preference.PreferenceFragmentCompat;
import android.support.v7.preference.PreferenceScreen;
Expand Down Expand Up @@ -278,4 +280,28 @@ public boolean onPreferenceChange(Preference preference, Object o) {
activeScreen = "encryption";
}
}

@Override
public void onDisplayPreferenceDialog(Preference preference) {
if (preference.getKey().equals("rescan")) {
AlertDialog.Builder alert = new AlertDialog.Builder(getContext());
alert.setTitle("Rescan");

alert.setMessage("Rescan from wallet birthday?");
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Canceled.
}
});
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
wallet.rescan();
}
});
alert.setCancelable(true);
alert.show();
} else {
super.onDisplayPreferenceDialog(preference);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,12 @@ public long balance() throws Exception {
return reply.getSpendable();
}

public void rescan() {
WalletServiceGrpc.WalletServiceBlockingStub stub = WalletServiceGrpc.newBlockingStub(this.channel).withCallCredentials(this.creds);
Api.RescanRequest request = Api.RescanRequest.newBuilder().build();
stub.rescan(request);
}

public boolean validateAddress(String addr) throws Exception {
WalletServiceGrpc.WalletServiceBlockingStub stub = WalletServiceGrpc.newBlockingStub(this.channel).withCallCredentials(this.creds);
Api.ValidateAddressRequest request = Api.ValidateAddressRequest.newBuilder().setAddress(addr).build();
Expand Down
Binary file added app/src/main/res/drawable/rescan.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/rescan_icon_small.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

<item
android:drawable="@drawable/rescan"
android:width="30dp"
android:height="30dp"
/>

</layer-list >
6 changes: 6 additions & 0 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@
android:icon="@drawable/key_icon_small"
app:summary="Decrypt wallet and return to unencrypted state."/>

<cash.bchd.android_neutrino.DialogPreference
app:key="rescan"
app:title="Rescan Blocks"
app:icon="@drawable/rescan_icon_small"
app:summary="Rescan blocks for missing transactions." />

<android.support.v7.preference.SwitchPreferenceCompat
app:key="blocksonly"
app:icon="@drawable/block_icon_small"
Expand Down

0 comments on commit 5796470

Please sign in to comment.