mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -119,6 +119,7 @@ object PreferKey {
|
||||
const val ttsTimer = "ttsTimer"
|
||||
const val noAnimScrollPage = "noAnimScrollPage"
|
||||
const val webDavDeviceName = "webDavDeviceName"
|
||||
const val wakeLock = "wakeLock"
|
||||
|
||||
const val cPrimary = "colorPrimary"
|
||||
const val cAccent = "colorAccent"
|
||||
|
||||
@@ -31,7 +31,8 @@ object BackupConfig {
|
||||
PreferKey.webDavAccount,
|
||||
PreferKey.webDavPassword,
|
||||
PreferKey.launcherIcon,
|
||||
PreferKey.bitmapCacheSize
|
||||
PreferKey.bitmapCacheSize,
|
||||
PreferKey.wakeLock
|
||||
)
|
||||
|
||||
//配置忽略标题
|
||||
|
||||
@@ -9,7 +9,6 @@ import android.content.IntentFilter
|
||||
import android.graphics.BitmapFactory
|
||||
import android.media.AudioManager
|
||||
import android.os.Bundle
|
||||
import android.os.PowerManager
|
||||
import android.support.v4.media.session.MediaSessionCompat
|
||||
import android.support.v4.media.session.PlaybackStateCompat
|
||||
import androidx.annotation.CallSuper
|
||||
@@ -29,7 +28,6 @@ import io.legado.app.ui.book.read.page.entities.TextChapter
|
||||
import io.legado.app.utils.*
|
||||
import kotlinx.coroutines.*
|
||||
import splitties.systemservices.audioManager
|
||||
import splitties.systemservices.powerManager
|
||||
|
||||
/**
|
||||
* 朗读服务
|
||||
@@ -55,11 +53,6 @@ abstract class BaseReadAloudService : BaseService(),
|
||||
}
|
||||
}
|
||||
|
||||
private val wakeLock by lazy {
|
||||
powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "legado:readAloud").apply {
|
||||
setReferenceCounted(false)
|
||||
}
|
||||
}
|
||||
private val mFocusRequest: AudioFocusRequestCompat by lazy {
|
||||
MediaHelp.buildAudioFocusRequestCompat(this)
|
||||
}
|
||||
@@ -85,7 +78,6 @@ abstract class BaseReadAloudService : BaseService(),
|
||||
@SuppressLint("WakelockTimeout")
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
wakeLock.acquire()
|
||||
isRun = true
|
||||
pause = false
|
||||
observeLiveBus()
|
||||
@@ -107,7 +99,6 @@ abstract class BaseReadAloudService : BaseService(),
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
wakeLock.release()
|
||||
isRun = false
|
||||
pause = true
|
||||
abandonFocus()
|
||||
@@ -176,7 +167,6 @@ abstract class BaseReadAloudService : BaseService(),
|
||||
postEvent(EventBus.ALOUD_STATE, Status.PAUSE)
|
||||
ReadBook.uploadProgress()
|
||||
doDs()
|
||||
wakeLock.release()
|
||||
}
|
||||
|
||||
@SuppressLint("WakelockTimeout")
|
||||
@@ -185,7 +175,6 @@ abstract class BaseReadAloudService : BaseService(),
|
||||
pause = false
|
||||
upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PLAYING)
|
||||
postEvent(EventBus.ALOUD_STATE, Status.PLAY)
|
||||
wakeLock.acquire()
|
||||
}
|
||||
|
||||
abstract fun upSpeechRate(reset: Boolean = false)
|
||||
|
||||
@@ -16,6 +16,7 @@ import io.legado.app.receiver.NetworkChangedListener
|
||||
import io.legado.app.utils.*
|
||||
import io.legado.app.web.HttpServer
|
||||
import io.legado.app.web.WebSocketServer
|
||||
import splitties.init.appCtx
|
||||
import splitties.systemservices.powerManager
|
||||
|
||||
import java.io.IOException
|
||||
@@ -36,6 +37,7 @@ class WebService : BaseService() {
|
||||
|
||||
}
|
||||
|
||||
private val useWakeLock = appCtx.getPrefBoolean(PreferKey.wakeLock, false)
|
||||
private val wakeLock by lazy {
|
||||
powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "legado:webService")
|
||||
}
|
||||
@@ -49,7 +51,9 @@ class WebService : BaseService() {
|
||||
@SuppressLint("WakelockTimeout")
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
wakeLock.acquire()
|
||||
if (useWakeLock) {
|
||||
wakeLock.acquire()
|
||||
}
|
||||
isRun = true
|
||||
notificationContent = getString(R.string.service_starting)
|
||||
upNotification()
|
||||
@@ -81,7 +85,9 @@ class WebService : BaseService() {
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
wakeLock.release()
|
||||
if (useWakeLock) {
|
||||
wakeLock.release()
|
||||
}
|
||||
networkChangedListener.unRegister()
|
||||
isRun = false
|
||||
if (httpServer?.isAlive == true) {
|
||||
|
||||
@@ -1045,4 +1045,6 @@
|
||||
<string name="sure_clear_search_history">是否确认清除所有搜索历史记录</string>
|
||||
<string name="no_anim_scroll_page">禁用滚动点击动画</string>
|
||||
<string name="webdav_device_name">设备名称</string>
|
||||
<string name="wake_lock">唤醒锁</string>
|
||||
<string name="wake_lock_summary">开启web服务的时候启用唤醒锁,有些手机开启唤醒锁会被杀后台</string>
|
||||
</resources>
|
||||
|
||||
@@ -1048,4 +1048,6 @@
|
||||
<string name="sure_clear_search_history">是否确认清除所有搜索历史记录</string>
|
||||
<string name="no_anim_scroll_page">禁用滚动点击动画</string>
|
||||
<string name="webdav_device_name">设备名称</string>
|
||||
<string name="wake_lock">唤醒锁</string>
|
||||
<string name="wake_lock_summary">开启web服务的时候启用唤醒锁,有些手机开启唤醒锁会被杀后台</string>
|
||||
</resources>
|
||||
|
||||
@@ -1048,4 +1048,6 @@
|
||||
<string name="sure_clear_search_history">是否确认清除所有搜索历史记录</string>
|
||||
<string name="no_anim_scroll_page">禁用滚动点击动画</string>
|
||||
<string name="webdav_device_name">设备名称</string>
|
||||
<string name="wake_lock">唤醒锁</string>
|
||||
<string name="wake_lock_summary">开启web服务的时候启用唤醒锁,有些手机开启唤醒锁会被杀后台</string>
|
||||
</resources>
|
||||
|
||||
@@ -1045,4 +1045,6 @@
|
||||
<string name="sure_clear_search_history">是否确认清除所有搜索历史记录</string>
|
||||
<string name="no_anim_scroll_page">禁用滚动点击动画</string>
|
||||
<string name="webdav_device_name">设备名称</string>
|
||||
<string name="wake_lock">唤醒锁</string>
|
||||
<string name="wake_lock_summary">开启web服务的时候启用唤醒锁,有些手机开启唤醒锁会被杀后台</string>
|
||||
</resources>
|
||||
|
||||
@@ -1047,4 +1047,6 @@
|
||||
<string name="sure_clear_search_history">是否确认清除所有搜索历史记录</string>
|
||||
<string name="no_anim_scroll_page">禁用滚动点击动画</string>
|
||||
<string name="webdav_device_name">设备名称</string>
|
||||
<string name="wake_lock">唤醒锁</string>
|
||||
<string name="wake_lock_summary">开启web服务的时候启用唤醒锁,有些手机开启唤醒锁会被杀后台</string>
|
||||
</resources>
|
||||
|
||||
@@ -1047,4 +1047,6 @@
|
||||
<string name="sure_clear_search_history">是否确认清除所有搜索历史记录</string>
|
||||
<string name="no_anim_scroll_page">禁用滚动点击动画</string>
|
||||
<string name="webdav_device_name">设备名称</string>
|
||||
<string name="wake_lock">唤醒锁</string>
|
||||
<string name="wake_lock_summary">开启web服务的时候启用唤醒锁,有些手机开启唤醒锁会被杀后台</string>
|
||||
</resources>
|
||||
|
||||
@@ -1048,4 +1048,6 @@
|
||||
<string name="sure_clear_search_history">是否确认清除所有搜索历史记录</string>
|
||||
<string name="no_anim_scroll_page">禁用滚动点击动画</string>
|
||||
<string name="webdav_device_name">设备名称</string>
|
||||
<string name="wake_lock">唤醒锁</string>
|
||||
<string name="wake_lock_summary">开启web服务的时候启用唤醒锁,有些手机开启唤醒锁会被杀后台</string>
|
||||
</resources>
|
||||
|
||||
@@ -56,6 +56,12 @@
|
||||
android:key="userAgent"
|
||||
android:title="@string/user_agent" />
|
||||
|
||||
<io.legado.app.lib.prefs.SwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:key="wakeLock"
|
||||
android:title="@string/wake_lock"
|
||||
android:summary="@string/wake_lock_summary" />
|
||||
|
||||
<io.legado.app.lib.prefs.Preference
|
||||
android:key="defaultBookTreeUri"
|
||||
android:summary="@string/book_tree_uri_s"
|
||||
|
||||
Reference in New Issue
Block a user