|
@@ -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)
|
|
|
|