From d172062c00f0fed8feb621c5e92a85f731dbd244 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 10 Jul 2021 17:29:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/help/coroutine/Coroutine.kt | 4 ++++ .../main/java/io/legado/app/service/help/ReadBook.kt | 12 ++++++------ .../legado/app/ui/book/search/HistoryKeyAdapter.kt | 9 ++------- .../io/legado/app/ui/book/search/SearchActivity.kt | 4 ++++ .../io/legado/app/ui/book/search/SearchViewModel.kt | 4 ++++ .../main/java/io/legado/app/ui/dict/DictDialog.kt | 7 ++++++- 6 files changed, 26 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt b/app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt index 6cb5892b5..1577e6bda 100644 --- a/app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt +++ b/app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt @@ -24,6 +24,10 @@ class Coroutine( return Coroutine(scope, context, block) } + fun cancel() { + DEFAULT.cancel() + } + } private val job: Job diff --git a/app/src/main/java/io/legado/app/service/help/ReadBook.kt b/app/src/main/java/io/legado/app/service/help/ReadBook.kt index 31adc1e33..569f50430 100644 --- a/app/src/main/java/io/legado/app/service/help/ReadBook.kt +++ b/app/src/main/java/io/legado/app/service/help/ReadBook.kt @@ -16,10 +16,7 @@ import io.legado.app.ui.book.read.page.provider.ChapterProvider import io.legado.app.ui.book.read.page.provider.ImageProvider import io.legado.app.utils.msg import io.legado.app.utils.toastOnUi -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.delay -import kotlinx.coroutines.launch import splitties.init.appCtx import kotlin.math.max import kotlin.math.min @@ -139,7 +136,7 @@ object ReadBook { callBack?.upContent() } loadContent(durChapterIndex.plus(1), upContent, false) - GlobalScope.launch(Dispatchers.IO) { + Coroutine.async { val maxChapterIndex = min(chapterSize - 1, durChapterIndex + AppConfig.preDownloadNum) for (i in durChapterIndex.plus(2)..maxChapterIndex) { @@ -157,7 +154,10 @@ object ReadBook { } } - fun moveToPrevChapter(upContent: Boolean, toLast: Boolean = true): Boolean { + fun moveToPrevChapter( + upContent: Boolean, + toLast: Boolean = true + ): Boolean { if (durChapterIndex > 0) { durChapterPos = if (toLast) prevTextChapter?.lastReadLength ?: 0 else 0 durChapterIndex-- @@ -171,7 +171,7 @@ object ReadBook { callBack?.upContent() } loadContent(durChapterIndex.minus(1), upContent, false) - GlobalScope.launch(Dispatchers.IO) { + Coroutine.async { val minChapterIndex = max(0, durChapterIndex - 5) for (i in durChapterIndex.minus(2) downTo minChapterIndex) { delay(1000) diff --git a/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt b/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt index 660410c44..f7bbd8297 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt @@ -3,13 +3,9 @@ package io.legado.app.ui.book.search import android.view.ViewGroup import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.RecyclerAdapter -import io.legado.app.data.appDb import io.legado.app.data.entities.SearchKeyword import io.legado.app.databinding.ItemFilletTextBinding import io.legado.app.ui.widget.anima.explosion_field.ExplosionField -import kotlinx.coroutines.Dispatchers.IO -import kotlinx.coroutines.GlobalScope -import kotlinx.coroutines.launch import splitties.views.onLongClick class HistoryKeyAdapter(activity: SearchActivity, val callBack: CallBack) : @@ -42,9 +38,7 @@ class HistoryKeyAdapter(activity: SearchActivity, val callBack: CallBack) : onLongClick { explosionField.explode(this, true) getItem(holder.layoutPosition)?.let { - GlobalScope.launch(IO) { - appDb.searchKeywordDao.delete(it) - } + callBack.deleteHistory(it) } } } @@ -52,5 +46,6 @@ class HistoryKeyAdapter(activity: SearchActivity, val callBack: CallBack) : interface CallBack { fun searchHistory(key: String) + fun deleteHistory(searchKeyword: SearchKeyword) } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt index 8d6da964f..03f1deb8e 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt @@ -366,4 +366,8 @@ class SearchActivity : VMBaseActivity= Build.VERSION_CODES.N) { + binding.tvDict.text = Html.fromHtml(it, Html.FROM_HTML_MODE_LEGACY) + } else { + binding.tvDict.text = Html.fromHtml(it) + } } viewModel.dict(word)