fix the last source stop checking by itself

pull/1251/head
Jason Yao 3 years ago
parent d3bc69800d
commit 144f29f501
  1. 9
      app/src/main/java/io/legado/app/model/Debug.kt
  2. 8
      app/src/main/java/io/legado/app/service/CheckSourceService.kt
  3. 5
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt

@ -11,11 +11,9 @@ import io.legado.app.utils.HtmlFormatter
import io.legado.app.utils.isAbsUrl import io.legado.app.utils.isAbsUrl
import io.legado.app.utils.msg import io.legado.app.utils.msg
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.flow
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.* import java.util.*
import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.ConcurrentHashMap
import kotlin.collections.ArrayList
object Debug { object Debug {
var callback: Callback? = null var callback: Callback? = null
@ -48,10 +46,10 @@ object Debug {
printMsg = "$time $printMsg" printMsg = "$time $printMsg"
} }
it.printLog(state, printMsg) it.printLog(state, printMsg)
Log.d(EventBus.CHECK_SOURCE_MESSAGE, "debugMessage to filter $printMsg")
if (sourceUrl != null && printMsg.length < 30) { if (sourceUrl != null && printMsg.length < 30) {
debugMessageMap[sourceUrl] = printMsg debugMessageMap[sourceUrl] = printMsg
callback?.printCheckSourceMessage(sourceUrl, printMsg) callback?.printCheckSourceMessage(sourceUrl, printMsg)
Log.d(EventBus.CHECK_SOURCE_MESSAGE, "debugMessage after filter $printMsg")
} }
} }
} }
@ -76,6 +74,11 @@ object Debug {
debugMessageMap[source.bookSourceUrl] = "开始校验" debugMessageMap[source.bookSourceUrl] = "开始校验"
} }
fun finishChecking() {
callback = null
isChecking = false
}
fun startDebug(scope: CoroutineScope, rssSource: RssSource) { fun startDebug(scope: CoroutineScope, rssSource: RssSource) {
cancelDebug() cancelDebug()
debugSource = rssSource.sourceUrl debugSource = rssSource.sourceUrl

@ -37,7 +37,7 @@ class CheckSourceService : BaseService() {
@Synchronized @Synchronized
override fun printCheckSourceMessage(sourceUrl: String, msg: String) { override fun printCheckSourceMessage(sourceUrl: String, msg: String) {
postEvent(EventBus.CHECK_SOURCE_MESSAGE, Pair(sourceUrl, null)) postEvent(EventBus.CHECK_SOURCE_MESSAGE, Pair(sourceUrl, null))
Log.d(EventBus.CHECK_SOURCE_MESSAGE, "printCheckSourceMessage to post $msg") Log.d(EventBus.CHECK_SOURCE_MESSAGE, "printCheckSourceMessage to post $sourceUrl $msg")
} }
} }
private val notificationBuilder by lazy { private val notificationBuilder by lazy {
@ -77,8 +77,6 @@ class CheckSourceService : BaseService() {
super.onDestroy() super.onDestroy()
tasks.clear() tasks.clear()
searchCoroutine.close() searchCoroutine.close()
Debug.callback = null
Debug.isChecking = false
postEvent(EventBus.CHECK_SOURCE_DONE, 0) postEvent(EventBus.CHECK_SOURCE_DONE, 0)
} }
@ -112,7 +110,6 @@ class CheckSourceService : BaseService() {
if (index < allIds.size) { if (index < allIds.size) {
val sourceUrl = allIds[index] val sourceUrl = allIds[index]
appDb.bookSourceDao.getBookSource(sourceUrl)?.let { source -> appDb.bookSourceDao.getBookSource(sourceUrl)?.let { source ->
Debug.startChecking(source)
check(source) check(source)
} ?: onNext(sourceUrl, "") } ?: onNext(sourceUrl, "")
} }
@ -121,6 +118,7 @@ class CheckSourceService : BaseService() {
fun check(source: BookSource) { fun check(source: BookSource) {
execute(context = searchCoroutine) { execute(context = searchCoroutine) {
Debug.startChecking(source)
val webBook = WebBook(source) val webBook = WebBook(source)
var books = webBook.searchBookAwait(this, CheckSource.keyword) var books = webBook.searchBookAwait(this, CheckSource.keyword)
if (books.isEmpty()) { if (books.isEmpty()) {
@ -181,7 +179,7 @@ class CheckSourceService : BaseService() {
notificationMsg = notificationMsg =
getString(R.string.progress_show, sourceName, checkedIds.size, allIds.size) getString(R.string.progress_show, sourceName, checkedIds.size, allIds.size)
upNotification() upNotification()
if (processIndex >= allIds.size + threadCount - 1) { if (processIndex > allIds.size + threadCount - 1) {
stopSelf() stopSelf()
} }
} }

@ -440,6 +440,7 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
observeEvent<Int>(EventBus.CHECK_SOURCE_DONE) { observeEvent<Int>(EventBus.CHECK_SOURCE_DONE) {
adapter.notifyItemRangeChanged(0, adapter.itemCount, bundleOf(Pair("checkSourceDone", null))) adapter.notifyItemRangeChanged(0, adapter.itemCount, bundleOf(Pair("checkSourceDone", null)))
snackBar?.dismiss() snackBar?.dismiss()
Debug.finishChecking()
snackBar = null snackBar = null
// groups.map { group -> // groups.map { group ->
// if (group.contains("失效")) { // if (group.contains("失效")) {
@ -451,12 +452,10 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
observeEvent<Pair<String, String?>>(EventBus.CHECK_SOURCE_MESSAGE) { messagePair -> observeEvent<Pair<String, String?>>(EventBus.CHECK_SOURCE_MESSAGE) { messagePair ->
sourceFlowJob?.cancel() sourceFlowJob?.cancel()
sourceFlowJob = launch { sourceFlowJob = launch {
var index: Int = -1
appDb.bookSourceDao.flowSearch(messagePair.first) appDb.bookSourceDao.flowSearch(messagePair.first)
.map { adapter.getItems().indexOf(it[0]) } .map { adapter.getItems().indexOf(it[0]) }
.collect { .collect {
index = it adapter.notifyItemChanged(it, bundleOf(Pair(EventBus.CHECK_SOURCE_MESSAGE, messagePair.second))) }
adapter.notifyItemChanged(index, bundleOf(Pair(EventBus.CHECK_SOURCE_MESSAGE, messagePair.second))) }
} }

Loading…
Cancel
Save