优化
This commit is contained in:
@@ -14,6 +14,7 @@ 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.dialogs.selector
|
import io.legado.app.lib.dialogs.selector
|
||||||
import io.legado.app.lib.theme.primaryTextColor
|
import io.legado.app.lib.theme.primaryTextColor
|
||||||
|
import io.legado.app.model.localBook.LocalBook
|
||||||
import io.legado.app.ui.book.read.ReadBookActivity
|
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.*
|
import io.legado.app.utils.*
|
||||||
@@ -93,7 +94,7 @@ abstract class BaseImportBookActivity<VM : ViewModel> : VMBaseActivity<ActivityI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun onArchiveFileClick(fileDoc: FileDoc) {
|
protected fun onArchiveFileClick(fileDoc: FileDoc) {
|
||||||
val fileNames = ArchiveUtils.getArchiveFilesName(fileDoc) {
|
val fileNames = ArchiveUtils.getArchiveFilesName(fileDoc) {
|
||||||
it.matches(AppPattern.bookFileRegex)
|
it.matches(AppPattern.bookFileRegex)
|
||||||
}
|
}
|
||||||
@@ -122,11 +123,17 @@ abstract class BaseImportBookActivity<VM : ViewModel> : VMBaseActivity<ActivityI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun addArchiveToBookShelf(
|
/* 添加压缩包内指定文件到书架 */
|
||||||
|
private inline fun addArchiveToBookShelf(
|
||||||
fileDoc: FileDoc,
|
fileDoc: FileDoc,
|
||||||
fileName: String,
|
fileName: String,
|
||||||
onSuccess: (String) -> Unit
|
onSuccess: (String) -> Unit
|
||||||
) {
|
) {
|
||||||
|
LocalBook.importArchiveFile(fileDoc.uri, fileName) {
|
||||||
|
it.contains(fileName)
|
||||||
|
}.firstOrNull()?.run {
|
||||||
|
onSuccess.invoke(bookUrl)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 提示是否重新导入所点击的压缩文件 */
|
/* 提示是否重新导入所点击的压缩文件 */
|
||||||
|
|||||||
@@ -303,11 +303,4 @@ class ImportBookActivity : BaseImportBookActivity<ImportBookViewModel>(),
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun addArchiveToBookShelf(
|
|
||||||
fileDoc: FileDoc,
|
|
||||||
fileName: String,
|
|
||||||
onSuccess: (String) -> Unit
|
|
||||||
) {
|
|
||||||
viewModel.addArchiveToBookShelf(fileDoc, fileName, onSuccess)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,18 +97,6 @@ class ImportBookViewModel(application: Application) : BaseViewModel(application)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addArchiveToBookShelf(
|
|
||||||
fileDoc: FileDoc,
|
|
||||||
fileName: String,
|
|
||||||
onSuccess: (String) -> Unit
|
|
||||||
) {
|
|
||||||
LocalBook.importArchiveFile(fileDoc.uri, fileName) {
|
|
||||||
it.contains(fileName)
|
|
||||||
}.firstOrNull()?.run {
|
|
||||||
onSuccess.invoke(bookUrl)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun deleteDoc(uriList: HashSet<String>, finally: () -> Unit) {
|
fun deleteDoc(uriList: HashSet<String>, finally: () -> Unit) {
|
||||||
execute {
|
execute {
|
||||||
uriList.forEach {
|
uriList.forEach {
|
||||||
|
|||||||
@@ -9,7 +9,9 @@ import androidx.activity.viewModels
|
|||||||
import androidx.core.view.isGone
|
import androidx.core.view.isGone
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import io.legado.app.R
|
import io.legado.app.R
|
||||||
|
import io.legado.app.data.appDb
|
||||||
import io.legado.app.data.entities.Book
|
import io.legado.app.data.entities.Book
|
||||||
|
import io.legado.app.help.config.AppConfig
|
||||||
import io.legado.app.help.config.LocalConfig
|
import io.legado.app.help.config.LocalConfig
|
||||||
import io.legado.app.lib.theme.backgroundColor
|
import io.legado.app.lib.theme.backgroundColor
|
||||||
import io.legado.app.model.remote.RemoteBook
|
import io.legado.app.model.remote.RemoteBook
|
||||||
@@ -17,6 +19,8 @@ import io.legado.app.ui.about.AppLogDialog
|
|||||||
import io.legado.app.ui.book.import.BaseImportBookActivity
|
import io.legado.app.ui.book.import.BaseImportBookActivity
|
||||||
import io.legado.app.ui.widget.SelectActionBar
|
import io.legado.app.ui.widget.SelectActionBar
|
||||||
import io.legado.app.ui.widget.dialog.TextDialog
|
import io.legado.app.ui.widget.dialog.TextDialog
|
||||||
|
import io.legado.app.utils.FileDoc
|
||||||
|
import io.legado.app.utils.find
|
||||||
import io.legado.app.utils.showDialogFragment
|
import io.legado.app.utils.showDialogFragment
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.conflate
|
import kotlinx.coroutines.flow.conflate
|
||||||
@@ -197,6 +201,41 @@ class RemoteBookActivity : BaseImportBookActivity<RemoteBookViewModel>(),
|
|||||||
showDialogFragment(TextDialog(getString(R.string.help), mdText, TextDialog.Mode.MD))
|
showDialogFragment(TextDialog(getString(R.string.help), mdText, TextDialog.Mode.MD))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun startRead(book: Book) = startReadBook(book.bookUrl)
|
private fun showRemoteBookDownloadAlert(
|
||||||
|
remoteBook: RemoteBook,
|
||||||
|
onDownloadFinish: (() -> Unit)? = null
|
||||||
|
) {
|
||||||
|
alert(
|
||||||
|
R.string.draw,
|
||||||
|
R.string.archive_not_found
|
||||||
|
) {
|
||||||
|
okButton {
|
||||||
|
viewModel.addToBookshelf(hashSetOf<RemoteBook>(remoteBook) {
|
||||||
|
onDownloadFinish?.invoke()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
noButton()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun startRead(remoteBook: RemoteBook) {
|
||||||
|
val downloadFileName = remoteBook.filename
|
||||||
|
if (!ArchiveUtils.isArchive(downloadFileName)) {
|
||||||
|
appDb.bookDao.getBookByFileName(downloadFileName)?.let {
|
||||||
|
startReadBook(it.bookUrl)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
AppConfig.defaultBookTreeUri ?: return
|
||||||
|
val downloadArchiveFileDoc = FileDoc.fromUri(Uri.parse(AppConfig.defaultBookTreeUri), true)
|
||||||
|
.find(downloadFileName)
|
||||||
|
if (downloadArchiveFileDoc == null) {
|
||||||
|
showRemoteBookDownloadAlert(remoteBook) {
|
||||||
|
startRead(remoteBook)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
onArchiveFileClick(downloadArchiveFileDoc)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -7,7 +7,6 @@ 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.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
|
||||||
@@ -88,9 +87,7 @@ class RemoteBookAdapter(context: Context, val callBack: CallBack) :
|
|||||||
callBack.upCountView()
|
callBack.upCountView()
|
||||||
} else {
|
} else {
|
||||||
/* 点击开始阅读 */
|
/* 点击开始阅读 */
|
||||||
appDb.bookDao.getBookByFileName(it.filename)?.let {
|
callBack.startRead(it)
|
||||||
callBack.startRead(it)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -147,6 +144,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)
|
fun startRead(remoteBook: RemoteBook)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1084,4 +1084,5 @@
|
|||||||
<string name="no_books_dir">没有设置书籍保存位置!</string>
|
<string name="no_books_dir">没有设置书籍保存位置!</string>
|
||||||
<string name="delete_alert">删除提醒</string>
|
<string name="delete_alert">删除提醒</string>
|
||||||
<string name="no_book_found_bookshelf">No book found in bookshelf, import again ?</string>
|
<string name="no_book_found_bookshelf">No book found in bookshelf, import again ?</string>
|
||||||
|
<string name="archive_not_found">Can not find archive selected, continue to download ?</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -1087,4 +1087,5 @@
|
|||||||
<string name="no_books_dir">没有设置书籍保存位置!</string>
|
<string name="no_books_dir">没有设置书籍保存位置!</string>
|
||||||
<string name="delete_alert">删除提醒</string>
|
<string name="delete_alert">删除提醒</string>
|
||||||
<string name="no_book_found_bookshelf">No book found in bookshelf, import again ?</string>
|
<string name="no_book_found_bookshelf">No book found in bookshelf, import again ?</string>
|
||||||
|
<string name="archive_not_found">Can not find archive selected, continue to download ?</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -1087,4 +1087,5 @@
|
|||||||
<string name="no_books_dir">没有设置书籍保存位置!</string>
|
<string name="no_books_dir">没有设置书籍保存位置!</string>
|
||||||
<string name="delete_alert">删除提醒</string>
|
<string name="delete_alert">删除提醒</string>
|
||||||
<string name="no_book_found_bookshelf">No book found in bookshelf, import again ?</string>
|
<string name="no_book_found_bookshelf">No book found in bookshelf, import again ?</string>
|
||||||
|
<string name="archive_not_found">Can not find archive selected, continue to download ?</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -1084,4 +1084,5 @@
|
|||||||
<string name="no_books_dir">没有设置书籍保存位置!</string>
|
<string name="no_books_dir">没有设置书籍保存位置!</string>
|
||||||
<string name="delete_alert">删除提醒</string>
|
<string name="delete_alert">删除提醒</string>
|
||||||
<string name="no_book_found_bookshelf">未在书架上找到所选书籍, 是否重新导入?</string>
|
<string name="no_book_found_bookshelf">未在书架上找到所选书籍, 是否重新导入?</string>
|
||||||
|
<string name="archive_not_found">未能在书籍保存目录找到压缩文件,是否重新导入?</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -1086,4 +1086,5 @@
|
|||||||
<string name="no_books_dir">没有设置书籍保存位置!</string>
|
<string name="no_books_dir">没有设置书籍保存位置!</string>
|
||||||
<string name="delete_alert">删除提醒</string>
|
<string name="delete_alert">删除提醒</string>
|
||||||
<string name="no_book_found_bookshelf">未在书架上找到所选书籍, 是否重新导入?</string>
|
<string name="no_book_found_bookshelf">未在书架上找到所选书籍, 是否重新导入?</string>
|
||||||
|
<string name="archive_not_found">未能在书籍保存目录找到压缩文件,是否重新导入?</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -1086,4 +1086,5 @@
|
|||||||
<string name="no_books_dir">没有设置书籍保存位置!</string>
|
<string name="no_books_dir">没有设置书籍保存位置!</string>
|
||||||
<string name="delete_alert">删除提醒</string>
|
<string name="delete_alert">删除提醒</string>
|
||||||
<string name="no_book_found_bookshelf">未在书架上找到所选书籍, 是否重新导入?</string>
|
<string name="no_book_found_bookshelf">未在书架上找到所选书籍, 是否重新导入?</string>
|
||||||
|
<string name="archive_not_found">未能在书籍保存目录找到压缩文件,是否重新导入?</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -1087,4 +1087,5 @@
|
|||||||
<string name="no_books_dir">没有设置书籍保存位置!</string>
|
<string name="no_books_dir">没有设置书籍保存位置!</string>
|
||||||
<string name="delete_alert">删除提醒</string>
|
<string name="delete_alert">删除提醒</string>
|
||||||
<string name="no_book_found_bookshelf">No book found in bookshelf, import again ?</string>
|
<string name="no_book_found_bookshelf">No book found in bookshelf, import again ?</string>
|
||||||
|
<string name="archive_not_found">Can not find archive selected, continue to download ?</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user