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