优化
This commit is contained in:
@@ -0,0 +1,23 @@
|
|||||||
|
package io.legado.app.receiver
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.content.IntentFilter
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 监测网络变化
|
||||||
|
*/
|
||||||
|
class NetworkChangedReceiver : BroadcastReceiver() {
|
||||||
|
|
||||||
|
val filter = IntentFilter().apply {
|
||||||
|
addAction("android.net.conn.CONNECTIVITY_CHANGE")
|
||||||
|
addAction("android.net.wifi.WIFI_STATE_CHANGED")
|
||||||
|
addAction("android.net.wifi.STATE_CHANGE")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onReceive(context: Context?, intent: Intent?) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -11,17 +11,9 @@ import io.legado.app.utils.postEvent
|
|||||||
|
|
||||||
class TimeBatteryReceiver : BroadcastReceiver() {
|
class TimeBatteryReceiver : BroadcastReceiver() {
|
||||||
|
|
||||||
companion object {
|
val filter = IntentFilter().apply {
|
||||||
|
addAction(Intent.ACTION_TIME_TICK)
|
||||||
fun register(context: Context): TimeBatteryReceiver {
|
addAction(Intent.ACTION_BATTERY_CHANGED)
|
||||||
val receiver = TimeBatteryReceiver()
|
|
||||||
val filter = IntentFilter()
|
|
||||||
filter.addAction(Intent.ACTION_TIME_TICK)
|
|
||||||
filter.addAction(Intent.ACTION_BATTERY_CHANGED)
|
|
||||||
context.registerReceiver(receiver, filter)
|
|
||||||
return receiver
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onReceive(context: Context?, intent: Intent?) {
|
override fun onReceive(context: Context?, intent: Intent?) {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import io.legado.app.constant.AppConst
|
|||||||
import io.legado.app.constant.EventBus
|
import io.legado.app.constant.EventBus
|
||||||
import io.legado.app.constant.IntentAction
|
import io.legado.app.constant.IntentAction
|
||||||
import io.legado.app.constant.PreferKey
|
import io.legado.app.constant.PreferKey
|
||||||
|
import io.legado.app.receiver.NetworkChangedReceiver
|
||||||
import io.legado.app.utils.*
|
import io.legado.app.utils.*
|
||||||
import io.legado.app.web.HttpServer
|
import io.legado.app.web.HttpServer
|
||||||
import io.legado.app.web.WebSocketServer
|
import io.legado.app.web.WebSocketServer
|
||||||
@@ -35,6 +36,7 @@ class WebService : BaseService() {
|
|||||||
private var httpServer: HttpServer? = null
|
private var httpServer: HttpServer? = null
|
||||||
private var webSocketServer: WebSocketServer? = null
|
private var webSocketServer: WebSocketServer? = null
|
||||||
private var notificationContent = ""
|
private var notificationContent = ""
|
||||||
|
private val networkChangedReceiver = NetworkChangedReceiver()
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
@@ -42,6 +44,7 @@ class WebService : BaseService() {
|
|||||||
notificationContent = getString(R.string.service_starting)
|
notificationContent = getString(R.string.service_starting)
|
||||||
upNotification()
|
upNotification()
|
||||||
upTile(true)
|
upTile(true)
|
||||||
|
registerReceiver(networkChangedReceiver, networkChangedReceiver.filter)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||||
@@ -55,6 +58,7 @@ class WebService : BaseService() {
|
|||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
|
unregisterReceiver(networkChangedReceiver)
|
||||||
isRun = false
|
isRun = false
|
||||||
if (httpServer?.isAlive == true) {
|
if (httpServer?.isAlive == true) {
|
||||||
httpServer?.stop()
|
httpServer?.stop()
|
||||||
|
|||||||
@@ -148,8 +148,8 @@ class ReadBookActivity : BaseReadBookActivity(),
|
|||||||
set(value) {
|
set(value) {
|
||||||
field = value && isShowingSearchResult
|
field = value && isShowingSearchResult
|
||||||
}
|
}
|
||||||
|
private val timeBatteryReceiver = TimeBatteryReceiver()
|
||||||
private var screenTimeOut: Long = 0
|
private var screenTimeOut: Long = 0
|
||||||
private var timeBatteryReceiver: TimeBatteryReceiver? = null
|
|
||||||
private var loadStates: Boolean = false
|
private var loadStates: Boolean = false
|
||||||
override val pageFactory: TextPageFactory get() = binding.readView.pageFactory
|
override val pageFactory: TextPageFactory get() = binding.readView.pageFactory
|
||||||
override val headerHeight: Int get() = binding.readView.curPage.headerHeight
|
override val headerHeight: Int get() = binding.readView.curPage.headerHeight
|
||||||
@@ -185,7 +185,7 @@ class ReadBookActivity : BaseReadBookActivity(),
|
|||||||
super.onResume()
|
super.onResume()
|
||||||
ReadBook.readStartTime = System.currentTimeMillis()
|
ReadBook.readStartTime = System.currentTimeMillis()
|
||||||
upSystemUiVisibility()
|
upSystemUiVisibility()
|
||||||
timeBatteryReceiver = TimeBatteryReceiver.register(this)
|
registerReceiver(timeBatteryReceiver, timeBatteryReceiver.filter)
|
||||||
binding.readView.upTime()
|
binding.readView.upTime()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,10 +194,7 @@ class ReadBookActivity : BaseReadBookActivity(),
|
|||||||
autoPageStop()
|
autoPageStop()
|
||||||
backupJob?.cancel()
|
backupJob?.cancel()
|
||||||
ReadBook.saveRead()
|
ReadBook.saveRead()
|
||||||
timeBatteryReceiver?.let {
|
unregisterReceiver(timeBatteryReceiver)
|
||||||
unregisterReceiver(it)
|
|
||||||
timeBatteryReceiver = null
|
|
||||||
}
|
|
||||||
upSystemUiVisibility()
|
upSystemUiVisibility()
|
||||||
if (!BuildConfig.DEBUG) {
|
if (!BuildConfig.DEBUG) {
|
||||||
ReadBook.uploadProgress()
|
ReadBook.uploadProgress()
|
||||||
|
|||||||
Reference in New Issue
Block a user