Merge "Use separate container for ContactsUnavailableFragment" into ub-contactsdialer-h-dev
diff --git a/res/layout/people_activity.xml b/res/layout/people_activity.xml
index 8810af0..978f47a 100644
--- a/res/layout/people_activity.xml
+++ b/res/layout/people_activity.xml
@@ -20,6 +20,14 @@
android:layout_width="match_parent"
android:layout_height="match_parent" >
+ <!-- This is kind of a hack. Really we should be able to put the ContactsUnavailableFragment
+ into contacts_list_container but that causes issues with the fragment back stack
+ on older API levels -->
+ <FrameLayout
+ android:id="@+id/contacts_unavailable_container"
+ android:layout_height="match_parent"
+ android:layout_width="match_parent" />
+
<FrameLayout
android:id="@+id/contacts_list_container"
android:layout_height="match_parent"
diff --git a/src/com/android/contacts/activities/PeopleActivity.java b/src/com/android/contacts/activities/PeopleActivity.java
index 4532833..c2198bb 100644
--- a/src/com/android/contacts/activities/PeopleActivity.java
+++ b/src/com/android/contacts/activities/PeopleActivity.java
@@ -107,7 +107,6 @@
private View mFloatingActionButtonContainer;
private boolean wasLastFabAnimationScaleIn = false;
- private ContactsUnavailableFragment mContactsUnavailableFragment;
private ProviderStatusWatcher mProviderStatusWatcher;
private Integer mProviderStatus;
@@ -219,24 +218,6 @@
return (mProviderStatus != null) && mProviderStatus.equals(ProviderStatus.STATUS_NORMAL);
}
- /**
- * Initialize fragments that are (or may not be) in the layout.
- *
- * For the fragments that are in the layout, we initialize them in
- * {@link #createViewsAndFragments()} after inflating the layout.
- *
- * However, the {@link ContactsUnavailableFragment} is a special fragment which may not
- * be in the layout, so we have to do the initialization here.
- *
- * The ContactsUnavailableFragment is always created at runtime.
- */
- @Override
- public void onAttachFragment(Fragment fragment) {
- if (fragment instanceof ContactsUnavailableFragment) {
- mContactsUnavailableFragment = (ContactsUnavailableFragment)fragment;
- }
- }
-
@Override
protected void onCreate(Bundle savedState) {
if (Log.isLoggable(Constants.PERFORMANCE_TAG, Log.DEBUG)) {
@@ -562,27 +543,27 @@
// actually at least one real account (not "local" account) on device.
if (shouldShowList()) {
if (mAllFragment != null) {
- transaction.show(mAllFragment);
+ final Fragment unavailableFragment = fragmentManager
+ .findFragmentByTag(TAG_UNAVAILABLE);
+ if (unavailableFragment != null) {
+ transaction.remove(unavailableFragment);
+ }
+ if (mAllFragment.isHidden()) {
+ transaction.show(mAllFragment);
+ }
mAllFragment.setContactsAvailable(areContactsAvailable());
mAllFragment.setEnabled(true);
}
- if (mContactsUnavailableFragment != null) {
- transaction.hide(mContactsUnavailableFragment);
- }
} else {
// Setting up the page so that the user can still use the app
// even without an account.
if (mAllFragment != null) {
mAllFragment.setEnabled(false);
- transaction.hide(mAllFragment);
}
- if (mContactsUnavailableFragment == null) {
- mContactsUnavailableFragment = new ContactsUnavailableFragment();
- transaction.add(R.id.contacts_list_container, mContactsUnavailableFragment,
- TAG_UNAVAILABLE);
- }
- transaction.show(mContactsUnavailableFragment);
- mContactsUnavailableFragment.updateStatus(mProviderStatus);
+ final ContactsUnavailableFragment fragment = new ContactsUnavailableFragment();
+ transaction.hide(mAllFragment);
+ transaction.replace(R.id.contacts_unavailable_container, fragment, TAG_UNAVAILABLE);
+ fragment.updateStatus(mProviderStatus);
}
if (!transaction.isEmpty()) {
transaction.commit();