aleyds 1 year ago
parent
commit
4bdd9c255b

+ 2 - 1
app/build.gradle

@@ -46,7 +46,7 @@ android {
             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
             buildConfigField "String", "API_HOST", rootProject.ext.debug.apiHost
             buildConfigField "String", "API_PATH", rootProject.ext.debug.apiName
-            buildConfigField "String", "prjectName", rootProject.ext.release.prjectName
+            buildConfigField "String", "prjectName", rootProject.ext.debug.prjectName
             buildConfigField "String", "FILEAPI_HOST", rootProject.ext.debug.fileApiHost
             buildConfigField "String", "FILEAPI_PATH", rootProject.ext.debug.fileApiName
         }
@@ -129,6 +129,7 @@ dependencies {
 
     implementation 'com.sunmi:sunmiui:1.1.27'
     implementation 'com.sunmi:printerlibrary:1.0.18'
+    implementation 'cn.yhq:android-dialog:1.6.0'
 }
 
 // SH1: 84:DD:2A:D6:4A:63:12:6B:06:9F:24:38:1F:57:32:8F:4D:5F:EE:78

+ 24 - 2
app/src/main/AndroidManifest.xml

@@ -115,11 +115,11 @@
 
         <activity android:name="com.hw.nativeapp.ui.activity.SettingActivity"
             android:configChanges="orientation|screenSize"
-            android:theme="@style/ThemeNoTitleBar" />
+            android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
 
         <provider
             android:name="androidx.core.content.FileProvider"
-            android:authorities="com.hw.airportwine.provider"
+            android:authorities="com.hw.great.provider"
             android:exported="false"
             android:grantUriPermissions="true"
             tools:replace="android:authorities,android:exported">
@@ -128,6 +128,28 @@
                 android:resource="@xml/file_paths" />
         </provider>
 
+<!--        <provider-->
+<!--            android:name="androidx.core.content.FileProvider"-->
+<!--            android:authorities="${applicationId}.fileprovider"-->
+<!--            android:exported="false"-->
+<!--            android:grantUriPermissions="true"-->
+<!--            tools:replace="android:authorities,android:exported">-->
+<!--            <meta-data-->
+<!--                android:name="android.support.FILE_PROVIDER_PATHS"-->
+<!--                android:resource="@xml/file_paths" />-->
+<!--        </provider>-->
+
+<!--        <provider-->
+<!--        android:name="androidx.core.content.FileProvider"-->
+<!--        android:authorities="${applicationId}.fileprovider"-->
+<!--        android:exported="false"-->
+<!--        android:grantUriPermissions="true"-->
+<!--        tools:replace="android:authorities,android:exported">-->
+<!--        <meta-data-->
+<!--            android:name="android.support.FILE_PROVIDER_PATHS"-->
+<!--            android:resource="@xml/file_paths" />-->
+<!--    </provider>-->
+
         <activity android:name=".ui.activity.ScanQRCodeActivity"
             android:screenOrientation="fullSensor"
             tools:replace="screenOrientation"/>

+ 1 - 0
app/src/main/java/com/hw/nativeapp/httpnet/entity/UpdateVerAskBean.java

@@ -7,6 +7,7 @@ public class UpdateVerAskBean {
     public String  versionName;
     public String  note;
     public String  downloadUrl;
+    public Integer fileSize;
 
 
 }

+ 57 - 26
app/src/main/java/com/hw/nativeapp/ui/activity/SettingActivity.java

@@ -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();
     }
 
 }

+ 1 - 1
app/src/main/java/com/hw/nativeapp/update/UpdateHandler.java

@@ -118,7 +118,7 @@ public class UpdateHandler {
             intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
             Uri contentUri = FileProvider.getUriForFile(
                     this.context
-                    , "com.hw.parkingpda.fileprovider"
+                    , "com.hw.great.provider"
                     , apkFile);
             intent.setDataAndType(contentUri, "application/vnd.android.package-archive");
         } else {