Skip to content

Commit

Permalink
Focus HomeRowsFragment by default, fix wrong focus on resume
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsvanvelzen committed Nov 8, 2022
1 parent 5657dfb commit f53dba8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package org.jellyfin.androidtv.ui.home

import android.os.Build
import android.os.Bundle
import android.view.KeyEvent
import android.view.View
import androidx.core.view.ViewCompat
import androidx.leanback.app.RowsSupportFragment
import androidx.leanback.widget.ListRow
import androidx.leanback.widget.OnItemViewClickedListener
Expand Down Expand Up @@ -133,9 +131,6 @@ class HomeRowsFragment : RowsSupportFragment(), AudioEventListener, View.OnKeyLi
notificationsRow.addToRowsAdapter(requireContext(), cardPresenter, adapter as MutableObjectAdapter<Row>)
nowPlaying.addToRowsAdapter(requireContext(), cardPresenter, adapter as MutableObjectAdapter<Row>)
for (row in rows) row.addToRowsAdapter(requireContext(), cardPresenter, adapter as MutableObjectAdapter<Row>)

// Manually set focus if focusedByDefault is not available
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) view?.requestFocus()
}
}

Expand Down Expand Up @@ -169,13 +164,6 @@ class HomeRowsFragment : RowsSupportFragment(), AudioEventListener, View.OnKeyLi
return KeyProcessor.HandleKey(keyCode, currentItem, activity)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

// Make sure to focus the cards instead of the toolbar
ViewCompat.setFocusedByDefault(view, true)
}

override fun onResume() {
super.onResume()

Expand Down
8 changes: 7 additions & 1 deletion app/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,11 @@
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:focusedByDefault="true" />
android:descendantFocusability="afterDescendants"
android:focusable="true"
android:focusableInTouchMode="true"
android:focusedByDefault="true">

<requestFocus />
</androidx.fragment.app.FragmentContainerView>
</LinearLayout>

0 comments on commit f53dba8

Please sign in to comment.