This commit is contained in:
Horis
2025-11-12 08:40:12 +08:00
parent 476d2a04fd
commit 2300510319
13 changed files with 42 additions and 13 deletions
@@ -142,7 +142,7 @@ internal class AndroidAlertBuilder(override val ctx: Context) : AlertBuilder<Ale
} }
override fun build(): AlertDialog { override fun build(): AlertDialog {
var dialog = builder.create() val dialog = builder.create()
if (AppConfig.isEInkMode) { if (AppConfig.isEInkMode) {
dialog.window?.run { dialog.window?.run {
val attr = attributes val attr = attributes
@@ -156,7 +156,7 @@ internal class AndroidAlertBuilder(override val ctx: Context) : AlertBuilder<Ale
} }
override fun show(): AlertDialog { override fun show(): AlertDialog {
var dialog = builder.show().applyTint() val dialog = builder.show().applyTint()
if (AppConfig.isEInkMode) { if (AppConfig.isEInkMode) {
dialog.window?.run { dialog.window?.run {
val attr = attributes val attr = attributes
@@ -221,9 +221,9 @@ object ReadBook : CoroutineScope by MainScope() {
} }
fun clearTextChapter() { fun clearTextChapter() {
prevTextChapter?.cancelLayout() prevChapterLoadingJob?.cancel()
curTextChapter?.cancelLayout() curChapterLoadingJob?.cancel()
nextTextChapter?.cancelLayout() nextChapterLoadingJob?.cancel()
prevTextChapter = null prevTextChapter = null
curTextChapter = null curTextChapter = null
nextTextChapter = null nextTextChapter = null
@@ -336,7 +336,7 @@ object ReadBook : CoroutineScope by MainScope() {
if (durChapterIndex < simulatedChapterSize - 1) { if (durChapterIndex < simulatedChapterSize - 1) {
durChapterPos = 0 durChapterPos = 0
durChapterIndex++ durChapterIndex++
prevTextChapter?.cancelLayout() prevChapterLoadingJob?.cancel()
prevTextChapter = curTextChapter prevTextChapter = curTextChapter
curTextChapter = nextTextChapter curTextChapter = nextTextChapter
nextTextChapter = null nextTextChapter = null
@@ -367,7 +367,7 @@ object ReadBook : CoroutineScope by MainScope() {
if (durChapterIndex < simulatedChapterSize - 1) { if (durChapterIndex < simulatedChapterSize - 1) {
durChapterPos = 0 durChapterPos = 0
durChapterIndex++ durChapterIndex++
prevTextChapter?.cancelLayout() prevChapterLoadingJob?.cancel()
prevTextChapter = curTextChapter prevTextChapter = curTextChapter
curTextChapter = nextTextChapter curTextChapter = nextTextChapter
nextTextChapter = null nextTextChapter = null
@@ -718,6 +718,7 @@ object ReadBook : CoroutineScope by MainScope() {
when (offset) { when (offset) {
0 -> curChapterLoadingLock.withLock { 0 -> curChapterLoadingLock.withLock {
withContext(Main) { withContext(Main) {
ensureActive()
curTextChapter = textChapter curTextChapter = textChapter
} }
callBack?.upMenuView() callBack?.upMenuView()
@@ -744,6 +745,7 @@ object ReadBook : CoroutineScope by MainScope() {
-1 -> prevChapterLoadingLock.withLock { -1 -> prevChapterLoadingLock.withLock {
withContext(Main) { withContext(Main) {
ensureActive()
prevTextChapter = textChapter prevTextChapter = textChapter
} }
textChapter.layoutChannel.receiveAsFlow().collect() textChapter.layoutChannel.receiveAsFlow().collect()
@@ -752,6 +754,7 @@ object ReadBook : CoroutineScope by MainScope() {
1 -> nextChapterLoadingLock.withLock { 1 -> nextChapterLoadingLock.withLock {
withContext(Main) { withContext(Main) {
ensureActive()
nextTextChapter = textChapter nextTextChapter = textChapter
} }
for (page in textChapter.layoutChannel) { for (page in textChapter.layoutChannel) {
@@ -172,7 +172,7 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
when (item.itemId) { when (item.itemId) {
R.id.menu_download, R.id.menu_download,
R.id.menu_download_after -> { R.id.menu_download_after -> {
if (!CacheBook.isRun) { if (!CacheBook.isRun) sureCacheBook {
adapter.getItems().forEach { book -> adapter.getItems().forEach { book ->
CacheBook.start( CacheBook.start(
this@CacheActivity, this@CacheActivity,
@@ -187,7 +187,7 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
} }
R.id.menu_download_all -> { R.id.menu_download_all -> {
if (!CacheBook.isRun) { if (!CacheBook.isRun) sureCacheBook {
adapter.getItems().forEach { book -> adapter.getItems().forEach { book ->
CacheBook.start( CacheBook.start(
this@CacheActivity, this@CacheActivity,
@@ -555,6 +555,16 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
} }
} }
private fun sureCacheBook(action: () -> Unit) {
alert(R.string.draw) {
setMessage(R.string.sure_cache_book)
noButton()
yesButton {
action.invoke()
}
}
}
override val cacheChapters: HashMap<String, HashSet<String>> override val cacheChapters: HashMap<String, HashSet<String>>
get() = viewModel.cacheChapters get() = viewModel.cacheChapters
@@ -29,7 +29,9 @@ import io.legado.app.utils.onEachParallel
import io.legado.app.utils.postEvent import io.legado.app.utils.postEvent
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
import kotlinx.coroutines.asCoroutineDispatcher import kotlinx.coroutines.asCoroutineDispatcher
import kotlinx.coroutines.currentCoroutineContext
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.ensureActive
import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flow
@@ -175,6 +177,7 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
ReadBook.onChapterListUpdated(book) ReadBook.onChapterListUpdated(book)
addDownload(source, book) addDownload(source, book)
}.onFailure { }.onFailure {
currentCoroutineContext().ensureActive()
AppLog.put("${book.name} 更新目录失败\n${it.localizedMessage}", it) AppLog.put("${book.name} 更新目录失败\n${it.localizedMessage}", it)
//这里可能因为时间太长书籍信息已经更改,所以重新获取 //这里可能因为时间太长书籍信息已经更改,所以重新获取
appDb.bookDao.getBook(book.bookUrl)?.let { book -> appDb.bookDao.getBook(book.bookUrl)?.let { book ->
@@ -3,7 +3,7 @@ package io.legado.app.ui.widget.recycler
import android.content.Context import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.ViewGroup import android.view.View
import android.widget.FrameLayout import android.widget.FrameLayout
import androidx.annotation.ColorRes import androidx.annotation.ColorRes
import io.legado.app.R import io.legado.app.R
@@ -28,7 +28,7 @@ class LoadMoreView(context: Context, attrs: AttributeSet? = null) : FrameLayout(
init { init {
super.setOnClickListener { super.setOnClickListener {
if (!showErrorDialog()) { if (!showErrorDialog(it)) {
onClickListener?.onClick(it) onClickListener?.onClick(it)
} }
} }
@@ -40,7 +40,7 @@ class LoadMoreView(context: Context, attrs: AttributeSet? = null) : FrameLayout(
override fun onAttachedToWindow() { override fun onAttachedToWindow() {
super.onAttachedToWindow() super.onAttachedToWindow()
layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT layoutParams.width = LayoutParams.MATCH_PARENT
} }
fun startLoad() { fun startLoad() {
@@ -89,12 +89,17 @@ class LoadMoreView(context: Context, attrs: AttributeSet? = null) : FrameLayout(
binding.tvText.setTextColor(context.getCompatColor(color)) binding.tvText.setTextColor(context.getCompatColor(color))
} }
private fun showErrorDialog(): Boolean { private fun showErrorDialog(view: View): Boolean {
if (errorMsg.isBlank()) { if (errorMsg.isBlank()) {
return false return false
} }
context.alert(R.string.error) { context.alert(R.string.error) {
setMessage(errorMsg) setMessage(errorMsg)
if (onClickListener != null) {
neutralButton(R.string.retry) {
onClickListener?.onClick(view)
}
}
} }
return true return true
} }
@@ -1221,4 +1221,5 @@
<string name="manga_epaper_value">阈值</string> <string name="manga_epaper_value">阈值</string>
<string name="disable_horizontal_animation">禁用水平滚动动画</string> <string name="disable_horizontal_animation">禁用水平滚动动画</string>
<string name="enable_manga_gray">开启图片灰色</string> <string name="enable_manga_gray">开启图片灰色</string>
<string name="sure_cache_book">是否确认开始缓存?</string>
</resources> </resources>
@@ -1224,4 +1224,5 @@
<string name="manga_epaper_value">阈值</string> <string name="manga_epaper_value">阈值</string>
<string name="disable_horizontal_animation">禁用水平滚动动画</string> <string name="disable_horizontal_animation">禁用水平滚动动画</string>
<string name="enable_manga_gray">开启图片灰色</string> <string name="enable_manga_gray">开启图片灰色</string>
<string name="sure_cache_book">是否确认开始缓存?</string>
</resources> </resources>
@@ -1224,4 +1224,5 @@
<string name="manga_epaper_value">阈值</string> <string name="manga_epaper_value">阈值</string>
<string name="disable_horizontal_animation">禁用水平滚动动画</string> <string name="disable_horizontal_animation">禁用水平滚动动画</string>
<string name="enable_manga_gray">开启图片灰色</string> <string name="enable_manga_gray">开启图片灰色</string>
<string name="sure_cache_book">是否确认开始缓存?</string>
</resources> </resources>
+1
View File
@@ -1215,4 +1215,5 @@
<string name="disable_horizontal_animation">Tắt hoạt ảnh cuộn ngang</string> <string name="disable_horizontal_animation">Tắt hoạt ảnh cuộn ngang</string>
<string name="enable_manga_gray">Bật ảnh xám</string> <string name="enable_manga_gray">Bật ảnh xám</string>
<string name="play_mode">Chế độ phát</string> <string name="play_mode">Chế độ phát</string>
<string name="sure_cache_book">是否确认开始缓存?</string>
</resources> </resources>
@@ -1219,4 +1219,5 @@
<string name="manga_epaper_value">阈值</string> <string name="manga_epaper_value">阈值</string>
<string name="disable_horizontal_animation">禁用水平滚动动画</string> <string name="disable_horizontal_animation">禁用水平滚动动画</string>
<string name="enable_manga_gray">开启图片灰色</string> <string name="enable_manga_gray">开启图片灰色</string>
<string name="sure_cache_book">是否确认开始缓存?</string>
</resources> </resources>
@@ -1220,4 +1220,5 @@
<string name="manga_epaper_value">阈值</string> <string name="manga_epaper_value">阈值</string>
<string name="disable_horizontal_animation">禁用水平滚动动画</string> <string name="disable_horizontal_animation">禁用水平滚动动画</string>
<string name="enable_manga_gray">开启图片灰色</string> <string name="enable_manga_gray">开启图片灰色</string>
<string name="sure_cache_book">是否确认开始缓存?</string>
</resources> </resources>
+1
View File
@@ -1226,4 +1226,5 @@
<string name="manga_epaper_value">阈值</string> <string name="manga_epaper_value">阈值</string>
<string name="disable_horizontal_animation">禁用水平滚动动画</string> <string name="disable_horizontal_animation">禁用水平滚动动画</string>
<string name="enable_manga_gray">开启图片灰色</string> <string name="enable_manga_gray">开启图片灰色</string>
<string name="sure_cache_book">是否确认开始缓存?</string>
</resources> </resources>
+1
View File
@@ -1228,4 +1228,5 @@
<string name="disable_horizontal_animation">禁用水平滚动动画</string> <string name="disable_horizontal_animation">禁用水平滚动动画</string>
<string name="enable_manga_gray">开启图片灰色</string> <string name="enable_manga_gray">开启图片灰色</string>
<string name="play_mode">播放模式</string> <string name="play_mode">播放模式</string>
<string name="sure_cache_book">是否确认开始缓存?</string>
</resources> </resources>