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

Commit 2efb7b62 authored by Andy Wickham's avatar Andy Wickham
Browse files

Fixes a list equality check and adds a refreshResults() method.

Previously, the lists being compared could point to the same
object (e.g. from a separate class like ZeroStateResultProvider),
thus always being equal. This prevented the RecyclerView from
updating in certain cases.

Also added an option new method to SearchUiManager which can be
used to trigger a refresh.

Bug: 207651359
Test: Manual
Change-Id: I9c7f02fcd9dfb91326eccf1d4eb8692904702ab0
parent 5b79bbbc
Loading
Loading
Loading
Loading
+13 −10
Original line number Diff line number Diff line
@@ -81,7 +81,7 @@ public class AlphabeticalAppsList<T extends Context & ActivityContext> implement
    private final List<FastScrollSectionInfo> mFastScrollerSections = new ArrayList<>();

    // The of ordered component names as a result of a search query
    private ArrayList<AdapterItem> mSearchResults;
    private final ArrayList<AdapterItem> mSearchResults = new ArrayList<>();
    private BaseAllAppsAdapter<T> mAdapter;
    private AppInfoComparator mAppNameComparator;
    private final int mNumAppsPerRow;
@@ -171,30 +171,33 @@ public class AlphabeticalAppsList<T extends Context & ActivityContext> implement
     * Returns whether there are is a filter set.
     */
    public boolean hasFilter() {
        return (mSearchResults != null);
        return !mSearchResults.isEmpty();
    }

    /**
     * Returns whether there are no filtered results.
     */
    public boolean hasNoFilteredResults() {
        return (mSearchResults != null) && mAccessibilityResultsCount == 0;
        return hasFilter() && mAccessibilityResultsCount == 0;
    }

    /**
     * Sets results list for search
     */
    public boolean setSearchResults(ArrayList<AdapterItem> results) {
        if (!Objects.equals(results, mSearchResults)) {
            mSearchResults = results;
        if (Objects.equals(results, mSearchResults)) {
            return false;
        }
        mSearchResults.clear();
        if (results != null) {
            mSearchResults.addAll(results);
        }
        updateAdapterItems();
        return true;
    }
        return false;
    }

    public boolean appendSearchResults(ArrayList<AdapterItem> results) {
        if (mSearchResults != null && results != null && results.size() > 0) {
        if (hasFilter() && results != null && results.size() > 0) {
            updateSearchAdapterItems(results, mSearchResults.size());
            refreshRecyclerView();
            return true;
@@ -259,7 +262,7 @@ public class AlphabeticalAppsList<T extends Context & ActivityContext> implement
        }

        // Recompose the set of adapter items from the current set of apps
        if (mSearchResults == null) {
        if (mSearchResults.isEmpty()) {
            updateAdapterItems();
        }
    }
+3 −0
Original line number Diff line number Diff line
@@ -65,4 +65,7 @@ public interface SearchUiManager {
     * sets highlight result's title
     */
    default void setFocusedResultTitle(@Nullable  CharSequence title) { }

    /** Refresh the currently displayed list of results. */
    default void refreshResults() {}
}