Просмотр исходного кода

Merge pull request #1783 from fansangg/fix/bugfix

fix:一些bug修复
Kudomaga 3 месяцев назад
Родитель
Сommit
a6f8a37cde

+ 24 - 13
app/src/main/java/io/legado/app/ui/book/changesource/ChangeChapterSourceViewModel.kt

@@ -18,7 +18,9 @@ import kotlinx.coroutines.flow.MutableStateFlow
 import kotlinx.coroutines.flow.asSharedFlow
 import kotlinx.coroutines.flow.asSharedFlow
 import kotlinx.coroutines.flow.asStateFlow
 import kotlinx.coroutines.flow.asStateFlow
 import kotlinx.coroutines.flow.update
 import kotlinx.coroutines.flow.update
+import kotlinx.coroutines.Dispatchers
 import kotlinx.coroutines.launch
 import kotlinx.coroutines.launch
+import kotlinx.coroutines.withContext
 
 
 class ChangeChapterSourceViewModel(
 class ChangeChapterSourceViewModel(
     private val changeSourceSearchUseCase: ChangeSourceSearchUseCase,
     private val changeSourceSearchUseCase: ChangeSourceSearchUseCase,
@@ -85,7 +87,9 @@ class ChangeChapterSourceViewModel(
         }
         }
         if (searchJob?.isActive != true) {
         if (searchJob?.isActive != true) {
             viewModelScope.launch {
             viewModelScope.launch {
-                val dbBooks = getDbSearchBooks()
+                val dbBooks = withContext(Dispatchers.IO) {
+                    getDbSearchBooks()
+                }
                 if (dbBooks.isNotEmpty()) {
                 if (dbBooks.isNotEmpty()) {
                     searchResults.clear()
                     searchResults.clear()
                     searchResults.addAll(dbBooks)
                     searchResults.addAll(dbBooks)
@@ -330,15 +334,19 @@ class ChangeChapterSourceViewModel(
     }
     }
 
 
     private fun refreshResults() {
     private fun refreshResults() {
-        searchResults.clear()
-        bookMap.clear()
-        val dbBooks = getDbSearchBooks()
-        if (dbBooks.isNotEmpty()) {
-            searchResults.addAll(dbBooks)
-            searchResults.forEach { bookMap[it.primaryStr()] = it }
-            filterResults()
-        } else {
-            startSearch()
+        viewModelScope.launch {
+            val dbBooks = withContext(Dispatchers.IO) {
+                getDbSearchBooks()
+            }
+            searchResults.clear()
+            bookMap.clear()
+            if (dbBooks.isNotEmpty()) {
+                searchResults.addAll(dbBooks)
+                searchResults.forEach { bookMap[it.primaryStr()] = it }
+                filterResults()
+            } else {
+                startSearch()
+            }
         }
         }
     }
     }
 
 
@@ -387,7 +395,9 @@ class ChangeChapterSourceViewModel(
         }
         }
         viewModelScope.launch {
         viewModelScope.launch {
             try {
             try {
-                val (toc, _) = getChapterContentUseCase.getToc(book)
+                val (toc, _) = withContext(Dispatchers.IO) {
+                    getChapterContentUseCase.getToc(book)
+                }
                 val currentTocIndex = getChapterContentUseCase.getDurChapterIndex(
                 val currentTocIndex = getChapterContentUseCase.getDurChapterIndex(
                     chapterIndex = chapterIndex,
                     chapterIndex = chapterIndex,
                     chapterTitle = chapterTitle,
                     chapterTitle = chapterTitle,
@@ -401,7 +411,7 @@ class ChangeChapterSourceViewModel(
                         currentTocIndex = currentTocIndex,
                         currentTocIndex = currentTocIndex,
                     )
                     )
                 }
                 }
-            } catch (e: Exception) {
+            } catch (_: Exception) {
                 _uiState.update {
                 _uiState.update {
                     it.copy(
                     it.copy(
                         showToc = false,
                         showToc = false,
@@ -426,8 +436,9 @@ class ChangeChapterSourceViewModel(
                 val searchBook = selectedSearchBook.toBook()
                 val searchBook = selectedSearchBook.toBook()
                 val toc = _uiState.value.tocItems
                 val toc = _uiState.value.tocItems
                 val nextChapterUrl = toc.getOrNull(chapter.index + 1)?.url
                 val nextChapterUrl = toc.getOrNull(chapter.index + 1)?.url
-                val content =
+                val content = withContext(Dispatchers.IO) {
                     getChapterContentUseCase.getContent(searchBook, chapter, nextChapterUrl)
                     getChapterContentUseCase.getContent(searchBook, chapter, nextChapterUrl)
+                }
                 _uiState.update { it.copy(isLoadingToc = false) }
                 _uiState.update { it.copy(isLoadingToc = false) }
                 _effects.tryEmit(ChangeChapterSourceEffect.ReplaceContent(content))
                 _effects.tryEmit(ChangeChapterSourceEffect.ReplaceContent(content))
                 _effects.tryEmit(ChangeChapterSourceEffect.Dismiss)
                 _effects.tryEmit(ChangeChapterSourceEffect.Dismiss)

+ 1 - 0
app/src/main/java/io/legado/app/ui/book/info/BookInfoContract.kt

@@ -60,6 +60,7 @@ data class BookInfoBookUi(
     val latestChapterTitle: String?,
     val latestChapterTitle: String?,
     val totalChapterNum: Int,
     val totalChapterNum: Int,
     val durChapterIndex: Int,
     val durChapterIndex: Int,
+    val durChapterPos: Int,
     val remark: String?,
     val remark: String?,
     val displayIntro: String?,
     val displayIntro: String?,
 )
 )

+ 5 - 1
app/src/main/java/io/legado/app/ui/book/info/BookInfoScreen.kt

@@ -1129,7 +1129,11 @@ private fun BookInfoSummary(
                 color = LegadoTheme.colorScheme.secondary
                 color = LegadoTheme.colorScheme.secondary
             )
             )
             AnimatedTextLine(
             AnimatedTextLine(
-                text = if (book.durChapterIndex + 1 == book.totalChapterNum && book.totalChapterNum > 0) "已读完" else stringResource(R.string.read_chapter_index, book.durChapterIndex + 1),
+                text = when {
+                    book.durChapterIndex == 0 && book.durChapterPos == 0 -> stringResource(R.string.is_unread)
+                    book.durChapterIndex + 1 == book.totalChapterNum && book.totalChapterNum > 0 -> "已读完"
+                    else -> stringResource(R.string.read_chapter_index, book.durChapterIndex + 1)
+                },
                 style = LegadoTheme.typography.labelMedium,
                 style = LegadoTheme.typography.labelMedium,
                 color = LegadoTheme.colorScheme.secondary,
                 color = LegadoTheme.colorScheme.secondary,
             )
             )

+ 3 - 1
app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt

@@ -176,7 +176,8 @@ class BookInfoViewModel(
         origin: String? = null,
         origin: String? = null,
         coverPath: String? = null
         coverPath: String? = null
     ) {
     ) {
-        if (currentBook?.bookUrl == bookUrl) return
+        val current = currentBook
+        if (current != null) return
         _uiState.value = BookInfoUiState() // 立即重置 UI 状态
         _uiState.value = BookInfoUiState() // 立即重置 UI 状态
         currentBook = if (!name.isNullOrBlank() && !author.isNullOrBlank()) {
         currentBook = if (!name.isNullOrBlank() && !author.isNullOrBlank()) {
             Book(
             Book(
@@ -1517,6 +1518,7 @@ class BookInfoViewModel(
             latestChapterTitle = latestChapterTitle,
             latestChapterTitle = latestChapterTitle,
             totalChapterNum = totalChapterNum,
             totalChapterNum = totalChapterNum,
             durChapterIndex = durChapterIndex,
             durChapterIndex = durChapterIndex,
+            durChapterPos = durChapterPos,
             remark = remark,
             remark = remark,
             displayIntro = getDisplayIntro(),
             displayIntro = getDisplayIntro(),
         )
         )

+ 2 - 2
app/src/main/java/io/legado/app/ui/book/read/ReadBookMenuBar.kt

@@ -1675,7 +1675,7 @@ private fun MenuTitleBarMergedGlassButton(
             ) { dismiss ->
             ) { dismiss ->
                 RoundDropdownMenuItem(
                 RoundDropdownMenuItem(
                     text = stringResource(R.string.change_origin),
                     text = stringResource(R.string.change_origin),
-                    onClick = { dismiss(); onIntent(ReadBookIntent.MenuChangeSource) },
+                    onClick = { dismiss(); onIntent(ReadBookIntent.MenuBookChangeSource) },
                 )
                 )
                 RoundDropdownMenuItem(
                 RoundDropdownMenuItem(
                     text = stringResource(R.string.chapter_change_source),
                     text = stringResource(R.string.chapter_change_source),
@@ -1733,7 +1733,7 @@ private fun SourceActionButton(
         ) { dismiss ->
         ) { dismiss ->
             RoundDropdownMenuItem(
             RoundDropdownMenuItem(
                 text = stringResource(R.string.change_origin),
                 text = stringResource(R.string.change_origin),
-                onClick = { dismiss(); onIntent(ReadBookIntent.MenuChangeSource) },
+                onClick = { dismiss(); onIntent(ReadBookIntent.MenuBookChangeSource) },
             )
             )
             RoundDropdownMenuItem(
             RoundDropdownMenuItem(
                 text = stringResource(R.string.chapter_change_source),
                 text = stringResource(R.string.chapter_change_source),

+ 1 - 1
app/src/main/java/io/legado/app/ui/widget/components/log/AppLogSheet.kt

@@ -59,7 +59,7 @@ fun AppLogSheet(
         }
         }
     ) {
     ) {
         if (logs.isEmpty()) {
         if (logs.isEmpty()) {
-            EmptyMessage(message = stringResource(R.string.no_logs))
+            EmptyMessage(modifier = Modifier.fillMaxWidth(),message = stringResource(R.string.no_logs))
         } else {
         } else {
             LazyColumn(
             LazyColumn(
                 modifier = Modifier.fillMaxWidth(),
                 modifier = Modifier.fillMaxWidth(),