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)
}
fun cancel() {
DEFAULT.cancel()
}
}
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.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)

@ -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)
}
}

@ -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() {
super.onCleared()
searchBookModel.close()

@ -1,5 +1,6 @@
package io.legado.app.ui.dict
import android.os.Build
import android.os.Bundle
import android.text.Html
import android.text.method.LinkMovementMethod
@ -59,8 +60,12 @@ class DictDialog : BaseDialogFragment() {
}
viewModel.dictHtmlData.observe(viewLifecycleOwner) {
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)
}
}
viewModel.dict(word)
}

Loading…
Cancel
Save