6.7.0 - Alpha6 - 修复 APK 文件类型信息对话框可能无法获取应用名称及 SDK 信息的问题
This commit is contained in:
@@ -31,7 +31,7 @@ object MaterialDialogExtensions {
|
||||
@JvmStatic
|
||||
@JvmOverloads
|
||||
fun MaterialDialog.makeTextCopyable(textView: TextView?, textValue: String? = textView?.text?.toString()) {
|
||||
if (textValue != null) {
|
||||
if (!textValue.isNullOrBlank()) {
|
||||
val context = this.context
|
||||
textView?.setOnClickListener {
|
||||
ClipboardUtils.setClip(context, textValue)
|
||||
@@ -45,10 +45,17 @@ object MaterialDialogExtensions {
|
||||
}
|
||||
|
||||
fun MaterialDialog.setCopyableTextIfAbsent(textView: TextView, textValue: String?, suffix: String? = null) {
|
||||
if (textView.text == context.getString(R.string.ellipsis_six)) {
|
||||
textView.text = textValue.takeUnless { it.isNullOrBlank() }?.let { it + (suffix ?: "") } ?: context.getString(R.string.text_unknown)
|
||||
when {
|
||||
textValue.isNullOrBlank() -> {
|
||||
if (textView.isNullOrBlank() || textView.isEllipsisSix()) {
|
||||
textView.setUnknown()
|
||||
}
|
||||
}
|
||||
textView.isNullOrBlank() || textView.isEllipsisSix() || textView.isUnknown() -> {
|
||||
textView.text = textValue + (suffix ?: "")
|
||||
this.makeTextCopyable(textView, textValue)
|
||||
}
|
||||
}
|
||||
this.makeTextCopyable(textView, textValue)
|
||||
}
|
||||
|
||||
fun MaterialDialog.setCopyableTextIfAbsent(textView: TextView, scope: CoroutineScope, f: () -> String?) {
|
||||
@@ -65,8 +72,15 @@ object MaterialDialogExtensions {
|
||||
}
|
||||
|
||||
fun MaterialDialog.setCopyableText(textView: TextView, textValue: String?) {
|
||||
textView.text = textValue.takeUnless { it.isNullOrBlank() } ?: context.getString(R.string.text_unknown)
|
||||
this.makeTextCopyable(textView, textValue)
|
||||
when {
|
||||
textValue.isNullOrBlank() -> {
|
||||
textView.setUnknown()
|
||||
}
|
||||
else -> {
|
||||
textView.text = textValue
|
||||
this.makeTextCopyable(textView, textValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@@ -79,4 +93,9 @@ object MaterialDialogExtensions {
|
||||
it.widgetColor(ThemeColorHelper.getThemeColorStateList(context))
|
||||
}
|
||||
|
||||
private fun TextView.setUnknown() = setText(R.string.text_unknown)
|
||||
private fun TextView.isUnknown() = text == context.getString(R.string.text_unknown)
|
||||
private fun TextView.isEllipsisSix() = text == context.getString(R.string.ellipsis_six)
|
||||
private fun TextView.isNullOrBlank() = text.isNullOrBlank()
|
||||
|
||||
}
|
||||
|
||||
@@ -79,6 +79,7 @@ object ApkInfoDialogManager {
|
||||
scope.launch {
|
||||
val apkInfoDeferred = async(Dispatchers.IO) { getApkInfo(apkFile) }
|
||||
val packageInfoDeferred = async(Dispatchers.IO) { getPackageInfo(packageManager, apkFilePath) }
|
||||
val sysBasicDeferred = async(Dispatchers.IO) { getBasicInfoFromPackageArchive(context, apkFilePath) }
|
||||
|
||||
val firstPackageName: String? = select {
|
||||
apkInfoDeferred.onAwait { it?.packageName }
|
||||
@@ -115,6 +116,13 @@ object ApkInfoDialogManager {
|
||||
dialog.setCopyableTextIfAbsent(binding.fileSizeValue, this) { PFiles.getHumanReadableSize(apkFile.length()) }
|
||||
dialog.setCopyableTextIfAbsent(binding.signatureSchemeValue, this) { getApkSignatureInfo(apkFile) }
|
||||
|
||||
withContext(Dispatchers.Main) {
|
||||
val sys = sysBasicDeferred.await()
|
||||
dialog.setCopyableTextIfAbsent(binding.labelNameValue, sys?.label)
|
||||
dialog.setCopyableTextIfAbsent(binding.minSdkValue, sys?.minSdk?.toString())
|
||||
dialog.setCopyableTextIfAbsent(binding.targetSdkValue, sys?.targetSdk?.toString())
|
||||
}
|
||||
|
||||
launch(Dispatchers.IO) {
|
||||
val apkInfo = apkInfoDeferred.await()
|
||||
|
||||
@@ -255,6 +263,26 @@ object ApkInfoDialogManager {
|
||||
}
|
||||
}.getOrNull()
|
||||
|
||||
private fun getBasicInfoFromPackageArchive(context: Context, apkPath: String): SysBasicInfo? = runCatching {
|
||||
val pm = context.packageManager
|
||||
val pi = pm.getPackageArchiveInfo(apkPath, GET_META_DATA) ?: return@runCatching null
|
||||
val ai = pi.applicationInfo?.apply {
|
||||
sourceDir = apkPath
|
||||
publicSourceDir = apkPath
|
||||
}
|
||||
SysBasicInfo(
|
||||
label = ai?.loadLabel(pm)?.toString(),
|
||||
minSdk = this.runCatching { ai?.minSdkVersion }.getOrNull()?.takeIf { it != 0 },
|
||||
targetSdk = ai?.targetSdkVersion?.takeIf { it != 0 },
|
||||
)
|
||||
}.getOrNull()
|
||||
|
||||
private data class SysBasicInfo(
|
||||
val label: String?,
|
||||
val minSdk: Int?,
|
||||
val targetSdk: Int?,
|
||||
)
|
||||
|
||||
private data class ApkInfo(
|
||||
val label: String?,
|
||||
val packageName: String?,
|
||||
|
||||
Reference in New Issue
Block a user