pull/1114/head
gedoor 3 years ago
parent 4adff555b9
commit d172062c00
  1. 4
      app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt
  2. 12
      app/src/main/java/io/legado/app/service/help/ReadBook.kt
  3. 9
      app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt
  4. 4
      app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt
  5. 4
      app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt
  6. 5
      app/src/main/java/io/legado/app/ui/dict/DictDialog.kt

@ -24,6 +24,10 @@ class Coroutine<T>(
return Coroutine(scope, context, block) return Coroutine(scope, context, block)
} }
fun cancel() {
DEFAULT.cancel()
}
} }
private val job: Job private val job: Job

@ -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.ui.book.read.page.provider.ImageProvider
import io.legado.app.utils.msg import io.legado.app.utils.msg
import io.legado.app.utils.toastOnUi import io.legado.app.utils.toastOnUi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import splitties.init.appCtx import splitties.init.appCtx
import kotlin.math.max import kotlin.math.max
import kotlin.math.min import kotlin.math.min
@ -139,7 +136,7 @@ object ReadBook {
callBack?.upContent() callBack?.upContent()
} }
loadContent(durChapterIndex.plus(1), upContent, false) loadContent(durChapterIndex.plus(1), upContent, false)
GlobalScope.launch(Dispatchers.IO) { Coroutine.async {
val maxChapterIndex = val maxChapterIndex =
min(chapterSize - 1, durChapterIndex + AppConfig.preDownloadNum) min(chapterSize - 1, durChapterIndex + AppConfig.preDownloadNum)
for (i in durChapterIndex.plus(2)..maxChapterIndex) { 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) { if (durChapterIndex > 0) {
durChapterPos = if (toLast) prevTextChapter?.lastReadLength ?: 0 else 0 durChapterPos = if (toLast) prevTextChapter?.lastReadLength ?: 0 else 0
durChapterIndex-- durChapterIndex--
@ -171,7 +171,7 @@ object ReadBook {
callBack?.upContent() callBack?.upContent()
} }
loadContent(durChapterIndex.minus(1), upContent, false) loadContent(durChapterIndex.minus(1), upContent, false)
GlobalScope.launch(Dispatchers.IO) { Coroutine.async {
val minChapterIndex = max(0, durChapterIndex - 5) val minChapterIndex = max(0, durChapterIndex - 5)
for (i in durChapterIndex.minus(2) downTo minChapterIndex) { for (i in durChapterIndex.minus(2) downTo minChapterIndex) {
delay(1000) delay(1000)

@ -3,13 +3,9 @@ package io.legado.app.ui.book.search
import android.view.ViewGroup import android.view.ViewGroup
import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.RecyclerAdapter import io.legado.app.base.adapter.RecyclerAdapter
import io.legado.app.data.appDb
import io.legado.app.data.entities.SearchKeyword import io.legado.app.data.entities.SearchKeyword
import io.legado.app.databinding.ItemFilletTextBinding import io.legado.app.databinding.ItemFilletTextBinding
import io.legado.app.ui.widget.anima.explosion_field.ExplosionField 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 import splitties.views.onLongClick
class HistoryKeyAdapter(activity: SearchActivity, val callBack: CallBack) : class HistoryKeyAdapter(activity: SearchActivity, val callBack: CallBack) :
@ -42,9 +38,7 @@ class HistoryKeyAdapter(activity: SearchActivity, val callBack: CallBack) :
onLongClick { onLongClick {
explosionField.explode(this, true) explosionField.explode(this, true)
getItem(holder.layoutPosition)?.let { getItem(holder.layoutPosition)?.let {
GlobalScope.launch(IO) { callBack.deleteHistory(it)
appDb.searchKeywordDao.delete(it)
}
} }
} }
} }
@ -52,5 +46,6 @@ class HistoryKeyAdapter(activity: SearchActivity, val callBack: CallBack) :
interface CallBack { interface CallBack {
fun searchHistory(key: String) fun searchHistory(key: String)
fun deleteHistory(searchKeyword: SearchKeyword)
} }
} }

@ -366,4 +366,8 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
} }
} }
} }
override fun deleteHistory(searchKeyword: SearchKeyword) {
viewModel.deleteHistory(searchKeyword)
}
} }

@ -186,6 +186,10 @@ class SearchViewModel(application: Application) : BaseViewModel(application),
} }
} }
fun deleteHistory(searchKeyword: SearchKeyword) {
appDb.searchKeywordDao.delete(searchKeyword)
}
override fun onCleared() { override fun onCleared() {
super.onCleared() super.onCleared()
searchBookModel.close() searchBookModel.close()

@ -1,5 +1,6 @@
package io.legado.app.ui.dict package io.legado.app.ui.dict
import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.text.Html import android.text.Html
import android.text.method.LinkMovementMethod import android.text.method.LinkMovementMethod
@ -59,8 +60,12 @@ class DictDialog : BaseDialogFragment() {
} }
viewModel.dictHtmlData.observe(viewLifecycleOwner) { viewModel.dictHtmlData.observe(viewLifecycleOwner) {
binding.rotateLoading.invisible() binding.rotateLoading.invisible()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
binding.tvDict.text = Html.fromHtml(it, Html.FROM_HTML_MODE_LEGACY)
} else {
binding.tvDict.text = Html.fromHtml(it) binding.tvDict.text = Html.fromHtml(it)
} }
}
viewModel.dict(word) viewModel.dict(word)
} }

Loading…
Cancel
Save