fix the last source stop checking by itself

pull/1251/head
Jason Yao 3 years ago
parent 3539c118e2
commit dee96f874f
  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.msg
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.flow
import java.text.SimpleDateFormat
import java.util.*
import java.util.concurrent.ConcurrentHashMap
import kotlin.collections.ArrayList
object Debug {
var callback: Callback? = null
@ -48,10 +46,10 @@ object Debug {
printMsg = "$time $printMsg"
}
it.printLog(state, printMsg)
Log.d(EventBus.CHECK_SOURCE_MESSAGE, "debugMessage to filter $printMsg")
if (sourceUrl != null && printMsg.length < 30) {
debugMessageMap[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] = "开始校验"
}
fun finishChecking() {
callback = null
isChecking = false
}
fun startDebug(scope: CoroutineScope, rssSource: RssSource) {
cancelDebug()
debugSource = rssSource.sourceUrl

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

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

Loading…
Cancel
Save