From a9f178ac8c0ac72aadb072ec8b5d0cbef2a6e590 Mon Sep 17 00:00:00 2001 From: SuperMonster003 Date: Fri, 9 May 2025 17:18:35 +0800 Subject: [PATCH] =?UTF-8?q?6.6.3=20-=20Alpha2=20-=20=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E5=AF=B9=E8=AF=9D=E6=A1=86=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E6=94=AF=E6=8C=81=20"=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=80=BC"=20=E8=8F=9C=E5=8D=95=E9=80=89?= =?UTF-8?q?=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changelog/lang_zh-Hans.json | 1 + .../preference/MaterialListPreference.kt | 22 ++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/.changelog/lang_zh-Hans.json b/.changelog/lang_zh-Hans.json index 536544be..a9244438 100644 --- a/.changelog/lang_zh-Hans.json +++ b/.changelog/lang_zh-Hans.json @@ -22,6 +22,7 @@ "improvement": [ "主页抽屉在横向屏幕或超宽屏幕的宽度适应性", "关于应用与开发者页面增加水平布局及小屏布局适配", + "设置页面对话框相关设置支持 \"使用默认值\" 菜单选项", "文件管理器浮动按钮展开后点击其他区域可自动隐藏", "打包单文件时自动读取并勾选已安装应用的声明权限 _[`issue #362`](http://issues.autojs6.com/362)_", "已忽略更新记录及客户端模式连接地址记录支持清空操作", diff --git a/app/src/main/java/org/autojs/autojs/theme/preference/MaterialListPreference.kt b/app/src/main/java/org/autojs/autojs/theme/preference/MaterialListPreference.kt index f7223a71..9236f080 100644 --- a/app/src/main/java/org/autojs/autojs/theme/preference/MaterialListPreference.kt +++ b/app/src/main/java/org/autojs/autojs/theme/preference/MaterialListPreference.kt @@ -4,7 +4,6 @@ import android.content.Context import android.os.Bundle import android.text.TextUtils import android.util.AttributeSet -import androidx.preference.Preference.SummaryProvider import com.afollestad.materialdialogs.MaterialDialog import org.autojs.autojs.core.pref.Pref import org.autojs.autojs.ui.common.NotAskAgainDialog @@ -32,6 +31,12 @@ open class MaterialListPreference : MaterialDialogPreference { protected val entry: CharSequence? get() = mItemValues.takeIf { it.isNotEmpty() }?.toList()?.get(itemPrefIndex ?: mItemDefaultIndex) + protected val defaultEntry: CharSequence? + get() { + val keyIndex = getKeyIndex(mItemDefaultKey) ?: return null + return mItemValues.takeIf { it.isNotEmpty() }?.toList()?.get(keyIndex) + } + constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int, bundle: Bundle) : super(context, attrs, defStyleAttr, defStyleRes) { init(context, attrs, defStyleAttr, defStyleRes, bundle) } @@ -53,7 +58,13 @@ open class MaterialListPreference : MaterialDialogPreference { .let { a -> getAttrString(a, R.styleable.MaterialListPreference_dialogTitle)?.also { dialogTitle = it } getAttrString(a, R.styleable.MaterialListPreference_dialogContent)?.also { dialogContent = it } + getAttrColor(a, R.styleable.MaterialListPreference_negativeColor)?.takeIf { it != -1 }?.let { + negativeColor = it + } positiveText = getAttrString(a, R.styleable.MaterialListPreference_positiveText) ?: context.getString(R.string.dialog_button_confirm) + getAttrColor(a, R.styleable.MaterialListPreference_positiveColor)?.takeIf { it != -1 }?.let { + positiveColor = it + } negativeText = getAttrString(a, R.styleable.MaterialListPreference_negativeText) ?: context.getString(R.string.dialog_button_cancel) getAttrTextArray(a, R.styleable.MaterialListPreference_itemKeys)?.also { mItemKeys = it.toList() } getAttrTextArray(a, R.styleable.MaterialListPreference_itemValues)?.also { mItemValues = it.toList() } @@ -88,6 +99,15 @@ open class MaterialListPreference : MaterialDialogPreference { } return@itemsCallbackSingleChoice true } + if (defaultEntry != null) { + builder.options( + listOf( + MaterialDialog.OptionMenuItemSpec(context.getString(R.string.dialog_button_use_default)) { dialog -> + dialog.selectedIndex = mItemDefaultIndex + }, + ) + ) + } } }