From 97eda4b767d6afb174a5248714a7322355ccb47d Mon Sep 17 00:00:00 2001 From: LuftVerbot <97435834+LuftVerbot@users.noreply.github.com> Date: Wed, 7 Aug 2024 15:37:50 +0200 Subject: [PATCH] show button only when there is summary --- .../echo/ui/settings/ExtensionFragment.kt | 2 +- .../echo/utils/MaterialListPreference.kt | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/dev/brahmkshatriya/echo/ui/settings/ExtensionFragment.kt b/app/src/main/java/dev/brahmkshatriya/echo/ui/settings/ExtensionFragment.kt index f420c3da..852dd246 100644 --- a/app/src/main/java/dev/brahmkshatriya/echo/ui/settings/ExtensionFragment.kt +++ b/app/src/main/java/dev/brahmkshatriya/echo/ui/settings/ExtensionFragment.kt @@ -148,7 +148,7 @@ class ExtensionFragment : BaseSettingsFragment() { it.entryValues = this.entryValues.toTypedArray() it.isIconSpaceReserved = false - it.layoutResource = R.layout.preference_summary_button + it.layoutResource = R.layout.preference preferenceGroup.addPreference(it) } } diff --git a/app/src/main/java/dev/brahmkshatriya/echo/utils/MaterialListPreference.kt b/app/src/main/java/dev/brahmkshatriya/echo/utils/MaterialListPreference.kt index 6056d936..81bb8607 100644 --- a/app/src/main/java/dev/brahmkshatriya/echo/utils/MaterialListPreference.kt +++ b/app/src/main/java/dev/brahmkshatriya/echo/utils/MaterialListPreference.kt @@ -8,7 +8,7 @@ import dev.brahmkshatriya.echo.R class MaterialListPreference(context: Context) : ListPreference(context) { - private var customSummary: String? = null + private var customSummary: CharSequence? = null override fun onBindViewHolder(holder: PreferenceViewHolder) { super.onBindViewHolder(holder) @@ -21,7 +21,12 @@ class MaterialListPreference(context: Context) : ListPreference(context) { override fun onSetInitialValue(defaultValue: Any?) { super.onSetInitialValue(defaultValue) - customSummary = summary.toString() + customSummary = summary + layoutResource = if (customSummary != null){ + R.layout.preference_summary_button + } else { + this.layoutResource + } updateSummary() } @@ -46,7 +51,7 @@ class MaterialListPreference(context: Context) : ListPreference(context) { private fun showSummaryDialog() { MaterialAlertDialogBuilder(context) - .setMessage(customSummary) + .setMessage(customSummary.toString()) .setPositiveButton(android.R.string.ok, null) .show() }