Quellcode durchsuchen

本地书籍界面点击阅读

Xwite vor 3 Jahren
Ursprung
Commit
aecc483902

+ 31 - 0
app/src/main/java/io/legado/app/ui/book/import/BaseImportBookActivity.kt

@@ -8,8 +8,11 @@ import androidx.lifecycle.ViewModel
 import io.legado.app.R
 import io.legado.app.base.VMBaseActivity
 import io.legado.app.databinding.ActivityImportBookBinding
+import io.legado.app.data.appDb
+import io.legado.app.constant.AppPattern
 import io.legado.app.help.config.AppConfig
 import io.legado.app.lib.dialogs.alert
+import io.legado.app.lib.dialogs.selector
 import io.legado.app.lib.theme.primaryTextColor
 import io.legado.app.ui.book.read.ReadBookActivity
 import io.legado.app.ui.document.HandleFileContract
@@ -90,6 +93,34 @@ abstract class BaseImportBookActivity<VM : ViewModel> : VMBaseActivity<ActivityI
         }
     }
 
+    protected fun onArchiveFileClick(fileDoc: FileDoc) {
+        val fileNames = ArchiveUtils.getArchiveFilesName(fileDoc) {
+            it.matches(AppPattern.bookFileRegex)
+        }
+        if (fileNames.size == 1) {
+            appDb.bookDao.getBookByFileName(fileNames[0])?.let {
+                startReadBook(it.bookUrl)
+            } ?: toastOnUi(R.string.no_book_found_bookshelf)
+        } else {
+            showSelectBookReadAlert(fileNames)
+        }
+    }
+
+    private fun showSelectBookReadAlert(fileNames: List<String>) {
+        if (fileNames.isEmpty()) {
+            toastOnUi(R.string.unsupport_archivefile_entry)
+            return
+        }
+        selector(
+            R.string.start_read
+            fileNames
+        ) { _, name, _ ->
+            appDb.bookDao.getBookByFileName(name)?.let {
+                startReadBook(it.bookUrl)
+            } ?: toastOnUi(R.string.no_book_found_bookshelf)
+        }
+    }
+
     private fun initSearchView() {
         searchView.applyTint(primaryTextColor)
         searchView.onActionViewExpanded()

+ 1 - 11
app/src/main/java/io/legado/app/ui/book/import/local/ImportBookActivity.kt

@@ -11,7 +11,6 @@ import androidx.documentfile.provider.DocumentFile
 import androidx.recyclerview.widget.LinearLayoutManager
 import io.legado.app.R
 import io.legado.app.constant.AppConst
-import io.legado.app.constant.AppPattern
 import io.legado.app.constant.PreferKey
 import io.legado.app.data.appDb
 import io.legado.app.databinding.DialogEditTextBinding
@@ -305,16 +304,7 @@ class ImportBookActivity : BaseImportBookActivity<ImportBookViewModel>(),
         if (!ArchiveUtils.isArchive(fileDoc.name)) {
             startReadBook(fileDoc.toString())
         } else {
-            val fileNames = ArchiveUtils.getArchiveFilesName(fileDoc) {
-                it.matches(AppPattern.bookFileRegex)
-            }
-            if (fileNames.size == 1) {
-                appDb.bookDao.getBookByFileName(fileNames[0])?.let {
-                    startReadBook(it.bookUrl)
-                }
-            } else {
-                //onArchiveFileClick(fileNames)
-            }
+            onArchiveFileClick(fileDoc)
         }
     }
 

+ 1 - 0
app/src/main/res/values-es-rES/strings.xml

@@ -1083,4 +1083,5 @@
     <string name="unsupport_archivefile_entry">Cannot find supported files in archive</string>
     <string name="no_books_dir">没有设置书籍保存位置!</string>
     <string name="delete_alert">删除提醒</string>
+    <string name="no_book_found_bookshelf">No book found in bookshelf</string>
 </resources>

+ 1 - 0
app/src/main/res/values-ja-rJP/strings.xml

@@ -1086,4 +1086,5 @@
     <string name="unsupport_archivefile_entry">Cannot find supported files in archive</string>
     <string name="no_books_dir">没有设置书籍保存位置!</string>
     <string name="delete_alert">删除提醒</string>
+    <string name="no_book_found_bookshelf">No book found in bookshelf</string>
 </resources>

+ 1 - 0
app/src/main/res/values-pt-rBR/strings.xml

@@ -1086,4 +1086,5 @@
     <string name="unsupport_archivefile_entry">Cannot find supported files in archive</string>
     <string name="no_books_dir">没有设置书籍保存位置!</string>
     <string name="delete_alert">删除提醒</string>
+    <string name="no_book_found_bookshelf">No book found in bookshelf</string>
 </resources>

+ 1 - 0
app/src/main/res/values-zh-rHK/strings.xml

@@ -1083,4 +1083,5 @@
     <string name="unsupport_archivefile_entry">压缩文件内没有支持的文件</string>
     <string name="no_books_dir">没有设置书籍保存位置!</string>
     <string name="delete_alert">删除提醒</string>
+    <string name="no_book_found_bookshelf">未在书架上找到所选书籍</string>
 </resources>

+ 1 - 0
app/src/main/res/values-zh-rTW/strings.xml

@@ -1085,4 +1085,5 @@
     <string name="unsupport_archivefile_entry">压缩文件内没有支持的文件</string>
     <string name="no_books_dir">没有设置书籍保存位置!</string>
     <string name="delete_alert">删除提醒</string>
+    <string name="no_book_found_bookshelf">未在书架上找到所选书籍</string>
 </resources>

+ 1 - 0
app/src/main/res/values-zh/strings.xml

@@ -1085,4 +1085,5 @@
     <string name="unsupport_archivefile_entry">压缩文件内没有支持的文件</string>
     <string name="no_books_dir">没有设置书籍保存位置!</string>
     <string name="delete_alert">删除提醒</string>
+    <string name="no_book_found_bookshelf">未在书架上找到所选书籍</string>
 </resources>

+ 1 - 0
app/src/main/res/values/strings.xml

@@ -1086,4 +1086,5 @@
     <string name="unsupport_archivefile_entry">Cannot find supported files in archive</string>
     <string name="no_books_dir">没有设置书籍保存位置!</string>
     <string name="delete_alert">删除提醒</string>
+    <string name="no_book_found_bookshelf">No book found in bookshelf</string>
 </resources>