Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
gedoor committed Mar 12, 2023
2 parents 8b95ada + c835ff2 commit d70dee1
Show file tree
Hide file tree
Showing 15 changed files with 41 additions and 24 deletions.
3 changes: 3 additions & 0 deletions app/src/main/java/io/legado/app/data/dao/BookDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,4 +300,6 @@ class ImportBookActivity : BaseImportBookActivity<ImportBookViewModel>(),
binding.selectActionBar.upCountView(adapter.selectedUris.size, adapter.checkableCount)
}

override fun startRead(bookUrl: String) = startReadBook(bookUrl)

}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand All @@ -67,25 +67,28 @@ 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 {
selectedUris.remove(it.toString())
}
notifyItemChanged(holder.layoutPosition, true)
callBack.upCountView()
} else {
/* 点击开始阅读 */
callBack.startRead(it.toString())
}
}
}
}

@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()
Expand All @@ -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++
}
}
Expand All @@ -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())
}
}
Expand All @@ -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 {
Expand All @@ -141,6 +144,7 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
interface CallBack {
fun nextDoc(fileDoc: FileDoc)
fun upCountView()
fun startRead(bookUrl: String)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -184,7 +179,7 @@ class ImportBookViewModel(application: Application) : BaseViewModel(application)
fun addItems(fileDocs: List<FileDoc>)

fun clear()

fun screen(key: String?)

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
}
}
Expand Down Expand Up @@ -140,5 +147,6 @@ class RemoteBookAdapter(context: Context, val callBack: CallBack) :
interface CallBack {
fun openDir(remoteBook: RemoteBook)
fun upCountView()
fun startRead(book: Book)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class RemoteBookViewModel(application: Application) : BaseViewModel(application)
trySend(
list.filter { it.filename.contains(key) }
)

}
}
}
Expand Down Expand Up @@ -159,7 +158,7 @@ class RemoteBookViewModel(application: Application) : BaseViewModel(application)
fun addItems(remoteFiles: List<RemoteBook>)

fun clear()

fun screen(key: String?)

}
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-es-rES/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
1 change: 0 additions & 1 deletion app/src/main/res/values-ja-rJP/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
1 change: 0 additions & 1 deletion app/src/main/res/values-pt-rBR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
1 change: 0 additions & 1 deletion app/src/main/res/values-zh-rHK/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
1 change: 0 additions & 1 deletion app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
1 change: 0 additions & 1 deletion app/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
1 change: 0 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

0 comments on commit d70dee1

Please sign in to comment.