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:
@@ -161,7 +161,6 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
}
|
||||
|
||||
public void setSuggestionsV2(List<Suggestion> data) {
|
||||
// TODO: Tint icon
|
||||
final DashboardData prevData = mDashboardData;
|
||||
mDashboardData = new DashboardData.Builder(prevData)
|
||||
.setSuggestionsV2(data)
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -59,6 +59,8 @@ public class SuggestionControllerMixin implements SuggestionController.ServiceCo
|
||||
private final SuggestionController mSuggestionController;
|
||||
private final SuggestionControllerHost mHost;
|
||||
|
||||
private boolean mSuggestionLoaded;
|
||||
|
||||
public SuggestionControllerMixin(Context context, SuggestionControllerHost host,
|
||||
Lifecycle lifecycle) {
|
||||
mContext = context.getApplicationContext();
|
||||
@@ -106,6 +108,7 @@ public class SuggestionControllerMixin implements SuggestionController.ServiceCo
|
||||
@Override
|
||||
public Loader<List<Suggestion>> onCreateLoader(int id, Bundle args) {
|
||||
if (id == SuggestionLoader.LOADER_ID_SUGGESTIONS) {
|
||||
mSuggestionLoaded = false;
|
||||
return new SuggestionLoader(mContext, mSuggestionController);
|
||||
}
|
||||
throw new IllegalArgumentException("This loader id is not supported " + id);
|
||||
@@ -113,12 +116,17 @@ public class SuggestionControllerMixin implements SuggestionController.ServiceCo
|
||||
|
||||
@Override
|
||||
public void onLoadFinished(Loader<List<Suggestion>> loader, List<Suggestion> data) {
|
||||
mSuggestionLoaded = true;
|
||||
mHost.onSuggestionReady(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoaderReset(Loader<List<Suggestion>> loader) {
|
||||
mSuggestionLoaded = false;
|
||||
}
|
||||
|
||||
public boolean isSuggestionLoaded() {
|
||||
return mSuggestionLoaded;
|
||||
}
|
||||
|
||||
public void dismissSuggestion(Suggestion suggestion) {
|
||||
|
Reference in New Issue
Block a user