From 38d8582abe01ced40333f77d99c43d6111b047ed Mon Sep 17 00:00:00 2001 From: Doris Ling Date: Fri, 15 Jul 2016 11:18:23 -0700 Subject: [PATCH] Combine setCategories() and setSuggestions() in DashboardAdapter. In DashboardSummary.rebuildUI(), we first update the adapter with the current categories, then run the async task to update the adapter with the suggestions. This causes the adapter to first layout the existing categories, and relayout when the suggestions is available. This causes the suggestions view and categories view to overlap before the relayout is complete. Since categories and suggestions are borh set each time we try to rebuild the UI, delaying the update for categories until the suggestions are ready will avoid the unnecessary relayout of the list elements. Ran app launch test for Settings app with the change and launch time is between 412ms and 486ms in 10 runs, which does not show much delay in app launch time with delaying updating the categories. Bug: 29318104 Change-Id: I03ae2386392315f28fe2c361682f2f3252e9f827 --- .../settings/dashboard/DashboardAdapter.java | 17 ++++++----------- .../settings/dashboard/DashboardSummary.java | 8 +++----- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/com/android/settings/dashboard/DashboardAdapter.java b/src/com/android/settings/dashboard/DashboardAdapter.java index b161c4151e1..ca09e51d232 100644 --- a/src/com/android/settings/dashboard/DashboardAdapter.java +++ b/src/com/android/settings/dashboard/DashboardAdapter.java @@ -110,14 +110,10 @@ public class DashboardAdapter extends RecyclerView.Adapter suggestions) { - if (!Objects.equals(mSuggestions, suggestions)) { - mSuggestions = suggestions; - recountItems(); - } - } - public Tile getTile(ComponentName component) { + if (mCategories == null) { + return null; + } for (int i = 0; i < mCategories.size(); i++) { for (int j = 0; j < mCategories.get(i).tiles.size(); j++) { Tile tile = mCategories.get(i).tiles.get(j); @@ -129,10 +125,9 @@ public class DashboardAdapter extends RecyclerView.Adapter categories) { - if (Objects.equals(mCategories, categories)) { - return; - } + public void setCategoriesAndSuggestions(List categories, + List suggestions) { + mSuggestions = suggestions; mCategories = categories; // TODO: Better place for tinting? diff --git a/src/com/android/settings/dashboard/DashboardSummary.java b/src/com/android/settings/dashboard/DashboardSummary.java index 24b5aee7b7f..3a75c8aec8f 100644 --- a/src/com/android/settings/dashboard/DashboardSummary.java +++ b/src/com/android/settings/dashboard/DashboardSummary.java @@ -200,10 +200,6 @@ public class DashboardSummary extends InstrumentedFragment return; } - List categories = - ((SettingsActivity) getActivity()).getDashboardCategories(); - mAdapter.setCategories(categories); - // recheck to see if any suggestions have been changed. new SuggestionLoader().execute(); } @@ -235,7 +231,9 @@ public class DashboardSummary extends InstrumentedFragment @Override protected void onPostExecute(List tiles) { - mAdapter.setSuggestions(tiles); + List categories = + ((SettingsActivity) getActivity()).getDashboardCategories(); + mAdapter.setCategoriesAndSuggestions(categories, tiles); } } }