diff --git a/app/build.gradle b/app/build.gradle index 096a72b..4254f8e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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 { diff --git a/app/src/main/java/io/xdag/xdagwallet/activity/UsageActivity.java b/app/src/main/java/io/xdag/xdagwallet/activity/UsageActivity.java index 4258b78..bcca744 100644 --- a/app/src/main/java/io/xdag/xdagwallet/activity/UsageActivity.java +++ b/app/src/main/java/io/xdag/xdagwallet/activity/UsageActivity.java @@ -9,11 +9,15 @@ 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; @@ -21,6 +25,7 @@ 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 @@ -40,6 +45,8 @@ public class UsageActivity extends ToolbarActivity View mRootRemindLayout; CheckBox mCbRootRemind; + AlertDialog.Builder mBuilder; + @Override protected int getLayoutResId() { @@ -54,13 +61,12 @@ 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() ); @@ -68,6 +74,12 @@ protected void initView(View rootView, Bundle savedInstanceState) { 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); } @@ -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()) { @@ -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(); } diff --git a/app/src/main/java/io/xdag/xdagwallet/wrapper/XdagHandlerWrapper.java b/app/src/main/java/io/xdag/xdagwallet/wrapper/XdagHandlerWrapper.java index b03dbe8..265b318 100644 --- a/app/src/main/java/io/xdag/xdagwallet/wrapper/XdagHandlerWrapper.java +++ b/app/src/main/java/io/xdag/xdagwallet/wrapper/XdagHandlerWrapper.java @@ -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); } @@ -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(); diff --git a/app/src/main/res/layout/activity_use_explain.xml b/app/src/main/res/layout/activity_use_explain.xml index 4430bd0..aad65bf 100644 --- a/app/src/main/res/layout/activity_use_explain.xml +++ b/app/src/main/res/layout/activity_use_explain.xml @@ -18,13 +18,22 @@ android:lineSpacingExtra="@dimen/space_8" tools:text="说明文字"/> +