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) { when (doc.name) {
"myBookShelf.json" -> "myBookShelf.json" ->
kotlin.runCatching { kotlin.runCatching {
DocumentUtils.readText(context, doc.uri)?.let { json -> DocumentUtils.readText(context, doc.uri).let { json ->
val importCount = importOldBookshelf(json) val importCount = importOldBookshelf(json)
context.toastOnUi("成功导入书籍${importCount}") context.toastOnUi("成功导入书籍${importCount}")
} }
@ -25,7 +25,7 @@ object ImportOldData {
} }
"myBookSource.json" -> "myBookSource.json" ->
kotlin.runCatching { kotlin.runCatching {
DocumentUtils.readText(context, doc.uri)?.let { json -> DocumentUtils.readText(context, doc.uri).let { json ->
val importCount = importOldSource(json) val importCount = importOldSource(json)
context.toastOnUi("成功导入书源${importCount}") context.toastOnUi("成功导入书源${importCount}")
} }
@ -34,7 +34,7 @@ object ImportOldData {
} }
"myBookReplaceRule.json" -> "myBookReplaceRule.json" ->
kotlin.runCatching { kotlin.runCatching {
DocumentUtils.readText(context, doc.uri)?.let { json -> DocumentUtils.readText(context, doc.uri).let { json ->
val importCount = importOldReplaceRule(json) val importCount = importOldReplaceRule(json)
context.toastOnUi("成功导入替换规则${importCount}") context.toastOnUi("成功导入替换规则${importCount}")
} }

@ -72,7 +72,7 @@ object Restore {
DocumentFile.fromTreeUri(context, Uri.parse(path))?.listFiles()?.forEach { doc -> DocumentFile.fromTreeUri(context, Uri.parse(path))?.listFiles()?.forEach { doc ->
for (fileName in Backup.backupFileNames) { for (fileName in Backup.backupFileNames) {
if (doc.name == fileName) { if (doc.name == fileName) {
DocumentUtils.readText(context, doc.uri)?.let { DocumentUtils.readText(context, doc.uri).let {
FileUtils.createFileIfNotExist("${Backup.backupPath}${File.separator}$fileName") FileUtils.createFileIfNotExist("${Backup.backupPath}${File.separator}$fileName")
.writeText(it) .writeText(it)
} }

@ -67,7 +67,7 @@ object LocalBook {
val bookFile = cacheFolder.getFile(it.name!!) val bookFile = cacheFolder.getFile(it.name!!)
if (!bookFile.exists()) { if (!bookFile.exists()) {
bookFile.createNewFile() bookFile.createNewFile()
doc.readBytes(appCtx)?.let { bytes -> doc.readBytes(appCtx).let { bytes ->
bookFile.writeBytes(bytes) bookFile.writeBytes(bytes)
} }
} }

@ -267,7 +267,7 @@ class TextFile {
val bookFile = LocalBook.cacheFolder.getFile(book.originName) val bookFile = LocalBook.cacheFolder.getFile(book.originName)
if (!bookFile.exists()) { if (!bookFile.exists()) {
bookFile.createNewFile() bookFile.createNewFile()
DocumentUtils.readBytes(appCtx, uri)?.let { DocumentUtils.readBytes(appCtx, uri).let {
bookFile.writeBytes(it) bookFile.writeBytes(it)
} }
} }

@ -278,11 +278,9 @@ class CacheViewModel(application: Application) : BaseViewModel(application) {
if (file.isFile) { if (file.isFile) {
when { when {
//正文模板 //正文模板
file.name.equals( file.name.equals("chapter.html", true)
"chapter.html", || file.name.equals("chapter.xhtml", true) -> {
true contentModel = file.readText(context)
) || file.name.equals("chapter.xhtml", true) -> {
contentModel = file.readText(context) ?: ""
} }
//封面等其他模板 //封面等其他模板
true == file.name?.endsWith("html", true) -> { true == file.name?.endsWith("html", true) -> {
@ -296,7 +294,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) {
book.getDisplayIntro(), book.getDisplayIntro(),
book.kind, book.kind,
book.wordCount, book.wordCount,
file.readText(context) ?: "", file.readText(context),
"${folder.name}/${file.name}" "${folder.name}/${file.name}"
) )
) )

@ -223,7 +223,7 @@ class BgTextConfigDialog : BaseDialogFragment(R.layout.dialog_read_bg_text) {
if (fontPath.isNotEmpty()) { if (fontPath.isNotEmpty()) {
val fontName = FileUtils.getName(fontPath) val fontName = FileUtils.getName(fontPath)
val fontBytes = fontPath.parseToUri().readBytes(requireContext()) val fontBytes = fontPath.parseToUri().readBytes(requireContext())
fontBytes?.let { fontBytes.let {
val fontExportFile = FileUtils.createFileIfNotExist(configDir, fontName) val fontExportFile = FileUtils.createFileIfNotExist(configDir, fontName)
fontExportFile.writeBytes(it) fontExportFile.writeBytes(it)
exportFiles.add(fontExportFile) exportFiles.add(fontExportFile)
@ -309,7 +309,7 @@ class BgTextConfigDialog : BaseDialogFragment(R.layout.dialog_read_bg_text) {
private fun importConfig(uri: Uri) { private fun importConfig(uri: Uri) {
execute { execute {
@Suppress("BlockingMethodInNonBlockingContext") @Suppress("BlockingMethodInNonBlockingContext")
importConfig(uri.readBytes(requireContext())!!) importConfig(uri.readBytes(requireContext()))
}.onError { }.onError {
Timber.e(it) Timber.e(it)
longToast("导入失败:${it.localizedMessage}") longToast("导入失败:${it.localizedMessage}")

Loading…
Cancel
Save