Răsfoiți Sursa

书籍导入界面点击已在书架的开始阅读

Xwite 3 ani în urmă
părinte
comite
ff3e60441b

+ 3 - 0
app/src/main/java/io/legado/app/data/dao/BookDao.kt

@@ -62,6 +62,9 @@ interface BookDao {
     @Query("SELECT * FROM books WHERE `name` in (:names)")
     @Query("SELECT * FROM books WHERE `name` in (:names)")
     fun findByName(vararg names: String): List<Book>
     fun findByName(vararg names: String): List<Book>
 
 
+    @Query("select * from books where originName = :fileName")
+    fun getBookByFileName(fileName: String): Book?
+
     @Query("SELECT * FROM books WHERE bookUrl = :bookUrl")
     @Query("SELECT * FROM books WHERE bookUrl = :bookUrl")
     fun getBook(bookUrl: String): Book?
     fun getBook(bookUrl: String): Book?
 
 

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

@@ -5,13 +5,17 @@ import androidx.appcompat.widget.SearchView
 import androidx.lifecycle.ViewModel
 import androidx.lifecycle.ViewModel
 import io.legado.app.R
 import io.legado.app.R
 import io.legado.app.base.VMBaseActivity
 import io.legado.app.base.VMBaseActivity
+import io.legado.app.data.entities.Book
 import io.legado.app.databinding.ActivityImportBookBinding
 import io.legado.app.databinding.ActivityImportBookBinding
 import io.legado.app.help.config.AppConfig
 import io.legado.app.help.config.AppConfig
 import io.legado.app.lib.dialogs.alert
 import io.legado.app.lib.dialogs.alert
 import io.legado.app.lib.theme.primaryTextColor
 import io.legado.app.lib.theme.primaryTextColor
+import io.legado.app.ui.book.read.ReadBookActivity
 import io.legado.app.ui.document.HandleFileContract
 import io.legado.app.ui.document.HandleFileContract
 import io.legado.app.utils.applyTint
 import io.legado.app.utils.applyTint
+import io.legado.app.utils.startActivity
 import io.legado.app.utils.viewbindingdelegate.viewBinding
 import io.legado.app.utils.viewbindingdelegate.viewBinding
+
 import kotlin.coroutines.resume
 import kotlin.coroutines.resume
 import kotlin.coroutines.suspendCoroutine
 import kotlin.coroutines.suspendCoroutine
 
 
@@ -68,6 +72,14 @@ abstract class BaseImportBookActivity<VM : ViewModel> : VMBaseActivity<ActivityI
 
 
     abstract fun onSearchTextChange(newText: String?)
     abstract fun onSearchTextChange(newText: String?)
 
 
+    protected fun startRead(book: Book) = startRead(book.bookUrl)
+
+    protected fun startRead(bookUrl: String) {
+        startActivity<ReadBookActivity> {
+            putExtra("bookUrl", bookUrl)
+        }
+    }
+
     private fun initSearchView() {
     private fun initSearchView() {
         searchView.applyTint(primaryTextColor)
         searchView.applyTint(primaryTextColor)
         searchView.onActionViewExpanded()
         searchView.onActionViewExpanded()

+ 12 - 8
app/src/main/java/io/legado/app/ui/book/import/local/ImportBookAdapter.kt

@@ -16,7 +16,7 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
     RecyclerAdapter<FileDoc, ItemImportBookBinding>(context) {
     RecyclerAdapter<FileDoc, ItemImportBookBinding>(context) {
     val selectedUris = hashSetOf<String>()
     val selectedUris = hashSetOf<String>()
     var checkableCount = 0
     var checkableCount = 0
-    private val bookFileNames = arrayListOf<String>()
+    private val bookNamesOnBookShelf = arrayListOf<String>()
 
 
     override fun getViewBinding(parent: ViewGroup): ItemImportBookBinding {
     override fun getViewBinding(parent: ViewGroup): ItemImportBookBinding {
         return ItemImportBookBinding.inflate(inflater, parent, false)
         return ItemImportBookBinding.inflate(inflater, parent, false)
@@ -41,7 +41,7 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
                     llBrief.gone()
                     llBrief.gone()
                     cbSelect.isChecked = false
                     cbSelect.isChecked = false
                 } else {
                 } else {
-                    if (bookFileNames.contains(item.name)) {
+                    if (bookNamesOnBookShelf.contains(item.name)) {
                         ivIcon.setImageResource(R.drawable.ic_book_has)
                         ivIcon.setImageResource(R.drawable.ic_book_has)
                         ivIcon.visible()
                         ivIcon.visible()
                         cbSelect.invisible()
                         cbSelect.invisible()
@@ -67,7 +67,7 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
             getItem(holder.layoutPosition)?.let {
             getItem(holder.layoutPosition)?.let {
                 if (it.isDir) {
                 if (it.isDir) {
                     callBack.nextDoc(it)
                     callBack.nextDoc(it)
-                } else if (!bookFileNames.contains(it.name)) {
+                } else if (!bookNamesOnBookShelf.contains(it.name)) {
                     if (!selectedUris.contains(it.toString())) {
                     if (!selectedUris.contains(it.toString())) {
                         selectedUris.add(it.toString())
                         selectedUris.add(it.toString())
                     } else {
                     } else {
@@ -75,6 +75,9 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
                     }
                     }
                     notifyItemChanged(holder.layoutPosition, true)
                     notifyItemChanged(holder.layoutPosition, true)
                     callBack.upCountView()
                     callBack.upCountView()
+                } else {
+                    /* 点击开始阅读 */
+                    callBack.startRead(it.toString())
                 }
                 }
             }
             }
         }
         }
@@ -82,10 +85,10 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
 
 
     @SuppressLint("NotifyDataSetChanged")
     @SuppressLint("NotifyDataSetChanged")
     fun upBookHas(bookUrls: List<String>) {
     fun upBookHas(bookUrls: List<String>) {
-        bookFileNames.clear()
+        bookNamesOnBookShelf.clear()
         bookUrls.forEach {
         bookUrls.forEach {
             val path = Uri.decode(it)
             val path = Uri.decode(it)
-            bookFileNames.add(FileUtils.getName(path))
+            bookNamesOnBookShelf.add(FileUtils.getName(path))
         }
         }
         notifyDataSetChanged()
         notifyDataSetChanged()
         upCheckableCount()
         upCheckableCount()
@@ -94,7 +97,7 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
     private fun upCheckableCount() {
     private fun upCheckableCount() {
         checkableCount = 0
         checkableCount = 0
         getItems().forEach {
         getItems().forEach {
-            if (!it.isDir && !bookFileNames.contains(it.name)) {
+            if (!it.isDir && !bookNamesOnBookShelf.contains(it.name)) {
                 checkableCount++
                 checkableCount++
             }
             }
         }
         }
@@ -105,7 +108,7 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
     fun selectAll(selectAll: Boolean) {
     fun selectAll(selectAll: Boolean) {
         if (selectAll) {
         if (selectAll) {
             getItems().forEach {
             getItems().forEach {
-                if (!it.isDir && !bookFileNames.contains(it.name)) {
+                if (!it.isDir && !bookNamesOnBookShelf.contains(it.name)) {
                     selectedUris.add(it.toString())
                     selectedUris.add(it.toString())
                 }
                 }
             }
             }
@@ -118,7 +121,7 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
 
 
     fun revertSelection() {
     fun revertSelection() {
         getItems().forEach {
         getItems().forEach {
-            if (!it.isDir && !bookFileNames.contains(it.name)) {
+            if (!it.isDir && !bookNamesOnBookShelf.contains(it.name)) {
                 if (selectedUris.contains(it.toString())) {
                 if (selectedUris.contains(it.toString())) {
                     selectedUris.remove(it.toString())
                     selectedUris.remove(it.toString())
                 } else {
                 } else {
@@ -141,6 +144,7 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
     interface CallBack {
     interface CallBack {
         fun nextDoc(fileDoc: FileDoc)
         fun nextDoc(fileDoc: FileDoc)
         fun upCountView()
         fun upCountView()
+        fun startRead(bookUrl: String)
     }
     }
 
 
 }
 }

+ 2 - 7
app/src/main/java/io/legado/app/ui/book/import/local/ImportBookViewModel.kt

@@ -149,12 +149,7 @@ class ImportBookViewModel(application: Application) : BaseViewModel(application)
                 }
                 }
                 if (docItem.isDir) {
                 if (docItem.isDir) {
                     scanDoc(docItem, false, scope)
                     scanDoc(docItem, false, scope)
-                } else if (docItem.name.endsWith(".txt", true)
-                    || docItem.name.endsWith(".epub", true) || docItem.name.endsWith(
-                        ".pdf",
-                        true
-                    ) || docItem.name.endsWith(".umd", true)
-                ) {
+                } else if (docItem.name.matches(bookFileRegex)) {
                     list.add(docItem)
                     list.add(docItem)
                 }
                 }
             }
             }
@@ -184,7 +179,7 @@ class ImportBookViewModel(application: Application) : BaseViewModel(application)
         fun addItems(fileDocs: List<FileDoc>)
         fun addItems(fileDocs: List<FileDoc>)
 
 
         fun clear()
         fun clear()
-        
+
         fun screen(key: String?)
         fun screen(key: String?)
 
 
     }
     }

+ 8 - 0
app/src/main/java/io/legado/app/ui/book/import/remote/RemoteBookAdapter.kt

@@ -7,6 +7,8 @@ import io.legado.app.R
 import io.legado.app.base.adapter.ItemViewHolder
 import io.legado.app.base.adapter.ItemViewHolder
 import io.legado.app.base.adapter.RecyclerAdapter
 import io.legado.app.base.adapter.RecyclerAdapter
 import io.legado.app.constant.AppConst
 import io.legado.app.constant.AppConst
+import io.legado.app.data.appDb
+import io.legado.app.data.entities.Book
 import io.legado.app.databinding.ItemImportBookBinding
 import io.legado.app.databinding.ItemImportBookBinding
 import io.legado.app.model.remote.RemoteBook
 import io.legado.app.model.remote.RemoteBook
 import io.legado.app.utils.ConvertUtils
 import io.legado.app.utils.ConvertUtils
@@ -84,6 +86,11 @@ class RemoteBookAdapter(context: Context, val callBack: CallBack) :
                     }
                     }
                     notifyItemChanged(holder.layoutPosition, true)
                     notifyItemChanged(holder.layoutPosition, true)
                     callBack.upCountView()
                     callBack.upCountView()
+                } else {
+                    /* 点击开始阅读 */
+                    appDb.bookDao.getBookByFileName(it.filename)?.let {
+                        callBack.startRead(it)
+                    }
                 }
                 }
             }
             }
         }
         }
@@ -140,5 +147,6 @@ class RemoteBookAdapter(context: Context, val callBack: CallBack) :
     interface CallBack {
     interface CallBack {
         fun openDir(remoteBook: RemoteBook)
         fun openDir(remoteBook: RemoteBook)
         fun upCountView()
         fun upCountView()
+        fun startRead(book: Book)
     }
     }
 }
 }

+ 1 - 2
app/src/main/java/io/legado/app/ui/book/import/remote/RemoteBookViewModel.kt

@@ -57,7 +57,6 @@ class RemoteBookViewModel(application: Application) : BaseViewModel(application)
                     trySend(
                     trySend(
                         list.filter { it.filename.contains(key) }
                         list.filter { it.filename.contains(key) }
                     )
                     )
-                    
                 }
                 }
             }
             }
         }
         }
@@ -159,7 +158,7 @@ class RemoteBookViewModel(application: Application) : BaseViewModel(application)
         fun addItems(remoteFiles: List<RemoteBook>)
         fun addItems(remoteFiles: List<RemoteBook>)
 
 
         fun clear()
         fun clear()
-        
+
         fun screen(key: String?)
         fun screen(key: String?)
 
 
     }
     }

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

@@ -1080,5 +1080,4 @@
     <string name="keep_group">保留分组</string>
     <string name="keep_group">保留分组</string>
     <string name="server_config">服务器配置</string>
     <string name="server_config">服务器配置</string>
     <string name="sure_upload">Remote webDav url exists, Continue?</string>
     <string name="sure_upload">Remote webDav url exists, Continue?</string>
-    <string name="after_add_bookshelf">Add this book to Bookshelf first</string>
 </resources>
 </resources>

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

@@ -1083,5 +1083,4 @@
     <string name="keep_group">保留分组</string>
     <string name="keep_group">保留分组</string>
     <string name="server_config">服务器配置</string>
     <string name="server_config">服务器配置</string>
     <string name="sure_upload">Remote webDav url exists, Continue?</string>
     <string name="sure_upload">Remote webDav url exists, Continue?</string>
-    <string name="after_add_bookshelf">Add this book to Bookshelf first</string>
 </resources>
 </resources>

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

@@ -1083,5 +1083,4 @@
     <string name="keep_group">保留分组</string>
     <string name="keep_group">保留分组</string>
     <string name="server_config">服务器配置</string>
     <string name="server_config">服务器配置</string>
     <string name="sure_upload">Remote webDav url exists, Continue?</string>
     <string name="sure_upload">Remote webDav url exists, Continue?</string>
-    <string name="after_add_bookshelf">Add this book to Bookshelf first</string>
 </resources>
 </resources>

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

@@ -1080,5 +1080,4 @@
     <string name="keep_group">保留分组</string>
     <string name="keep_group">保留分组</string>
     <string name="server_config">服务器配置</string>
     <string name="server_config">服务器配置</string>
     <string name="sure_upload">远程webDav链接已存在,是否继续</string>
     <string name="sure_upload">远程webDav链接已存在,是否继续</string>
-    <string name="after_add_bookshelf">先将书籍加入书架</string>
 </resources>
 </resources>

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

@@ -1082,5 +1082,4 @@
     <string name="keep_group">保留分组</string>
     <string name="keep_group">保留分组</string>
     <string name="server_config">服务器配置</string>
     <string name="server_config">服务器配置</string>
     <string name="sure_upload">远程webDav链接已存在,是否继续</string>
     <string name="sure_upload">远程webDav链接已存在,是否继续</string>
-    <string name="after_add_bookshelf">先将书籍加入书架</string>
 </resources>
 </resources>

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

@@ -1082,5 +1082,4 @@
     <string name="keep_group">保留分组</string>
     <string name="keep_group">保留分组</string>
     <string name="server_config">服务器配置</string>
     <string name="server_config">服务器配置</string>
     <string name="sure_upload">远程webDav链接已存在,是否继续</string>
     <string name="sure_upload">远程webDav链接已存在,是否继续</string>
-    <string name="after_add_bookshelf">先将书籍加入书架</string>
 </resources>
 </resources>

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

@@ -1083,5 +1083,4 @@
     <string name="keep_group">Keep group</string>
     <string name="keep_group">Keep group</string>
     <string name="server_config">服务器配置</string>
     <string name="server_config">服务器配置</string>
     <string name="sure_upload">Remote webDav url exists, Continue?</string>
     <string name="sure_upload">Remote webDav url exists, Continue?</string>
-    <string name="after_add_bookshelf">Add this book to Bookshelf first</string>
 </resources>
 </resources>