pull/490/head
gedoor 4 years ago
parent 4bc62189a8
commit 668e16120f
  1. 2
      app/src/main/java/io/legado/app/model/webBook/BookContent.kt
  2. 20
      app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt
  3. 17
      app/src/main/java/io/legado/app/ui/filepicker/FilePicker.kt
  4. 2
      app/src/main/java/io/legado/app/ui/filepicker/FilePickerDialog.kt
  5. 2
      app/src/main/java/io/legado/app/ui/filepicker/adapter/FileAdapter.kt

@ -120,7 +120,7 @@ object BookContent {
val cQueryTTF = QueryTTF(correctFont!!)
val contentArray = contentStr.toStringArray()
contentArray.forEachIndexed { index, s ->
val code = cQueryTTF.getCodeByGlyf(queryTTF.getGlyfByCode(s.toInt()))
val code = cQueryTTF.GetCodeByGlyf(queryTTF.GetGlyfByCode(s.toInt()))
contentArray[index] = code.toString()
}
contentStr = contentArray.joinToString("")

@ -22,6 +22,8 @@ import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.backgroundColor
import io.legado.app.ui.book.source.debug.BookSourceDebugActivity
import io.legado.app.ui.filepicker.FilePicker
import io.legado.app.ui.filepicker.FilePickerDialog
import io.legado.app.ui.login.SourceLogin
import io.legado.app.ui.qrcode.QrCodeActivity
import io.legado.app.ui.widget.KeyboardToolPop
@ -33,11 +35,13 @@ import kotlin.math.abs
class BookSourceEditActivity :
VMBaseActivity<BookSourceEditViewModel>(R.layout.activity_book_source_edit, false),
FilePickerDialog.CallBack,
KeyboardToolPop.CallBack {
override val viewModel: BookSourceEditViewModel
get() = getViewModel(BookSourceEditViewModel::class.java)
private val qrRequestCode = 101
private val selectPathRequestCode = 102
private val adapter = BookSourceEditAdapter()
private val sourceEntities: ArrayList<EditEntity> = ArrayList()
private val searchEntities: ArrayList<EditEntity> = ArrayList()
@ -234,7 +238,7 @@ class BookSourceEditActivity :
add(EditEntity("replaceRegex", cr?.replaceRegex, R.string.rule_replace_regex))
add(EditEntity("imageStyle", cr?.imageStyle, R.string.rule_image_style))
add(EditEntity("font", cr?.font, R.string.rule_font))
add(EditEntity("correctFont", cr?.font, R.string.rule_correct_font))
add(EditEntity("correctFont", cr?.correctFont, R.string.rule_correct_font))
}
//发现
val er = source?.getExploreRule()
@ -339,7 +343,7 @@ class BookSourceEditActivity :
"replaceRegex" -> contentRule.replaceRegex = it.value
"imageStyle" -> contentRule.imageStyle = it.value
"font" -> contentRule.font = it.value
"correctFont" -> contentRule.font = it.value
"correctFont" -> contentRule.correctFont = it.value
}
}
source.ruleSearch = searchRule
@ -382,12 +386,13 @@ class BookSourceEditActivity :
}
private fun showHelpDialog() {
val items = arrayListOf("插入URL参数", "书源教程", "正则教程")
val items = arrayListOf("插入URL参数", "书源教程", "正则教程", "选择文件")
selector(getString(R.string.help), items) { _, index ->
when (index) {
0 -> insertText(AppConst.urlOption)
1 -> openUrl("https://alanskycn.gitee.io/teachme/Rule/source.html")
2 -> showRegexHelp()
3 -> FilePicker.selectFile(this, selectPathRequestCode)
}
}
}
@ -420,6 +425,15 @@ class BookSourceEditActivity :
}
}
}
selectPathRequestCode -> if (resultCode == RESULT_OK) {
data?.data?.let { uri ->
if (uri.isContentScheme()) {
sendText(uri.toString())
} else {
sendText(uri.path.toString())
}
}
}
}
}

@ -119,7 +119,7 @@ object FilePicker {
activity: BaseActivity,
requestCode: Int,
title: String = activity.getString(R.string.select_file),
allowExtensions: Array<String>,
allowExtensions: Array<String> = arrayOf(),
otherActions: List<String>? = null,
otherFun: ((action: String) -> Unit)? = null
) {
@ -177,7 +177,7 @@ object FilePicker {
fragment: Fragment,
requestCode: Int,
title: String = fragment.getString(R.string.select_file),
allowExtensions: Array<String>,
allowExtensions: Array<String> = arrayOf(),
otherActions: List<String>? = null,
otherFun: ((action: String) -> Unit)? = null
) {
@ -267,10 +267,15 @@ object FilePicker {
private fun typesOfExtensions(allowExtensions: Array<String>): Array<String> {
val types = hashSetOf<String>()
allowExtensions.forEach {
when (it) {
"txt", "xml" -> types.add("text/*")
else -> types.add("application/$it")
if (allowExtensions.isNullOrEmpty()) {
types.add("*/*")
} else {
allowExtensions.forEach {
when (it) {
"*" -> types.add("*/*")
"txt", "xml" -> types.add("text/*")
else -> types.add("application/$it")
}
}
}
return types.toTypedArray()

@ -169,7 +169,7 @@ class FilePickerDialog : DialogFragment(),
fileItem?.path?.let { path ->
if (mode == DIRECTORY) {
toast("这是文件夹选择,不能选择文件,点击右上角的确定选择文件夹")
} else if (allowExtensions == null ||
} else if (allowExtensions.isNullOrEmpty() ||
allowExtensions?.contains(FileUtils.getExtension(path)) == true
) {
setData(path)

@ -97,7 +97,7 @@ class FileAdapter(context: Context, val callBack: CallBack) :
text_view.setTextColor(disabledTextColor)
} else {
callBack.allowExtensions?.let {
if (it.contains(FileUtils.getExtension(item.path))) {
if (it.isEmpty() || it.contains(FileUtils.getExtension(item.path))) {
text_view.setTextColor(primaryTextColor)
} else {
text_view.setTextColor(disabledTextColor)

Loading…
Cancel
Save