mirror of
https://github.com/gedoor/legado.git
synced 2024-09-01 09:34:25 +08:00
优化
This commit is contained in:
parent
009555b2f8
commit
c884340dcd
@ -16,7 +16,7 @@ object ImportOldData {
|
||||
when (doc.name) {
|
||||
"myBookShelf.json" ->
|
||||
kotlin.runCatching {
|
||||
DocumentUtils.readText(context, doc.uri)?.let { json ->
|
||||
DocumentUtils.readText(context, doc.uri).let { json ->
|
||||
val importCount = importOldBookshelf(json)
|
||||
context.toastOnUi("成功导入书籍${importCount}")
|
||||
}
|
||||
@ -25,7 +25,7 @@ object ImportOldData {
|
||||
}
|
||||
"myBookSource.json" ->
|
||||
kotlin.runCatching {
|
||||
DocumentUtils.readText(context, doc.uri)?.let { json ->
|
||||
DocumentUtils.readText(context, doc.uri).let { json ->
|
||||
val importCount = importOldSource(json)
|
||||
context.toastOnUi("成功导入书源${importCount}")
|
||||
}
|
||||
@ -34,7 +34,7 @@ object ImportOldData {
|
||||
}
|
||||
"myBookReplaceRule.json" ->
|
||||
kotlin.runCatching {
|
||||
DocumentUtils.readText(context, doc.uri)?.let { json ->
|
||||
DocumentUtils.readText(context, doc.uri).let { json ->
|
||||
val importCount = importOldReplaceRule(json)
|
||||
context.toastOnUi("成功导入替换规则${importCount}")
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ object Restore {
|
||||
DocumentFile.fromTreeUri(context, Uri.parse(path))?.listFiles()?.forEach { doc ->
|
||||
for (fileName in Backup.backupFileNames) {
|
||||
if (doc.name == fileName) {
|
||||
DocumentUtils.readText(context, doc.uri)?.let {
|
||||
DocumentUtils.readText(context, doc.uri).let {
|
||||
FileUtils.createFileIfNotExist("${Backup.backupPath}${File.separator}$fileName")
|
||||
.writeText(it)
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ object LocalBook {
|
||||
val bookFile = cacheFolder.getFile(it.name!!)
|
||||
if (!bookFile.exists()) {
|
||||
bookFile.createNewFile()
|
||||
doc.readBytes(appCtx)?.let { bytes ->
|
||||
doc.readBytes(appCtx).let { bytes ->
|
||||
bookFile.writeBytes(bytes)
|
||||
}
|
||||
}
|
||||
|
@ -267,7 +267,7 @@ class TextFile {
|
||||
val bookFile = LocalBook.cacheFolder.getFile(book.originName)
|
||||
if (!bookFile.exists()) {
|
||||
bookFile.createNewFile()
|
||||
DocumentUtils.readBytes(appCtx, uri)?.let {
|
||||
DocumentUtils.readBytes(appCtx, uri).let {
|
||||
bookFile.writeBytes(it)
|
||||
}
|
||||
}
|
||||
|
@ -278,11 +278,9 @@ class CacheViewModel(application: Application) : BaseViewModel(application) {
|
||||
if (file.isFile) {
|
||||
when {
|
||||
//正文模板
|
||||
file.name.equals(
|
||||
"chapter.html",
|
||||
true
|
||||
) || file.name.equals("chapter.xhtml", true) -> {
|
||||
contentModel = file.readText(context) ?: ""
|
||||
file.name.equals("chapter.html", true)
|
||||
|| file.name.equals("chapter.xhtml", true) -> {
|
||||
contentModel = file.readText(context)
|
||||
}
|
||||
//封面等其他模板
|
||||
true == file.name?.endsWith("html", true) -> {
|
||||
@ -296,7 +294,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) {
|
||||
book.getDisplayIntro(),
|
||||
book.kind,
|
||||
book.wordCount,
|
||||
file.readText(context) ?: "",
|
||||
file.readText(context),
|
||||
"${folder.name}/${file.name}"
|
||||
)
|
||||
)
|
||||
|
@ -223,7 +223,7 @@ class BgTextConfigDialog : BaseDialogFragment(R.layout.dialog_read_bg_text) {
|
||||
if (fontPath.isNotEmpty()) {
|
||||
val fontName = FileUtils.getName(fontPath)
|
||||
val fontBytes = fontPath.parseToUri().readBytes(requireContext())
|
||||
fontBytes?.let {
|
||||
fontBytes.let {
|
||||
val fontExportFile = FileUtils.createFileIfNotExist(configDir, fontName)
|
||||
fontExportFile.writeBytes(it)
|
||||
exportFiles.add(fontExportFile)
|
||||
@ -309,7 +309,7 @@ class BgTextConfigDialog : BaseDialogFragment(R.layout.dialog_read_bg_text) {
|
||||
private fun importConfig(uri: Uri) {
|
||||
execute {
|
||||
@Suppress("BlockingMethodInNonBlockingContext")
|
||||
importConfig(uri.readBytes(requireContext())!!)
|
||||
importConfig(uri.readBytes(requireContext()))
|
||||
}.onError {
|
||||
Timber.e(it)
|
||||
longToast("导入失败:${it.localizedMessage}")
|
||||
|
Loading…
Reference in New Issue
Block a user