|
@@ -6,6 +6,7 @@ import android.content.pm.PackageInfo;
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
|
|
import android.os.Bundle;
|
|
|
+import android.util.Log;
|
|
|
import android.view.View;
|
|
|
import android.widget.EditText;
|
|
|
import android.widget.ImageView;
|
|
@@ -31,10 +32,14 @@ import com.hw.nativeapp.utils.RxUtil;
|
|
|
import com.hw.nativeapp.utils.sunmi.SunmiPrintHelper;
|
|
|
|
|
|
import java.io.File;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
|
|
|
import butterknife.BindView;
|
|
|
import butterknife.ButterKnife;
|
|
|
import butterknife.OnClick;
|
|
|
+import cn.yhq.dialog.core.DialogBuilder;
|
|
|
+import cn.yhq.dialog.core.IDialog;
|
|
|
|
|
|
/**
|
|
|
* 设置页面
|
|
@@ -133,44 +138,70 @@ private static final String TAG = "SettingActivity";
|
|
|
|
|
|
|
|
|
private void showUpdate(UpdateVerAskBean bean,PackageInfo packageInfo){
|
|
|
- String note = "当前版本:" + packageInfo.versionName + "." + packageInfo.versionCode + "\n" +
|
|
|
- "新版本:" + bean.versionName + "." + bean.versionCode + "\n" +
|
|
|
+ String note = "版本:" + packageInfo.versionName + "." + packageInfo.versionCode + "->" +
|
|
|
+ bean.versionName + "." + bean.versionCode + "\n" +
|
|
|
"版本描述:" + bean.note;
|
|
|
- dialogUpdate = new Dialog_Update(note,this);
|
|
|
- dialogUpdate.show();
|
|
|
- dialogUpdate.setOnDialogListener(new Dialog_Update.OnDialogListener() {
|
|
|
- @Override
|
|
|
- public void update() {
|
|
|
- startDownload(bean.downloadUrl);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void cancel() {
|
|
|
- }
|
|
|
- });
|
|
|
+
|
|
|
+ DialogBuilder.alertDialog(this).setMessage(note)
|
|
|
+ .setOnPositiveButtonClickListener((dialog, which) ->
|
|
|
+ startDownload(bean.downloadUrl,bean.fileSize))
|
|
|
+ .create().show();
|
|
|
}
|
|
|
|
|
|
- private void startDownload(String downUrl){
|
|
|
- dialogUpdateProgress = new Dialog_UpdateProgress(this, new Dialog_UpdateProgress.OnDialogListener() {
|
|
|
- @Override
|
|
|
- public void opend() {
|
|
|
- UpdateHandler updateHandler = new UpdateHandler(SettingActivity.this,downUrl);
|
|
|
- updateHandler.setOnListener(new UpdateHandler.OnDownloadListener() {
|
|
|
+ private void startDownload(String downUrl, Integer fileSize){
|
|
|
+
|
|
|
+ DialogBuilder.ProgressHandler progressHandler =
|
|
|
+ new DialogBuilder.ProgressHandler();
|
|
|
+
|
|
|
+ IDialog dialogBuilder = DialogBuilder.progressDialog(this).progressHandler(progressHandler).show();
|
|
|
+
|
|
|
+ UpdateHandler updateHandler = new UpdateHandler(SettingActivity.this,downUrl);
|
|
|
+ updateHandler.setOnListener(new UpdateHandler.OnDownloadListener() {
|
|
|
@Override
|
|
|
public void complate() {
|
|
|
- dialogUpdateProgress.dismiss();
|
|
|
+// progressHandler.();
|
|
|
+ dialogBuilder.dismiss();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void progress(int soFarBytes, int totalBytes) {
|
|
|
- dialogUpdateProgress.setTxProgress(soFarBytes, totalBytes);
|
|
|
- dialogUpdateProgress.setProgressBar(soFarBytes, totalBytes);
|
|
|
+ if (totalBytes <= 0){
|
|
|
+ totalBytes = fileSize;
|
|
|
+ }
|
|
|
+ BigDecimal a = BigDecimal.valueOf(soFarBytes);
|
|
|
+ BigDecimal b = BigDecimal.valueOf(totalBytes);
|
|
|
+
|
|
|
+ int pprogress = a.divide(b,2,BigDecimal.ROUND_HALF_UP)
|
|
|
+ .multiply(BigDecimal.valueOf(100))
|
|
|
+ .intValue();
|
|
|
+// Log.d("aleyds", "soFarBytes:" + soFarBytes + ":: totalBytes:" + totalBytes + " -> "+ pprogress);
|
|
|
+ progressHandler.setProgress(pprogress);
|
|
|
}
|
|
|
});
|
|
|
updateHandler.start();
|
|
|
- }
|
|
|
- });
|
|
|
- dialogUpdateProgress.show();
|
|
|
+
|
|
|
+ // 更新进度
|
|
|
+
|
|
|
+// dialogUpdateProgress = new Dialog_UpdateProgress(this, new Dialog_UpdateProgress.OnDialogListener() {
|
|
|
+// @Override
|
|
|
+// public void opend() {
|
|
|
+// UpdateHandler updateHandler = new UpdateHandler(SettingActivity.this,downUrl);
|
|
|
+// updateHandler.setOnListener(new UpdateHandler.OnDownloadListener() {
|
|
|
+// @Override
|
|
|
+// public void complate() {
|
|
|
+// dialogUpdateProgress.dismiss();
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public void progress(int soFarBytes, int totalBytes) {
|
|
|
+// dialogUpdateProgress.setTxProgress(soFarBytes, totalBytes);
|
|
|
+// dialogUpdateProgress.setProgressBar(soFarBytes, totalBytes);
|
|
|
+// }
|
|
|
+// });
|
|
|
+// updateHandler.start();
|
|
|
+// }
|
|
|
+// });
|
|
|
+// dialogUpdateProgress.show();
|
|
|
}
|
|
|
|
|
|
}
|