Fix color scheme preference

pull/478/head
Koitharu 3 years ago
parent 05241f73d9
commit 34fb4af9fe
Signed by: Koitharu
GPG Key ID: 676DEE768C17A9D7

@ -12,6 +12,7 @@ import android.view.ViewTreeObserver
import android.widget.HorizontalScrollView import android.widget.HorizontalScrollView
import androidx.appcompat.view.ContextThemeWrapper import androidx.appcompat.view.ContextThemeWrapper
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.core.view.updatePaddingRelative
import androidx.customview.view.AbsSavedState import androidx.customview.view.AbsSavedState
import androidx.preference.Preference import androidx.preference.Preference
import androidx.preference.PreferenceViewHolder import androidx.preference.PreferenceViewHolder
@ -52,7 +53,11 @@ class ThemeChooserPreference @JvmOverloads constructor(
binding.linear.removeAllViews() binding.linear.removeAllViews()
for (theme in entries) { for (theme in entries) {
val context = ContextThemeWrapper(context, theme.styleResId) val context = ContextThemeWrapper(context, theme.styleResId)
val item = ItemColorSchemeBinding.inflate(LayoutInflater.from(context), binding.linear, false) val item =
ItemColorSchemeBinding.inflate(LayoutInflater.from(context), binding.linear, false)
if (binding.linear.childCount == 0) {
item.root.updatePaddingRelative(start = 0)
}
val isSelected = theme == currentValue val isSelected = theme == currentValue
item.card.isChecked = isSelected item.card.isChecked = isSelected
item.card.strokeWidth = if (isSelected) context.resources.getDimensionPixelSize( item.card.strokeWidth = if (isSelected) context.resources.getDimensionPixelSize(
@ -76,7 +81,8 @@ class ThemeChooserPreference @JvmOverloads constructor(
} }
binding.scrollView.viewTreeObserver.run { binding.scrollView.viewTreeObserver.run {
scrollPersistListener?.let { removeOnScrollChangedListener(it) } scrollPersistListener?.let { removeOnScrollChangedListener(it) }
scrollPersistListener = ScrollPersistListener(WeakReference(binding.scrollView), lastScrollPosition) scrollPersistListener =
ScrollPersistListener(WeakReference(binding.scrollView), lastScrollPosition)
addOnScrollChangedListener(scrollPersistListener) addOnScrollChangedListener(scrollPersistListener)
} }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
@ -133,7 +139,7 @@ class ThemeChooserPreference @JvmOverloads constructor(
constructor( constructor(
superState: Parcelable, superState: Parcelable,
scrollPosition: Int scrollPosition: Int,
) : super(superState) { ) : super(superState) {
this.scrollPosition = scrollPosition this.scrollPosition = scrollPosition
} }
@ -151,7 +157,8 @@ class ThemeChooserPreference @JvmOverloads constructor(
@Suppress("unused") @Suppress("unused")
@JvmField @JvmField
val CREATOR: Parcelable.Creator<SavedState> = object : Parcelable.Creator<SavedState> { val CREATOR: Parcelable.Creator<SavedState> = object : Parcelable.Creator<SavedState> {
override fun createFromParcel(`in`: Parcel) = SavedState(`in`, SavedState::class.java.classLoader) override fun createFromParcel(`in`: Parcel) =
SavedState(`in`, SavedState::class.java.classLoader)
override fun newArray(size: Int): Array<SavedState?> = arrayOfNulls(size) override fun newArray(size: Int): Array<SavedState?> = arrayOfNulls(size)
} }

@ -8,70 +8,53 @@
android:clipChildren="false" android:clipChildren="false"
android:clipToPadding="false" android:clipToPadding="false"
android:gravity="center_vertical" android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeightSmall" android:minHeight="?android:attr/listPreferredItemHeight"
android:orientation="horizontal" android:orientation="vertical"
android:paddingStart="?android:attr/listPreferredItemPaddingStart" android:paddingVertical="8dp"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
tools:ignore="PrivateResource"> tools:ignore="PrivateResource">
<include layout="@layout/image_frame" /> <TextView
android:id="@android:id/title"
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:labelFor="@id/scrollView"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceListItem"
tools:ignore="LabelFor"
tools:text="@string/color_theme" />
<HorizontalScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp" android:layout_marginTop="4dp"
android:layout_marginBottom="8dp"
android:clipChildren="false"
android:clipToPadding="false" android:clipToPadding="false"
android:orientation="vertical"> android:descendantFocusability="blocksDescendants"
android:scrollbars="none">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:id="@+id/linear"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:baselineAligned="true" android:orientation="horizontal"
android:baselineAlignedChildIndex="0" android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:orientation="horizontal"> android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" />
<TextView
android:id="@android:id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="marquee"
android:labelFor="@id/seekbar"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceListItem"
tools:ignore="LabelFor" />
<TextView </HorizontalScrollView>
android:id="@android:id/summary"
style="@style/PreferenceSummaryTextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAlignment="viewStart"
android:textColor="?android:attr/textColorSecondary" />
</LinearLayout> <TextView
android:id="@android:id/summary"
<HorizontalScrollView style="@style/PreferenceSummaryTextStyle"
android:id="@+id/scrollView" android:layout_width="wrap_content"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:layout_marginTop="2dp"
android:layout_marginTop="2dp" android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:clipToPadding="false" android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:descendantFocusability="blocksDescendants" android:singleLine="true"
android:paddingStart="0dp" android:textAlignment="viewStart"
android:paddingEnd="16dp" android:textColor="?android:attr/textColorSecondary" />
android:scrollbars="none"
tools:ignore="UnusedAttribute">
<LinearLayout
android:id="@+id/linear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" />
</HorizontalScrollView>
</LinearLayout>
</LinearLayout> </LinearLayout>

Loading…
Cancel
Save