From eb4b19017930f51a1c8df6d90d2e7fc4217d47ec Mon Sep 17 00:00:00 2001 From: Sarmad Hashmi Date: Sun, 28 Feb 2016 22:26:29 -0800 Subject: Fix voicemail tab showing even after being disabled. +Redraw voicemail tab every time notifyDataSetChanged method is called +Remove voicemail fragment once it is disabled BUG=23522864 Change-Id: I9cb1e6a0bbb91c38709a0ac5b8908f4f1252e509 --- src/com/android/dialer/list/ListsFragment.java | 33 +++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/com/android/dialer/list/ListsFragment.java b/src/com/android/dialer/list/ListsFragment.java index 5b7c950bf..52bf3cbb5 100644 --- a/src/com/android/dialer/list/ListsFragment.java +++ b/src/com/android/dialer/list/ListsFragment.java @@ -48,6 +48,7 @@ import com.android.dialer.voicemail.VoicemailStatusHelperImpl; import com.android.dialer.widget.ActionBarController; import java.util.ArrayList; +import java.util.List; /** * Fragment that is used as the main screen of the Dialer. @@ -106,8 +107,13 @@ public class ListsFragment extends Fragment private CallLogQueryHandler mCallLogQueryHandler; public class ViewPagerAdapter extends FragmentPagerAdapter { + private final List mFragments = new ArrayList<>(); + public ViewPagerAdapter(FragmentManager fm) { super(fm); + for (int i = 0; i < TAB_COUNT_WITH_VOICEMAIL; i++) { + mFragments.add(null); + } } @Override @@ -135,7 +141,7 @@ public class ListsFragment extends Fragment } @Override - public Object instantiateItem(ViewGroup container, int position) { + public Fragment instantiateItem(ViewGroup container, int position) { // On rotation the FragmentManager handles rotation. Therefore getItem() isn't called. // Copy the fragments that the FragmentManager finds so that we can store them in // instance variables for later. @@ -150,9 +156,25 @@ public class ListsFragment extends Fragment } else if (fragment instanceof CallLogFragment && position == TAB_INDEX_VOICEMAIL) { mVoicemailFragment = (CallLogFragment) fragment; } + mFragments.set(position, fragment); return fragment; } + /** + * When {@link android.support.v4.view.PagerAdapter#notifyDataSetChanged} is called, + * this method is called on all pages to determine whether they need to be recreated. + * When the voicemail tab is removed, the view needs to be recreated by returning + * POSITION_NONE. If notifyDataSetChanged is called for some other reason, the voicemail + * tab is recreated only if it is active. All other tabs do not need to be recreated + * and POSITION_UNCHANGED is returned. + */ + @Override + public int getItemPosition(Object object) { + return !mHasActiveVoicemailProvider && + mFragments.indexOf(object) == TAB_INDEX_VOICEMAIL ? POSITION_NONE : + POSITION_UNCHANGED; + } + @Override public int getCount() { return mHasActiveVoicemailProvider ? TAB_COUNT_WITH_VOICEMAIL : TAB_COUNT_DEFAULT; @@ -313,6 +335,7 @@ public class ListsFragment extends Fragment mViewPagerTabs.updateTab(TAB_INDEX_VOICEMAIL); } else { mViewPagerTabs.removeTab(TAB_INDEX_VOICEMAIL); + removeVoicemailFragment(); } mPrefs.edit() @@ -453,4 +476,12 @@ public class ListsFragment extends Fragment } Logger.logScreenView(screenType, getActivity()); } + + private void removeVoicemailFragment() { + if (mVoicemailFragment != null) { + getChildFragmentManager().beginTransaction().remove(mVoicemailFragment) + .commitAllowingStateLoss(); + mVoicemailFragment = null; + } + } } -- cgit v1.2.3