Skip to content

Commit

Permalink
Merge pull request #111 from XDagger/develop_ssyijiu
Browse files Browse the repository at this point in the history
Add backup wallet on splash page
  • Loading branch information
ssyijiu authored Apr 6, 2023
2 parents 0085c38 + be08604 commit cd92b9f
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 9 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "io.xdag.xdagwallet"
minSdkVersion min_version
targetSdkVersion target_version
versionCode 30
versionName "0.3.0"
versionCode 31
versionName "0.3.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
Expand Down
48 changes: 45 additions & 3 deletions app/src/main/java/io/xdag/xdagwallet/activity/UsageActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,23 @@
import butterknife.BindView;
import butterknife.OnClick;
import com.scottyab.rootbeer.RootBeer;
import com.yanzhenjie.permission.AndPermission;
import com.yanzhenjie.permission.Permission;

import io.reactivex.disposables.Disposable;
import io.xdag.common.Common;
import io.xdag.common.base.ToolbarActivity;
import io.xdag.common.tool.ActivityStack;
import io.xdag.common.tool.ToolbarMode;
import io.xdag.common.util.DeviceUtils;
import io.xdag.common.util.TextStyleUtil;
import io.xdag.xdagwallet.MainActivity;
import io.xdag.xdagwallet.R;
import io.xdag.xdagwallet.config.Config;
import io.xdag.xdagwallet.net.HttpRequest;
import io.xdag.xdagwallet.util.AlertUtil;
import io.xdag.xdagwallet.util.RxUtil;
import io.xdag.xdagwallet.wrapper.XdagHandlerWrapper;

/**
* created by ssyijiu on 2018/7/22
Expand All @@ -40,6 +45,8 @@ public class UsageActivity extends ToolbarActivity
View mRootRemindLayout;
CheckBox mCbRootRemind;

AlertDialog.Builder mBuilder;


@Override
protected int getLayoutResId() {
Expand All @@ -54,20 +61,25 @@ protected void initView(View rootView, Bundle savedInstanceState) {
.append(getString(R.string.use_explain_1))
.append(getString(R.string.use_explain_2))
.append(getString(R.string.use_explain_3))
.setForegroundColor(Common.getColor(R.color.RED))
.append(getString(R.string.use_explain_4))
.append(getString(R.string.use_explain_5))
.setForegroundColor(Common.getColor(R.color.RED))
.appendLine()
.append(getString(R.string.use_explain_6))
.append(getString(R.string.use_explain_7))
.append(getString(R.string.network_upgrade_0_6_1))
.setForegroundColor(Common.getColor(R.color.RED))
.create()
);

mCbBackup.setOnCheckedChangeListener(this);
mCbNoShow.setOnCheckedChangeListener(this);
mRootRemindLayout = View.inflate(mContext, R.layout.dialog_item_checkbox, null);
mCbRootRemind = mRootRemindLayout.findViewById(R.id.dialog_cb);

mBuilder = new AlertDialog.Builder(mContext)
.setTitle(R.string.warning)
.setMessage(R.string.cover_explain)
.setPositiveButton(R.string.cover, (dialog, which) -> backupWallet())
.setNegativeButton(R.string.cancel, null);
}


Expand Down Expand Up @@ -109,6 +121,20 @@ protected void initView(View rootView, Bundle savedInstanceState) {
}


@OnClick(R.id.explain_btn_backup)
void explain_btn_backup() {
if (DeviceUtils.afterQ()) {
checkBackup();
} else {
AndPermission.with(mContext)
.runtime()
.permission(Permission.READ_EXTERNAL_STORAGE, Permission.WRITE_EXTERNAL_STORAGE)
.onGranted(data -> checkBackup())
.onDenied(strings -> AlertUtil.show(mContext, getString(R.string.no_file_access_permission)))
.start();
}
}

@OnClick(R.id.explain_btn_start)
void explain_btn_start() {
if (!Config.isUserBackup()) {
Expand All @@ -128,6 +154,22 @@ void explain_btn_pool() {
}


private void checkBackup() {
if (XdagHandlerWrapper.hasBackup()) {
mBuilder.create().show();
} else {
backupWallet();
}
}

private void backupWallet() {
if (XdagHandlerWrapper.getInstance(this).backupWallet()) {
AlertUtil.show(mContext, R.string.success_backup_xdag_wallet);
} else {
AlertUtil.show(mContext, R.string.error_backup_xdag_wallet);
}
}

public static boolean isNotDisplay() {
return Config.isUserBackup() && Config.isNotDisplayUsage();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ public class XdagHandlerWrapper {
private static XdagHandlerWrapper sInstance = null;


public static XdagHandlerWrapper getInstance(MainActivity activity) {
public static XdagHandlerWrapper getInstance(Activity activity) {
synchronized (XdagHandlerWrapper.class) {
if (sInstance == null) {
if (sInstance == null || activity.isDestroyed() || activity.isFinishing()) {
synchronized (XdagHandlerWrapper.class) {
sInstance = new XdagHandlerWrapper(activity);
}
Expand All @@ -72,7 +72,7 @@ public static XdagHandlerWrapper getInstance(MainActivity activity) {
}


private XdagHandlerWrapper(MainActivity activity) {
private XdagHandlerWrapper(Activity activity) {
mActivity = activity;
HandlerThread handlerThread = new HandlerThread("XdagProcessThread");
handlerThread.start();
Expand Down
12 changes: 11 additions & 1 deletion app/src/main/res/layout/activity_use_explain.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,22 @@
android:lineSpacingExtra="@dimen/space_8"
tools:text="说明文字"/>

<Button
style="@style/XDAG.Button"
android:id="@+id/explain_btn_backup"
android:text="@string/more_backup_wallet"
android:layout_marginTop="@dimen/space_16"
app:layout_constraintBottom_toTopOf="@id/explain_btn_pool"
app:layout_constraintTop_toBottomOf="@id/explain_tv_explain_text"
app:layout_constraintVertical_chainStyle="packed"/>

<Button
style="@style/XDAG.Button"
android:id="@+id/explain_btn_pool"
android:layout_marginTop="@dimen/space_16"
android:text="@string/more_pool"
app:layout_constraintBottom_toTopOf="@id/explain_btn_start"
app:layout_constraintTop_toBottomOf="@id/explain_tv_explain_text"
app:layout_constraintTop_toBottomOf="@id/explain_btn_backup"
app:layout_constraintVertical_chainStyle="packed"/>

<Button
Expand Down Expand Up @@ -53,6 +62,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/space_4"
android:text="@string/not_show_explain"
android:visibility="gone"
android:textSize="@dimen/size_text"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="@id/explain_btn_start"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/fragment_more.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
android:id="@+id/more_setting"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:background="@color/WHITE"
android:text="@string/setting" />

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
<string name="use_explain_5">任何卸载应用、删除数据的行为都将造成钱包文件丢失,且无法找回,请您在进行这些操作前务必备份您的钱包。\n</string>
<string name="use_explain_6">为保证钱包事物的连续性,目前的版本应用内的很多弹框都不可取消,请您见谅。\n</string>
<string name="use_explain_7">我们在后续版本中将改善这个问题。</string>
<string name="network_upgrade_0_6_1">XDAG 0.6.1 主网升级后,该安卓钱包将不再支持转账操作,请务必将钱包备份文件导出到电脑钱包使用。\n钱包备份路径:Documents/xdag_backup.zip</string>
<string name="restore_explain_1">XDAG 因为其独特的设计,\n</string>
<string name="restore_explain_2">目前不支持私钥、助记词等方式备份和恢复钱包。\n</string>
<string name="restore_explain_3">您只能通过以下钱包文件来备份和恢复您的钱包:\n</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
<string name="use_explain_5">Uninstalling or deleting data will cause loss of wallet, and NO WAY TO RECOVER. Please backup your wallet first.\n</string>
<string name="use_explain_6">To ensure transactions, popups are not cancelable.\n</string>
<string name="use_explain_7">We will improve this in later releases.</string>
<string name="network_upgrade_0_6_1">After the XDAG 0.6.1 mainnet upgrade, this Android wallet will no longer support transfer operations. Please make sure to export the wallet backup file to your computer wallet for use.\nWallet backup path: Documents/xdag_backup.zip</string>
<string name="restore_explain_1">Due to special data structure of XDAG, \n</string>
<string name="restore_explain_2">XDAG wallet doesn\'t support backup or restore through private key or mnemonic code currently.\n</string>
<string name="restore_explain_3">You can only backup and restore your wallet by files in xdag folder.\n</string>
Expand Down

0 comments on commit cd92b9f

Please sign in to comment.