Skip to content

Commit

Permalink
improve SliderPreference value display
Browse files Browse the repository at this point in the history
  • Loading branch information
RobozinhoD committed Jul 13, 2024
1 parent 2c959dc commit 89bdb1a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import com.ichi2.annotations.NeedsTest
* Format `string` or `plurals` to be used as template to display the value in the preference summary.
* There must be ONLY ONE placeholder, which will be replaced by the preference value.
* * app:displayValue (*optional*): whether to show the current preference value on a TextView
* by the end of the slider
* by the end of the preference
* * app:displayFormat (*optional*): Format string to be used as template to display the value by
* the end of the slider. There must be ONLY ONE placeholder,
* which will be replaced by the preference value.
Expand Down Expand Up @@ -137,7 +137,7 @@ class SliderPreference(context: Context, attrs: AttributeSet? = null) : Preferen
summaryView.visibility = View.VISIBLE
}

val displayValueTextView = holder.findViewById(R.id.valueDisplay) as TextView
val displayValueTextView = holder.findViewById(R.id.value_display) as TextView
if (displayValue) {
displayValueTextView.text = displayFormat?.let { String.format(it, value) }
?: value.toString()
Expand Down
98 changes: 43 additions & 55 deletions AnkiDroid/src/main/res/layout/preference_slider.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,68 +24,56 @@
android:clipChildren="false"
android:clipToPadding="false">

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1">

<TextView
android:id="@android:id/title"
android:labelFor="@id/slider"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceListItem"
android:ellipsize="marquee"
tools:text="Title"/>

<TextView
android:id="@android:id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@android:id/title"
android:layout_alignStart="@android:id/title"
android:layout_gravity="start"
android:textAlignment="viewStart"
android:textColor="?android:attr/textColorSecondary"
android:maxLines="4"
style="@style/PreferenceSummaryTextStyle"
tools:text="Summary"/>
</RelativeLayout>

<LinearLayout
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingStart="0dp"
android:paddingEnd="16dp"
android:clipChildren="false"
android:clipToPadding="false">

<com.google.android.material.slider.Slider
android:id="@+id/slider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:saveEnabled="false"
android:stepSize="1"
app:thumbRadius="8dp"
/>
android:layout_height="wrap_content">

<TextView
android:id="@+id/valueDisplay"
android:minWidth="40sp"
android:paddingStart="0dp"
android:paddingEnd="0dp"
android:layout_width="wrap_content"
android:id="@android:id/title"
android:labelFor="@id/slider"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="end"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceListItem"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:scrollbars="none"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/value_display"
tools:text="Title"/>

<TextView
android:id="@android:id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:textAlignment="viewStart"
android:textColor="?android:attr/textColorSecondary"
android:maxLines="4"
style="@style/PreferenceSummaryTextStyle"
app:layout_constraintTop_toBottomOf="@android:id/title"
app:layout_constraintStart_toStartOf="parent"
tools:text="Summary"/>

<TextView
android:id="@+id/value_display"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?android:attr/textColorSecondary"
android:maxLines="1"
style="@style/PreferenceSummaryTextStyle"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:paddingStart="8dp"
tools:text="100%"/>
</LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

<com.google.android.material.slider.Slider
android:id="@+id/slider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:saveEnabled="false"
android:stepSize="1"
/>
</LinearLayout>
</LinearLayout>

0 comments on commit 89bdb1a

Please sign in to comment.