pull/2138/head
821938089 2 years ago
parent 270030c3be
commit 69e365bc06
  1. 6
      app/src/main/java/io/legado/app/model/CheckSource.kt
  2. 1
      app/src/main/java/io/legado/app/service/CheckSourceService.kt
  3. 51
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt

@ -38,6 +38,12 @@ object CheckSource {
} }
} }
fun resume(context: Context) {
context.startService<CheckSourceService> {
action = IntentAction.resume
}
}
fun putConfig() { fun putConfig() {
CacheManager.put("checkSourceTimeout", timeout) CacheManager.put("checkSourceTimeout", timeout)
CacheManager.put("checkSearch", checkSearch) CacheManager.put("checkSearch", checkSearch)

@ -69,6 +69,7 @@ class CheckSourceService : BaseService() {
IntentAction.start -> intent.getStringArrayListExtra("selectIds")?.let { IntentAction.start -> intent.getStringArrayListExtra("selectIds")?.let {
check(it) check(it)
} }
IntentAction.resume -> upNotification()
else -> stopSelf() else -> stopSelf()
} }
return super.onStartCommand(intent, flags, startId) return super.onStartCommand(intent, flags, startId)

@ -1,11 +1,10 @@
package io.legado.app.ui.book.source.manage package io.legado.app.ui.book.source.manage
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Context
import android.hardware.display.DisplayManager
import android.os.Bundle import android.os.Bundle
import android.view.Menu import android.view.*
import android.view.MenuItem
import android.view.SubMenu
import android.view.WindowManager
import androidx.activity.viewModels import androidx.activity.viewModels
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.appcompat.widget.PopupMenu import androidx.appcompat.widget.PopupMenu
@ -29,6 +28,7 @@ import io.legado.app.lib.theme.primaryColor
import io.legado.app.lib.theme.primaryTextColor import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.model.CheckSource import io.legado.app.model.CheckSource
import io.legado.app.model.Debug import io.legado.app.model.Debug
import io.legado.app.service.CheckSourceService
import io.legado.app.ui.association.ImportBookSourceDialog import io.legado.app.ui.association.ImportBookSourceDialog
import io.legado.app.ui.book.local.rule.TxtTocRuleActivity import io.legado.app.ui.book.local.rule.TxtTocRuleActivity
import io.legado.app.ui.book.source.debug.BookSourceDebugActivity import io.legado.app.ui.book.source.debug.BookSourceDebugActivity
@ -70,6 +70,9 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
private var sort = Sort.Default private var sort = Sort.Default
private var sortAscending = true private var sortAscending = true
private var snackBar: Snackbar? = null private var snackBar: Snackbar? = null
private val displayManager by lazy {
getSystemService(Context.DISPLAY_SERVICE) as DisplayManager
}
private val qrResult = registerForActivityResult(QrCodeResult()) { private val qrResult = registerForActivityResult(QrCodeResult()) {
it ?: return@registerForActivityResult it ?: return@registerForActivityResult
showDialogFragment(ImportBookSourceDialog(it)) showDialogFragment(ImportBookSourceDialog(it))
@ -109,6 +112,7 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
upBookSource() upBookSource()
initLiveDataGroup() initLiveDataGroup()
initSelectActionBar() initSelectActionBar()
resumeCheckSource()
if (!LocalConfig.bookSourcesHelpVersionIsLast) { if (!LocalConfig.bookSourcesHelpVersionIsLast) {
showHelp() showHelp()
} }
@ -399,6 +403,15 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
} }
} }
private fun resumeCheckSource() {
if (!Debug.isChecking) {
return
}
keepScreenOn(true)
CheckSource.resume(this)
checkMessageRefreshJob(0, 0).start()
}
@SuppressLint("InflateParams") @SuppressLint("InflateParams")
private fun selectionAddToGroups() { private fun selectionAddToGroups() {
alert(titleResource = R.string.add_group) { alert(titleResource = R.string.add_group) {
@ -516,11 +529,21 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
delay(300L) delay(300L)
} }
}.collect { }.collect {
adapter.notifyItemRangeChanged( if (isScreenOn()) {
firstItem, if (lastItem == 0) {
lastItem + 1, adapter.notifyItemRangeChanged(
bundleOf(Pair("checkSourceMessage", null)) 0,
) adapter.itemCount,
bundleOf(Pair("checkSourceMessage", null))
)
} else {
adapter.notifyItemRangeChanged(
firstItem,
lastItem + 1,
bundleOf(Pair("checkSourceMessage", null))
)
}
}
if (!it) { if (!it) {
this.cancel() this.cancel()
} }
@ -532,7 +555,8 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
* 保持亮屏 * 保持亮屏
*/ */
private fun keepScreenOn(on: Boolean) { private fun keepScreenOn(on: Boolean) {
val isScreenOn = (window.attributes.flags and WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) != 0 val isScreenOn =
(window.attributes.flags and WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) != 0
if (on == isScreenOn) return if (on == isScreenOn) return
if (on) { if (on) {
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
@ -541,6 +565,13 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
} }
} }
private fun isScreenOn(): Boolean {
return displayManager.displays.any {
it ?: return@any false
it.state != Display.STATE_OFF
}
}
override fun upCountView() { override fun upCountView() {
binding.selectActionBar binding.selectActionBar
.upCountView(adapter.selection.size, adapter.itemCount) .upCountView(adapter.selection.size, adapter.itemCount)

Loading…
Cancel
Save