This commit is contained in:
Xwite
2023-03-17 11:13:29 +08:00
parent 6a9fad03b3
commit 7ceb206a61
10 changed files with 54 additions and 12 deletions

View File

@@ -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()
}
}

View File

@@ -308,4 +308,11 @@ class ImportBookActivity : BaseImportBookActivity<ImportBookViewModel>(),
}
}
override fun addArchiveToBookShelf(
fileDoc: FileDoc,
fileName: String,
onSuccess: (String) -> Unit
) {
viewModel.addArchiveToBookShelf(fileDoc, fileName, onSuccess)
}
}

View File

@@ -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 {

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>