snack bar 取消时更新信息

pull/1254/head
Jason Yao 3 years ago
parent 59c42c4506
commit 4e33e262ff
  1. 8
      app/src/main/java/io/legado/app/model/Debug.kt
  2. 5
      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
  4. 9
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt

@ -87,6 +87,14 @@ object Debug {
isChecking = false
}
fun updateFinalMessage(sourceUrl: String, state: String) {
if (debugTimeMap[sourceUrl] != null && debugMessageMap[sourceUrl] != null) {
val time = DEBUG_TIME_FORMAT.format(Date(System.currentTimeMillis() - debugTimeMap[sourceUrl]!!))
val originalMessage = debugMessageMap[sourceUrl]!!.substringAfter("] ")
debugMessageMap[sourceUrl] = "$time $originalMessage $state"
}
}
fun startDebug(scope: CoroutineScope, rssSource: RssSource) {
cancelDebug()
debugSource = rssSource.sourceUrl

@ -65,6 +65,7 @@ class CheckSourceService : BaseService() {
override fun onDestroy() {
super.onDestroy()
Debug.finishChecking()
tasks.clear()
searchCoroutine.close()
postEvent(EventBus.CHECK_SOURCE_DONE, 0)
@ -141,7 +142,7 @@ class CheckSourceService : BaseService() {
${source.bookSourceComment}"
""".trimIndent()
if (showCheckSourceMessage) {
Debug.debugMessageMap[source.bookSourceUrl] = Debug.debugMessageMap[source.bookSourceUrl] + " 失败"
Debug.updateFinalMessage(source.bookSourceUrl, "失败")
}
appDb.bookSourceDao.update(source)
}.onSuccess(searchCoroutine) {
@ -152,7 +153,7 @@ class CheckSourceService : BaseService() {
it.startsWith("error:")
}?.joinToString("\n")
if (showCheckSourceMessage) {
Debug.debugMessageMap[source.bookSourceUrl] = Debug.debugMessageMap[source.bookSourceUrl] + " 成功"
Debug.updateFinalMessage(source.bookSourceUrl, "成功")
}
appDb.bookSourceDao.update(source)
}.onFinally(searchCoroutine) {

@ -435,11 +435,14 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
.make(binding.root, msg, Snackbar.LENGTH_INDEFINITE)
.setAction(R.string.cancel) {
CheckSource.stop(this)
if (AppConfig.checkSourceMessage) {
Debug.finishChecking()
adapter.notifyItemRangeChanged(0, adapter.itemCount, bundleOf(Pair("checkSourceMessage", null)))
}
}.apply { show() }
}
}
observeEvent<Int>(EventBus.CHECK_SOURCE_DONE) {
Debug.finishChecking()
snackBar?.dismiss()
snackBar = null
groups.map { group ->

@ -118,11 +118,16 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
"checkSourceMessage" -> {
ivDebugText.text = Debug.debugMessageMap[item.bookSourceUrl] ?: ""
val isEmpty = ivDebugText.text.toString().isEmpty()
var isFinalMessage = ivDebugText.text.toString().contains(Regex("成功|失败"))
if (!isEmpty && !Debug.isChecking && !isFinalMessage){
Debug.updateFinalMessage(item.bookSourceUrl, "失败")
ivDebugText.text = Debug.debugMessageMap[item.bookSourceUrl] ?: ""
isFinalMessage = true
}
ivDebugText.visibility =
if (!isEmpty) View.VISIBLE else View.GONE
ivProgressBar.visibility =
if (ivDebugText.text.toString().contains(Regex("成功|失败")) || isEmpty) View.GONE
else View.VISIBLE
if (isFinalMessage || isEmpty) View.GONE else View.VISIBLE
}
}
}

Loading…
Cancel
Save