pull/1391/head
gedoor 3 years ago
parent 009555b2f8
commit c884340dcd
  1. 6
      app/src/main/java/io/legado/app/help/storage/ImportOldData.kt
  2. 2
      app/src/main/java/io/legado/app/help/storage/Restore.kt
  3. 2
      app/src/main/java/io/legado/app/model/localBook/LocalBook.kt
  4. 2
      app/src/main/java/io/legado/app/model/localBook/TextFile.kt
  5. 10
      app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt
  6. 4
      app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt

@ -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…
Cancel
Save