Browse Source

提交人:jtm
提交内容:bug fixed

江天明 1 year ago
parent
commit
e515616a79

+ 113 - 40
BusinessCommon/src/main/java/com/develop/common/utils/AppVersionUtil.kt

@@ -7,14 +7,17 @@ import android.net.Uri
 import android.os.PowerManager
 import android.provider.Settings
 import androidx.core.content.ContextCompat.getSystemService
+import com.azhon.appupdate.listener.OnDownloadListener
 import com.azhon.appupdate.util.LogUtil
 import com.blankj.utilcode.util.FileUtils
 import com.blankj.utilcode.util.ZipUtils
 import com.develop.base.ext.fromJson
 import com.develop.base.ext.globalApp
 import com.develop.base.util.FileKit
+import com.develop.base.util.GlobalToast
 import com.develop.base.util.MMkvUtils
 import com.develop.base.util.TopResumedAtyHolder
+import com.develop.common.R
 import com.develop.common.data_repo.FoodDataProvider
 import com.develop.common.data_repo.db.entity.DevRecipeCategory
 import com.develop.common.data_repo.db.entity.DevVersion
@@ -23,6 +26,8 @@ import com.develop.common.data_repo.net.converter.SerializationConverter.Compani
 import com.develop.common.data_repo.net.model.request.DeviceInfoBody
 import com.develop.common.data_repo.net.model.response.DevInfoResult
 import com.develop.common.data_repo.net.model.response.RecipeDataConfig
+import com.develop.common.dialog.CancelConfirmDialog
+import com.develop.common.dialog.CommonDialog
 import com.develop.common.dialog.RecipeUpdateDialog
 import com.develop.common.tag.SCREENSAVER
 import com.drake.net.Get
@@ -48,49 +53,116 @@ object AppVersionUtil {
                     val result = Post<DevInfoResult>(Api.DEV_INFO) {
                         body = DeviceInfoBody.genDeviceInfoBody()
                     }.await()
-                    val downloadDir = this@apply.externalCacheDir.toString()
-                    val downloadName = System.nanoTime().toString()
-                    val recipeUpdateTime = result.recipeUpdateTime
-                    val newRecipes = LinkedList(result.newRecipes)
-                    if (newRecipes.isEmpty() && shoNoUpdateDialog) {
-                        val dialog = RecipeUpdateDialog()
-                        dialog.onDialogClickListener =
-                            object : RecipeUpdateDialog.OnDialogClickListener {
+                    if (result.apkUpdate) {
+                        val commonDialog = CommonDialog()
+                        commonDialog.msg = getString(com.develop.common.R.string.update_msg)
+                        commonDialog.title = getString(com.develop.common.R.string.update)
+                        commonDialog.hasOKBtn = false
+                        val cancelConfirmDialog = CancelConfirmDialog()
+                        cancelConfirmDialog.title =
+                            getString(com.develop.common.R.string.update_title)
+                        cancelConfirmDialog.showDialog(
+                            supportFragmentManager,
+                            "cancelConfirmDialog"
+                        )
+                        cancelConfirmDialog.onDialogClickListener =
+                            object : CancelConfirmDialog.OnDialogClickListener {
                                 override fun onConfirm() {
-
+                                    commonDialog.showDialog(supportFragmentManager, "commonDialog")
+                                    UpdateUtil.updateApp(
+                                        this@apply,
+                                        result.apkUrl,
+                                        object : OnDownloadListener {
+                                            override fun cancel() {
+                                                runOnUiThread {
+                                                    commonDialog.removeSelf()
+                                                }
+                                            }
+
+                                            override fun done(apk: File) {
+                                                GlobalToast.showToast(getString(R.string.finish_download))
+                                                UpdateUtil.installPackage(this@apply, apk)
+                                                commonDialog.updateProgress(getString(R.string.installing))
+                                            }
+
+                                            override fun downloading(max: Int, progress: Int) {
+                                                runOnUiThread {
+                                                    commonDialog.updateProgress(
+                                                        "${
+                                                            String.format(
+                                                                "%.0f",
+                                                                ((progress.toFloat() / max.toFloat()) * 100f)
+                                                            )
+                                                        }%"
+                                                    )
+                                                }
+                                            }
+
+                                            override fun error(e: Throwable) {
+                                                GlobalToast.showToast(getString(R.string.download_fail))
+                                                runOnUiThread {
+                                                    commonDialog.removeSelf()
+                                                }
+                                            }
+
+                                            override fun start() {
+//                                GlobalToast.showToast(getString(com.develop.common.R.string.start_download))
+                                            }
+
+                                        })
                                 }
 
                                 override fun onCancel() {
+
                                 }
                             }
-                        dialog.showNoUpdateTips(supportFragmentManager, "RECIPE_UPDATE_DIALOG")
-
-                    }
-                    if (newRecipes.isNotEmpty()) {
-                        val dialog = RecipeUpdateDialog()
-                        dialog.onDialogClickListener =
-                            object : RecipeUpdateDialog.OnDialogClickListener {
-                                override fun onConfirm() {
-                                    updateRecipe = !updateRecipe
-
-                                    EventBus.getDefault().post(NoScreenEvent(true))
-                                    downloadRecipes(
-                                        newRecipes,
-                                        dialog,
-                                        newRecipes.size.toLong(),
-                                        downloadDir,
-                                        downloadName,
-                                        recipeUpdateTime
-                                    )
+                    } else {
+                        val downloadDir = this@apply.externalCacheDir.toString()
+                        val downloadName = System.nanoTime().toString()
+                        val recipeUpdateTime = result.recipeUpdateTime
+                        val newRecipes = LinkedList(result.newRecipes)
+                        if (newRecipes.isEmpty() && shoNoUpdateDialog) {
+                            val dialog = RecipeUpdateDialog()
+                            dialog.onDialogClickListener =
+                                object : RecipeUpdateDialog.OnDialogClickListener {
+                                    override fun onConfirm() {
+
+                                    }
+
+                                    override fun onCancel() {
+                                    }
                                 }
+                            dialog.showNoUpdateTips(supportFragmentManager, "RECIPE_UPDATE_DIALOG")
 
-                                override fun onCancel() {
-                                }
+                        }
+                        if (newRecipes.isNotEmpty()) {
+                            val dialog = RecipeUpdateDialog()
+                            dialog.onDialogClickListener =
+                                object : RecipeUpdateDialog.OnDialogClickListener {
+                                    override fun onConfirm() {
+                                        updateRecipe = !updateRecipe
+
+                                        EventBus.getDefault().post(NoScreenEvent(true))
+                                        downloadRecipes(
+                                            newRecipes,
+                                            dialog,
+                                            newRecipes.size.toLong(),
+                                            downloadDir,
+                                            downloadName,
+                                            recipeUpdateTime
+                                        )
+                                    }
+
+                                    override fun onCancel() {
+                                    }
 
-                            }
-                        dialog.showUpdateTips(
-                            supportFragmentManager, "RECIPE_UPDATE_DIALOG", newRecipes.size.toLong()
-                        )
+                                }
+                            dialog.showUpdateTips(
+                                supportFragmentManager,
+                                "RECIPE_UPDATE_DIALOG",
+                                newRecipes.size.toLong()
+                            )
+                        }
                     }
                 } catch (e: java.lang.Exception) {
                     e.printStackTrace()
@@ -115,7 +187,7 @@ object AppVersionUtil {
     ) {
 
         //取消标识退出
-        if(!updateRecipe){
+        if (!updateRecipe) {
             return
         }
 
@@ -126,7 +198,7 @@ object AppVersionUtil {
             "tag"
         );
         mWakeLock?.setReferenceCounted(false);
-        mWakeLock?.acquire(10*60*1000L /*10 minutes*/)
+        mWakeLock?.acquire(10 * 60 * 1000L /*10 minutes*/)
 
         TopResumedAtyHolder.getCurrentActivity()?.apply {
             if (newRecipes.isEmpty()) {
@@ -207,14 +279,15 @@ object AppVersionUtil {
                     insertDevRecipeAccessorys(contentData.devRecipeAccessorys)
 
                     val categorys = queryAllCategory()
-                    val categoryMap = HashMap<String,DevRecipeCategory>()
+                    val categoryMap = HashMap<String, DevRecipeCategory>()
                     for (category in categorys) {
                         categoryMap[category.number + ":" + category.lang] = category
                     }
                     for (devRecipeCategory in contentData.devRecipeCategorys) {
-                          if(categoryMap.containsKey(devRecipeCategory.number + ":" + devRecipeCategory.lang)){
-                              devRecipeCategory.code = categoryMap[devRecipeCategory.number + ":" + devRecipeCategory.lang]?.code.toString()
-                          }
+                        if (categoryMap.containsKey(devRecipeCategory.number + ":" + devRecipeCategory.lang)) {
+                            devRecipeCategory.code =
+                                categoryMap[devRecipeCategory.number + ":" + devRecipeCategory.lang]?.code.toString()
+                        }
                     }
                     insertDevRecipeCategorys(contentData.devRecipeCategorys)
 

+ 0 - 2
BusinessMain/src/main/res/layout/item_filter_and_sort_view.xml

@@ -11,7 +11,6 @@
         android:layout_height="@dimen/convert_21px"
         android:layout_alignParentEnd="true"
         android:layout_centerVertical="true"
-        android:layout_marginEnd="@dimen/convert_39px"
         android:background="@drawable/ic_check" />
 
     <androidx.appcompat.widget.AppCompatTextView
@@ -21,7 +20,6 @@
         android:layout_centerVertical="true"
         android:layout_marginStart="@dimen/convert_29px"
         android:textColor="@color/sort_filter_name"
-        android:layout_marginEnd="@dimen/convert_40px"
         android:layout_toStartOf="@id/iv_check"
         android:gravity="center_vertical"
         android:textSize="@dimen/convert_30px" />