mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -62,6 +62,9 @@ interface BookDao {
|
||||
@Query("SELECT * FROM books WHERE `name` in (:names)")
|
||||
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")
|
||||
fun getBook(bookUrl: String): Book?
|
||||
|
||||
|
||||
@@ -9,9 +9,12 @@ import io.legado.app.databinding.ActivityImportBookBinding
|
||||
import io.legado.app.help.config.AppConfig
|
||||
import io.legado.app.lib.dialogs.alert
|
||||
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.utils.applyTint
|
||||
import io.legado.app.utils.startActivity
|
||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||
|
||||
import kotlin.coroutines.resume
|
||||
import kotlin.coroutines.suspendCoroutine
|
||||
|
||||
@@ -68,6 +71,12 @@ abstract class BaseImportBookActivity<VM : ViewModel> : VMBaseActivity<ActivityI
|
||||
|
||||
abstract fun onSearchTextChange(newText: String?)
|
||||
|
||||
protected fun startReadBook(bookUrl: String) {
|
||||
startActivity<ReadBookActivity> {
|
||||
putExtra("bookUrl", bookUrl)
|
||||
}
|
||||
}
|
||||
|
||||
private fun initSearchView() {
|
||||
searchView.applyTint(primaryTextColor)
|
||||
searchView.onActionViewExpanded()
|
||||
|
||||
@@ -300,4 +300,6 @@ class ImportBookActivity : BaseImportBookActivity<ImportBookViewModel>(),
|
||||
binding.selectActionBar.upCountView(adapter.selectedUris.size, adapter.checkableCount)
|
||||
}
|
||||
|
||||
override fun startRead(bookUrl: String) = startReadBook(bookUrl)
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
|
||||
RecyclerAdapter<FileDoc, ItemImportBookBinding>(context) {
|
||||
val selectedUris = hashSetOf<String>()
|
||||
var checkableCount = 0
|
||||
private val bookFileNames = arrayListOf<String>()
|
||||
private val bookNamesOnBookShelf = arrayListOf<String>()
|
||||
|
||||
override fun getViewBinding(parent: ViewGroup): ItemImportBookBinding {
|
||||
return ItemImportBookBinding.inflate(inflater, parent, false)
|
||||
@@ -41,7 +41,7 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
|
||||
llBrief.gone()
|
||||
cbSelect.isChecked = false
|
||||
} else {
|
||||
if (bookFileNames.contains(item.name)) {
|
||||
if (bookNamesOnBookShelf.contains(item.name)) {
|
||||
ivIcon.setImageResource(R.drawable.ic_book_has)
|
||||
ivIcon.visible()
|
||||
cbSelect.invisible()
|
||||
@@ -67,7 +67,7 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
|
||||
getItem(holder.layoutPosition)?.let {
|
||||
if (it.isDir) {
|
||||
callBack.nextDoc(it)
|
||||
} else if (!bookFileNames.contains(it.name)) {
|
||||
} else if (!bookNamesOnBookShelf.contains(it.name)) {
|
||||
if (!selectedUris.contains(it.toString())) {
|
||||
selectedUris.add(it.toString())
|
||||
} else {
|
||||
@@ -75,6 +75,9 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
|
||||
}
|
||||
notifyItemChanged(holder.layoutPosition, true)
|
||||
callBack.upCountView()
|
||||
} else {
|
||||
/* 点击开始阅读 */
|
||||
callBack.startRead(it.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,10 +85,10 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
fun upBookHas(bookUrls: List<String>) {
|
||||
bookFileNames.clear()
|
||||
bookNamesOnBookShelf.clear()
|
||||
bookUrls.forEach {
|
||||
val path = Uri.decode(it)
|
||||
bookFileNames.add(FileUtils.getName(path))
|
||||
bookNamesOnBookShelf.add(FileUtils.getName(path))
|
||||
}
|
||||
notifyDataSetChanged()
|
||||
upCheckableCount()
|
||||
@@ -94,7 +97,7 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
|
||||
private fun upCheckableCount() {
|
||||
checkableCount = 0
|
||||
getItems().forEach {
|
||||
if (!it.isDir && !bookFileNames.contains(it.name)) {
|
||||
if (!it.isDir && !bookNamesOnBookShelf.contains(it.name)) {
|
||||
checkableCount++
|
||||
}
|
||||
}
|
||||
@@ -105,7 +108,7 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
|
||||
fun selectAll(selectAll: Boolean) {
|
||||
if (selectAll) {
|
||||
getItems().forEach {
|
||||
if (!it.isDir && !bookFileNames.contains(it.name)) {
|
||||
if (!it.isDir && !bookNamesOnBookShelf.contains(it.name)) {
|
||||
selectedUris.add(it.toString())
|
||||
}
|
||||
}
|
||||
@@ -118,7 +121,7 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
|
||||
|
||||
fun revertSelection() {
|
||||
getItems().forEach {
|
||||
if (!it.isDir && !bookFileNames.contains(it.name)) {
|
||||
if (!it.isDir && !bookNamesOnBookShelf.contains(it.name)) {
|
||||
if (selectedUris.contains(it.toString())) {
|
||||
selectedUris.remove(it.toString())
|
||||
} else {
|
||||
@@ -141,6 +144,7 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
|
||||
interface CallBack {
|
||||
fun nextDoc(fileDoc: FileDoc)
|
||||
fun upCountView()
|
||||
fun startRead(bookUrl: String)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -149,12 +149,7 @@ class ImportBookViewModel(application: Application) : BaseViewModel(application)
|
||||
}
|
||||
if (docItem.isDir) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
@@ -184,7 +179,7 @@ class ImportBookViewModel(application: Application) : BaseViewModel(application)
|
||||
fun addItems(fileDocs: List<FileDoc>)
|
||||
|
||||
fun clear()
|
||||
|
||||
|
||||
fun screen(key: String?)
|
||||
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import androidx.activity.viewModels
|
||||
import androidx.core.view.isGone
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import io.legado.app.R
|
||||
import io.legado.app.data.entities.Book
|
||||
import io.legado.app.help.config.LocalConfig
|
||||
import io.legado.app.lib.theme.backgroundColor
|
||||
import io.legado.app.model.remote.RemoteBook
|
||||
@@ -195,4 +196,7 @@ class RemoteBookActivity : BaseImportBookActivity<RemoteBookViewModel>(),
|
||||
val mdText = String(assets.open("help/${fileName}.md").readBytes())
|
||||
showDialogFragment(TextDialog(getString(R.string.help), mdText, TextDialog.Mode.MD))
|
||||
}
|
||||
|
||||
override fun startRead(book: Book) = startReadBook(book.bookUrl)
|
||||
|
||||
}
|
||||
@@ -7,6 +7,8 @@ import io.legado.app.R
|
||||
import io.legado.app.base.adapter.ItemViewHolder
|
||||
import io.legado.app.base.adapter.RecyclerAdapter
|
||||
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.model.remote.RemoteBook
|
||||
import io.legado.app.utils.ConvertUtils
|
||||
@@ -84,6 +86,11 @@ class RemoteBookAdapter(context: Context, val callBack: CallBack) :
|
||||
}
|
||||
notifyItemChanged(holder.layoutPosition, true)
|
||||
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 {
|
||||
fun openDir(remoteBook: RemoteBook)
|
||||
fun upCountView()
|
||||
fun startRead(book: Book)
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,6 @@ class RemoteBookViewModel(application: Application) : BaseViewModel(application)
|
||||
trySend(
|
||||
list.filter { it.filename.contains(key) }
|
||||
)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -159,7 +158,7 @@ class RemoteBookViewModel(application: Application) : BaseViewModel(application)
|
||||
fun addItems(remoteFiles: List<RemoteBook>)
|
||||
|
||||
fun clear()
|
||||
|
||||
|
||||
fun screen(key: String?)
|
||||
|
||||
}
|
||||
|
||||
@@ -1080,5 +1080,4 @@
|
||||
<string name="keep_group">保留分组</string>
|
||||
<string name="server_config">服务器配置</string>
|
||||
<string name="sure_upload">Remote webDav url exists, Continue?</string>
|
||||
<string name="after_add_bookshelf">Add this book to Bookshelf first</string>
|
||||
</resources>
|
||||
|
||||
@@ -1083,5 +1083,4 @@
|
||||
<string name="keep_group">保留分组</string>
|
||||
<string name="server_config">服务器配置</string>
|
||||
<string name="sure_upload">Remote webDav url exists, Continue?</string>
|
||||
<string name="after_add_bookshelf">Add this book to Bookshelf first</string>
|
||||
</resources>
|
||||
|
||||
@@ -1083,5 +1083,4 @@
|
||||
<string name="keep_group">保留分组</string>
|
||||
<string name="server_config">服务器配置</string>
|
||||
<string name="sure_upload">Remote webDav url exists, Continue?</string>
|
||||
<string name="after_add_bookshelf">Add this book to Bookshelf first</string>
|
||||
</resources>
|
||||
|
||||
@@ -1080,5 +1080,4 @@
|
||||
<string name="keep_group">保留分组</string>
|
||||
<string name="server_config">服务器配置</string>
|
||||
<string name="sure_upload">远程webDav链接已存在,是否继续</string>
|
||||
<string name="after_add_bookshelf">先将书籍加入书架</string>
|
||||
</resources>
|
||||
|
||||
@@ -1082,5 +1082,4 @@
|
||||
<string name="keep_group">保留分组</string>
|
||||
<string name="server_config">服务器配置</string>
|
||||
<string name="sure_upload">远程webDav链接已存在,是否继续</string>
|
||||
<string name="after_add_bookshelf">先将书籍加入书架</string>
|
||||
</resources>
|
||||
|
||||
@@ -1082,5 +1082,4 @@
|
||||
<string name="keep_group">保留分组</string>
|
||||
<string name="server_config">服务器配置</string>
|
||||
<string name="sure_upload">远程webDav链接已存在,是否继续</string>
|
||||
<string name="after_add_bookshelf">先将书籍加入书架</string>
|
||||
</resources>
|
||||
|
||||
@@ -1083,5 +1083,4 @@
|
||||
<string name="keep_group">Keep group</string>
|
||||
<string name="server_config">服务器配置</string>
|
||||
<string name="sure_upload">Remote webDav url exists, Continue?</string>
|
||||
<string name="after_add_bookshelf">Add this book to Bookshelf first</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user