优化
This commit is contained in:
@@ -31,6 +31,7 @@ import io.legado.app.help.source.SourceHelp
|
|||||||
import io.legado.app.help.storage.Backup
|
import io.legado.app.help.storage.Backup
|
||||||
import io.legado.app.model.BookCover
|
import io.legado.app.model.BookCover
|
||||||
import io.legado.app.utils.ChineseUtils
|
import io.legado.app.utils.ChineseUtils
|
||||||
|
import io.legado.app.utils.LogUtils
|
||||||
import io.legado.app.utils.defaultSharedPreferences
|
import io.legado.app.utils.defaultSharedPreferences
|
||||||
import io.legado.app.utils.getPrefBoolean
|
import io.legado.app.utils.getPrefBoolean
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@@ -45,6 +46,7 @@ class App : Application() {
|
|||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
|
LogUtils.d("App", "onCreate")
|
||||||
oldConfig = Configuration(resources.configuration)
|
oldConfig = Configuration(resources.configuration)
|
||||||
CrashHandler(this)
|
CrashHandler(this)
|
||||||
//预下载Cronet so
|
//预下载Cronet so
|
||||||
@@ -53,6 +55,7 @@ class App : Application() {
|
|||||||
LiveEventBus.config()
|
LiveEventBus.config()
|
||||||
.lifecycleObserverAlwaysActive(true)
|
.lifecycleObserverAlwaysActive(true)
|
||||||
.autoClear(false)
|
.autoClear(false)
|
||||||
|
.enableLogger(BuildConfig.DEBUG || AppConfig.recordLog)
|
||||||
applyDayNight(this)
|
applyDayNight(this)
|
||||||
registerActivityLifecycleCallbacks(LifecycleHelp)
|
registerActivityLifecycleCallbacks(LifecycleHelp)
|
||||||
defaultSharedPreferences.registerOnSharedPreferenceChangeListener(AppConfig)
|
defaultSharedPreferences.registerOnSharedPreferenceChangeListener(AppConfig)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import android.app.Activity
|
|||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import io.legado.app.base.BaseService
|
import io.legado.app.base.BaseService
|
||||||
|
import io.legado.app.utils.LogUtils
|
||||||
import java.lang.ref.WeakReference
|
import java.lang.ref.WeakReference
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -12,6 +13,8 @@ import java.lang.ref.WeakReference
|
|||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
object LifecycleHelp : Application.ActivityLifecycleCallbacks {
|
object LifecycleHelp : Application.ActivityLifecycleCallbacks {
|
||||||
|
|
||||||
|
private const val TAG = "LifecycleHelp"
|
||||||
|
|
||||||
private val activities: MutableList<WeakReference<Activity>> = arrayListOf()
|
private val activities: MutableList<WeakReference<Activity>> = arrayListOf()
|
||||||
private val services: MutableList<WeakReference<BaseService>> = arrayListOf()
|
private val services: MutableList<WeakReference<BaseService>> = arrayListOf()
|
||||||
private var appFinishedListener: (() -> Unit)? = null
|
private var appFinishedListener: (() -> Unit)? = null
|
||||||
@@ -55,16 +58,19 @@ object LifecycleHelp : Application.ActivityLifecycleCallbacks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onActivityPaused(activity: Activity) {
|
override fun onActivityPaused(activity: Activity) {
|
||||||
|
LogUtils.d(TAG, "${activity::class.simpleName} onPause")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onActivityResumed(activity: Activity) {
|
override fun onActivityResumed(activity: Activity) {
|
||||||
|
LogUtils.d(TAG, "${activity::class.simpleName} onResume")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onActivityStarted(activity: Activity) {
|
override fun onActivityStarted(activity: Activity) {
|
||||||
|
LogUtils.d(TAG, "${activity::class.simpleName} onStart")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onActivityDestroyed(activity: Activity) {
|
override fun onActivityDestroyed(activity: Activity) {
|
||||||
|
LogUtils.d(TAG, "${activity::class.simpleName} onDestroy")
|
||||||
for (temp in activities) {
|
for (temp in activities) {
|
||||||
if (temp.get() != null && temp.get() === activity) {
|
if (temp.get() != null && temp.get() === activity) {
|
||||||
activities.remove(temp)
|
activities.remove(temp)
|
||||||
@@ -77,22 +83,27 @@ object LifecycleHelp : Application.ActivityLifecycleCallbacks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {
|
override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {
|
||||||
|
LogUtils.d(TAG, "${activity::class.simpleName} onSaveInstanceState")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onActivityStopped(activity: Activity) {
|
override fun onActivityStopped(activity: Activity) {
|
||||||
|
LogUtils.d(TAG, "${activity::class.simpleName} onStop")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
|
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
|
||||||
|
LogUtils.d(TAG, "${activity::class.simpleName} onCreate")
|
||||||
activities.add(WeakReference(activity))
|
activities.add(WeakReference(activity))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
fun onServiceCreate(service: BaseService) {
|
fun onServiceCreate(service: BaseService) {
|
||||||
|
LogUtils.d(TAG, "${service::class.simpleName} onCreate")
|
||||||
services.add(WeakReference(service))
|
services.add(WeakReference(service))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
fun onServiceDestroy(service: BaseService) {
|
fun onServiceDestroy(service: BaseService) {
|
||||||
|
LogUtils.d(TAG, "${service::class.simpleName} onDestroy")
|
||||||
for (temp in services) {
|
for (temp in services) {
|
||||||
if (temp.get() != null && temp.get() === service) {
|
if (temp.get() != null && temp.get() === service) {
|
||||||
services.remove(temp)
|
services.remove(temp)
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import androidx.core.view.postDelayed
|
|||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
import androidx.preference.ListPreference
|
import androidx.preference.ListPreference
|
||||||
import androidx.preference.Preference
|
import androidx.preference.Preference
|
||||||
|
import com.jeremyliao.liveeventbus.LiveEventBus
|
||||||
import io.legado.app.R
|
import io.legado.app.R
|
||||||
import io.legado.app.constant.EventBus
|
import io.legado.app.constant.EventBus
|
||||||
import io.legado.app.constant.PreferKey
|
import io.legado.app.constant.PreferKey
|
||||||
@@ -25,7 +26,14 @@ import io.legado.app.receiver.SharedReceiverActivity
|
|||||||
import io.legado.app.service.WebService
|
import io.legado.app.service.WebService
|
||||||
import io.legado.app.ui.file.HandleFileContract
|
import io.legado.app.ui.file.HandleFileContract
|
||||||
import io.legado.app.ui.widget.number.NumberPickerDialog
|
import io.legado.app.ui.widget.number.NumberPickerDialog
|
||||||
import io.legado.app.utils.*
|
import io.legado.app.utils.LogUtils
|
||||||
|
import io.legado.app.utils.postEvent
|
||||||
|
import io.legado.app.utils.putPrefBoolean
|
||||||
|
import io.legado.app.utils.putPrefString
|
||||||
|
import io.legado.app.utils.removePref
|
||||||
|
import io.legado.app.utils.restart
|
||||||
|
import io.legado.app.utils.setEdgeEffectColor
|
||||||
|
import io.legado.app.utils.showDialogFragment
|
||||||
import splitties.init.appCtx
|
import splitties.init.appCtx
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -80,6 +88,7 @@ class OtherConfigFragment : PreferenceFragment(),
|
|||||||
title = getString(R.string.select_book_folder)
|
title = getString(R.string.select_book_folder)
|
||||||
mode = HandleFileContract.DIR_SYS
|
mode = HandleFileContract.DIR_SYS
|
||||||
}
|
}
|
||||||
|
|
||||||
PreferKey.preDownloadNum -> NumberPickerDialog(requireContext())
|
PreferKey.preDownloadNum -> NumberPickerDialog(requireContext())
|
||||||
.setTitle(getString(R.string.pre_download))
|
.setTitle(getString(R.string.pre_download))
|
||||||
.setMaxValue(9999)
|
.setMaxValue(9999)
|
||||||
@@ -88,6 +97,7 @@ class OtherConfigFragment : PreferenceFragment(),
|
|||||||
.show {
|
.show {
|
||||||
AppConfig.preDownloadNum = it
|
AppConfig.preDownloadNum = it
|
||||||
}
|
}
|
||||||
|
|
||||||
PreferKey.threadCount -> NumberPickerDialog(requireContext())
|
PreferKey.threadCount -> NumberPickerDialog(requireContext())
|
||||||
.setTitle(getString(R.string.threads_num_title))
|
.setTitle(getString(R.string.threads_num_title))
|
||||||
.setMaxValue(999)
|
.setMaxValue(999)
|
||||||
@@ -96,6 +106,7 @@ class OtherConfigFragment : PreferenceFragment(),
|
|||||||
.show {
|
.show {
|
||||||
AppConfig.threadCount = it
|
AppConfig.threadCount = it
|
||||||
}
|
}
|
||||||
|
|
||||||
PreferKey.webPort -> NumberPickerDialog(requireContext())
|
PreferKey.webPort -> NumberPickerDialog(requireContext())
|
||||||
.setTitle(getString(R.string.web_port_title))
|
.setTitle(getString(R.string.web_port_title))
|
||||||
.setMaxValue(60000)
|
.setMaxValue(60000)
|
||||||
@@ -104,6 +115,7 @@ class OtherConfigFragment : PreferenceFragment(),
|
|||||||
.show {
|
.show {
|
||||||
AppConfig.webPort = it
|
AppConfig.webPort = it
|
||||||
}
|
}
|
||||||
|
|
||||||
PreferKey.cleanCache -> clearCache()
|
PreferKey.cleanCache -> clearCache()
|
||||||
PreferKey.uploadRule -> showDialogFragment<DirectLinkUploadConfig>()
|
PreferKey.uploadRule -> showDialogFragment<DirectLinkUploadConfig>()
|
||||||
PreferKey.checkSource -> showDialogFragment<CheckSourceConfig>()
|
PreferKey.checkSource -> showDialogFragment<CheckSourceConfig>()
|
||||||
@@ -118,6 +130,7 @@ class OtherConfigFragment : PreferenceFragment(),
|
|||||||
ImageProvider.bitmapLruCache.resize(ImageProvider.cacheSize)
|
ImageProvider.bitmapLruCache.resize(ImageProvider.cacheSize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PreferKey.sourceEditMaxLine -> {
|
PreferKey.sourceEditMaxLine -> {
|
||||||
NumberPickerDialog(requireContext())
|
NumberPickerDialog(requireContext())
|
||||||
.setTitle(getString(R.string.source_edit_text_max_line))
|
.setTitle(getString(R.string.source_edit_text_max_line))
|
||||||
@@ -141,10 +154,12 @@ class OtherConfigFragment : PreferenceFragment(),
|
|||||||
PreferKey.preDownloadNum -> {
|
PreferKey.preDownloadNum -> {
|
||||||
upPreferenceSummary(key, AppConfig.preDownloadNum.toString())
|
upPreferenceSummary(key, AppConfig.preDownloadNum.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
PreferKey.threadCount -> {
|
PreferKey.threadCount -> {
|
||||||
upPreferenceSummary(key, AppConfig.threadCount.toString())
|
upPreferenceSummary(key, AppConfig.threadCount.toString())
|
||||||
postEvent(PreferKey.threadCount, "")
|
postEvent(PreferKey.threadCount, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
PreferKey.webPort -> {
|
PreferKey.webPort -> {
|
||||||
upPreferenceSummary(key, AppConfig.webPort.toString())
|
upPreferenceSummary(key, AppConfig.webPort.toString())
|
||||||
if (WebService.isRun) {
|
if (WebService.isRun) {
|
||||||
@@ -152,26 +167,37 @@ class OtherConfigFragment : PreferenceFragment(),
|
|||||||
WebService.start(requireContext())
|
WebService.start(requireContext())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PreferKey.defaultBookTreeUri -> {
|
PreferKey.defaultBookTreeUri -> {
|
||||||
upPreferenceSummary(key, AppConfig.defaultBookTreeUri)
|
upPreferenceSummary(key, AppConfig.defaultBookTreeUri)
|
||||||
}
|
}
|
||||||
PreferKey.recordLog -> LogUtils.upLevel()
|
|
||||||
|
PreferKey.recordLog -> {
|
||||||
|
LogUtils.upLevel()
|
||||||
|
LiveEventBus.config().enableLogger(AppConfig.recordLog)
|
||||||
|
}
|
||||||
|
|
||||||
PreferKey.processText -> sharedPreferences?.let {
|
PreferKey.processText -> sharedPreferences?.let {
|
||||||
setProcessTextEnable(it.getBoolean(key, true))
|
setProcessTextEnable(it.getBoolean(key, true))
|
||||||
}
|
}
|
||||||
|
|
||||||
PreferKey.showDiscovery, PreferKey.showRss -> postEvent(EventBus.NOTIFY_MAIN, true)
|
PreferKey.showDiscovery, PreferKey.showRss -> postEvent(EventBus.NOTIFY_MAIN, true)
|
||||||
PreferKey.language -> listView.postDelayed(1000) {
|
PreferKey.language -> listView.postDelayed(1000) {
|
||||||
appCtx.restart()
|
appCtx.restart()
|
||||||
}
|
}
|
||||||
|
|
||||||
PreferKey.userAgent -> listView.post {
|
PreferKey.userAgent -> listView.post {
|
||||||
upPreferenceSummary(PreferKey.userAgent, AppConfig.userAgent)
|
upPreferenceSummary(PreferKey.userAgent, AppConfig.userAgent)
|
||||||
}
|
}
|
||||||
|
|
||||||
PreferKey.checkSource -> listView.post {
|
PreferKey.checkSource -> listView.post {
|
||||||
upPreferenceSummary(PreferKey.checkSource, CheckSource.summary)
|
upPreferenceSummary(PreferKey.checkSource, CheckSource.summary)
|
||||||
}
|
}
|
||||||
|
|
||||||
PreferKey.bitmapCacheSize -> {
|
PreferKey.bitmapCacheSize -> {
|
||||||
upPreferenceSummary(key, AppConfig.bitmapCacheSize.toString())
|
upPreferenceSummary(key, AppConfig.bitmapCacheSize.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
PreferKey.sourceEditMaxLine -> {
|
PreferKey.sourceEditMaxLine -> {
|
||||||
upPreferenceSummary(key, AppConfig.sourceEditMaxLine.toString())
|
upPreferenceSummary(key, AppConfig.sourceEditMaxLine.toString())
|
||||||
}
|
}
|
||||||
@@ -183,12 +209,15 @@ class OtherConfigFragment : PreferenceFragment(),
|
|||||||
when (preferenceKey) {
|
when (preferenceKey) {
|
||||||
PreferKey.preDownloadNum -> preference.summary =
|
PreferKey.preDownloadNum -> preference.summary =
|
||||||
getString(R.string.pre_download_s, value)
|
getString(R.string.pre_download_s, value)
|
||||||
|
|
||||||
PreferKey.threadCount -> preference.summary = getString(R.string.threads_num, value)
|
PreferKey.threadCount -> preference.summary = getString(R.string.threads_num, value)
|
||||||
PreferKey.webPort -> preference.summary = getString(R.string.web_port_summary, value)
|
PreferKey.webPort -> preference.summary = getString(R.string.web_port_summary, value)
|
||||||
PreferKey.bitmapCacheSize -> preference.summary =
|
PreferKey.bitmapCacheSize -> preference.summary =
|
||||||
getString(R.string.bitmap_cache_size_summary, value)
|
getString(R.string.bitmap_cache_size_summary, value)
|
||||||
|
|
||||||
PreferKey.sourceEditMaxLine -> preference.summary =
|
PreferKey.sourceEditMaxLine -> preference.summary =
|
||||||
getString(R.string.source_edit_max_line_summary, value)
|
getString(R.string.source_edit_max_line_summary, value)
|
||||||
|
|
||||||
else -> if (preference is ListPreference) {
|
else -> if (preference is ListPreference) {
|
||||||
val index = preference.findIndexOfValue(value)
|
val index = preference.findIndexOfValue(value)
|
||||||
// Set the summary to reflect the new value.
|
// Set the summary to reflect the new value.
|
||||||
|
|||||||
Reference in New Issue
Block a user