fix
This commit is contained in:
@@ -2,6 +2,7 @@ package io.legado.app.ui.book.info
|
|||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
@@ -329,7 +330,7 @@ class BookInfoActivity :
|
|||||||
viewModel.bookData.value?.let { book ->
|
viewModel.bookData.value?.let { book ->
|
||||||
if (book.isWebFile) {
|
if (book.isWebFile) {
|
||||||
showWebFileDownloadAlert {
|
showWebFileDownloadAlert {
|
||||||
readBook(book)
|
readBook(it)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
readBook(book)
|
readBook(book)
|
||||||
@@ -342,11 +343,7 @@ class BookInfoActivity :
|
|||||||
deleteBook()
|
deleteBook()
|
||||||
} else {
|
} else {
|
||||||
if (book.isWebFile) {
|
if (book.isWebFile) {
|
||||||
showWebFileDownloadAlert {
|
showWebFileDownloadAlert()
|
||||||
viewModel.addToBookshelf {
|
|
||||||
upTvBookshelf()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
viewModel.addToBookshelf {
|
viewModel.addToBookshelf {
|
||||||
upTvBookshelf()
|
upTvBookshelf()
|
||||||
@@ -497,13 +494,13 @@ class BookInfoActivity :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showWebFileDownloadAlert(onClick: (() -> Unit)?) {
|
private fun showWebFileDownloadAlert(onClick: ((Book) -> Unit)?) {
|
||||||
viewModel.webFileData.value?.let {
|
viewModel.webFileData.value?.let {
|
||||||
alert(titleResource = R.string.download_and_import_file) {
|
alert(titleResource = R.string.download_and_import_file) {
|
||||||
items<BookInfoViewModel.WebFile>(it) { _, webFile, _ ->
|
items<BookInfoViewModel.WebFile>(it) { _, webFile, _ ->
|
||||||
if (webFile.isSupported) {
|
if (webFile.isSupported) {
|
||||||
viewModel.importOrDownloadWebFile(webFile) {
|
viewModel.importOrDownloadWebFile<Book>(webFile) {
|
||||||
onClick?.invoke()
|
onClick?.invoke(it)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
alert(
|
alert(
|
||||||
@@ -511,8 +508,8 @@ class BookInfoActivity :
|
|||||||
message = getString(R.string.file_not_supported, webFile.name)
|
message = getString(R.string.file_not_supported, webFile.name)
|
||||||
) {
|
) {
|
||||||
neutralButton(R.string.open_fun) {
|
neutralButton(R.string.open_fun) {
|
||||||
viewModel.importOrDownloadWebFile(webFile) { uri ->
|
viewModel.importOrDownloadWebFile<Uri>(webFile) { uri ->
|
||||||
openFileUri(uri!!, "*/*")
|
openFileUri(uri, "*/*")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
noButton()
|
noButton()
|
||||||
|
|||||||
@@ -270,18 +270,18 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun importOrDownloadWebFile(webFile: WebFile, success: ((Uri?) -> Unit)?) {
|
fun <T> importOrDownloadWebFile(webFile: WebFile, success: ((T) -> Unit)?) {
|
||||||
bookSource ?: return
|
bookSource ?: return
|
||||||
execute {
|
execute {
|
||||||
if (webFile.isSupported) {
|
if (webFile.isSupported) {
|
||||||
LocalBook.importFileOnLine(webFile.url, webFile.name, bookSource).let {
|
val book = LocalBook.importFileOnLine(webFile.url, webFile.name, bookSource)
|
||||||
changeToLocalBook(it)
|
changeToLocalBook(book)
|
||||||
}
|
book
|
||||||
} else {
|
} else {
|
||||||
LocalBook.saveBookFile(webFile.url, webFile.name, bookSource)
|
LocalBook.saveBookFile(webFile.url, webFile.name, bookSource)
|
||||||
}
|
}
|
||||||
}.onSuccess {
|
}.onSuccess {
|
||||||
success?.invoke(it as? Uri)
|
success?.invoke(it as T)
|
||||||
}.onError {
|
}.onError {
|
||||||
context.toastOnUi("ImportWebFileError\n${it.localizedMessage}")
|
context.toastOnUi("ImportWebFileError\n${it.localizedMessage}")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user