|
@@ -6,9 +6,11 @@ import android.os.PowerManager
|
|
|
import android.view.LayoutInflater
|
|
|
import com.alibaba.android.arouter.facade.annotation.Route
|
|
|
import com.develop.food.base.manager.wifi.WifiHelp
|
|
|
+import com.develop.food.base.repo.CURRENT_USER_ID
|
|
|
import com.develop.food.base.repo.FoodDataProvider
|
|
|
import com.develop.food.base.router.Screens
|
|
|
import com.develop.food.base.ui.BaseActivity
|
|
|
+import com.develop.food.base.utils.ThreadUtils
|
|
|
import com.develop.food.base.widgets.CancelConfirmDialog
|
|
|
import com.develop.setting.R
|
|
|
import com.develop.setting.databinding.ActivityRestoreBinding
|
|
@@ -34,25 +36,33 @@ class RestoreActivity : BaseActivity<ActivityRestoreBinding>() {
|
|
|
|
|
|
dailog.onDialogClickListener = object:CancelConfirmDialog.OnDialogClickListener {
|
|
|
override fun onConfirm() {
|
|
|
- FoodDataProvider.deleteAll()
|
|
|
- WifiHelp.Build(this@RestoreActivity).build().removeAllWifi()
|
|
|
- var cacheDirectory = getCacheDir();
|
|
|
- var applicationDirectory = File(cacheDirectory.getParent());
|
|
|
- if (applicationDirectory.exists()) {
|
|
|
-
|
|
|
- var files = applicationDirectory.listFiles();
|
|
|
-
|
|
|
- for (file in files) {
|
|
|
-
|
|
|
- if (!file.name.equals("lib")) {
|
|
|
- com.blankj.utilcode.util.FileUtils.delete(file)
|
|
|
+ ThreadUtils.runOnWorkThread({
|
|
|
+ FoodDataProvider.deleteAll()
|
|
|
+ val cacheDirectory = cacheDir
|
|
|
+ WifiHelp.Build(this@RestoreActivity).build().removeAllWifi()
|
|
|
+ FoodDataProvider.getUserDatabase().userInfoDao().apply {
|
|
|
+ removeAllOnlineRecipe(CURRENT_USER_ID)
|
|
|
+ removeAllFavouriteRecipe(CURRENT_USER_ID)
|
|
|
+ removeAllHistoryRecipe(CURRENT_USER_ID)
|
|
|
+ }
|
|
|
+ FoodDataProvider.getUserDatabase().devConfigDao().apply {
|
|
|
+ removeAllDevVersion()
|
|
|
+ }
|
|
|
+ val applicationDirectory = cacheDirectory.parent?.let { File(it) }
|
|
|
+ if (applicationDirectory?.exists() == true) {
|
|
|
+
|
|
|
+ val files = applicationDirectory.listFiles() ?: emptyArray()
|
|
|
+ for (file in files) {
|
|
|
+ if (!file.name.equals("lib")) {
|
|
|
+ com.blankj.utilcode.util.FileUtils.delete(file)
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
- }
|
|
|
- val pm = getSystemService(Context.POWER_SERVICE) as PowerManager
|
|
|
- pm.reboot("")
|
|
|
+ runOnUiThread {
|
|
|
+ val pm = getSystemService(Context.POWER_SERVICE) as PowerManager
|
|
|
+ pm.reboot("")
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
override fun onCancel() {
|