This commit is contained in:
Xwite
2023-03-17 11:15:22 +08:00
parent 6a9fad03b3
commit 7ceb206a61
10 changed files with 54 additions and 12 deletions
@@ -98,15 +98,16 @@ abstract class BaseImportBookActivity<VM : ViewModel> : VMBaseActivity<ActivityI
it.matches(AppPattern.bookFileRegex) it.matches(AppPattern.bookFileRegex)
} }
if (fileNames.size == 1) { if (fileNames.size == 1) {
appDb.bookDao.getBookByFileName(fileNames[0])?.let { val name = fileNames[0]
appDb.bookDao.getBookByFileName(name)?.let {
startReadBook(it.bookUrl) startReadBook(it.bookUrl)
} ?: toastOnUi(R.string.no_book_found_bookshelf) } ?: showImportAlert(fileDoc, name)
} else { } else {
showSelectBookReadAlert(fileNames) showSelectBookReadAlert(fileDoc, fileNames)
} }
} }
private fun showSelectBookReadAlert(fileNames: List<String>) { private fun showSelectBookReadAlert(fileDoc: FileDoc, fileNames: List<String>) {
if (fileNames.isEmpty()) { if (fileNames.isEmpty()) {
toastOnUi(R.string.unsupport_archivefile_entry) toastOnUi(R.string.unsupport_archivefile_entry)
return return
@@ -117,7 +118,29 @@ abstract class BaseImportBookActivity<VM : ViewModel> : VMBaseActivity<ActivityI
) { _, name, _ -> ) { _, name, _ ->
appDb.bookDao.getBookByFileName(name)?.let { appDb.bookDao.getBookByFileName(name)?.let {
startReadBook(it.bookUrl) 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) { fun deleteDoc(uriList: HashSet<String>, finally: () -> Unit) {
execute { execute {
uriList.forEach { uriList.forEach {
+1 -1
View File
@@ -1083,5 +1083,5 @@
<string name="unsupport_archivefile_entry">Cannot find supported files in archive</string> <string name="unsupport_archivefile_entry">Cannot find supported files in archive</string>
<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</string> <string name="no_book_found_bookshelf">No book found in bookshelf, import again ?</string>
</resources> </resources>
+1 -1
View File
@@ -1086,5 +1086,5 @@
<string name="unsupport_archivefile_entry">Cannot find supported files in archive</string> <string name="unsupport_archivefile_entry">Cannot find supported files in archive</string>
<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</string> <string name="no_book_found_bookshelf">No book found in bookshelf, import again ?</string>
</resources> </resources>
+1 -1
View File
@@ -1086,5 +1086,5 @@
<string name="unsupport_archivefile_entry">Cannot find supported files in archive</string> <string name="unsupport_archivefile_entry">Cannot find supported files in archive</string>
<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</string> <string name="no_book_found_bookshelf">No book found in bookshelf, import again ?</string>
</resources> </resources>
+1 -1
View File
@@ -1083,5 +1083,5 @@
<string name="unsupport_archivefile_entry">压缩文件内没有支持的文件</string> <string name="unsupport_archivefile_entry">压缩文件内没有支持的文件</string>
<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>
</resources> </resources>
+1 -1
View File
@@ -1085,5 +1085,5 @@
<string name="unsupport_archivefile_entry">压缩文件内没有支持的文件</string> <string name="unsupport_archivefile_entry">压缩文件内没有支持的文件</string>
<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>
</resources> </resources>
+1 -1
View File
@@ -1085,5 +1085,5 @@
<string name="unsupport_archivefile_entry">压缩文件内没有支持的文件</string> <string name="unsupport_archivefile_entry">压缩文件内没有支持的文件</string>
<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>
</resources> </resources>
+1 -1
View File
@@ -1086,5 +1086,5 @@
<string name="unsupport_archivefile_entry">Cannot find supported files in archive</string> <string name="unsupport_archivefile_entry">Cannot find supported files in archive</string>
<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</string> <string name="no_book_found_bookshelf">No book found in bookshelf, import again ?</string>
</resources> </resources>