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

Commit f52d4437 authored by Zhen Zhang's avatar Zhen Zhang Committed by Android (Google) Code Review
Browse files

Merge "Refactor and override creation of the async sorting task"

parents d45e024e f8fa5866
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
@@ -1624,7 +1624,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;

@@ -1785,10 +1785,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
@@ -1805,21 +1818,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;