From 31073e2acf0fbeae62373573bfcdea1a7bbc735c Mon Sep 17 00:00:00 2001 From: Severiano Jaramillo Date: Wed, 21 Aug 2019 15:09:59 -0500 Subject: [PATCH] Fix crash in BalancesFragment. - The crash was happening in a very weird scenario, but it was good because it forced us to search an alternative to update the BalancesFragment when the user navigates back to the HomeFragment. The solution was to use the childFragmentManager instead of the fragmentManager to create the PagerAdapter used in the ViewPager that displays the BalancesFragment. Basically, because we are using nested fragments we need to use the childFragmentManager instead of just the fragmentManager, to use the correct LyfeCycle events. --- .../bitsybitshareswallet/fragments/BalancesFragment.kt | 8 -------- .../bitsybitshareswallet/fragments/HomeFragment.kt | 2 +- .../bitsybitshareswallet/fragments/NetWorthFragment.kt | 8 -------- 3 files changed, 1 insertion(+), 17 deletions(-) diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/BalancesFragment.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/BalancesFragment.kt index d33aa0c..17c4250 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/BalancesFragment.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/BalancesFragment.kt @@ -43,12 +43,4 @@ class BalancesFragment: Fragment() { balancesAdapter.replaceAll(balancesDetails) }) } - - override fun setUserVisibleHint(isVisibleToUser: Boolean) { - super.setUserVisibleHint(isVisibleToUser) - if (isVisibleToUser) { - // TODO find a better way to recreate the fragment, that does it only when the theme has been changed - fragmentManager?.beginTransaction()?.detach(this)?.attach(this)?.commit() - } - } } \ No newline at end of file diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/HomeFragment.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/HomeFragment.kt index dfdc661..af4d3d5 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/HomeFragment.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/HomeFragment.kt @@ -112,7 +112,7 @@ class HomeFragment : Fragment() { } // Configure ViewPager with PagerAdapter and TabLayout to display the Balances/NetWorth section - val pagerAdapter = PagerAdapter(fragmentManager!!) + val pagerAdapter = PagerAdapter(childFragmentManager) viewPager.adapter = pagerAdapter tabLayout.setupWithViewPager(viewPager) // Set the pie chart icon for the third tab diff --git a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/NetWorthFragment.kt b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/NetWorthFragment.kt index 9fa2447..5996cfe 100644 --- a/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/NetWorthFragment.kt +++ b/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/NetWorthFragment.kt @@ -17,12 +17,4 @@ class NetWorthFragment: Fragment() { return inflater.inflate(R.layout.fragment_net_worth, container, false) } - - override fun setUserVisibleHint(isVisibleToUser: Boolean) { - super.setUserVisibleHint(isVisibleToUser) - if (isVisibleToUser) { - // TODO find a better way to recreate the fragment, that does it only when the theme has been changed - fragmentManager?.beginTransaction()?.detach(this)?.attach(this)?.commit() - } - } } \ No newline at end of file