modify switch address type
MODIFY
bither-android/src/net/bither/fragment/hot/OptionHotFragment.java
bither-android/src/net/bither/fragment/hot/OptionHotFragment.java
@@ -463,43 +463,34 @@ public class OptionHotFragment extends Fragment implements Selectable,
private OnClickListener changeAddressTypeClick = new OnClickListener() {
@Override
public void onClick(View v) {
+
if (AppSharedPreference.getInstance().isSegwitAddressType()) {
- changeAddressType();
+ changeAddressType(false);
return;
}
final AddressManager addressManager = AddressManager.getInstance();
if (addressManager.hasHDAccountHot()) {
if (addressManager.hasHDAccountMonitored() && AbstractDb.hdAccountProvider.getSegwitExternalPub(addressManager.getHDAccountMonitored().getHdSeedId()) == null) {
- DialogConfirmTask dialogConfirmTask = new DialogConfirmTask(getActivity(), getString(R.string.address_type_switch_hd_account_cold_no_segwit_pub_tips), new Runnable() {
+ DialogConfirmTask tip = new DialogConfirmTask(getActivity(), getString(R.string.address_type_switch_hd_account_cold_no_segwit_pub_tips), new Runnable() {
@Override
public void run() {
- changeAddressType();
+ changeAddressType(false);
}
}, false);
- dialogConfirmTask.setCancelable(false);
- dialogConfirmTask.show();
+ tip.setCancelable(false);
+ tip.show();
} else {
if (addressManager.getHDAccountHot().getExternalPub(AbstractHD.PathType.EXTERNAL_BIP49_PATH) == null) {
- DialogPassword dialogPassword = new DialogPassword(getActivity(),
- new IDialogPasswordListener() {
- @Override
- public void onPasswordEntered(SecureCharSequence password) {
- addressManager.getHDAccountHot().addSegwitPub(password);
- if (addressManager.getHDAccountHot().getExternalPub(AbstractHD.PathType.EXTERNAL_BIP49_PATH) != null) {
- changeAddressType();
- }
- }
- });
- dialogPassword.show();
+ changeAddressType(true);
} else {
- changeAddressType();
+ changeAddressType(false);
}
}
} else if (addressManager.hasHDAccountMonitored()) {
if (AbstractDb.hdAccountProvider.getSegwitExternalPub(addressManager.getHDAccountMonitored().getHdSeedId()) == null) {
DropdownMessage.showDropdownMessage(getActivity(), getString(R.string.address_type_switch_hd_account_cold_no_segwit_pub_tips));
} else {
- changeAddressType();
+ changeAddressType(false);
}
} else {
DropdownMessage.showDropdownMessage(getActivity(), getString(R.string.open_segwit_only_support_hd_account));
@@ -507,11 +498,49 @@ public class OptionHotFragment extends Fragment implements Selectable,
}
};
- private void changeAddressType() {
- AppSharedPreference instance = AppSharedPreference.getInstance();
- boolean isSegwit = !instance.isSegwitAddressType();
- AppSharedPreference.getInstance().setIsSegwitAddressType(isSegwit);
- showChangeAddressType(isSegwit);
+ private void changeAddressType(final boolean isOpenSegwit) {
+ final AppSharedPreference instance = AppSharedPreference.getInstance();
+ final boolean isSegwit = !instance.isSegwitAddressType();
+ DialogConfirmTask confirmTask = new DialogConfirmTask(getActivity(), getString(R.string.address_type_switch_tips, getString(isSegwit ? R.string.address_segwit_type : R.string.address_normal_type)), new Runnable() {
+ @Override
+ public void run() {
+ if (isOpenSegwit) {
+ ThreadUtil.runOnMainThread(new Runnable() {
+ @Override
+ public void run() {
+ DialogPassword dialogPassword = new DialogPassword(getActivity(),
+ new IDialogPasswordListener() {
+ @Override
+ public void onPasswordEntered(SecureCharSequence password) {
+ ThreadUtil.runOnMainThread(new Runnable() {
+ @Override
+ public void run() {
+ if (dp == null) {
+ dp = new DialogProgress(getActivity(), R.string.please_wait);
+ }
+ dp.show();
+ }
+ });
+ AddressManager addressManager = AddressManager.getInstance();
+ addressManager.getHDAccountHot().addSegwitPub(password);
+ if (addressManager.getHDAccountHot().getExternalPub(AbstractHD.PathType.EXTERNAL_BIP49_PATH) != null) {
+ showChangeAddressType(isSegwit, true);
+ } else {
+ DropdownMessage.showDropdownMessage(getActivity(), R.string.address_type_switch_failure_tips);
+ }
+ }
+ });
+ dialogPassword.show();
+ }
+ });
+ } else {
+ instance.setIsSegwitAddressType(isSegwit);
+ showChangeAddressType(isSegwit, true);
+ }
+ }
+ });
+ confirmTask.setCancelable(false);
+ confirmTask.show();
}
private OnClickListener websiteClick = new OnClickListener() {
@@ -865,11 +894,11 @@ public class OptionHotFragment extends Fragment implements Selectable,
ivLogo.setOnClickListener(logoClickListener);
setAvatar(AppSharedPreference.getInstance().getUserAvatar());
tvPrivacyPolicy.setOnClickListener(privacyPolicyClick);
- showChangeAddressType(AppSharedPreference.getInstance().isSegwitAddressType());
+ showChangeAddressType(AppSharedPreference.getInstance().isSegwitAddressType(), false);
btnChangeAddressType.setOnClickListener(changeAddressTypeClick);
}
- private void showChangeAddressType(final boolean isSegwit) {
+ private void showChangeAddressType(final boolean isSegwit, final boolean isChange) {
ThreadUtil.runOnMainThread(new Runnable() {
@Override
public void run() {
@@ -878,6 +907,12 @@ public class OptionHotFragment extends Fragment implements Selectable,
} else {
btnChangeAddressType.setText(getString(R.string.address_type_switch_to_segwit));
}
+ if (isChange) {
+ DropdownMessage.showDropdownMessage(getActivity(), R.string.address_type_switch_success_tips);
+ }
+ if (dp != null && dp.isShowing()) {
+ dp.dismiss();
+ }
}
});

MODIFY
bither-android/src/net/bither/ui/base/AddressDetailHeader.java
bither-android/src/net/bither/ui/base/AddressDetailHeader.java
@@ -78,7 +78,6 @@ public class AddressDetailHeader extends FrameLayout implements DialogFragmentFa
private DialogProgress dp;
private FutureTask<DialogBalanceDetail.Info> balanceDetailFuture;
private String strAddress;
- private Boolean isSegwitAddress;
public AddressDetailHeader(AddressDetailActivity activity) {
super(activity);
@@ -117,9 +116,6 @@ public class AddressDetailHeader extends FrameLayout implements DialogFragmentFa
public void showAddress(final Address address, int addressPosition, boolean isSegwitAddress) {
this.addressPosition = addressPosition;
- this.isSegwitAddress = isSegwitAddress;
- System.out.println(isSegwitAddress);
- System.out.println(addressPosition);
String addrStr;
if (address.isHDAccount()) {
addrStr = address.getAddress(isSegwitAddress);

MODIFY
bither-android/src/net/bither/ui/base/dialog/DialogHdAccountOptions.java
bither-android/src/net/bither/ui/base/dialog/DialogHdAccountOptions.java
@@ -26,6 +26,7 @@ import net.bither.activity.hot.HDAccountDetailActivity;
import net.bither.bitherj.core.AbstractHD;
import net.bither.bitherj.core.HDAccount;
import net.bither.bitherj.crypto.SecureCharSequence;
+import net.bither.bitherj.db.AbstractDb;
import net.bither.ui.base.DropdownMessage;
import net.bither.ui.base.listener.IDialogPasswordListener;
import net.bither.util.DetectAnotherAssetsUtil;
@@ -59,33 +60,10 @@ public class DialogHdAccountOptions extends DialogWithActions {
@Override
protected List<Action> getActions() {
- final ArrayList<Action> actions = new ArrayList<Action>();
+ final ArrayList<Action> actions = new ArrayList<>();
if (fromDetail) {
- if (!isSegwitAddress) {
- actions.add(new Action(R.string.address_segwit, new Runnable() {
- @Override
- public void run() {
- final DialogProgress dp = new DialogProgress(activity, R.string.please_wait);
- dp.setCancelable(false);
- dp.show();
- new Thread() {
- @Override
- public void run() {
- ThreadUtil.runOnMainThread(new Runnable() {
- @Override
- public void run() {
- dp.dismiss();
- ((AddressDetailActivity) activity).isSegwitAddress =
- !isSegwitAddress;
- ((HDAccountDetailActivity) activity).loadData();
- }
- });
- }
- }.start();
- }
- }));
- } else {
- actions.add(new Action(R.string.address_normal, new Runnable() {
+ if (isSegwitAddress || (!isSegwitAddress && AbstractDb.hdAccountProvider.getSegwitExternalPub(account.getHdSeedId()) != null)) {
+ actions.add(new Action(!isSegwitAddress ? R.string.address_segwit : R.string.address_normal, new Runnable() {
@Override
public void run() {
final DialogProgress dp = new DialogProgress(activity, R.string.please_wait);

MODIFY
bitherj
bitherj
-Subproject commit 9cb77cc86e21dbb90fd4cfc9cf557e111249556f
+Subproject commit 880df8e5af5a7f040fc6720e4d0534bc37a571e6

modify switch address type