Reuse existing nullable binding variables.

This commit is contained in:
Isira Seneviratne 2023-04-01 18:52:21 +05:30
parent 21541b9578
commit 66b64a7474
2 changed files with 6 additions and 7 deletions

View File

@ -243,7 +243,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = FragmentPlayerBinding.inflate(layoutInflater)
_binding = FragmentPlayerBinding.inflate(inflater)
return binding.root
}
@ -271,7 +271,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
* somehow the bottom bar is invisible on low screen resolutions, this fixes it
*/
private fun showBottomBar() {
if (isAdded && !binding.player.isPlayerLocked) {
if (_binding?.player?.isPlayerLocked == false) {
playerBinding.bottomBar.isVisible = true
}
handler.postDelayed(this::showBottomBar, 100)

View File

@ -45,7 +45,7 @@ class SearchResultFragment : Fragment() {
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = FragmentSearchResultBinding.inflate(layoutInflater)
_binding = FragmentSearchResultBinding.inflate(inflater)
return binding.root
}
@ -78,7 +78,7 @@ class SearchResultFragment : Fragment() {
fetchSearch()
binding.searchRecycler.viewTreeObserver.addOnScrollChangedListener {
if (isAdded && !binding.searchRecycler.canScrollVertically(1) &&
if (_binding?.searchRecycler?.canScrollVertically(1) == false &&
nextPage != null
) {
fetchNextSearchItems()
@ -144,9 +144,8 @@ class SearchResultFragment : Fragment() {
}
}
override fun onDestroy() {
super.onDestroy()
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
}