Merge remote-tracking branch 'origin/master' into master

pull/1114/head
bushixuanqi 3 years ago
commit 4a4208c031
  1. 2
      app/build.gradle
  2. 7
      app/src/main/assets/updateLog.md
  3. 4
      app/src/main/java/io/legado/app/App.kt
  4. 3
      app/src/main/java/io/legado/app/base/BaseService.kt
  5. 92
      app/src/main/java/io/legado/app/help/LifecycleHelp.kt
  6. 8
      app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt

@ -175,7 +175,7 @@ dependencies {
implementation 'com.jayway.jsonpath:json-path:2.6.0'
//JS rhino
implementation 'com.github.gedoor:rhino-android:1.5'
implementation 'com.github.gedoor:rhino-android:1.6'
//
implementation 'com.squareup.okhttp3:okhttp:4.9.1'

@ -8,6 +8,13 @@
* 正文出现缺字漏字、内容缺失、排版错乱等情况,有可能是净化规则出现问题。先关闭替换净化并刷新,再观察是否正常。如果正常说明净化规则存在误杀,如果关闭后仍然出现相关问题,请点击源链接查看原文与正文是否相同,如果不同,再进行反馈。
* 漫画源看书显示乱码,**阅读与其他软件的源并不通用**,请导入阅读的支持的漫画源!
**2021/07/11**
1. 开启JS沙箱限制
* 禁止在js里exec运行命令
* 禁止在js里通过geClass反射
* 禁止在js里创建File对象
* 禁止在js里获取Packages scope
**2021/07/10**
1. 阅读界面长按菜单改回原来样式
2. 解决导入书源时重命名分组和保留名称冲突的问题

@ -10,9 +10,9 @@ import com.jeremyliao.liveeventbus.LiveEventBus
import io.legado.app.constant.AppConst.channelIdDownload
import io.legado.app.constant.AppConst.channelIdReadAloud
import io.legado.app.constant.AppConst.channelIdWeb
import io.legado.app.help.ActivityHelp
import io.legado.app.help.AppConfig
import io.legado.app.help.CrashHandler
import io.legado.app.help.LifecycleHelp
import io.legado.app.help.ThemeConfig.applyDayNight
import io.legado.app.utils.LanguageUtils
import io.legado.app.utils.defaultSharedPreferences
@ -28,7 +28,7 @@ class App : MultiDexApplication() {
LiveEventBus.config()
.lifecycleObserverAlwaysActive(true)
.autoClear(false)
registerActivityLifecycleCallbacks(ActivityHelp)
registerActivityLifecycleCallbacks(LifecycleHelp)
defaultSharedPreferences.registerOnSharedPreferenceChangeListener(AppConfig)
}

@ -4,6 +4,7 @@ import android.app.Service
import android.content.Intent
import android.os.IBinder
import androidx.annotation.CallSuper
import io.legado.app.help.LifecycleHelp
import io.legado.app.help.coroutine.Coroutine
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
@ -22,6 +23,7 @@ abstract class BaseService : Service(), CoroutineScope by MainScope() {
@CallSuper
override fun onCreate() {
super.onCreate()
LifecycleHelp.onServiceCreate(this)
}
@CallSuper
@ -38,5 +40,6 @@ abstract class BaseService : Service(), CoroutineScope by MainScope() {
override fun onDestroy() {
super.onDestroy()
cancel()
LifecycleHelp.onServiceDestroy(this)
}
}

@ -3,6 +3,8 @@ package io.legado.app.help
import android.app.Activity
import android.app.Application
import android.os.Bundle
import io.legado.app.base.BaseService
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.utils.LanguageUtils
import java.lang.ref.WeakReference
import java.util.*
@ -11,18 +13,20 @@ import java.util.*
* Activity管理器,管理项目中Activity的状态
*/
@Suppress("unused")
object ActivityHelp : Application.ActivityLifecycleCallbacks {
object LifecycleHelp : Application.ActivityLifecycleCallbacks {
private val activities: MutableList<WeakReference<Activity>> = arrayListOf()
private val services: MutableList<WeakReference<BaseService>> = arrayListOf()
private var finishedListener: (() -> Unit)? = null
fun size(): Int {
fun activitySize(): Int {
return activities.size
}
/**
* 判断指定Activity是否存在
*/
fun isExist(activityClass: Class<*>): Boolean {
fun isExistActivity(activityClass: Class<*>): Boolean {
activities.forEach { item ->
if (item.get()?.javaClass == activityClass) {
return true
@ -31,47 +35,6 @@ object ActivityHelp : Application.ActivityLifecycleCallbacks {
return false
}
/**
* 添加Activity
*/
fun add(activity: Activity) {
activities.add(WeakReference(activity))
}
/**
* 移除Activity
*/
fun remove(activity: Activity) {
for (temp in activities) {
if (null != temp.get() && temp.get() === activity) {
activities.remove(temp)
break
}
}
}
/**
* 移除Activity
*/
fun remove(activityClass: Class<*>) {
val iterator = activities.iterator()
while (iterator.hasNext()) {
val item = iterator.next()
if (item.get()?.javaClass == activityClass) {
iterator.remove()
}
}
}
/**
* 关闭指定 activity
*/
fun finishActivity(vararg activities: Activity) {
activities.forEach { activity ->
activity.finish()
}
}
/**
* 关闭指定 activity(class)
*/
@ -90,6 +53,10 @@ object ActivityHelp : Application.ActivityLifecycleCallbacks {
}
}
fun setOnFinishedListener(finishedListener: (() -> Unit)) {
this.finishedListener = finishedListener
}
override fun onActivityPaused(activity: Activity) {
}
@ -101,7 +68,15 @@ object ActivityHelp : Application.ActivityLifecycleCallbacks {
}
override fun onActivityDestroyed(activity: Activity) {
remove(activity)
for (temp in activities) {
if (temp.get() != null && temp.get() === activity) {
activities.remove(temp)
if (services.size == 0 && activities.size == 0) {
onFinished()
}
break
}
}
}
override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {
@ -111,9 +86,32 @@ object ActivityHelp : Application.ActivityLifecycleCallbacks {
}
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
add(activity)
if (!LanguageUtils.isSameWithSetting(activity)){
activities.add(WeakReference(activity))
if (!LanguageUtils.isSameWithSetting(activity)) {
LanguageUtils.setConfiguration(activity)
}
}
@Synchronized
fun onServiceCreate(service: BaseService) {
services.add(WeakReference(service))
}
@Synchronized
fun onServiceDestroy(service: BaseService) {
for (temp in services) {
if (temp.get() != null && temp.get() === service) {
services.remove(temp)
if (services.size == 0 && activities.size == 0) {
onFinished()
}
break
}
}
}
private fun onFinished() {
Coroutine.cancel()
finishedListener?.invoke()
}
}

@ -6,8 +6,8 @@ import android.content.Intent
import android.view.KeyEvent
import io.legado.app.constant.EventBus
import io.legado.app.data.appDb
import io.legado.app.help.ActivityHelp
import io.legado.app.help.AppConfig
import io.legado.app.help.LifecycleHelp
import io.legado.app.service.AudioPlayService
import io.legado.app.service.BaseReadAloudService
import io.legado.app.service.help.AudioPlay
@ -69,13 +69,13 @@ class MediaButtonReceiver : BroadcastReceiver() {
} else {
AudioPlay.pause(context)
}
ActivityHelp.isExist(ReadBookActivity::class.java) ->
LifecycleHelp.isExistActivity(ReadBookActivity::class.java) ->
postEvent(EventBus.MEDIA_BUTTON, true)
ActivityHelp.isExist(AudioPlayActivity::class.java) ->
LifecycleHelp.isExistActivity(AudioPlayActivity::class.java) ->
postEvent(EventBus.MEDIA_BUTTON, true)
else -> if (AppConfig.mediaButtonOnExit || !isMediaKey) {
appDb.bookDao.lastReadBook?.let {
if (!ActivityHelp.isExist(MainActivity::class.java)) {
if (!LifecycleHelp.isExistActivity(MainActivity::class.java)) {
Intent(context, MainActivity::class.java).let {
it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(it)

Loading…
Cancel
Save