mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -98,15 +98,16 @@ abstract class BaseImportBookActivity<VM : ViewModel> : VMBaseActivity<ActivityI
|
||||
it.matches(AppPattern.bookFileRegex)
|
||||
}
|
||||
if (fileNames.size == 1) {
|
||||
appDb.bookDao.getBookByFileName(fileNames[0])?.let {
|
||||
val name = fileNames[0]
|
||||
appDb.bookDao.getBookByFileName(name)?.let {
|
||||
startReadBook(it.bookUrl)
|
||||
} ?: toastOnUi(R.string.no_book_found_bookshelf)
|
||||
} ?: showImportAlert(fileDoc, name)
|
||||
} else {
|
||||
showSelectBookReadAlert(fileNames)
|
||||
showSelectBookReadAlert(fileDoc, fileNames)
|
||||
}
|
||||
}
|
||||
|
||||
private fun showSelectBookReadAlert(fileNames: List<String>) {
|
||||
private fun showSelectBookReadAlert(fileDoc: FileDoc, fileNames: List<String>) {
|
||||
if (fileNames.isEmpty()) {
|
||||
toastOnUi(R.string.unsupport_archivefile_entry)
|
||||
return
|
||||
@@ -117,7 +118,29 @@ abstract class BaseImportBookActivity<VM : ViewModel> : VMBaseActivity<ActivityI
|
||||
) { _, name, _ ->
|
||||
appDb.bookDao.getBookByFileName(name)?.let {
|
||||
startReadBook(it.bookUrl)
|
||||
} ?: toastOnUi(R.string.no_book_found_bookshelf)
|
||||
} ?: showImportAlert(fileDoc, name)
|
||||
}
|
||||
}
|
||||
|
||||
open fun addArchiveToBookShelf(
|
||||
fileDoc: FileDoc,
|
||||
fileName: String,
|
||||
onSuccess: (String) -> Unit
|
||||
) {
|
||||
}
|
||||
|
||||
/* 提示是否重新导入所点击的压缩文件 */
|
||||
private fun showImportAlert(fileDoc: FileDoc, fileName: String) {
|
||||
alert(
|
||||
R.string.draw,
|
||||
R.string.no_book_found_bookshelf
|
||||
) {
|
||||
okButton {
|
||||
addArchiveToBookShelf(fileDoc, fileName) {
|
||||
startReadBook(it)
|
||||
}
|
||||
}
|
||||
noButton()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -308,4 +308,11 @@ class ImportBookActivity : BaseImportBookActivity<ImportBookViewModel>(),
|
||||
}
|
||||
}
|
||||
|
||||
override fun addArchiveToBookShelf(
|
||||
fileDoc: FileDoc,
|
||||
fileName: String,
|
||||
onSuccess: (String) -> Unit
|
||||
) {
|
||||
viewModel.addArchiveToBookShelf(fileDoc, fileName, onSuccess)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,6 +97,18 @@ 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) {
|
||||
execute {
|
||||
uriList.forEach {
|
||||
|
||||
@@ -1083,5 +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>
|
||||
<string name="no_book_found_bookshelf">No book found in bookshelf, import again ?</string>
|
||||
</resources>
|
||||
|
||||
@@ -1086,5 +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>
|
||||
<string name="no_book_found_bookshelf">No book found in bookshelf, import again ?</string>
|
||||
</resources>
|
||||
|
||||
@@ -1086,5 +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>
|
||||
<string name="no_book_found_bookshelf">No book found in bookshelf, import again ?</string>
|
||||
</resources>
|
||||
|
||||
@@ -1083,5 +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>
|
||||
<string name="no_book_found_bookshelf">未在书架上找到所选书籍, 是否重新导入?</string>
|
||||
</resources>
|
||||
|
||||
@@ -1085,5 +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>
|
||||
<string name="no_book_found_bookshelf">未在书架上找到所选书籍, 是否重新导入?</string>
|
||||
</resources>
|
||||
|
||||
@@ -1085,5 +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>
|
||||
<string name="no_book_found_bookshelf">未在书架上找到所选书籍, 是否重新导入?</string>
|
||||
</resources>
|
||||
|
||||
@@ -1086,5 +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>
|
||||
<string name="no_book_found_bookshelf">No book found in bookshelf, import again ?</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user