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

Commit 1db00f68 authored by Makoto Onuki's avatar Makoto Onuki
Browse files

Fix the double query issue on phone

The issue was that fragments had separate methods for search: setSearchMode()
and setQueryString().  But now that fragments will never be in search mode
when query is empty, there's no need to expose both methods.

Changed setSearchMode() to non-public, and let setQueryString() call it
when necessary, so now we don't have to issue unnecessary queries.

Note this CL doesn't modify adapters, so they still have setSearchMode()
and setQueryString() as separate, public methods.

Also did a bit of cleaning up on how PeopleActivity handles search mode.
(When I worked on it first time I wasn't too familiar with the code, so was
afraid to change existing code too much, which left the code unnecessarily
complicated.)

Also removed all fragment.setSearchMode()/setQueryString() calls in
ContactSelectionActivity.configureListFragment().  As far as I checked
there's no way to invoke this activity with reqeust.isSearchMode/getQueryText
set.

Also removed ContactEntryListFragment.get/setContactRequest, which weren't used
anywhere.

Bug 5274171

Change-Id: I794db7ed54cb6b8f45d69430ec2f77e7fa83fb8c
parent d25f3189
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -211,14 +211,16 @@ public class ActionBarAdapter implements OnQueryTextListener, OnCloseListener {
        return mCurrentTab;
    }

    /**
     * @return Whether in search mode, i.e. if the search view is visible/expanded.
     *
     * Note even if the action bar is in search mode, if the query is empty, the search fragment
     * will not be in search mode.
     */
    public boolean isSearchMode() {
        return mSearchMode;
    }

    public boolean shouldShowSearchResult() {
        return mSearchMode && !TextUtils.isEmpty(mQueryString);
    }

    public void setSearchMode(boolean flag) {
        if (mSearchMode != flag) {
            mSearchMode = flag;
@@ -235,7 +237,7 @@ public class ActionBarAdapter implements OnQueryTextListener, OnCloseListener {
    }

    public String getQueryString() {
        return mQueryString;
        return mSearchMode ? mQueryString : null;
    }

    public void setQueryString(String query) {
+0 −8
Original line number Diff line number Diff line
@@ -327,7 +327,6 @@ public class ContactSelectionActivity extends ContactsActivity

            case ContactsRequest.ACTION_PICK_CONTACT: {
                ContactPickerFragment fragment = new ContactPickerFragment();
                fragment.setSearchMode(mRequest.isSearchMode());
                fragment.setIncludeProfile(mRequest.shouldIncludeProfile());
                mListFragment = fragment;
                break;
@@ -341,8 +340,6 @@ public class ContactSelectionActivity extends ContactsActivity

            case ContactsRequest.ACTION_CREATE_SHORTCUT_CONTACT: {
                ContactPickerFragment fragment = new ContactPickerFragment();
                fragment.setSearchMode(mRequest.isSearchMode());
                fragment.setQueryString(mRequest.getQueryString(), false);
                fragment.setShortcutRequested(true);
                mListFragment = fragment;
                break;
@@ -362,7 +359,6 @@ public class ContactSelectionActivity extends ContactsActivity
            case ContactsRequest.ACTION_CREATE_SHORTCUT_CALL: {
                PhoneNumberPickerFragment fragment = new PhoneNumberPickerFragment();
                fragment.setShortcutAction(Intent.ACTION_CALL);
                fragment.setSearchMode(mRequest.isSearchMode());

                mListFragment = fragment;
                break;
@@ -387,9 +383,6 @@ public class ContactSelectionActivity extends ContactsActivity
        }

        mListFragment.setLegacyCompatibilityMode(mRequest.isLegacyCompatibilityMode());
        mListFragment.setContactsRequest(mRequest);
        mListFragment.setSearchMode(mRequest.isSearchMode());
        mListFragment.setQueryString(mRequest.getQueryString(), false);
        mListFragment.setDirectoryResultLimit(DEFAULT_DIRECTORY_RESULT_LIMIT);

        getFragmentManager().beginTransaction()
@@ -537,7 +530,6 @@ public class ContactSelectionActivity extends ContactsActivity
    @Override
    public boolean onQueryTextChange(String newText) {
        mListFragment.setQueryString(newText, true);
        mListFragment.setSearchMode(!TextUtils.isEmpty(newText));
        return false;
    }

+0 −1
Original line number Diff line number Diff line
@@ -363,7 +363,6 @@ public class DialtactsActivity extends Activity {
                public boolean onQueryTextChange(String newText) {
                    // Show search result with non-empty text. Show a bare list otherwise.
                    mSearchFragment.setQueryString(newText, true);
                    mSearchFragment.setSearchMode(!TextUtils.isEmpty(newText));
                    return true;
                }
    };
+5 −16
Original line number Diff line number Diff line
@@ -566,12 +566,12 @@ public class PeopleActivity extends ContactsActivity
                invalidateOptionsMenu();
                break;
            case STOP_SEARCH_MODE:
                clearSearch();
                setQueryTextToFragment("");
                updateFragmentsVisibility();
                invalidateOptionsMenu();
                break;
            case CHANGE_SEARCH_QUERY:
                loadSearch(mActionBarAdapter.getQueryString());
                setQueryTextToFragment(mActionBarAdapter.getQueryString());
                break;
            default:
                throw new IllegalStateException("Unkonwn ActionBarAdapter action: " + action);
@@ -842,26 +842,19 @@ public class PeopleActivity extends ContactsActivity
        }
    }

    private void clearSearch() {
        loadSearch("");
    }

    private void loadSearch(String query) {
        configureFragments(false /* from request */);
    private void setQueryTextToFragment(String query) {
        mAllFragment.setQueryString(query, true);
        mAllFragment.setVisibleScrollbarEnabled(!mAllFragment.isSearchMode());
    }

    private void configureContactListFragmentForRequest() {
        mAllFragment.setContactsRequest(mRequest);

        Uri contactUri = mRequest.getContactUri();
        if (contactUri != null) {
            mAllFragment.setSelectedContactUri(contactUri);
        }

        mAllFragment.setFilter(mContactListFilterController.getFilter());
        mAllFragment.setSearchMode(mActionBarAdapter.isSearchMode());
        mAllFragment.setQueryString(mActionBarAdapter.getQueryString(), false);
        setQueryTextToFragment(mActionBarAdapter.getQueryString());

        if (mRequest.isDirectorySearchEnabled()) {
            mAllFragment.setDirectorySearchMode(DirectoryListLoader.SEARCH_MODE_DEFAULT);
@@ -874,11 +867,7 @@ public class PeopleActivity extends ContactsActivity
        // Filter may be changed when this Activity is in background.
        mAllFragment.setFilter(mContactListFilterController.getFilter());

        final boolean showSearchResult = mActionBarAdapter.shouldShowSearchResult();
        mAllFragment.setSearchMode(showSearchResult);

        final boolean useTwoPane = PhoneCapabilityTester.isUsingTwoPanes(this);
        mAllFragment.setVisibleScrollbarEnabled(!showSearchResult);
        mAllFragment.setVerticalScrollbarPosition(
                useTwoPane
                        ? View.SCROLLBAR_POSITION_LEFT
+1 −1
Original line number Diff line number Diff line
@@ -165,7 +165,7 @@ public abstract class ContactBrowseListFragment extends
    }

    @Override
    public void setSearchMode(boolean flag) {
    protected void setSearchMode(boolean flag) {
        if (isSearchMode() != flag) {
            if (!flag) {
                restoreSelectedUri(true);
Loading