Hack to wait for both suggestion/category to load

- This is unfortunately necessary to avoid a jank when category
  load completes before suggestion load, in which case user has to
  manually scroll up to see the suggestions.
- We could technically just add scrollTo(0), but that causes the list
  scroll on its own within 0.5 second of settings start, and that's bad.

Change-Id: I8dc869a69a5bf11bbf7644b281cc1778dd1a90e8
Fixes: 69068691
Test: visual
Test: robotests
This commit is contained in:
Fan Zhang
2017-12-04 14:31:30 -08:00
parent d786fc5bdd
commit cbc97bc7dd
4 changed files with 47 additions and 9 deletions

View File

@@ -81,6 +81,9 @@ public class DashboardSummary extends InstrumentedFragment
private boolean isOnCategoriesChangedCalled;
private boolean mOnConditionsChangedCalled;
private DashboardCategory mStagingCategory;
private List<Suggestion> mStagingSuggestions;
@Override
public int getMetricsCategory() {
return MetricsEvent.DASHBOARD_SUMMARY;
@@ -291,7 +294,13 @@ public class DashboardSummary extends InstrumentedFragment
@Override
public void onSuggestionReady(List<Suggestion> suggestions) {
mStagingSuggestions = suggestions;
mAdapter.setSuggestionsV2(suggestions);
if (mStagingCategory != null) {
Log.d(TAG, "Category has loaded, setting category from suggestionReady");
mHandler.removeCallbacksAndMessages(null);
mAdapter.setCategory(mStagingCategory);
}
}
/**
@@ -342,7 +351,19 @@ public class DashboardSummary extends InstrumentedFragment
final DashboardCategory category = mDashboardFeatureProvider.getTilesForCategory(
CategoryKey.CATEGORY_HOMEPAGE);
mSummaryLoader.updateSummaryToCache(category);
ThreadUtils.postOnMainThread(() -> mAdapter.setCategory(category));
mStagingCategory = category;
if (mSuggestionControllerMixin.isSuggestionLoaded()) {
Log.d(TAG, "Suggestion has loaded, setting suggestion/category");
ThreadUtils.postOnMainThread(() -> {
if (mStagingSuggestions != null) {
mAdapter.setSuggestionsV2(mStagingSuggestions);
}
mAdapter.setCategory(mStagingCategory);
});
} else {
Log.d(TAG, "Suggestion NOT loaded, delaying setCategory by " + MAX_WAIT_MILLIS + "ms");
mHandler.postDelayed(() -> mAdapter.setCategory(mStagingCategory), MAX_WAIT_MILLIS);
}
}
/**