Skip to content

Commit

Permalink
Modify RichListOption 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 7e8af2d commit 19fcb15
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package org.jellyfin.androidtv.ui.preference.custom

import android.content.res.ColorStateList
import android.graphics.Color
import android.os.Bundle
import android.util.Log
import android.util.TypedValue
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 @@ -16,7 +21,6 @@ import org.jellyfin.androidtv.R
import org.jellyfin.androidtv.databinding.PreferenceRichListBinding



class RichListDialogFragment : LeanbackPreferenceDialogFragmentCompat() {
companion object {
fun newInstance(key: String) = RichListDialogFragment().apply {
Expand Down Expand Up @@ -58,7 +62,6 @@ class RichListDialogFragment : LeanbackPreferenceDialogFragmentCompat() {
binding = PreferenceRichListBinding.inflate(styledInflater, container, false)


//Log.d("CUSTOMRYAN",button?.)
// Dialog
binding.decorTitle.text = preference.dialogTitle

Expand Down Expand Up @@ -117,10 +120,30 @@ class RichListDialogFragment : LeanbackPreferenceDialogFragmentCompat() {
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) = when (val item = items[position]) {
is RichListItem.RichListOption<*> -> {
holder as OptionViewHolder
val currentTintList: ColorStateList? = holder.button_tint.buttonTintList

holder.button.isChecked = item.key == selectedValue
holder.button_fg.background = if (isSubtitle) context?.resources?.getDrawable(R.drawable.subtitle_background) else null
holder.button_bg.background = if (isSubtitle) context?.resources?.getDrawable(R.drawable.subtitle_background,context?.theme) else null
holder.button_fg.backgroundTintList = if (isSubtitle) ColorStateList.valueOf(Color.parseColor(item.key.toString())) else null
//Color.parseColor(item.key.toString())
//Log.d("CUSTOMRYAN", holder.button_tint.buttonTintList.)

//val typedValue = TypedValue()
//context?.theme?.resolveAttribute(R.attr.buttonDefaultNormalBackground,typedValue,true)

//val typedArray = context?.theme?.obtainStyledAttributes(IntArray(R.attr.buttonDefaultNormalBackground))
//var color: Int? = typedArray?.getColor(0,0)
//color = context?.theme?.resources?.getColor(R.attr.buttonDefaultNormalBackground,context?.theme)
//Log.d("CUSTOMRYANAFTER", color.toString())

//holder.button_tint.buttonTintList =context?.let { ColorStateList.valueOf(context!!.resources.getColor(typedValue.to}
holder.button_tint.buttonTintList = if (!isSubtitle) ColorStateList.valueOf(Color.parseColor("#eeeeeeee")) else context?.getColor(R.color.transparent)?.let { ColorStateList.valueOf(it) }
// ?.let { ColorStateList.valueOf(it) } else context?.let { ColorStateList.valueOf(it.getColor(R.color.red)) }



//= if (isSubtitle) else null
//holder.button_button.text = null
holder.title.text = item.title
holder.summary.text = item.summary
holder.summary.isVisible = item.summary?.isNotBlank() == true
Expand Down Expand Up @@ -155,7 +178,9 @@ class RichListDialogFragment : LeanbackPreferenceDialogFragmentCompat() {
view: View,
private val clickListener: (viewHolder: OptionViewHolder) -> Unit
) : RecyclerView.ViewHolder(view), View.OnClickListener {
var button_bg = view.findViewById<View>(R.id.button)
var button_fg = view.findViewById<View>(R.id.button)
var button_tint = view.findViewById<RadioButton>(R.id.button)
val button = view.findViewById<View>(R.id.button) as Checkable
val title = view.findViewById<TextView>(R.id.title)
val summary = view.findViewById<TextView>(R.id.summary)
Expand Down
10 changes: 3 additions & 7 deletions app/src/main/res/layout/preference_rich_list_option.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
android:orientation="horizontal"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd">
<!-- android:buttonTint="@color/transparent"-->


<RadioButton
android:id="@+id/button"
style="?android:attr/radioButtonStyle"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/lb_preference_item_icon_margin_end"
android:background="@null"
Expand All @@ -31,11 +32,6 @@
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 19fcb15

Please sign in to comment.