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