TV UX improvements (#538)

* Update styles.xml
This commit is contained in:
self-similarity 2023-08-12 15:44:35 +00:00 committed by GitHub
parent 2d65aefc76
commit ecd529f73b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 20 deletions

View file

@ -1273,7 +1273,18 @@ class GeneratorPlayer : FullScreenPlayer() {
from, to from, to
).apply { ).apply {
addListener(onEnd = { addListener(onEnd = {
if (!show) playerBinding?.skipChapterButton?.isVisible = false if (show) {
if (!isShowing) {
// Automatically request focus if the menu is not opened
playerBinding?.skipChapterButton?.requestFocus()
}
} else {
playerBinding?.skipChapterButton?.isVisible = false
if (!isShowing) {
// Automatically return focus to play pause
playerBinding?.playerPausePlay?.requestFocus()
}
}
}) })
addUpdateListener { valueAnimator -> addUpdateListener { valueAnimator ->
val value = valueAnimator.animatedValue as Int val value = valueAnimator.animatedValue as Int

View file

@ -45,19 +45,9 @@ class SelectAdaptor(val callback: (Any) -> Unit) : RecyclerView.Adapter<Recycler
if(newIndex == selectedIndex) return if(newIndex == selectedIndex) return
val oldIndex = selectedIndex val oldIndex = selectedIndex
selectedIndex = newIndex selectedIndex = newIndex
recyclerView.apply {
for (i in 0 until itemCount) { notifyItemChanged(selectedIndex)
val viewHolder = getChildViewHolder( getChildAt(i) ?: continue) ?: continue notifyItemChanged(oldIndex)
val pos = viewHolder.absoluteAdapterPosition
if (viewHolder is SelectViewHolder) {
if (pos == oldIndex) {
viewHolder.update(false)
} else if (pos == newIndex) {
viewHolder.update(true)
}
}
}
}
} }
fun updateSelectionList(newList: List<SelectData>) { fun updateSelectionList(newList: List<SelectData>) {
@ -79,10 +69,6 @@ class SelectAdaptor(val callback: (Any) -> Unit) : RecyclerView.Adapter<Recycler
RecyclerView.ViewHolder(binding.root) { RecyclerView.ViewHolder(binding.root) {
private val item: MaterialButton = binding.root private val item: MaterialButton = binding.root
fun update(isSelected: Boolean) {
item.isSelected = isSelected
}
fun bind( fun bind(
data: SelectData, isSelected: Boolean, callback: (Any) -> Unit data: SelectData, isSelected: Boolean, callback: (Any) -> Unit
) { ) {

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:state_focused="true" android:color="@color/black"/>
<item android:state_selected="true" android:state_focused="false" android:color="@color/white"/>
<item android:color="@color/transparent"/>
</selector>

View file

@ -2,7 +2,7 @@
<com.google.android.material.button.MaterialButton xmlns:android="http://schemas.android.com/apk/res/android" <com.google.android.material.button.MaterialButton xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
style="@style/RegularButtonTV" style="@style/SelectableButtonTV"
android:layout_gravity="start" android:layout_gravity="start"
android:layout_margin="2dp" android:layout_margin="2dp"
android:minWidth="115dp" android:minWidth="115dp"

View file

@ -737,6 +737,11 @@
<item name="android:layout_marginEnd">0dp</item> <item name="android:layout_marginEnd">0dp</item>
</style> </style>
<style name="SelectableButtonTV" parent="RegularButtonTV">
<item name="icon">@drawable/ic_baseline_check_24_listview</item>
<item name="iconTint">@color/button_selector_color</item>
</style>
<style name="RegularButtonTV"> <style name="RegularButtonTV">
<item name="android:tag">@string/tv_no_focus_tag</item> <item name="android:tag">@string/tv_no_focus_tag</item>
<item name="android:stateListAnimator">@null</item> <item name="android:stateListAnimator">@null</item>
@ -839,4 +844,4 @@
@drawable/cast_ic_mini_controller_closed_caption @drawable/cast_ic_mini_controller_closed_caption
</item> </item>
</style> </style>
</resources> </resources>