From 81e4d2acfbcea4d3041e4a1c03e404b838d084cc Mon Sep 17 00:00:00 2001 From: gedoor Date: Thu, 25 Feb 2021 10:38:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/help/ThemeConfig.kt | 6 ++---- .../io/legado/app/help/storage/Restore.kt | 21 ++++++++++++------- .../java/io/legado/app/utils/LanguageUtils.kt | 1 - 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/ThemeConfig.kt b/app/src/main/java/io/legado/app/help/ThemeConfig.kt index b7ecd3f03..409b5be24 100644 --- a/app/src/main/java/io/legado/app/help/ThemeConfig.kt +++ b/app/src/main/java/io/legado/app/help/ThemeConfig.kt @@ -52,10 +52,8 @@ object ThemeConfig { } fun upConfig() { - getConfigs()?.let { - it.forEach { config -> - addConfig(config) - } + getConfigs()?.forEach { config -> + addConfig(config) } } diff --git a/app/src/main/java/io/legado/app/help/storage/Restore.kt b/app/src/main/java/io/legado/app/help/storage/Restore.kt index 39ab91ba0..9cf94102b 100644 --- a/app/src/main/java/io/legado/app/help/storage/Restore.kt +++ b/app/src/main/java/io/legado/app/help/storage/Restore.kt @@ -1,5 +1,7 @@ package io.legado.app.help.storage +import android.app.AlarmManager +import android.app.PendingIntent import android.content.Context import android.net.Uri import androidx.documentfile.provider.DocumentFile @@ -9,7 +11,6 @@ import com.jayway.jsonpath.Option import com.jayway.jsonpath.ParseContext import io.legado.app.BuildConfig import io.legado.app.R -import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey import io.legado.app.constant.androidId import io.legado.app.data.appDb @@ -18,14 +19,16 @@ import io.legado.app.help.DefaultData import io.legado.app.help.LauncherIconHelp import io.legado.app.help.ReadBookConfig import io.legado.app.help.ThemeConfig -import io.legado.app.service.help.ReadBook -import io.legado.app.ui.book.read.page.provider.ChapterProvider import io.legado.app.utils.* import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.Main +import kotlinx.coroutines.delay import kotlinx.coroutines.withContext import splitties.init.appCtx +import splitties.systemservices.alarmManager import java.io.File +import kotlin.system.exitProcess + object Restore { private val ignoreConfigPath = FileUtils.getPath(appCtx.filesDir, "restoreIgnore.json") @@ -220,17 +223,19 @@ object Restore { hideNavigationBar = appCtx.getPrefBoolean(PreferKey.hideNavigationBar) autoReadSpeed = appCtx.getPrefInt(PreferKey.autoReadSpeed, 46) } - ChapterProvider.upStyle() - ReadBook.loadContent(resetPageOffset = false) } withContext(Main) { appCtx.toastOnUi(R.string.restore_success) + delay(100) if (!BuildConfig.DEBUG) { LauncherIconHelp.changeIcon(appCtx.getPrefString(PreferKey.launcherIcon)) } - LanguageUtils.setConfiguration(appCtx) - ThemeConfig.applyDayNight(appCtx) - postEvent(EventBus.SHOW_RSS, "") + appCtx.packageManager.getLaunchIntentForPackage(appCtx.packageName)?.let { intent -> + val restartIntent = + PendingIntent.getActivity(appCtx, 0, intent, PendingIntent.FLAG_ONE_SHOT) + alarmManager[AlarmManager.RTC, System.currentTimeMillis() + 300] = restartIntent + exitProcess(0) + } } } diff --git a/app/src/main/java/io/legado/app/utils/LanguageUtils.kt b/app/src/main/java/io/legado/app/utils/LanguageUtils.kt index 7a8572ded..0eed85d6f 100644 --- a/app/src/main/java/io/legado/app/utils/LanguageUtils.kt +++ b/app/src/main/java/io/legado/app/utils/LanguageUtils.kt @@ -19,7 +19,6 @@ object LanguageUtils { val resources: Resources = context.resources val metrics = resources.displayMetrics val configuration: Configuration = resources.configuration - //Log.d("h11128", "set language to ${context.getPrefString(PreferKey.language)}") val targetLocale = getSetLocale(context) configuration.setLocale(targetLocale) configuration.setLocales(LocaleList(targetLocale))