Skip to content

Commit

Permalink
Improve D-pad navigation in HomeActivity
Browse files Browse the repository at this point in the history
- Make sure ViewPager doesn't steal the focus during navigation
- Hide RecyclerViews when server lists are empty

Related issue #73
  • Loading branch information
gujjwal00 committed Oct 26, 2022
1 parent fbae025 commit 1c8bc52
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/src/main/java/com/gaurav/avnc/ui/home/ServerTabs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ class ServerTabs(val activity: HomeActivity) {
discoveredServersTab = tabLayout.getTabAt(1)!!
discoveredServersTab.setIcon(R.drawable.ic_search)
discoveredServersTab.setContentDescription(R.string.desc_discovered_servers_tab)

//ViewPager2 uses a RecyclerView internally, and sets it's DescendantFocusability
//to 'FOCUS_BEFORE_DESCENDANTS', effectively breaking navigation via D-pad or arrow keys.
pager.forEach { (it as ViewGroup).descendantFocusability = ViewGroup.FOCUS_AFTER_DESCENDANTS }
}

fun showSavedServers() {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/server_discovery.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@string/desc_discovered_list"
app:isVisible="@{!viewModel.discovery.servers.empty}"
tools:listitem="@layout/server_discovery_item" />

<TextView
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/server_saved.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
android:id="@+id/servers_rv"
style="@style/ServerList"
android:layout_width="match_parent"
app:isVisible="@{!viewModel.serverProfiles.empty}"
android:layout_height="match_parent"
android:contentDescription="@string/desc_saved_servers_list"
tools:listitem="@layout/server_saved_item" />
Expand Down

0 comments on commit 1c8bc52

Please sign in to comment.