Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3f8c0394 authored by Katherine Kuan's avatar Katherine Kuan Committed by Android (Google) Code Review
Browse files

Merge "Intercept single contact mode and reset to last saved preference" into ics-mr1

parents caa3cae2 be79b8f0
Loading
Loading
Loading
Loading
+33 −0
Original line number Diff line number Diff line
@@ -183,6 +183,14 @@ public class PeopleActivity extends ContactsActivity
     */
    private boolean mFragmentInitialized;

    /**
     * Whether or not the current contact filter is valid or not. We need to do a check on
     * start of the app to verify that the user is not in single contact mode. If so, we should
     * dynamically change the filter, unless the incoming intent specifically requested a contact
     * that should be displayed in that mode.
     */
    private boolean mCurrentFilterIsValid;

    /** Sequential ID assigned to each instance; used for logging */
    private final int mInstanceId;
    private static final AtomicInteger sNextInstanceId = new AtomicInteger();
@@ -251,6 +259,7 @@ public class PeopleActivity extends ContactsActivity
        }

        mContactListFilterController = ContactListFilterController.getInstance(this);
        mContactListFilterController.checkFilterValidity(false);
        mContactListFilterController.addListener(this);

        mIsRecreatedInstance = (savedState != null);
@@ -269,6 +278,9 @@ public class PeopleActivity extends ContactsActivity
        }
        mActionBarAdapter.initialize(null, mRequest);

        mContactListFilterController.checkFilterValidity(false);
        mCurrentFilterIsValid = true;

        // Re-configure fragments.
        configureFragments(true /* from request */);
        invalidateOptionsMenuIfNeeded();
@@ -443,6 +455,19 @@ public class PeopleActivity extends ContactsActivity
             * (so the argument.)
             */
            configureFragments(!mIsRecreatedInstance);
        } else if (PhoneCapabilityTester.isUsingTwoPanes(this) && !mCurrentFilterIsValid) {
            // We only want to do the filter check in onStart for wide screen devices where it
            // is often possible to get into single contact mode. Only do this check if
            // the filter hasn't already been set properly (i.e. onCreate or onActivityResult).

            // Since there is only one {@link ContactListFilterController} across multiple
            // activity instances, make sure the filter controller is in sync withthe current
            // contact list fragment filter.
            // TODO: Clean this up. Perhaps change {@link ContactListFilterController} to not be a
            // singleton?
            mContactListFilterController.setContactListFilter(mAllFragment.getFilter(), true);
            mContactListFilterController.checkFilterValidity(true);
            mCurrentFilterIsValid = true;
        }
        super.onStart();
    }
@@ -473,6 +498,12 @@ public class PeopleActivity extends ContactsActivity
        updateFragmentsVisibility();
    }

    @Override
    protected void onStop() {
        super.onStop();
        mCurrentFilterIsValid = false;
    }

    @Override
    protected void onDestroy() {
        // Some of variables will be null if this Activity redirects Intent.
@@ -1491,6 +1522,8 @@ public class PeopleActivity extends ContactsActivity
                    if (mActionBarAdapter != null) {
                        mActionBarAdapter.clearFocusOnSearchView();
                    }
                    // No need to change the contact filter
                    mCurrentFilterIsValid = true;
                }
                break;
            }
+12 −2
Original line number Diff line number Diff line
@@ -153,7 +153,15 @@ public final class ContactListFilter implements Comparable<ContactListFilter>, P
        return true;
    }

    /**
     * Store the given {@link ContactListFilter} to preferences. If the requested filter is
     * of type {@link #FILTER_TYPE_SINGLE_CONTACT} then do not save it to preferences because
     * it is a temporary state.
     */
    public static void storeToPreferences(SharedPreferences prefs, ContactListFilter filter) {
        if (filter != null && filter.filterType == FILTER_TYPE_SINGLE_CONTACT) {
            return;
        }
        prefs.edit()
            .putInt(KEY_FILTER_TYPE, filter == null ? FILTER_TYPE_DEFAULT : filter.filterType)
            .putString(KEY_ACCOUNT_NAME, filter == null ? null : filter.accountName)
@@ -171,8 +179,10 @@ public final class ContactListFilter implements Comparable<ContactListFilter>, P
        if (filter == null) {
            filter = ContactListFilter.createFilterWithType(FILTER_TYPE_ALL_ACCOUNTS);
        }
        // "Group" filter is obsolete and thus is not exposed anymore.
        if (filter.filterType == FILTER_TYPE_GROUP) {
        // "Group" filter is obsolete and thus is not exposed anymore. The "single contact mode"
        // should also not be stored in preferences anymore since it is a temporary state.
        if (filter.filterType == FILTER_TYPE_GROUP ||
                filter.filterType == FILTER_TYPE_SINGLE_CONTACT) {
            filter = ContactListFilter.createFilterWithType(FILTER_TYPE_ALL_ACCOUNTS);
        }
        return filter;
+26 −11
Original line number Diff line number Diff line
@@ -65,9 +65,11 @@ public abstract class ContactListFilterController {
    /**
     * Checks if the current filter is valid and reset the filter if not. It may happen when
     * an account is removed while the filter points to the account with
     * {@link ContactListFilter#FILTER_TYPE_ACCOUNT} type, for example.
     * {@link ContactListFilter#FILTER_TYPE_ACCOUNT} type, for example. It may also happen if
     * the current filter is {@link ContactListFilter#FILTER_TYPE_SINGLE_CONTACT}, in
     * which case, we should switch to the last saved filter in {@link SharedPreferences}.
     */
    public abstract void checkFilterValidity();
    public abstract void checkFilterValidity(boolean notifyListeners);
}

/**
@@ -83,7 +85,7 @@ class ContactListFilterControllerImpl extends ContactListFilterController {
    public ContactListFilterControllerImpl(Context context) {
        mContext = context;
        mFilter = ContactListFilter.restoreDefaultPreferences(getSharedPreferences());
        checkFilterValidity();
        checkFilterValidity(true /* notify listeners */);
    }

    @Override
@@ -107,12 +109,17 @@ class ContactListFilterControllerImpl extends ContactListFilterController {

    @Override
    public void setContactListFilter(ContactListFilter filter, boolean persistent) {
        setContactListFilter(filter, persistent, true);
    }

    private void setContactListFilter(ContactListFilter filter, boolean persistent,
            boolean notifyListeners) {
        if (!filter.equals(mFilter)) {
            mFilter = filter;
            if (persistent) {
                ContactListFilter.storeToPreferences(getSharedPreferences(), mFilter);
            }
            if (!mListeners.isEmpty()) {
            if (notifyListeners && !mListeners.isEmpty()) {
                notifyContactListFilterChanged();
            }
        }
@@ -131,16 +138,24 @@ class ContactListFilterControllerImpl extends ContactListFilterController {
    }

    @Override
    public void checkFilterValidity() {
        if (mFilter == null || mFilter.filterType != ContactListFilter.FILTER_TYPE_ACCOUNT) {
    public void checkFilterValidity(boolean notifyListeners) {
        if (mFilter == null) {
            return;
        }

        if (!filterAccountExists()) {
            // The current account filter points to invalid account. Use "all" filter instead.
        switch (mFilter.filterType) {
            case ContactListFilter.FILTER_TYPE_SINGLE_CONTACT:
                setContactListFilter(
                    ContactListFilter.createFilterWithType(
                            ContactListFilter.FILTER_TYPE_ALL_ACCOUNTS), true);
                        ContactListFilter.restoreDefaultPreferences(getSharedPreferences()),
                        false, notifyListeners);
                break;
            case ContactListFilter.FILTER_TYPE_ACCOUNT:
                if (!filterAccountExists()) {
                    // The current account filter points to invalid account. Use "all" filter
                    // instead.
                    setContactListFilter(ContactListFilter.createFilterWithType(
                            ContactListFilter.FILTER_TYPE_ALL_ACCOUNTS), true, notifyListeners);
                }
        }
    }

+1 −1
Original line number Diff line number Diff line
@@ -212,7 +212,7 @@ class AccountTypeManagerImpl extends AccountTypeManager
    private final Runnable mCheckFilterValidityRunnable = new Runnable () {
        @Override
        public void run() {
            ContactListFilterController.getInstance(mContext).checkFilterValidity();
            ContactListFilterController.getInstance(mContext).checkFilterValidity(true);
        }
    };