- Auto focus popups

- Checkmarks on selectable buttons
This commit is contained in:
self-similarity 2023-08-05 04:18:16 +02:00
parent ec920d6d78
commit d10dc5322e
5 changed files with 27 additions and 19 deletions

View file

@ -1273,7 +1273,18 @@ class GeneratorPlayer : FullScreenPlayer() {
from, to
).apply {
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 ->
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
val oldIndex = selectedIndex
selectedIndex = newIndex
recyclerView.apply {
for (i in 0 until itemCount) {
val viewHolder = getChildViewHolder( getChildAt(i) ?: continue) ?: continue
val pos = viewHolder.absoluteAdapterPosition
if (viewHolder is SelectViewHolder) {
if (pos == oldIndex) {
viewHolder.update(false)
} else if (pos == newIndex) {
viewHolder.update(true)
}
}
}
}
notifyItemChanged(selectedIndex)
notifyItemChanged(oldIndex)
}
fun updateSelectionList(newList: List<SelectData>) {
@ -79,10 +69,6 @@ class SelectAdaptor(val callback: (Any) -> Unit) : RecyclerView.Adapter<Recycler
RecyclerView.ViewHolder(binding.root) {
private val item: MaterialButton = binding.root
fun update(isSelected: Boolean) {
item.isSelected = isSelected
}
fun bind(
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"
xmlns:tools="http://schemas.android.com/tools"
style="@style/RegularButtonTV"
style="@style/SelectableButtonTV"
android:layout_gravity="start"
android:layout_margin="2dp"
android:minWidth="115dp"

View file

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