Skip to content

Commit

Permalink
Modify RichListDialog to display subtitle colors
Browse files Browse the repository at this point in the history
  • Loading branch information
sparky3387 committed Jul 27, 2022
1 parent 13699f6 commit 7e8af2d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package org.jellyfin.androidtv.ui.preference.custom

import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Checkable
import android.widget.RadioButton
import android.widget.TextView
import androidx.appcompat.view.ContextThemeWrapper
import androidx.core.view.isVisible
Expand All @@ -33,7 +31,8 @@ class RichListDialogFragment : LeanbackPreferenceDialogFragmentCompat() {

private fun <K> RichListPreference<K>.createAdapter() = Adapter(
items = getItems(),
selectedValue = value
selectedValue = value,
isSubtitle = false
)

override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -42,6 +41,7 @@ class RichListDialogFragment : LeanbackPreferenceDialogFragmentCompat() {
adapter = when (val preference = preference) {
// Adapt ListPreference to RichListItems
is ListPreference -> Adapter(
isSubtitle = context?.resources?.getString(R.string.lbl_subtitle_fg) == preference.title,
items = preference.entryValues.mapIndexed { index, key ->
RichListItem.RichListOption(key.toString(), preference.entries[index].toString())
},
Expand Down Expand Up @@ -93,7 +93,8 @@ class RichListDialogFragment : LeanbackPreferenceDialogFragmentCompat() {

inner class Adapter<K>(
private val items: List<RichListItem<K>>,
private var selectedValue: K? = null
private var selectedValue: K? = null,
private var isSubtitle: Boolean
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
override fun getItemCount() = items.size

Expand All @@ -118,11 +119,13 @@ class RichListDialogFragment : LeanbackPreferenceDialogFragmentCompat() {
holder as OptionViewHolder

holder.button.isChecked = item.key == selectedValue
holder.button_fg.background=resources.getColor(R.color.subtitles_white)
holder.button_fg.background = if (isSubtitle) context?.resources?.getDrawable(R.drawable.subtitle_background) else null

holder.title.text = item.title
holder.summary.text = item.summary
holder.summary.isVisible = item.summary?.isNotBlank() == true
}

}
is RichListItem.RichListSection -> {
holder as CategoryViewHolder

Expand Down Expand Up @@ -152,8 +155,8 @@ class RichListDialogFragment : LeanbackPreferenceDialogFragmentCompat() {
view: View,
private val clickListener: (viewHolder: OptionViewHolder) -> Unit
) : RecyclerView.ViewHolder(view), View.OnClickListener {
var button_fg = view.findViewById<View>(R.id.button)
val button = view.findViewById<View>(R.id.button) as Checkable
val button_fg = view.findViewById<View>(R.id.button)
val title = view.findViewById<TextView>(R.id.title)
val summary = view.findViewById<TextView>(R.id.summary)
val container = view.findViewById<ViewGroup>(R.id.container).also {
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/subtitle_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
<solid android:color="#666666"/>
<size
android:width="8dp"
android:height="6dp"/>


</shape>
9 changes: 8 additions & 1 deletion app/src/main/res/layout/preference_rich_list_option.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd">


<RadioButton
android:id="@+id/button"
style="?android:attr/radioButtonStyle"
Expand All @@ -22,13 +23,19 @@
android:clickable="false"
android:focusable="false" />



<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:duplicateParentState="true"
android:orientation="vertical">

<ImageView
android:id="@+id/button_image"
android:src="@drawable/subtitle_background"
android:layout_width="24dp"
android:layout_height="32dp" />
<Space
android:layout_width="0dp"
android:layout_height="@dimen/lb_preference_item_text_space_top" />
Expand Down

0 comments on commit 7e8af2d

Please sign in to comment.