mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
fix bookimport bug
This commit is contained in:
@@ -102,7 +102,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) {
|
||||
val filename = "${getExportFileName(book)}.txt"
|
||||
DocumentUtils.delete(doc, filename)
|
||||
val bookDoc = DocumentUtils.createFileIfNotExist(doc, filename)
|
||||
?: throw NoStackTraceException("创建文档失败")
|
||||
?: throw NoStackTraceException("创建文档失败,请尝试重新设置导出文件夹")
|
||||
val stringBuilder = StringBuilder()
|
||||
context.contentResolver.openOutputStream(bookDoc.uri, "wa")?.use { bookOs ->
|
||||
getAllContents(scope, book) { text, srcList ->
|
||||
|
||||
@@ -48,10 +48,10 @@ class ImportBookActivity : VMBaseActivity<ActivityImportBookBinding, ImportBookV
|
||||
it.uri?.let { uri ->
|
||||
if (uri.isContentScheme()) {
|
||||
AppConfig.importBookPath = uri.toString()
|
||||
initRootDoc()
|
||||
initRootDoc(true)
|
||||
} else {
|
||||
AppConfig.importBookPath = uri.path
|
||||
initRootDoc()
|
||||
initRootDoc(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -146,10 +146,10 @@ class ImportBookActivity : VMBaseActivity<ActivityImportBookBinding, ImportBookV
|
||||
}
|
||||
}
|
||||
|
||||
private fun initRootDoc() {
|
||||
private fun initRootDoc(changedFolder: Boolean = false) {
|
||||
val lastPath = AppConfig.importBookPath
|
||||
when {
|
||||
viewModel.rootDoc != null -> upPath()
|
||||
viewModel.rootDoc != null && !changedFolder -> upPath()
|
||||
lastPath.isNullOrEmpty() -> {
|
||||
binding.tvEmptyMsg.visible()
|
||||
selectFolder.launch()
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.app.Application
|
||||
import android.net.Uri
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import io.legado.app.base.BaseViewModel
|
||||
import io.legado.app.constant.AppLog
|
||||
import io.legado.app.constant.AppPattern.bookFileRegex
|
||||
import io.legado.app.constant.PreferKey
|
||||
import io.legado.app.model.localBook.LocalBook
|
||||
@@ -76,6 +77,9 @@ class ImportBookViewModel(application: Application) : BaseViewModel(application)
|
||||
uriList.forEach {
|
||||
LocalBook.importFile(Uri.parse(it))
|
||||
}
|
||||
}.onError {
|
||||
context.toastOnUi("添加书架失败,请尝试重新选择文件夹")
|
||||
AppLog.put("添加书架失败\n${it.localizedMessage}", it)
|
||||
}.onFinally {
|
||||
finally.invoke()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user