From 4172087e254e6a890389401251d0d753ecf6b59a Mon Sep 17 00:00:00 2001 From: pppscn <35696959@qq.com> Date: Wed, 26 Jan 2022 10:02:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=9A=E4=B8=80=E9=94=AE?= =?UTF-8?q?=E5=85=8B=E9=9A=86=E6=9C=BA=E5=88=B6=E4=BC=98=E5=8C=96=EF=BC=8C?= =?UTF-8?q?=E6=8F=90=E9=AB=98=E6=88=90=E5=8A=9F=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../idormy/sms/forwarder/CloneActivity.java | 62 ++++++++++--------- .../sms/forwarder/model/vo/CloneInfoVo.java | 31 +++++++++- .../sms/forwarder/receiver/BaseServlet.java | 1 + .../idormy/sms/forwarder/utils/ZipUtils.java | 8 +-- app/src/main/res/layout/activity_clone.xml | 9 ++- app/src/main/res/values-en/strings.xml | 8 +++ app/src/main/res/values/strings.xml | 10 ++- 7 files changed, 90 insertions(+), 39 deletions(-) diff --git a/app/src/main/java/com/idormy/sms/forwarder/CloneActivity.java b/app/src/main/java/com/idormy/sms/forwarder/CloneActivity.java index aa6a6282..de88b086 100644 --- a/app/src/main/java/com/idormy/sms/forwarder/CloneActivity.java +++ b/app/src/main/java/com/idormy/sms/forwarder/CloneActivity.java @@ -66,7 +66,7 @@ public class CloneActivity extends AppCompatActivity { } else if (msg.what == DOWNLOAD) { String savePath = context.getCacheDir().getPath() + File.separator + BackupDbTask.BACKUP_FILE; Log.d(TAG, savePath); - downloadFile(msg.getData().getString("URL"), context.getCacheDir().getPath(), BackupDbTask.BACKUP_FILE); + downloadFile(msg.getData().getString("URL"), context.getCacheDir().getPath(), BackupDbTask.BACKUP_FILE, msg.getData().getString("INFO")); } } }; @@ -186,7 +186,7 @@ public class CloneActivity extends AppCompatActivity { client.newCall(request).enqueue(new Callback() { @Override public void onFailure(@NonNull Call call, @NonNull final IOException e) { - Toast(handError, TAG, "从发送端获取一键克隆信息失败"); + Toast(handError, TAG, getString(R.string.tips_get_info_failed)); } @Override @@ -195,44 +195,28 @@ public class CloneActivity extends AppCompatActivity { Log.d(TAG, "Response:" + response.code() + "," + responseStr); if (TextUtils.isEmpty(responseStr)) { - Toast(handError, TAG, "从发送端获取一键克隆信息失败"); + Toast(handError, TAG, getString(R.string.tips_get_info_failed)); return; } try { CloneInfoVo cloneInfoVo = JSON.parseObject(responseStr, CloneInfoVo.class); if (SettingUtil.getVersionCode() != cloneInfoVo.getVersionCode()) { - Toast(handError, TAG, "发送端与接收端的APP版本不一致,无法一键克隆!"); + Toast(handError, TAG, getString(R.string.tips_versions_inconsistent)); return; } - //应用配置 - SettingUtil.switchEnableSms(cloneInfoVo.isEnableSms()); - SettingUtil.switchEnablePhone(cloneInfoVo.isEnablePhone()); - SettingUtil.switchCallType1(cloneInfoVo.isCallType1()); - SettingUtil.switchCallType2(cloneInfoVo.isCallType2()); - SettingUtil.switchCallType3(cloneInfoVo.isCallType3()); - SettingUtil.switchEnableAppNotify(cloneInfoVo.isEnableAppNotify()); - SettingUtil.switchCancelAppNotify(cloneInfoVo.isCancelAppNotify()); - SettingUtil.smsHubApiUrl(cloneInfoVo.getSmsHubApiUrl()); - SettingUtil.setBatteryLevelAlarmMin(cloneInfoVo.getBatteryLevelAlarmMin()); - SettingUtil.setBatteryLevelAlarmMax(cloneInfoVo.getBatteryLevelAlarmMax()); - SettingUtil.switchBatteryLevelAlarmOnce(cloneInfoVo.isBatteryLevelAlarmOnce()); - SettingUtil.setRetryTimes(cloneInfoVo.getRetryTimes()); - SettingUtil.setDelayTime(cloneInfoVo.getDelayTime()); - SettingUtil.switchSmsTemplate(cloneInfoVo.isEnableSmsTemplate()); - SettingUtil.setSmsTemplate(cloneInfoVo.getSmsTemplate()); - //下载备份文件 Message msg = new Message(); msg.what = DOWNLOAD; Bundle bundle = new Bundle(); bundle.putString("URL", requestUrl); + bundle.putString("INFO", responseStr); msg.setData(bundle); handError.sendMessage(msg); } catch (Exception e) { - Toast(handError, TAG, "一键克隆失败:" + e.getMessage()); + Toast(handError, TAG, getString(R.string.tips_clone_failed) + e.getMessage()); } } }); @@ -256,11 +240,11 @@ public class CloneActivity extends AppCompatActivity { * * @param url 下载链接 */ - public void downloadFile(String url, final String destFileDir, final String destFileName) { + public void downloadFile(String url, final String destFileDir, final String destFileName, final String cloneInfo) { ProgressDialog progressDialog = new ProgressDialog(context); progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); - progressDialog.setTitle("正在下载"); - progressDialog.setMessage("请稍后..."); + progressDialog.setTitle(getString(R.string.tips_downloading)); + progressDialog.setMessage(getString(R.string.tips_please_wait)); progressDialog.setProgress(0); progressDialog.setMax(100); progressDialog.show(); @@ -269,7 +253,7 @@ public class CloneActivity extends AppCompatActivity { @Override public void onDownloadSuccess(File file) { if (progressDialog.isShowing()) { - Toast(handError, TAG, "下载完成,正准备还原数据..."); + Toast(handError, TAG, getString(R.string.tips_download_done)); progressDialog.dismiss(); } //下载完成进行相关逻辑操作 @@ -280,7 +264,27 @@ public class CloneActivity extends AppCompatActivity { String backup_version = task.doInBackground(BackupDbTask.COMMAND_RESTORE); Log.d(TAG, "backup_version = " + backup_version); - Toast(handError, TAG, "一键克隆操作成功!请进入通用设置检查各项开关是否已开启!"); + //应用配置 + CloneInfoVo cloneInfoVo = JSON.parseObject(cloneInfo, CloneInfoVo.class); + System.out.println(cloneInfoVo.toString()); + SettingUtil.init(context); + SettingUtil.switchEnableSms(cloneInfoVo.isEnableSms()); + SettingUtil.switchEnablePhone(cloneInfoVo.isEnablePhone()); + SettingUtil.switchCallType1(cloneInfoVo.isCallType1()); + SettingUtil.switchCallType2(cloneInfoVo.isCallType2()); + SettingUtil.switchCallType3(cloneInfoVo.isCallType3()); + SettingUtil.switchEnableAppNotify(cloneInfoVo.isEnableAppNotify()); + SettingUtil.switchCancelAppNotify(cloneInfoVo.isCancelAppNotify()); + SettingUtil.smsHubApiUrl(cloneInfoVo.getSmsHubApiUrl()); + SettingUtil.setBatteryLevelAlarmMin(cloneInfoVo.getBatteryLevelAlarmMin()); + SettingUtil.setBatteryLevelAlarmMax(cloneInfoVo.getBatteryLevelAlarmMax()); + SettingUtil.switchBatteryLevelAlarmOnce(cloneInfoVo.isBatteryLevelAlarmOnce()); + SettingUtil.setRetryTimes(cloneInfoVo.getRetryTimes()); + SettingUtil.setDelayTime(cloneInfoVo.getDelayTime()); + SettingUtil.switchSmsTemplate(cloneInfoVo.isEnableSmsTemplate()); + SettingUtil.setSmsTemplate(cloneInfoVo.getSmsTemplate()); + + Toast(handError, TAG, getString(R.string.tips_clone_done)); } @Override @@ -292,8 +296,8 @@ public class CloneActivity extends AppCompatActivity { @Override public void onDownloadFailed(Exception e) { //下载异常进行相关提示操作 - Log.e(TAG, "下载失败:" + e.getMessage()); - Toast(handError, TAG, "下载失败:" + e.getMessage()); + Log.e(TAG, getString(R.string.tips_download_failed) + e.getMessage()); + Toast(handError, TAG, getString(R.string.tips_download_failed) + e.getMessage()); } }); } diff --git a/app/src/main/java/com/idormy/sms/forwarder/model/vo/CloneInfoVo.java b/app/src/main/java/com/idormy/sms/forwarder/model/vo/CloneInfoVo.java index 846fc508..7634a8ca 100644 --- a/app/src/main/java/com/idormy/sms/forwarder/model/vo/CloneInfoVo.java +++ b/app/src/main/java/com/idormy/sms/forwarder/model/vo/CloneInfoVo.java @@ -1,10 +1,14 @@ package com.idormy.sms.forwarder.model.vo; +import androidx.annotation.NonNull; + import java.io.Serializable; -import lombok.Data; +import lombok.Getter; +import lombok.Setter; -@Data +@Setter +@Getter public class CloneInfoVo implements Serializable { private int versionCode; @@ -25,4 +29,27 @@ public class CloneInfoVo implements Serializable { private boolean enableSmsTemplate; private String smsTemplate; + @NonNull + @Override + public String toString() { + return "CloneInfoVo{" + + "versionCode='" + versionCode + '\'' + + ", versionName='" + versionName + '\'' + + ", enableSms=" + enableSms + + ", enablePhone=" + enablePhone + + ", callType1=" + callType1 + + ", callType2=" + callType2 + + ", callType3=" + callType3 + + ", enableAppNotify=" + enableAppNotify + + ", cancelAppNotify=" + cancelAppNotify + + ", smsHubApiUrl=" + smsHubApiUrl + + ", batteryLevelAlarmMin=" + batteryLevelAlarmMin + + ", batteryLevelAlarmMax=" + batteryLevelAlarmMax + + ", batteryLevelAlarmOnce=" + batteryLevelAlarmOnce + + ", retryTimes=" + retryTimes + + ", delayTime=" + delayTime + + ", enableSmsTemplate=" + enableSmsTemplate + + ", smsTemplate=" + smsTemplate + + '}'; + } } diff --git a/app/src/main/java/com/idormy/sms/forwarder/receiver/BaseServlet.java b/app/src/main/java/com/idormy/sms/forwarder/receiver/BaseServlet.java index 477c1170..c863ec3d 100644 --- a/app/src/main/java/com/idormy/sms/forwarder/receiver/BaseServlet.java +++ b/app/src/main/java/com/idormy/sms/forwarder/receiver/BaseServlet.java @@ -48,6 +48,7 @@ public class BaseServlet extends HttpServlet { public BaseServlet(String path, Context context) { this.path = path; this.context = context; + SettingUtil.init(context); } private final String path; diff --git a/app/src/main/java/com/idormy/sms/forwarder/utils/ZipUtils.java b/app/src/main/java/com/idormy/sms/forwarder/utils/ZipUtils.java index 673accb0..f3d616f5 100644 --- a/app/src/main/java/com/idormy/sms/forwarder/utils/ZipUtils.java +++ b/app/src/main/java/com/idormy/sms/forwarder/utils/ZipUtils.java @@ -44,10 +44,10 @@ public class ZipUtils { File folder = new File(outPathString + File.separator + szName); folder.mkdirs(); } else { - Log.e(TAG, outPathString + File.separator + szName); + Log.d(TAG, outPathString + File.separator + szName); File file = new File(outPathString + File.separator + szName); if (!file.exists()) { - Log.e(TAG, "Create the file:" + outPathString + File.separator + szName); + Log.d(TAG, "Create the file:" + outPathString + File.separator + szName); Objects.requireNonNull(file.getParentFile()).mkdirs(); file.createNewFile(); } @@ -78,10 +78,10 @@ public class ZipUtils { File folder = new File(outPathString + File.separator + szName); folder.mkdirs(); } else { - Log.e(TAG, outPathString + File.separator + szName); + Log.d(TAG, outPathString + File.separator + szName); File file = new File(outPathString + File.separator + szName); if (!file.exists()) { - Log.e(TAG, "Create the file:" + outPathString + File.separator + szName); + Log.d(TAG, "Create the file:" + outPathString + File.separator + szName); Objects.requireNonNull(file.getParentFile()).mkdirs(); file.createNewFile(); } diff --git a/app/src/main/res/layout/activity_clone.xml b/app/src/main/res/layout/activity_clone.xml index 886de481..27a36145 100644 --- a/app/src/main/res/layout/activity_clone.xml +++ b/app/src/main/res/layout/activity_clone.xml @@ -1,5 +1,6 @@ + android:layout_marginTop="10dp" + android:text="@string/operating_instruction" + android:textSize="10sp" + tools:ignore="SmallSp" /> \ No newline at end of file diff --git a/app/src/main/res/values-en/strings.xml b/app/src/main/res/values-en/strings.xml index 01caad72..87d3cee4 100644 --- a/app/src/main/res/values-en/strings.xml +++ b/app/src/main/res/values-en/strings.xml @@ -382,4 +382,12 @@ [Note] The upper and lower limits of the battery warning threshold are 0, and the continuous warning does not work. Compatible solution Please wait 3 seconds after clicking start + One-click clone operation is complete! \nPlease check whether the general settings and switches are turned on! + Download complete, preparing to restore data… + Download failed: + Downloading + Please wait… + One-click clone failed: + The APP versions of the sender and the receiver are inconsistent, and cannot be cloned with one click! + Failed to get one-click clone information from sender diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6487d4ec..19b37ac8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -217,7 +217,7 @@ POST GET 本机IP: - 操作说明:\n【注意】发送方与接收方的APP版本号必须一致!\n1.新旧手机连接同一个WiFi网络(禁用AP隔离)\n2.旧手机直接点【发送】按钮,获取到【服务端IP】\n3.新手机填写【服务端IP】后,点【接收】按钮\n【注意】新手机接收后,发送通道、转发规则将完全被覆盖,清空历史记录! + 操作说明:\n1.新旧手机连接同一个WiFi网络(禁用AP隔离)\n2.旧手机直接点【发送】按钮,获取到【服务端IP】\n3.新手机填写【服务端IP】后,点【接收】按钮\n\n注意事项:\n1.发送方与接收方的APP版本号必须一致,才能克隆!\n2.新手机接收后,发送通道、转发规则将完全被覆盖,清空历史记录!\n3.主动请求、保活措施、个性设置不在克隆范围 启动 停止 我是旧手机 @@ -381,4 +381,12 @@ 【注意】电量预警阈值上下限都是0,持续提醒不起作用 兼容方案 点击启动后请等待3秒 + 一键克隆操作完成!\n请检查·通用设置·各项开关是否已开启! + 下载完成,正准备还原数据... + 下载失败: + 正在下载 + 请稍后... + 一键克隆失败: + 发送端与接收端的APP版本不一致,无法一键克隆! + 从发送端获取一键克隆信息失败