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() {
CacheManager.put("checkSourceTimeout", timeout)
CacheManager.put("checkSearch", checkSearch)

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

@ -1,11 +1,10 @@
package io.legado.app.ui.book.source.manage
import android.annotation.SuppressLint
import android.content.Context
import android.hardware.display.DisplayManager
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.view.SubMenu
import android.view.WindowManager
import android.view.*
import androidx.activity.viewModels
import androidx.appcompat.app.AlertDialog
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.model.CheckSource
import io.legado.app.model.Debug
import io.legado.app.service.CheckSourceService
import io.legado.app.ui.association.ImportBookSourceDialog
import io.legado.app.ui.book.local.rule.TxtTocRuleActivity
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 sortAscending = true
private var snackBar: Snackbar? = null
private val displayManager by lazy {
getSystemService(Context.DISPLAY_SERVICE) as DisplayManager
}
private val qrResult = registerForActivityResult(QrCodeResult()) {
it ?: return@registerForActivityResult
showDialogFragment(ImportBookSourceDialog(it))
@ -109,6 +112,7 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
upBookSource()
initLiveDataGroup()
initSelectActionBar()
resumeCheckSource()
if (!LocalConfig.bookSourcesHelpVersionIsLast) {
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")
private fun selectionAddToGroups() {
alert(titleResource = R.string.add_group) {
@ -516,11 +529,21 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
delay(300L)
}
}.collect {
adapter.notifyItemRangeChanged(
firstItem,
lastItem + 1,
bundleOf(Pair("checkSourceMessage", null))
)
if (isScreenOn()) {
if (lastItem == 0) {
adapter.notifyItemRangeChanged(
0,
adapter.itemCount,
bundleOf(Pair("checkSourceMessage", null))
)
} else {
adapter.notifyItemRangeChanged(
firstItem,
lastItem + 1,
bundleOf(Pair("checkSourceMessage", null))
)
}
}
if (!it) {
this.cancel()
}
@ -532,7 +555,8 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
* 保持亮屏
*/
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) {
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() {
binding.selectActionBar
.upCountView(adapter.selection.size, adapter.itemCount)

Loading…
Cancel
Save