Skip to content

Commit

Permalink
Safer listener in ResourceItemFragment
Browse files Browse the repository at this point in the history
  • Loading branch information
levinli303 committed Jul 25, 2023
1 parent 79680f4 commit d4350d5
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ class ResourceItemFragment : NavigationFragment.SubFragment(), ResourceManager.L
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

resourceManager.addListener(this)
if (savedInstanceState != null) {
item = savedInstanceState.getSerializableValue(ARG_ITEM, ResourceItem::class.java)!!
lastUpdateDate = savedInstanceState.getSerializableValue(ARG_UPDATED_DATE, Date::class.java)!!
Expand Down Expand Up @@ -115,6 +114,8 @@ class ResourceItemFragment : NavigationFragment.SubFragment(), ResourceManager.L

updateUI()

resourceManager.addListener(this)

return view
}

Expand Down Expand Up @@ -170,10 +171,10 @@ class ResourceItemFragment : NavigationFragment.SubFragment(), ResourceManager.L
listener = null
}

override fun onDestroy() {
override fun onDestroyView() {
resourceManager.removeListener(this)

super.onDestroy()
super.onDestroyView()
}

override fun menuItemClicked(groupId: Int, id: Int): Boolean {
Expand Down

0 comments on commit d4350d5

Please sign in to comment.