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

Commit f8fa5866 authored by Zhen Zhang's avatar Zhen Zhang
Browse files

Refactor and override creation of the async sorting task

Refactor the creation of the async sorting task in ResolverActivity and
override it in ChooserActivity to use greatestOf method to find ranked
targets.

Bug: 142558305
Test: Passed all unit tests in ResolverActivityTest, ChooserActivityTest
and ResolverListControllerTest
Change-Id: I28fcc8a912d9ba5d42d4ad6ea58e13c97d55c6a2
parent b5adbe4d
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -2576,6 +2576,34 @@ public class ChooserActivity extends ResolverActivity {
            }
        }

        /**
         * Rather than fully sorting the input list, this sorting task will put the top k elements
         * in the head of input list and fill the tail with other elements in undetermined order.
         */
        @Override
        AsyncTask<List<ResolvedComponentInfo>,
                Void,
                List<ResolvedComponentInfo>> createSortingTask() {
            return new AsyncTask<List<ResolvedComponentInfo>,
                    Void,
                    List<ResolvedComponentInfo>>() {
                @Override
                protected List<ResolvedComponentInfo> doInBackground(
                        List<ResolvedComponentInfo>... params) {
                    mResolverListController.topK(params[0],
                            getMaxRankedTargets());
                    return params[0];
                }

                @Override
                protected void onPostExecute(List<ResolvedComponentInfo> sortedComponents) {
                    processSortedList(sortedComponents);
                    bindProfileView();
                    notifyDataSetChanged();
                }
            };
        }

        @Override
        public void onListRebuilt() {
            updateAlphabeticalList();
+24 −23
Original line number Diff line number Diff line
@@ -1618,7 +1618,7 @@ public class ResolverActivity extends Activity {
        private final List<ResolveInfo> mBaseResolveList;
        protected ResolveInfo mLastChosen;
        private DisplayResolveInfo mOtherProfile;
        private ResolverListController mResolverListController;
        ResolverListController mResolverListController;
        private int mPlaceholderCount;
        private boolean mAllTargetsAreBrowsers = false;

@@ -1779,10 +1779,23 @@ public class ResolverActivity extends Activity {
                        --placeholderCount;
                    }
                    setPlaceholderCount(placeholderCount);
                    createSortingTask().execute(currentResolveList);
                    postListReadyRunnable();
                    return false;
                } else {
                    processSortedList(currentResolveList);
                    return true;
                }
            } else {
                processSortedList(currentResolveList);
                return true;
            }
        }

        AsyncTask<List<ResolvedComponentInfo>,
                Void,
                            List<ResolvedComponentInfo>> sortingTask =
                            new AsyncTask<List<ResolvedComponentInfo>,
                List<ResolvedComponentInfo>> createSortingTask() {
            return new AsyncTask<List<ResolvedComponentInfo>,
                    Void,
                    List<ResolvedComponentInfo>>() {
                @Override
@@ -1799,21 +1812,9 @@ public class ResolverActivity extends Activity {
                    notifyDataSetChanged();
                }
            };
                    sortingTask.execute(currentResolveList);
                    postListReadyRunnable();
                    return false;
                } else {
                    processSortedList(currentResolveList);
                    return true;
        }
            } else {
                processSortedList(currentResolveList);
                return true;
            }
        }


        private void processSortedList(List<ResolvedComponentInfo> sortedComponents) {
        void processSortedList(List<ResolvedComponentInfo> sortedComponents) {
            int N;
            if (sortedComponents != null && (N = sortedComponents.size()) != 0) {
                mAllTargetsAreBrowsers = mUseLayoutForBrowsables;