Merge branch 'master' into master
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -20,7 +20,7 @@ val appDb by lazy {
|
||||
}
|
||||
|
||||
@Database(
|
||||
version = 46,
|
||||
version = 47,
|
||||
exportSchema = true,
|
||||
entities = [Book::class, BookGroup::class, BookSource::class, BookChapter::class,
|
||||
ReplaceRule::class, SearchBook::class, SearchKeyword::class, Cookie::class,
|
||||
@@ -30,7 +30,8 @@ val appDb by lazy {
|
||||
autoMigrations = [
|
||||
AutoMigration(from = 43, to = 44),
|
||||
AutoMigration(from = 44, to = 45),
|
||||
AutoMigration(from = 45, to = 46)
|
||||
AutoMigration(from = 45, to = 46),
|
||||
AutoMigration(from = 46, to = 47)
|
||||
]
|
||||
)
|
||||
abstract class AppDatabase : RoomDatabase() {
|
||||
|
||||
@@ -43,6 +43,9 @@ data class ReplaceRule(
|
||||
//是否正则
|
||||
@ColumnInfo(defaultValue = "1")
|
||||
var isRegex: Boolean = true,
|
||||
//超时时间
|
||||
@ColumnInfo(defaultValue = "3000")
|
||||
var timeoutMillisecond: Long = 3000L,
|
||||
//排序
|
||||
@ColumnInfo(name = "sortOrder", defaultValue = "0")
|
||||
var order: Int = 0
|
||||
|
||||
@@ -76,6 +76,8 @@ object CacheManager {
|
||||
val cache = queryTTFMap[key] ?: return null
|
||||
if (cache.first == 0L || cache.first > System.currentTimeMillis()) {
|
||||
return cache.second
|
||||
} else {
|
||||
queryTTFMap.remove(key)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package io.legado.app.receiver
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.net.ConnectivityManager
|
||||
|
||||
/**
|
||||
* 监测网络变化
|
||||
*/
|
||||
class NetworkChangedReceiver : BroadcastReceiver() {
|
||||
|
||||
var onReceiver: ((context: Context, intent: Intent) -> Unit)? = null
|
||||
|
||||
val filter = IntentFilter().apply {
|
||||
@Suppress("DEPRECATION")
|
||||
addAction(ConnectivityManager.CONNECTIVITY_ACTION)
|
||||
}
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
onReceiver?.invoke(context, intent)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,21 +11,13 @@ import io.legado.app.utils.postEvent
|
||||
|
||||
class TimeBatteryReceiver : BroadcastReceiver() {
|
||||
|
||||
companion object {
|
||||
|
||||
fun register(context: Context): TimeBatteryReceiver {
|
||||
val receiver = TimeBatteryReceiver()
|
||||
val filter = IntentFilter()
|
||||
filter.addAction(Intent.ACTION_TIME_TICK)
|
||||
filter.addAction(Intent.ACTION_BATTERY_CHANGED)
|
||||
context.registerReceiver(receiver, filter)
|
||||
return receiver
|
||||
}
|
||||
|
||||
val filter = IntentFilter().apply {
|
||||
addAction(Intent.ACTION_TIME_TICK)
|
||||
addAction(Intent.ACTION_BATTERY_CHANGED)
|
||||
}
|
||||
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
when (intent?.action) {
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
when (intent.action) {
|
||||
Intent.ACTION_TIME_TICK -> {
|
||||
postEvent(EventBus.TIME_CHANGED, "")
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import io.legado.app.constant.AppConst
|
||||
import io.legado.app.constant.EventBus
|
||||
import io.legado.app.constant.IntentAction
|
||||
import io.legado.app.constant.PreferKey
|
||||
import io.legado.app.receiver.NetworkChangedReceiver
|
||||
import io.legado.app.utils.*
|
||||
import io.legado.app.web.HttpServer
|
||||
import io.legado.app.web.WebSocketServer
|
||||
@@ -35,6 +36,7 @@ class WebService : BaseService() {
|
||||
private var httpServer: HttpServer? = null
|
||||
private var webSocketServer: WebSocketServer? = null
|
||||
private var notificationContent = ""
|
||||
private val networkChangedReceiver = NetworkChangedReceiver()
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
@@ -42,6 +44,10 @@ class WebService : BaseService() {
|
||||
notificationContent = getString(R.string.service_starting)
|
||||
upNotification()
|
||||
upTile(true)
|
||||
registerReceiver(networkChangedReceiver, networkChangedReceiver.filter)
|
||||
networkChangedReceiver.onReceiver = { _, _ ->
|
||||
upWebServer()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
@@ -55,6 +61,7 @@ class WebService : BaseService() {
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
unregisterReceiver(networkChangedReceiver)
|
||||
isRun = false
|
||||
if (httpServer?.isAlive == true) {
|
||||
httpServer?.stop()
|
||||
|
||||
@@ -148,8 +148,8 @@ class ReadBookActivity : BaseReadBookActivity(),
|
||||
set(value) {
|
||||
field = value && isShowingSearchResult
|
||||
}
|
||||
private val timeBatteryReceiver = TimeBatteryReceiver()
|
||||
private var screenTimeOut: Long = 0
|
||||
private var timeBatteryReceiver: TimeBatteryReceiver? = null
|
||||
private var loadStates: Boolean = false
|
||||
override val pageFactory: TextPageFactory get() = binding.readView.pageFactory
|
||||
override val headerHeight: Int get() = binding.readView.curPage.headerHeight
|
||||
@@ -185,7 +185,7 @@ class ReadBookActivity : BaseReadBookActivity(),
|
||||
super.onResume()
|
||||
ReadBook.readStartTime = System.currentTimeMillis()
|
||||
upSystemUiVisibility()
|
||||
timeBatteryReceiver = TimeBatteryReceiver.register(this)
|
||||
registerReceiver(timeBatteryReceiver, timeBatteryReceiver.filter)
|
||||
binding.readView.upTime()
|
||||
}
|
||||
|
||||
@@ -194,10 +194,7 @@ class ReadBookActivity : BaseReadBookActivity(),
|
||||
autoPageStop()
|
||||
backupJob?.cancel()
|
||||
ReadBook.saveRead()
|
||||
timeBatteryReceiver?.let {
|
||||
unregisterReceiver(it)
|
||||
timeBatteryReceiver = null
|
||||
}
|
||||
unregisterReceiver(timeBatteryReceiver)
|
||||
upSystemUiVisibility()
|
||||
if (!BuildConfig.DEBUG) {
|
||||
ReadBook.uploadProgress()
|
||||
|
||||
@@ -71,7 +71,7 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
|
||||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
upBottomMenu()
|
||||
binding.apply {
|
||||
binding.run {
|
||||
viewPagerMain.setEdgeEffectColor(primaryColor)
|
||||
viewPagerMain.offscreenPageLimit = 3
|
||||
viewPagerMain.adapter = TabFragmentPageAdapter(supportFragmentManager)
|
||||
|
||||
Reference in New Issue
Block a user