Merge branch 'master' into master

pull/1852/head
Xwite 3 years ago committed by GitHub
commit 73448b88f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1625
      app/schemas/io.legado.app.data.AppDatabase/47.json
  2. 5
      app/src/main/java/io/legado/app/data/AppDatabase.kt
  3. 3
      app/src/main/java/io/legado/app/data/entities/ReplaceRule.kt
  4. 2
      app/src/main/java/io/legado/app/help/CacheManager.kt
  5. 25
      app/src/main/java/io/legado/app/receiver/NetworkChangedReceiver.kt
  6. 18
      app/src/main/java/io/legado/app/receiver/TimeBatteryReceiver.kt
  7. 7
      app/src/main/java/io/legado/app/service/WebService.kt
  8. 9
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  9. 2
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt

File diff suppressed because it is too large Load Diff

@ -20,7 +20,7 @@ val appDb by lazy {
} }
@Database( @Database(
version = 46, version = 47,
exportSchema = true, exportSchema = true,
entities = [Book::class, BookGroup::class, BookSource::class, BookChapter::class, entities = [Book::class, BookGroup::class, BookSource::class, BookChapter::class,
ReplaceRule::class, SearchBook::class, SearchKeyword::class, Cookie::class, ReplaceRule::class, SearchBook::class, SearchKeyword::class, Cookie::class,
@ -30,7 +30,8 @@ val appDb by lazy {
autoMigrations = [ autoMigrations = [
AutoMigration(from = 43, to = 44), AutoMigration(from = 43, to = 44),
AutoMigration(from = 44, to = 45), AutoMigration(from = 44, to = 45),
AutoMigration(from = 45, to = 46) AutoMigration(from = 45, to = 46),
AutoMigration(from = 46, to = 47)
] ]
) )
abstract class AppDatabase : RoomDatabase() { abstract class AppDatabase : RoomDatabase() {

@ -43,6 +43,9 @@ data class ReplaceRule(
//是否正则 //是否正则
@ColumnInfo(defaultValue = "1") @ColumnInfo(defaultValue = "1")
var isRegex: Boolean = true, var isRegex: Boolean = true,
//超时时间
@ColumnInfo(defaultValue = "3000")
var timeoutMillisecond: Long = 3000L,
//排序 //排序
@ColumnInfo(name = "sortOrder", defaultValue = "0") @ColumnInfo(name = "sortOrder", defaultValue = "0")
var order: Int = 0 var order: Int = 0

@ -76,6 +76,8 @@ object CacheManager {
val cache = queryTTFMap[key] ?: return null val cache = queryTTFMap[key] ?: return null
if (cache.first == 0L || cache.first > System.currentTimeMillis()) { if (cache.first == 0L || cache.first > System.currentTimeMillis()) {
return cache.second return cache.second
} else {
queryTTFMap.remove(key)
} }
return null 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() { 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) {
when (intent?.action) { when (intent.action) {
Intent.ACTION_TIME_TICK -> { Intent.ACTION_TIME_TICK -> {
postEvent(EventBus.TIME_CHANGED, "") 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.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,10 @@ 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)
networkChangedReceiver.onReceiver = { _, _ ->
upWebServer()
}
} }
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
@ -55,6 +61,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()

@ -71,7 +71,7 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
upBottomMenu() upBottomMenu()
binding.apply { binding.run {
viewPagerMain.setEdgeEffectColor(primaryColor) viewPagerMain.setEdgeEffectColor(primaryColor)
viewPagerMain.offscreenPageLimit = 3 viewPagerMain.offscreenPageLimit = 3
viewPagerMain.adapter = TabFragmentPageAdapter(supportFragmentManager) viewPagerMain.adapter = TabFragmentPageAdapter(supportFragmentManager)

Loading…
Cancel
Save