优化排版导入

pull/363/head
gedoor 4 years ago
parent cda68d51b3
commit 70f0086b39
  1. 16
      app/src/main/java/io/legado/app/model/Debug.kt
  2. 58
      app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt
  3. 9
      app/src/main/java/io/legado/app/utils/ThrowableExtensions.kt

@ -7,7 +7,7 @@ import io.legado.app.model.rss.Rss
import io.legado.app.model.webBook.WebBook
import io.legado.app.utils.htmlFormat
import io.legado.app.utils.isAbsUrl
import org.jetbrains.anko.getStackTraceString
import io.legado.app.utils.msg
import java.text.SimpleDateFormat
import java.util.*
@ -77,7 +77,7 @@ object Debug {
}
}
.onError {
log(debugSource, "${it.localizedMessage}\n${it.getStackTraceString()}", state = -1)
log(debugSource, it.msg, state = -1)
}
}
@ -89,7 +89,7 @@ object Debug {
log(debugSource, "︽内容页解析完成", state = 1000)
}
.onError {
log(debugSource, "${it.localizedMessage}\n${it.getStackTraceString()}", state = -1)
log(debugSource, it.msg, state = -1)
}
}
@ -149,7 +149,7 @@ object Debug {
}
}
.onError {
log(debugSource, "${it.localizedMessage}\n${it.getStackTraceString()}", state = -1)
log(debugSource, it.msg, state = -1)
}
tasks.add(explore)
}
@ -168,7 +168,7 @@ object Debug {
}
}
.onError {
log(debugSource, "${it.localizedMessage}\n${it.getStackTraceString()}", state = -1)
log(debugSource, it.msg, state = -1)
}
tasks.add(search)
}
@ -182,7 +182,7 @@ object Debug {
tocDebug(webBook, book)
}
.onError {
log(debugSource, "${it.localizedMessage}\n${it.getStackTraceString()}", state = -1)
log(debugSource, it.msg, state = -1)
}
tasks.add(info)
}
@ -201,7 +201,7 @@ object Debug {
}
}
.onError {
log(debugSource, "${it.localizedMessage}\n${it.getStackTraceString()}", state = -1)
log(debugSource, it.msg, state = -1)
}
tasks.add(chapterList)
}
@ -218,7 +218,7 @@ object Debug {
log(debugSource, "︽正文页解析完成", state = 1000)
}
.onError {
log(debugSource, "${it.localizedMessage}\n${it.getStackTraceString()}", state = -1)
log(debugSource, it.msg, state = -1)
}
tasks.add(content)
}

@ -21,15 +21,22 @@ import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.constant.EventBus
import io.legado.app.help.ImageLoader
import io.legado.app.help.ReadBookConfig
import io.legado.app.help.http.HttpHelper
import io.legado.app.help.permission.Permissions
import io.legado.app.help.permission.PermissionsCompat
import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.dialogs.customView
import io.legado.app.lib.dialogs.noButton
import io.legado.app.lib.dialogs.okButton
import io.legado.app.lib.theme.bottomBackground
import io.legado.app.lib.theme.getPrimaryTextColor
import io.legado.app.lib.theme.getSecondaryTextColor
import io.legado.app.ui.book.read.ReadBookActivityHelp
import io.legado.app.ui.filechooser.FileChooserDialog
import io.legado.app.ui.filechooser.FilePicker
import io.legado.app.ui.widget.text.AutoCompleteTextView
import io.legado.app.utils.*
import kotlinx.android.synthetic.main.dialog_edit_text.view.*
import kotlinx.android.synthetic.main.dialog_read_bg_text.*
import kotlinx.android.synthetic.main.item_bg_image.view.*
import org.jetbrains.anko.sdk27.listeners.onCheckedChange
@ -151,11 +158,18 @@ class BgTextConfigDialog : BaseDialogFragment(), FileChooserDialog.CallBack {
postEvent(EventBus.UP_CONFIG, false)
}
tv_import.onClick {
val importFormNet = "网络导入"
val otherActions = arrayListOf(importFormNet)
FilePicker.selectFile(
this@BgTextConfigDialog,
requestCodeImport,
allowExtensions = arrayOf("zip")
)
allowExtensions = arrayOf("zip"),
otherActions = otherActions
) { action ->
when (action) {
importFormNet -> importNetConfigAlert()
}
}
}
tv_export.onClick {
FilePicker.selectFolder(this@BgTextConfigDialog, requestCodeExport)
@ -249,13 +263,51 @@ class BgTextConfigDialog : BaseDialogFragment(), FileChooserDialog.CallBack {
}
}
@SuppressLint("InflateParams")
private fun importNetConfigAlert() {
alert("输入地址") {
var editText: AutoCompleteTextView? = null
customView {
layoutInflater.inflate(R.layout.dialog_edit_text, null).apply {
editText = edit_view
}
}
okButton {
editText?.text?.toString()?.let { url ->
importNetConfig(url)
}
}
noButton { }
}.show().applyTint()
}
private fun importNetConfig(url: String) {
execute {
HttpHelper.simpleGetBytesAsync(url)?.let {
importConfig(it)
} ?: throw Exception("获取失败")
}.onError {
longToast(it.msg)
}
}
@Suppress("BlockingMethodInNonBlockingContext")
private fun importConfig(uri: Uri) {
execute {
importConfig(uri.readBytes(requireContext())!!)
}.onError {
it.printStackTrace()
longToast("导入失败:${it.localizedMessage}")
}
}
@Suppress("BlockingMethodInNonBlockingContext")
private fun importConfig(byteArray: ByteArray) {
execute {
val configZipPath = FileUtils.getPath(requireContext().eCacheDir, configFileName)
FileUtils.deleteFile(configZipPath)
val zipFile = FileUtils.createFileIfNotExist(configZipPath)
zipFile.writeBytes(uri.readBytes(requireContext())!!)
zipFile.writeBytes(byteArray)
val configDirPath = FileUtils.getPath(requireContext().eCacheDir, "readConfig")
FileUtils.deleteFile(configDirPath)
ZipUtils.unzipFile(zipFile, FileUtils.createFolderIfNotExist(configDirPath))

@ -0,0 +1,9 @@
package io.legado.app.utils
val Throwable.msg: String
get() {
val lMsg = this.localizedMessage
return if (lMsg.isNullOrEmpty()) this.stackTraceToString() else {
lMsg
}
}
Loading…
Cancel
Save