6.6.2 - Alpha - APK 文件类型信息对话框增加点击监听器

This commit is contained in:
SuperMonster003
2025-01-03 20:14:50 +08:00
parent fd13e20a98
commit c350041652
16 changed files with 85 additions and 51 deletions

View File

@@ -131,7 +131,7 @@ class AppUtils(context: Context, @get:ScriptInterface val fileProviderAuthority:
runCatching {
getPackageInfoCompat(mPackageManager, packageName!!, 0)
}.getOrElse {
throw Exception(mContext.getString(R.string.error_app_not_installed, packageName))
throw Exception(mContext.getString(R.string.error_app_not_installed_with_name, packageName))
}
}
@@ -141,7 +141,7 @@ class AppUtils(context: Context, @get:ScriptInterface val fileProviderAuthority:
runCatching {
getPackageInfoCompat(mPackageManager, app.packageName, 0)
}.getOrElse {
throw Exception("${mContext.getString(R.string.error_app_not_installed, app.getAppName())} [ ${app.packageName} ]")
throw Exception("${mContext.getString(R.string.error_app_not_installed_with_name, app.getAppName())} [ ${app.packageName} ]")
}
}

View File

@@ -5,6 +5,7 @@ import android.content.Context
import android.content.pm.PackageManager.GET_META_DATA
import android.os.Build
import android.view.LayoutInflater
import android.view.View
import android.view.View.MeasureSpec.UNSPECIFIED
import android.view.ViewGroup
import android.widget.TextView
@@ -20,7 +21,9 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.autojs.autojs.pio.PFiles
import org.autojs.autojs.runtime.api.AppUtils
import org.autojs.autojs.util.ClipboardUtils
import org.autojs.autojs.util.IntentUtils
import org.autojs.autojs.util.ViewUtils
import org.autojs.autojs6.R
import org.autojs.autojs6.databinding.ApkFileInfoDialogListItemBinding
import java.io.File
@@ -85,29 +88,48 @@ object ApkInfoDialogManager {
// ! 优先处理 "已安装版本", 决定是否显示其内容视图.
// ! 这是唯一一个在显示对话框之前需要考虑的内容视图.
// ! 此时可立即安全显示对话框, 因所有内容视图均已完成占位.
bindInstalledVersion(binding, context, packageName)
val installedPackageName: String? = packageName?.let { pkg ->
AppUtils.getInstalledVersionInfo(pkg)?.let { versionInfo ->
binding.installedVersionParent.isVisible = true
binding.installedVersionValue.setTextIfAbsent(dialog) { context.getString(R.string.text_full_version_info, versionInfo.versionName, versionInfo.versionCode) }
pkg /* returns as installedPackageName */
}
}
restoreEssentialViews(binding, context)
updateGuidelines(binding)
packageName?.let { binding.packageNameValue.text = it }
binding.deviceSdkValue.text = "${Build.VERSION.SDK_INT}"
bindVersionInfo(binding, context, versionName, versionCode)
when {
versionName != null -> {
binding.versionPlaceholderLabel.text = context.getString(R.string.text_version)
binding.versionPlaceholderValue.setTextIfAbsent(dialog) { context.getString(R.string.text_full_version_info, versionName, versionCode) }
}
versionCode != null -> {
binding.versionPlaceholderLabel.text = context.getString(R.string.text_version_code)
binding.versionPlaceholderValue.setTextIfAbsent(dialog) { "$versionCode" }
}
else -> binding.versionPlaceholderValue.setTextIfAbsent(dialog) { null }
}
binding.fileSizeValue.setTextIfAbsent { fileSize }
binding.signatureSchemeValue.setTextIfAbsent { signatureScheme }
binding.packageNameValue.setTextIfAbsent(dialog) { packageName }
binding.deviceSdkValue.setTextIfAbsent(dialog) { "${Build.VERSION.SDK_INT}" }
binding.fileSizeValue.setTextIfAbsent(dialog) { fileSize }
binding.signatureSchemeValue.setTextIfAbsent(dialog) { signatureScheme }
dialog.setIcon(applicationInfo?.apply {
sourceDir = apkFilePath
publicSourceDir = apkFilePath
}?.loadIcon(packageManager) ?: context.getDrawable(R.drawable.ic_packaging))
dialog.makeSettingsLaunchable({ it.iconView }, installedPackageName)
dialog.makeTextCopyable { it.titleView }
val apkInfo = getApkInfo(apkFile)
binding.labelNameValue.setTextIfAbsent { apkInfo?.label }
binding.packageNameValue.setTextIfAbsent { apkInfo?.packageName }
binding.minSdkValue.setTextIfAbsent { apkInfo?.minSdkVersion?.toString() }
binding.targetSdkValue.setTextIfAbsent { apkInfo?.targetSdkVersion?.toString() }
binding.labelNameValue.setTextIfAbsent(dialog) { apkInfo?.label }
binding.packageNameValue.setTextIfAbsent(dialog) { apkInfo?.packageName }
binding.minSdkValue.setTextIfAbsent(dialog) { apkInfo?.minSdkVersion?.toString() }
binding.targetSdkValue.setTextIfAbsent(dialog) { apkInfo?.targetSdkVersion?.toString() }
if (apkInfo != null) dialog.getActionButton(DialogAction.NEUTRAL).let { neutralButton ->
neutralButton.isVisible = true
@@ -133,35 +155,35 @@ object ApkInfoDialogManager {
}.getOrNull()
}
private fun bindVersionInfo(binding: ApkFileInfoDialogListItemBinding, context: Context, versionName: String?, versionCode: Long?) {
when {
versionName != null && versionCode != null -> {
binding.versionPlaceholderLabel.text = context.getString(R.string.text_version)
binding.versionPlaceholderValue.text = context.getString(R.string.text_full_version_info, versionName, versionCode)
}
else -> versionName?.let {
binding.versionPlaceholderLabel.text = context.getString(R.string.text_version_name)
binding.versionPlaceholderValue.text = it
} ?: versionCode?.let {
binding.versionPlaceholderLabel.text = context.getString(R.string.text_version_code)
binding.versionPlaceholderValue.text = "$it"
} ?: run { binding.versionPlaceholderValue.text = context.getString(R.string.text_unknown) }
private fun MaterialDialog.makeSettingsLaunchable(viewGetter: (dialog: MaterialDialog) -> View?, packageName: String?) {
viewGetter(this)?.setOnClickListener {
packageName?.let { pkg ->
IntentUtils.goToAppDetailSettings(this.context, pkg)
} ?: ViewUtils.showSnack(this.view, R.string.error_app_not_installed)
}
}
private fun TextView.setTextIfAbsent(f: () -> String?) {
if (this.text == context.getString(R.string.ellipsis_six)) {
this.text = f.invoke() ?: context.getString(R.string.text_unknown)
private fun MaterialDialog.makeTextCopyable(textViewGetter: (dialog: MaterialDialog) -> TextView?) {
makeTextCopyable(textViewGetter(this))
}
private fun MaterialDialog.makeTextCopyable(textView: TextView?, textValue: String? = textView?.text?.toString()) {
if (textValue != null) {
val context = this.context
textView?.setOnClickListener {
ClipboardUtils.setClip(context, textValue)
ViewUtils.showSnack(this.view, "${context.getString(R.string.text_already_copied_to_clip)}: $textValue")
}
}
}
private fun bindInstalledVersion(binding: ApkFileInfoDialogListItemBinding, context: Context, packageName: String?) {
packageName?.let {
AppUtils.getInstalledVersionInfo(it)?.let { versionInfo ->
binding.installedVersionParent.isVisible = true
binding.installedVersionValue.text = context.getString(R.string.text_full_version_info, versionInfo.versionName, versionInfo.versionCode)
}
} ?: run { binding.installedVersionValue.text = context.getString(R.string.text_unknown) }
private fun TextView.setTextIfAbsent(dialog: MaterialDialog, f: () -> String?) {
val textView = this
val textValue = f.invoke()
if (textView.text == context.getString(R.string.ellipsis_six)) {
textView.text = textValue ?: context.getString(R.string.text_unknown)
}
dialog.makeTextCopyable(textView, textValue)
}
private fun restoreEssentialViews(binding: ApkFileInfoDialogListItemBinding, context: Context) {

View File

@@ -58,7 +58,7 @@ class AboutAppAndDeveloperPreference : MaterialPreference {
}.let { context.startActivity(it) }
} catch (e: Exception) {
context.getString(
R.string.error_app_not_installed,
R.string.error_app_not_installed_with_name,
context.getString(R.string.app_name_qq),
).let { msg -> ViewUtils.showToast(context, msg, true) }
}

View File

@@ -104,7 +104,8 @@
<string name="error_action_cannot_be_completed_with_negative_coordinate">يتعذر إكمال العملية \"%1$s\" لأن المعلمة تحتوي على قيم إحداثيات سالبة (%2$d, %3$d)</string>
<string name="error_activity_is_required_for_ui_exec_mode">تتطلب عملية تنفيذ واجهة المستخدم نشاطًا يمكن توفيره من خلال وضع التنفيذ \"ui\"</string>
<string name="error_an_operation_is_not_implemented">لم يتم تنفيذ العملية</string>
<string name="error_app_not_installed">التطبيق غير مثبت: \"%s\"</string>
<string name="error_app_not_installed_with_name">التطبيق غير مثبت: \"%s\"</string>
<string name="error_app_not_installed">التطبيق غير مثبت</string>
<string name="error_argument_name_for_class_name_and_member_func_name_cannot_be_nullish">لا يمكن أن تكون الوسائط %1$s بالنسبة لـ %2$s#%3$s فارغة</string>
<string name="error_arguments_cannot_be_empty">لا يمكن أن تكون الوسائط فارغة</string>
<string name="error_arguments_must_be_empty">يجب أن تكون الوسائط فارغة</string>

View File

@@ -100,7 +100,8 @@
<string name="error_action_cannot_be_completed_with_negative_coordinate">The \"%1$s\" operation cannot be completed because the parameter contains negative coordinate values (%2$d, %3$d)</string>
<string name="error_activity_is_required_for_ui_exec_mode">An activity is required, which could be provided by running in \"ui\" execution mode</string>
<string name="error_an_operation_is_not_implemented">An operation is not implemented</string>
<string name="error_app_not_installed">App is not installed: \"%s\"</string>
<string name="error_app_not_installed_with_name">App is not installed: \"%s\"</string>
<string name="error_app_not_installed">App is not installed</string>
<string name="error_argument_name_for_class_name_and_member_func_name_cannot_be_nullish">Argument %1$s for %2$s#%3$s cannot be nullish</string>
<string name="error_arguments_cannot_be_empty">Arguments cannot be empty</string>
<string name="error_arguments_must_be_empty">Arguments must be empty</string>

View File

@@ -103,7 +103,8 @@
<string name="error_action_cannot_be_completed_with_negative_coordinate">La operación \"%1$s\" no puede completarse porque el parámetro contiene valores de coordenadas negativos (%2$d, %3$d)</string>
<string name="error_activity_is_required_for_ui_exec_mode">Se requiere una actividad, que podría proporcionarse ejecutando en modo de ejecución \"ui\"</string>
<string name="error_an_operation_is_not_implemented">Una operación no está implementada</string>
<string name="error_app_not_installed">La aplicación no está instalada: \"%s\"</string>
<string name="error_app_not_installed_with_name">La aplicación no está instalada: \"%s\"</string>
<string name="error_app_not_installed">La aplicación no está instalada</string>
<string name="error_argument_name_for_class_name_and_member_func_name_cannot_be_nullish">El argumento %1$s para %2$s#%3$s no puede ser nulo</string>
<string name="error_arguments_cannot_be_empty">Los argumentos no pueden estar vacíos</string>
<string name="error_arguments_must_be_empty">Los argumentos deben estar vacíos</string>

View File

@@ -103,7 +103,8 @@
<string name="error_action_cannot_be_completed_with_negative_coordinate">L\'opération \"%1$s\" ne peut pas être terminée car le paramètre contient des valeurs de coordonnées négatives (%2$d, %3$d)</string>
<string name="error_activity_is_required_for_ui_exec_mode">Une activité est requise, qui pourrait être fournie en exécutant en mode d\'exécution \"ui\"</string>
<string name="error_an_operation_is_not_implemented">Une opération n\'est pas mise en œuvre</string>
<string name="error_app_not_installed">L\'application n\'est pas installée: \"%s\"</string>
<string name="error_app_not_installed_with_name">L\'application n\'est pas installée: \"%s\"</string>
<string name="error_app_not_installed">L\'application n\'est pas installée</string>
<string name="error_argument_name_for_class_name_and_member_func_name_cannot_be_nullish">L\'argument %1$s pour %2$s#%3$s ne peut pas être nul</string>
<string name="error_arguments_cannot_be_empty">Les arguments ne peuvent pas être vides</string>
<string name="error_arguments_must_be_empty">Les arguments doivent être vides</string>

View File

@@ -103,7 +103,8 @@
<string name="error_action_cannot_be_completed_with_negative_coordinate">\"%1$s\" 操作はパラメータに負の座標値 (%2$d, %3$d) が含まれているため, 完了できません</string>
<string name="error_activity_is_required_for_ui_exec_mode">UI 実行モードに必要なアクティビティが不足しています</string>
<string name="error_an_operation_is_not_implemented">操作が実装されていません</string>
<string name="error_app_not_installed">\"%s\" アプリがインストールされていません</string>
<string name="error_app_not_installed_with_name">\"%s\" アプリがインストールされていません</string>
<string name="error_app_not_installed">アプリがインストールされていません</string>
<string name="error_argument_name_for_class_name_and_member_func_name_cannot_be_nullish">%2$s#%3$s の引数 %1$s を null 値にはできません</string>
<string name="error_arguments_cannot_be_empty">引数を空にできません</string>
<string name="error_arguments_must_be_empty">引数は空でなければなりません</string>

View File

@@ -104,7 +104,8 @@
<string name="error_action_cannot_be_completed_with_negative_coordinate">매개 변수에 음수 좌표 값 (%2$d, %3$d)이 포함되어 있으므로 \"%1$s\" 작업을 완료할 수 없습니다</string>
<string name="error_activity_is_required_for_ui_exec_mode">UI 실행 모드를 위한 활동이 필요합니다</string>
<string name="error_an_operation_is_not_implemented">작업이 구현되지 않았습니다</string>
<string name="error_app_not_installed">앱이 설치되지 않았습니다: \"%s\"</string>
<string name="error_app_not_installed_with_name">앱이 설치되지 않았습니다: \"%s\"</string>
<string name="error_app_not_installed">앱이 설치되지 않았습니다</string>
<string name="error_argument_name_for_class_name_and_member_func_name_cannot_be_nullish">%2$s#%3$s 에 대한 인수 %1$s 는 null 값을 가질 수 없습니다</string>
<string name="error_arguments_cannot_be_empty">인수를 비울 수 없습니다</string>
<string name="error_arguments_must_be_empty">인수는 비어 있어야 합니다</string>

View File

@@ -103,7 +103,8 @@
<string name="error_action_cannot_be_completed_with_negative_coordinate">Операция \"%1$s\" не может быть завершена, так как параметр содержит отрицательные значения координат (%2$d, %3$d)</string>
<string name="error_activity_is_required_for_ui_exec_mode">Требуется активность, которую можно предоставить, выполняя в режиме выполнения \"ui\"</string>
<string name="error_an_operation_is_not_implemented">Операция не выполняется</string>
<string name="error_app_not_installed">Приложение не установлено: \"%s\"</string>
<string name="error_app_not_installed_with_name">Приложение не установлено: \"%s\"</string>
<string name="error_app_not_installed">Приложение не установлено</string>
<string name="error_argument_name_for_class_name_and_member_func_name_cannot_be_nullish">Аргумент %1$s для %2$s#%3$s не может быть пустым</string>
<string name="error_arguments_cannot_be_empty">Аргументы не могут быть пустыми</string>
<string name="error_arguments_must_be_empty">Аргументы должны быть пустыми</string>

View File

@@ -102,7 +102,8 @@
<string name="error_action_cannot_be_completed_with_negative_coordinate">無法完成 \"%1$s\" 操作, 因為參數中包含負數座標值 (%2$d,%3$d)</string>
<string name="error_activity_is_required_for_ui_exec_mode">缺少必要的 activity 對象, 可通過 \"ui\" 執行模式來提供</string>
<string name="error_an_operation_is_not_implemented">操作尚未實現</string>
<string name="error_app_not_installed">應用未安裝: \"%s\"</string>
<string name="error_app_not_installed_with_name">應用未安裝: \"%s\"</string>
<string name="error_app_not_installed">應用未安裝</string>
<string name="error_argument_name_for_class_name_and_member_func_name_cannot_be_nullish">參數 %1$s 對於 %2$s#%3$s 不可為 nullish</string>
<string name="error_arguments_cannot_be_empty">參數列表不可為空</string>
<string name="error_arguments_must_be_empty">參數列表需為空</string>

View File

@@ -102,7 +102,8 @@
<string name="error_action_cannot_be_completed_with_negative_coordinate">無法完成 \"%1$s\" 操作, 因為引數中包含負數座標值 (%2$d,%3$d)</string>
<string name="error_activity_is_required_for_ui_exec_mode">缺少必要的 activity 物件, 可透過 \"ui\" 執行模式來提供</string>
<string name="error_an_operation_is_not_implemented">操作尚未實現</string>
<string name="error_app_not_installed">應用未安裝: \"%s\"</string>
<string name="error_app_not_installed_with_name">應用未安裝: \"%s\"</string>
<string name="error_app_not_installed">應用未安裝</string>
<string name="error_argument_name_for_class_name_and_member_func_name_cannot_be_nullish">引數 %1$s 對於 %2$s#%3$s 不可為 nullish</string>
<string name="error_arguments_cannot_be_empty">引數列表不可為空</string>
<string name="error_arguments_must_be_empty">引數列表需為空</string>

View File

@@ -98,7 +98,8 @@
<string name="error_action_cannot_be_completed_with_negative_coordinate">无法完成 \"%1$s\" 操作, 因为参数中包含负数坐标值 (%2$d,%3$d)</string>
<string name="error_activity_is_required_for_ui_exec_mode">缺少必要的 activity 对象, 可通过 \"ui\" 执行模式来提供</string>
<string name="error_an_operation_is_not_implemented">操作尚未实现</string>
<string name="error_app_not_installed">应用未安装: \"%s\"</string>
<string name="error_app_not_installed_with_name">应用未安装: \"%s\"</string>
<string name="error_app_not_installed">应用未安装</string>
<string name="error_argument_name_for_class_name_and_member_func_name_cannot_be_nullish">参数 %1$s 对于 %2$s#%3$s 不可为 nullish</string>
<string name="error_arguments_cannot_be_empty">参数列表不可为空</string>
<string name="error_arguments_must_be_empty">参数列表需为空</string>

View File

@@ -154,7 +154,8 @@
<string name="error_action_cannot_be_completed_with_negative_coordinate">The \"%1$s\" operation cannot be completed because the parameter contains negative coordinate values (%2$d, %3$d)</string>
<string name="error_activity_is_required_for_ui_exec_mode">An activity is required, which could be provided by running in \"ui\" execution mode</string>
<string name="error_an_operation_is_not_implemented">An operation is not implemented</string>
<string name="error_app_not_installed">App is not installed: \"%s\"</string>
<string name="error_app_not_installed_with_name">App is not installed: \"%s\"</string>
<string name="error_app_not_installed">App is not installed</string>
<string name="error_argument_name_for_class_name_and_member_func_name_cannot_be_nullish">Argument %1$s for %2$s#%3$s cannot be nullish</string>
<string name="error_arguments_cannot_be_empty">Arguments cannot be empty</string>
<string name="error_arguments_must_be_empty">Arguments must be empty</string>