|
@@ -2,13 +2,16 @@ package com.develop.common.utils
|
|
|
|
|
|
import android.annotation.SuppressLint
|
|
import android.annotation.SuppressLint
|
|
import android.app.Application
|
|
import android.app.Application
|
|
|
|
+import android.content.Context
|
|
import android.net.Uri
|
|
import android.net.Uri
|
|
import android.os.PowerManager
|
|
import android.os.PowerManager
|
|
import android.provider.Settings
|
|
import android.provider.Settings
|
|
|
|
+import androidx.core.content.ContextCompat.getSystemService
|
|
import com.azhon.appupdate.listener.OnDownloadListener
|
|
import com.azhon.appupdate.listener.OnDownloadListener
|
|
import com.azhon.appupdate.util.LogUtil
|
|
import com.azhon.appupdate.util.LogUtil
|
|
import com.blankj.utilcode.util.FileUtils
|
|
import com.blankj.utilcode.util.FileUtils
|
|
import com.blankj.utilcode.util.ZipUtils
|
|
import com.blankj.utilcode.util.ZipUtils
|
|
|
|
+import com.develop.base.ext.fromJson
|
|
import com.develop.base.ext.globalApp
|
|
import com.develop.base.ext.globalApp
|
|
import com.develop.base.util.FileKit
|
|
import com.develop.base.util.FileKit
|
|
import com.develop.base.util.GlobalToast
|
|
import com.develop.base.util.GlobalToast
|
|
@@ -26,7 +29,6 @@ import com.develop.common.data_repo.net.model.response.RecipeDataConfig
|
|
import com.develop.common.dialog.CancelConfirmDialog
|
|
import com.develop.common.dialog.CancelConfirmDialog
|
|
import com.develop.common.dialog.CommonDialog
|
|
import com.develop.common.dialog.CommonDialog
|
|
import com.develop.common.dialog.RecipeUpdateDialog
|
|
import com.develop.common.dialog.RecipeUpdateDialog
|
|
-import com.develop.common.event.RefreshDataEvent
|
|
|
|
import com.develop.common.tag.SCREENSAVER
|
|
import com.develop.common.tag.SCREENSAVER
|
|
import com.drake.net.Get
|
|
import com.drake.net.Get
|
|
import com.drake.net.Post
|
|
import com.drake.net.Post
|
|
@@ -60,13 +62,15 @@ object AppVersionUtil {
|
|
cancelConfirmDialog.title =
|
|
cancelConfirmDialog.title =
|
|
getString(com.develop.common.R.string.update_title)
|
|
getString(com.develop.common.R.string.update_title)
|
|
cancelConfirmDialog.showDialog(
|
|
cancelConfirmDialog.showDialog(
|
|
- supportFragmentManager, "cancelConfirmDialog"
|
|
|
|
|
|
+ supportFragmentManager,
|
|
|
|
+ "cancelConfirmDialog"
|
|
)
|
|
)
|
|
cancelConfirmDialog.onDialogClickListener =
|
|
cancelConfirmDialog.onDialogClickListener =
|
|
object : CancelConfirmDialog.OnDialogClickListener {
|
|
object : CancelConfirmDialog.OnDialogClickListener {
|
|
override fun onConfirm() {
|
|
override fun onConfirm() {
|
|
commonDialog.showDialog(supportFragmentManager, "commonDialog")
|
|
commonDialog.showDialog(supportFragmentManager, "commonDialog")
|
|
- UpdateUtil.updateApp(this@apply,
|
|
|
|
|
|
+ UpdateUtil.updateApp(
|
|
|
|
+ this@apply,
|
|
result.apkUrl,
|
|
result.apkUrl,
|
|
object : OnDownloadListener {
|
|
object : OnDownloadListener {
|
|
override fun cancel() {
|
|
override fun cancel() {
|
|
@@ -198,27 +202,8 @@ object AppVersionUtil {
|
|
|
|
|
|
TopResumedAtyHolder.getCurrentActivity()?.apply {
|
|
TopResumedAtyHolder.getCurrentActivity()?.apply {
|
|
if (newRecipes.isEmpty()) {
|
|
if (newRecipes.isEmpty()) {
|
|
- saveRecipeUpdateTime(recipeUpdateTime)
|
|
|
|
- scopeNetLife {
|
|
|
|
- //判断是否还有新菜谱
|
|
|
|
- val result = Post<DevInfoResult>(Api.DEV_INFO) {
|
|
|
|
- body = DeviceInfoBody.genDeviceInfoBody()
|
|
|
|
- }.await()
|
|
|
|
-
|
|
|
|
- val ut = result.recipeUpdateTime
|
|
|
|
- val nr = LinkedList(result.newRecipes)
|
|
|
|
- if (!nr.isEmpty()) {
|
|
|
|
- downloadRecipes(nr,recipeUpdateDialog,
|
|
|
|
- nr.size.toLong(),downloadDir,downloadName,ut)
|
|
|
|
- return@scopeNetLife
|
|
|
|
- }else{
|
|
|
|
- recipeUpdateDialog.removeSelf()
|
|
|
|
- showRecipesUpdateDialog(recipeUpdateTime)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+ recipeUpdateDialog.removeSelf()
|
|
|
|
+ showRecipesUpdateDialog(recipeUpdateTime)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
@@ -276,7 +261,7 @@ object AppVersionUtil {
|
|
}
|
|
}
|
|
val jsonContent = FileKit.readFileToStringB(jsonFile)
|
|
val jsonContent = FileKit.readFileToStringB(jsonFile)
|
|
val contentData = jsonDecoder.decodeFromString<RecipeDataConfig>(jsonContent)
|
|
val contentData = jsonDecoder.decodeFromString<RecipeDataConfig>(jsonContent)
|
|
- // contentData.resetAllCodes()
|
|
|
|
|
|
+ contentData.resetAllCodes()
|
|
FoodDataProvider.getDatabase().runInTransaction {
|
|
FoodDataProvider.getDatabase().runInTransaction {
|
|
FoodDataProvider.getDatabase().recipeDao().apply {
|
|
FoodDataProvider.getDatabase().recipeDao().apply {
|
|
|
|
|
|
@@ -322,29 +307,27 @@ object AppVersionUtil {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- private fun saveRecipeUpdateTime(recipeUpdateTime: Long?) {
|
|
|
|
- val v =
|
|
|
|
- FoodDataProvider.getUserDatabase().devConfigDao().recipeVersion() ?: DevVersion(0, 0)
|
|
|
|
- v.recipeUpdateTime = recipeUpdateTime
|
|
|
|
- FoodDataProvider.getUserDatabase().devConfigDao().saveDevVersion(v)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
private fun showRecipesUpdateDialog(recipeUpdateTime: Long?) {
|
|
private fun showRecipesUpdateDialog(recipeUpdateTime: Long?) {
|
|
TopResumedAtyHolder.getCurrentActivity()?.apply {
|
|
TopResumedAtyHolder.getCurrentActivity()?.apply {
|
|
val minute = MMkvUtils.getInt(SCREENSAVER)
|
|
val minute = MMkvUtils.getInt(SCREENSAVER)
|
|
if (minute != 0) {
|
|
if (minute != 0) {
|
|
Settings.System.putInt(
|
|
Settings.System.putInt(
|
|
- contentResolver, Settings.System.SCREEN_OFF_TIMEOUT, 1000 * 60 * minute
|
|
|
|
|
|
+ contentResolver,
|
|
|
|
+ Settings.System.SCREEN_OFF_TIMEOUT,
|
|
|
|
+ 1000 * 60 * minute
|
|
)
|
|
)
|
|
- val uri: Uri = Settings.System.getUriFor(Settings.System.SCREEN_OFF_TIMEOUT)
|
|
|
|
|
|
+ val uri: Uri = Settings.System
|
|
|
|
+ .getUriFor(Settings.System.SCREEN_OFF_TIMEOUT)
|
|
contentResolver.notifyChange(uri, null)
|
|
contentResolver.notifyChange(uri, null)
|
|
}
|
|
}
|
|
EventBus.getDefault().post(NoScreenEvent(false))
|
|
EventBus.getDefault().post(NoScreenEvent(false))
|
|
- EventBus.getDefault().post(RefreshDataEvent())
|
|
|
|
RecipeUpdateDialog().apply {
|
|
RecipeUpdateDialog().apply {
|
|
onDialogClickListener = object : RecipeUpdateDialog.OnDialogClickListener {
|
|
onDialogClickListener = object : RecipeUpdateDialog.OnDialogClickListener {
|
|
override fun onConfirm() {
|
|
override fun onConfirm() {
|
|
- saveRecipeUpdateTime(recipeUpdateTime)
|
|
|
|
|
|
+ val v = FoodDataProvider.getUserDatabase().devConfigDao().recipeVersion()
|
|
|
|
+ ?: DevVersion(0, 0)
|
|
|
|
+ v.recipeUpdateTime = recipeUpdateTime
|
|
|
|
+ FoodDataProvider.getUserDatabase().devConfigDao().saveDevVersion(v)
|
|
removeSelf()
|
|
removeSelf()
|
|
}
|
|
}
|
|
|
|
|