Fix focus issues on TV

This commit is contained in:
Luna712 2024-07-13 15:22:36 -06:00 committed by GitHub
parent a93163ff88
commit b69bc9069d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 40 additions and 46 deletions

View file

@ -97,6 +97,8 @@ class DownloadChildFragment : Fragment() {
setAppBarNoScrollFlagsOnTV()
}
binding?.downloadDeleteAppbar?.setAppBarNoScrollFlagsOnTV()
observe(downloadsViewModel.childCards) {
if (it.isEmpty()) {
activity?.onBackPressedDispatcher?.onBackPressed()
@ -126,8 +128,9 @@ class DownloadChildFragment : Fragment() {
binding?.selectItemsText?.isVisible = it.isEmpty()
val allSelected = downloadsViewModel.isAllSelected()
binding?.btnSelectAll?.isVisible = !allSelected
binding?.btnDeselectAll?.isVisible = allSelected
if (allSelected) {
binding?.btnToggleAll?.setText(R.string.deselect_all)
} else binding?.btnToggleAll?.setText(R.string.select_all)
}
val adapter = DownloadAdapter(
@ -180,14 +183,16 @@ class DownloadChildFragment : Fragment() {
downloadsViewModel.setIsMultiDeleteState(false)
}
binding?.btnSelectAll?.setOnClickListener {
(binding?.downloadChildList?.adapter as? DownloadAdapter)?.selectAllItems()
binding?.btnToggleAll?.setOnClickListener {
val allSelected = downloadsViewModel.isAllSelected()
val binding = binding?.downloadChildList?.adapter as? DownloadAdapter
if (allSelected) {
binding?.clearSelectedItems()
downloadsViewModel.clearSelectedItems()
} else {
binding?.selectAllItems()
downloadsViewModel.selectAllItems()
}
binding?.btnDeselectAll?.setOnClickListener {
(binding?.downloadChildList?.adapter as? DownloadAdapter)?.clearSelectedItems()
downloadsViewModel.clearSelectedItems()
}
downloadsViewModel.setIsMultiDeleteState(true)

View file

@ -94,6 +94,7 @@ class DownloadFragment : Fragment() {
super.onViewCreated(view, savedInstanceState)
hideKeyboard()
binding?.downloadStorageAppbar?.setAppBarNoScrollFlagsOnTV()
binding?.downloadDeleteAppbar?.setAppBarNoScrollFlagsOnTV()
/**
* We never want to retain multi-delete state
@ -167,8 +168,9 @@ class DownloadFragment : Fragment() {
binding?.selectItemsText?.isVisible = it.isEmpty()
val allSelected = downloadsViewModel.isAllSelected()
binding?.btnSelectAll?.isVisible = !allSelected
binding?.btnDeselectAll?.isVisible = allSelected
if (allSelected) {
binding?.btnToggleAll?.setText(R.string.deselect_all)
} else binding?.btnToggleAll?.setText(R.string.select_all)
}
val adapter = DownloadAdapter(
@ -193,7 +195,6 @@ class DownloadFragment : Fragment() {
setLinearListLayout(
isHorizontal = false,
nextRight = FOCUS_SELF,
nextUp = FOCUS_SELF,
nextDown = FOCUS_SELF,
)
}
@ -257,14 +258,16 @@ class DownloadFragment : Fragment() {
downloadsViewModel.setIsMultiDeleteState(false)
}
binding?.btnSelectAll?.setOnClickListener {
(binding?.downloadList?.adapter as? DownloadAdapter)?.selectAllItems()
binding?.btnToggleAll?.setOnClickListener {
val allSelected = downloadsViewModel.isAllSelected()
val binding = binding?.downloadList?.adapter as? DownloadAdapter
if (allSelected) {
binding?.clearSelectedItems()
downloadsViewModel.clearSelectedItems()
} else {
binding?.selectAllItems()
downloadsViewModel.selectAllItems()
}
binding?.btnDeselectAll?.setOnClickListener {
(binding?.downloadList?.adapter as? DownloadAdapter)?.clearSelectedItems()
downloadsViewModel.clearSelectedItems()
}
downloadsViewModel.setIsMultiDeleteState(true)

View file

@ -92,7 +92,9 @@ class DownloadViewModel : ViewModel() {
}
fun clearSelectedItems() {
_selectedItems.postValue(mutableListOf())
// We need this to be done immediately
// so we can't use postValue
_selectedItems.value = mutableListOf()
}
fun isAllSelected(): Boolean {

View file

@ -23,7 +23,7 @@
android:padding="8dp"
android:visibility="gone">
<ImageView
<ImageButton
android:id="@+id/btnCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -32,6 +32,7 @@
android:contentDescription="@string/cancel"
android:padding="8dp"
android:layout_gravity="center_vertical"
android:nextFocusLeft="@id/nav_rail_view"
app:tint="@android:color/white" />
<Button
@ -59,23 +60,14 @@
android:layout_weight="1" />
<Button
android:id="@+id/btnSelectAll"
android:id="@+id/btnToggleAll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:text="@string/select_all"
android:textColor="@android:color/white"
android:layout_marginEnd="8dp" />
<Button
android:id="@+id/btnDeselectAll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:text="@string/deselect_all"
android:textColor="@android:color/white"
android:layout_marginEnd="8dp"
android:visibility="gone" />
android:nextFocusDown="@id/download_child_list" />
</LinearLayout>
<com.google.android.material.appbar.MaterialToolbar

View file

@ -26,7 +26,7 @@
android:padding="8dp"
android:visibility="gone">
<ImageView
<ImageButton
android:id="@+id/btnCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -35,6 +35,7 @@
android:contentDescription="@string/cancel"
android:padding="8dp"
android:layout_gravity="center_vertical"
android:nextFocusLeft="@id/nav_rail_view"
app:tint="@android:color/white" />
<Button
@ -62,23 +63,14 @@
android:layout_weight="1" />
<Button
android:id="@+id/btnSelectAll"
android:id="@+id/btnToggleAll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:text="@string/select_all"
android:textColor="@android:color/white"
android:layout_marginEnd="8dp" />
<Button
android:id="@+id/btnDeselectAll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:text="@string/deselect_all"
android:textColor="@android:color/white"
android:layout_marginEnd="8dp"
android:visibility="gone" />
android:nextFocusDown="@id/download_list" />
</LinearLayout>
<LinearLayout