|
@@ -1,11 +1,17 @@
|
|
|
package com.develop.common.utils
|
|
|
|
|
|
+import android.annotation.SuppressLint
|
|
|
+import android.app.Application
|
|
|
+import android.content.Context
|
|
|
import android.net.Uri
|
|
|
+import android.os.PowerManager
|
|
|
import android.provider.Settings
|
|
|
+import androidx.core.content.ContextCompat.getSystemService
|
|
|
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.MMkvUtils
|
|
|
import com.develop.base.util.TopResumedAtyHolder
|
|
@@ -60,6 +66,8 @@ object AppVersionUtil {
|
|
|
dialog.onDialogClickListener =
|
|
|
object : RecipeUpdateDialog.OnDialogClickListener {
|
|
|
override fun onConfirm() {
|
|
|
+ updateRecipe = !updateRecipe
|
|
|
+
|
|
|
EventBus.getDefault().post(NoScreenEvent(true))
|
|
|
downloadRecipes(
|
|
|
newRecipes,
|
|
@@ -89,6 +97,9 @@ object AppVersionUtil {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ var updateRecipe = false
|
|
|
+
|
|
|
+ @SuppressLint("InvalidWakeLockTag")
|
|
|
private fun downloadRecipes(
|
|
|
newRecipes: LinkedList<String>,
|
|
|
recipeUpdateDialog: RecipeUpdateDialog,
|
|
@@ -97,12 +108,28 @@ object AppVersionUtil {
|
|
|
downloadName: String,
|
|
|
recipeUpdateTime: Long?
|
|
|
) {
|
|
|
+
|
|
|
+ //取消标识退出
|
|
|
+ if(!updateRecipe){
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //升级休眠
|
|
|
+ val pm = globalApp().getSystemService(Application.POWER_SERVICE) as PowerManager
|
|
|
+ val mWakeLock = pm.newWakeLock(
|
|
|
+ PowerManager.SCREEN_BRIGHT_WAKE_LOCK or PowerManager.ON_AFTER_RELEASE or PowerManager.ACQUIRE_CAUSES_WAKEUP,
|
|
|
+ "tag"
|
|
|
+ );
|
|
|
+ mWakeLock?.setReferenceCounted(false);
|
|
|
+ mWakeLock?.acquire(10*60*1000L /*10 minutes*/)
|
|
|
+
|
|
|
TopResumedAtyHolder.getCurrentActivity()?.apply {
|
|
|
if (newRecipes.isEmpty()) {
|
|
|
recipeUpdateDialog.removeSelf()
|
|
|
showRecipesUpdateDialog(recipeUpdateTime)
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
val recipeUrl = newRecipes.pop()
|
|
|
val recipeNumber = recipeUrl.split("@")[0]
|
|
|
val fileUrl = recipeUrl.split("@")[1]
|
|
@@ -138,7 +165,9 @@ object AppVersionUtil {
|
|
|
)
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
+ mWakeLock.release()
|
|
|
}
|
|
|
|
|
|
private fun prepareResource(file: File, recipeNumber: String) {
|