Skip to content

Commit

Permalink
fix: NPE crash on SearchByCodeFragment (#4652)
Browse files Browse the repository at this point in the history
* Fix crash
"at openfoodfacts.github.scrachx.openfood.features.searchbycode.SearchByCodeFragment.getBinding(SearchByCodeFragment.kt:30)"

* Better fix for the crash (thanks VaiTon)
  • Loading branch information
g123k committed Apr 9, 2022
1 parent c7438bb commit 53f79aa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Expand Up @@ -37,6 +37,7 @@ class SearchByCodeFragment : NavigationWithDrawerBaseFragment() {
}

override fun onDestroyView() {
removeDrawerListener()
super.onDestroyView()
_binding = null
}
Expand Down Expand Up @@ -107,6 +108,7 @@ class SearchByCodeFragment : NavigationWithDrawerBaseFragment() {
binding.editTextBarcode.requestFocus()
requireActivity().showKeyboard()
}

}

companion object {
Expand Down
Expand Up @@ -17,11 +17,14 @@ abstract class NavigationWithDrawerBaseFragment : NavigationBaseFragment(), OnNa
}

override fun onDetach() {
removeDrawerListener()
super.onDetach()
}

fun removeDrawerListener() {
if (requireContext() is NavigationDrawerHost) {
(context as NavigationDrawerHost).removeOnDrawerStatusChangedListener(this)
}

super.onDetach()
}

override fun onDrawerOpened() {
Expand Down

0 comments on commit 53f79aa

Please sign in to comment.