mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-19 00:59:17 +01:00
Remove top margin of PreferenceCategory if no title set (#5168)
This commit is contained in:
parent
3c186a3c8d
commit
b5a700276a
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user