diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/preference/PreferenceDSL.kt b/app/src/main/java/eu/kanade/tachiyomi/util/preference/PreferenceDSL.kt index 148b91ae2..03a74b48d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/preference/PreferenceDSL.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/preference/PreferenceDSL.kt @@ -16,6 +16,7 @@ import androidx.preference.PreferenceScreen import androidx.preference.SwitchPreferenceCompat import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.util.system.getResourceColor +import eu.kanade.tachiyomi.widget.preference.AdaptiveTitlePreferenceCategory import eu.kanade.tachiyomi.widget.preference.IntListPreference import eu.kanade.tachiyomi.widget.preference.SwitchPreferenceCategory import eu.kanade.tachiyomi.widget.preference.SwitchSettingsPreference @@ -77,7 +78,7 @@ inline fun PreferenceGroup.multiSelectListPreference(block: (@DSL MultiSelectLis } inline fun PreferenceScreen.preferenceCategory(block: (@DSL PreferenceCategory).() -> Unit): PreferenceCategory { - return addThenInit(PreferenceCategory(context), block) + return addThenInit(AdaptiveTitlePreferenceCategory(context), block) } inline fun PreferenceScreen.preferenceScreen(block: (@DSL PreferenceScreen).() -> Unit): PreferenceScreen { diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/AdaptiveTitlePreferenceCategory.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/AdaptiveTitlePreferenceCategory.kt new file mode 100644 index 000000000..d0448549d --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/AdaptiveTitlePreferenceCategory.kt @@ -0,0 +1,22 @@ +package eu.kanade.tachiyomi.widget.preference + +import android.content.Context +import androidx.core.view.updateLayoutParams +import androidx.preference.PreferenceCategory +import androidx.preference.PreferenceViewHolder +import androidx.recyclerview.widget.RecyclerView + +/** + * PreferenceCategory that hides the title placeholder layout if the title is unset + */ +class AdaptiveTitlePreferenceCategory(context: Context) : PreferenceCategory(context) { + override fun onBindViewHolder(holder: PreferenceViewHolder) { + super.onBindViewHolder(holder) + if (title.isNullOrBlank()) { + holder.itemView.updateLayoutParams { + height = 0 + topMargin = 0 + } + } + } +}