mirror of
https://github.com/gedoor/legado.git
synced 2024-07-06 23:47:49 +08:00
优化
This commit is contained in:
parent
cc71a6c22b
commit
70d8b184ad
@ -101,7 +101,9 @@ class FileAssociationActivity :
|
||||
viewModel.errorLive.observe(this) {
|
||||
binding.rotateLoading.gone()
|
||||
toastOnUi(it)
|
||||
finish()
|
||||
handler.postDelayed(2000) {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
viewModel.openBookLiveData.observe(this) {
|
||||
binding.rotateLoading.gone()
|
||||
@ -128,33 +130,24 @@ class FileAssociationActivity :
|
||||
}
|
||||
}
|
||||
intent.data?.let { data ->
|
||||
if (data.isContentScheme()) {
|
||||
if (data.canRead()) {
|
||||
viewModel.dispatchIntent(data)
|
||||
} else {
|
||||
dispatchWithPermission(data)
|
||||
}
|
||||
} else if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q) {
|
||||
dispatchWithPermission(data)
|
||||
if (data.isContentScheme() && data.canRead()) {
|
||||
viewModel.dispatchIntent(data)
|
||||
} else {
|
||||
toastOnUi("由于安卓系统限制,请使用系统文件管理重新打开。")
|
||||
finish()
|
||||
PermissionsCompat.Builder()
|
||||
.addPermissions(*Permissions.Group.STORAGE)
|
||||
.rationale(R.string.tip_perm_request_storage)
|
||||
.onGranted {
|
||||
viewModel.dispatchIntent(data)
|
||||
}.onDenied {
|
||||
toastOnUi("请求存储权限失败。")
|
||||
handler.postDelayed(2000) {
|
||||
finish()
|
||||
}
|
||||
}.request()
|
||||
}
|
||||
} ?: finish()
|
||||
}
|
||||
|
||||
private fun dispatchWithPermission(data: Uri) {
|
||||
PermissionsCompat.Builder()
|
||||
.addPermissions(*Permissions.Group.STORAGE)
|
||||
.rationale(R.string.tip_perm_request_storage)
|
||||
.onGranted {
|
||||
viewModel.dispatchIntent(data)
|
||||
}.onDenied {
|
||||
toastOnUi("请求存储权限失败。")
|
||||
finish()
|
||||
}.request()
|
||||
}
|
||||
|
||||
private fun importBook(uri: Uri) {
|
||||
if (uri.isContentScheme()) {
|
||||
val treeUriStr = AppConfig.defaultBookTreeUri
|
||||
|
@ -17,11 +17,10 @@ class FileAssociationViewModel(application: Application) : BaseAssociationViewMo
|
||||
|
||||
fun dispatchIntent(uri: Uri) {
|
||||
execute {
|
||||
lateinit var fileName: String
|
||||
//如果是普通的url,需要根据返回的内容判断是什么
|
||||
if (uri.isContentScheme() || uri.isFileScheme()) {
|
||||
val fileDoc = FileDoc.fromUri(uri, false)
|
||||
fileName = fileDoc.name
|
||||
val fileName = fileDoc.name
|
||||
if (fileName.matches(AppPattern.archiveFileRegex)) {
|
||||
ArchiveUtils.deCompress(fileDoc, ArchiveUtils.TEMP_PATH) {
|
||||
it.matches(bookFileRegex)
|
||||
@ -36,8 +35,9 @@ class FileAssociationViewModel(application: Application) : BaseAssociationViewMo
|
||||
}
|
||||
}.onError {
|
||||
it.printOnDebug()
|
||||
errorLive.postValue(it.localizedMessage)
|
||||
AppLog.put("无法打开文件\n${it.localizedMessage}", it)
|
||||
val msg = "无法打开文件\n${it.localizedMessage}"
|
||||
errorLive.postValue(msg)
|
||||
AppLog.put(msg, it)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ import kotlin.collections.ArrayList
|
||||
/**
|
||||
* 解析内容生成章节和页面
|
||||
*/
|
||||
@Suppress("DEPRECATION")
|
||||
@Suppress("DEPRECATION", "ConstPropertyName")
|
||||
object ChapterProvider {
|
||||
//用于图片字的替换
|
||||
private const val srcReplaceChar = "▩"
|
||||
@ -372,9 +372,9 @@ object ChapterProvider {
|
||||
textLayoutHeight = fistLine.lineTop - titleTopSpacing
|
||||
}
|
||||
textPage.lines.forEach {
|
||||
it.lineTop = it.lineTop - textLayoutHeight
|
||||
it.lineBase = it.lineBase - textLayoutHeight
|
||||
it.lineBottom = it.lineBottom - textLayoutHeight
|
||||
it.lineTop -= textLayoutHeight
|
||||
it.lineBase -= textLayoutHeight
|
||||
it.lineBottom -= textLayoutHeight
|
||||
}
|
||||
y - textLayoutHeight
|
||||
}
|
||||
@ -630,12 +630,15 @@ object ChapterProvider {
|
||||
val strList = ArrayList<String>()
|
||||
val textWidthList = ArrayList<Float>()
|
||||
val lastIndex = charArray.lastIndex
|
||||
var ca: CharArray? = null
|
||||
for (i in textWidths.indices) {
|
||||
if (charArray[i].isLowSurrogate()) {
|
||||
continue
|
||||
}
|
||||
val char = if (i + 1 <= lastIndex && charArray[i + 1].isLowSurrogate()) {
|
||||
charArray[i].toString() + charArray[i + 1].toString()
|
||||
if (ca == null) ca = CharArray(2)
|
||||
System.arraycopy(charArray, i, ca, 0, 2)
|
||||
String(ca)
|
||||
} else {
|
||||
charArray[i].toString()
|
||||
}
|
||||
@ -705,8 +708,8 @@ object ChapterProvider {
|
||||
for (i in 0..words.lastIndex) {
|
||||
textLine.getColumnReverseAt(i).let {
|
||||
val py = cc * (words.size - i)
|
||||
it.start = it.start - py
|
||||
it.end = it.end - py
|
||||
it.start -= py
|
||||
it.end -= py
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user