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 + }, + ) + ) + } } }