Skip to content

Instantly share code, notes, and snippets.

@dzolnai
Created May 23, 2018 13:46
Show Gist options
  • Save dzolnai/854a98f776991f013d1e4078ddd9eed4 to your computer and use it in GitHub Desktop.
Save dzolnai/854a98f776991f013d1e4078ddd9eed4 to your computer and use it in GitHub Desktop.
A BaseGridFragment contains a VerticalGridSupportFragment which is modified to allow focus to escape it.
abstract class BaseGridFragment : Fragment() {
private var lifecycleCallbacks: FragmentManager.FragmentLifecycleCallbacks? = null
/**
* If your fragment contains a VerticalGridSupportFragment, it automatically includes a search button you can disable.
* However, the focus search listener is not disabled, and it does conflict with our implementation for showing the menu.
* Don't forget to save a reference to the callbacks to unsubscribe when destroying the fragment.
*/
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
lifecycleCallbacks = object : FragmentManager.FragmentLifecycleCallbacks() {
override fun onFragmentStarted(fm: FragmentManager?, f: Fragment?) {
if (f is VerticalGridSupportFragment) {
val browseFrameLayout = f.getView()!!.findViewById<View>(
android.support.v17.leanback.R.id.grid_frame) as BrowseFrameLayout
browseFrameLayout.onFocusSearchListener = null
}
}
}
childFragmentManager.registerFragmentLifecycleCallbacks(lifecycleCallbacks, true)
}
override fun onDestroyView() {
childFragmentManager.unregisterFragmentLifecycleCallbacks(lifecycleCallbacks)
super.onDestroyView()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment