Remove top margin of PreferenceCategory if no title set (#5168)

This commit is contained in:
Ivan Iskandar 2021-05-24 20:10:13 +07:00 committed by GitHub
parent 3c186a3c8d
commit b5a700276a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View file

@ -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 {

View file

@ -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<RecyclerView.LayoutParams> {
height = 0
topMargin = 0
}
}
}
}