Merge "Skip redundant SuggestionLoader run during app start."
This commit is contained in:
committed by
Android (Google) Code Review
commit
ec6cd665b1
@@ -527,8 +527,9 @@ public class SettingsActivity extends SettingsDrawerActivity
|
||||
}
|
||||
}
|
||||
|
||||
if (DEBUG_TIMING) Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime)
|
||||
+ " ms");
|
||||
if (DEBUG_TIMING) {
|
||||
Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime) + " ms");
|
||||
}
|
||||
}
|
||||
|
||||
public void setDisplaySearchMenu(boolean displaySearch) {
|
||||
|
@@ -63,6 +63,7 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
private final DashboardFeatureProvider mDashboardFeatureProvider;
|
||||
private SuggestionParser mSuggestionParser;
|
||||
private boolean mFirstFrameDrawn;
|
||||
|
||||
@VisibleForTesting
|
||||
DashboardData mDashboardData;
|
||||
@@ -162,6 +163,15 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
notifyDashboardDataChanged(prevData);
|
||||
}
|
||||
|
||||
public void setCategory(List<DashboardCategory> category) {
|
||||
final DashboardData prevData = mDashboardData;
|
||||
Log.d(TAG, "adapter setCategory called");
|
||||
mDashboardData = new DashboardData.Builder(prevData)
|
||||
.setCategories(category)
|
||||
.build();
|
||||
notifyDashboardDataChanged(prevData);
|
||||
}
|
||||
|
||||
public void setConditions(List<Condition> conditions) {
|
||||
final DashboardData prevData = mDashboardData;
|
||||
Log.d(TAG, "adapter setConditions called");
|
||||
@@ -304,11 +314,12 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
}
|
||||
|
||||
private void notifyDashboardDataChanged(DashboardData prevData) {
|
||||
if (prevData != null) {
|
||||
if (mFirstFrameDrawn && prevData != null) {
|
||||
final DiffUtil.DiffResult diffResult = DiffUtil.calculateDiff(new DashboardData
|
||||
.ItemsDataDiffCallback(prevData.getItemList(), mDashboardData.getItemList()));
|
||||
diffResult.dispatchUpdatesTo(this);
|
||||
} else {
|
||||
mFirstFrameDrawn = true;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
@@ -27,6 +27,7 @@ import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
@@ -231,26 +232,25 @@ public class DashboardSummary extends InstrumentedFragment
|
||||
Log.d(TAG, "onViewCreated took "
|
||||
+ (System.currentTimeMillis() - startTime) + " ms");
|
||||
}
|
||||
rebuildUI();
|
||||
rebuildUI(true /* rebuildSuggestions */);
|
||||
}
|
||||
|
||||
private void rebuildUI() {
|
||||
if (!isAdded()) {
|
||||
Log.w(TAG, "Cannot build the DashboardSummary UI yet as the Fragment is not added");
|
||||
return;
|
||||
}
|
||||
|
||||
// recheck to see if any suggestions have been changed.
|
||||
new SuggestionLoader().execute();
|
||||
// Set categories on their own if loading suggestions takes too long.
|
||||
mHandler.postDelayed(() -> {
|
||||
private void rebuildUI(boolean rebuildSuggestions) {
|
||||
if (rebuildSuggestions) {
|
||||
// recheck to see if any suggestions have been changed.
|
||||
new SuggestionLoader().execute();
|
||||
// Set categories on their own if loading suggestions takes too long.
|
||||
mHandler.postDelayed(() -> {
|
||||
updateCategoryAndSuggestion(null /* tiles */);
|
||||
}, MAX_WAIT_MILLIS);
|
||||
} else {
|
||||
updateCategoryAndSuggestion(null /* tiles */);
|
||||
}, MAX_WAIT_MILLIS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCategoriesChanged() {
|
||||
rebuildUI();
|
||||
rebuildUI(false /* rebuildSuggestions */);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -264,7 +264,6 @@ public class DashboardSummary extends InstrumentedFragment
|
||||
}
|
||||
|
||||
private class SuggestionLoader extends AsyncTask<Void, Void, List<Tile>> {
|
||||
|
||||
@Override
|
||||
protected List<Tile> doInBackground(Void... params) {
|
||||
final Context context = getContext();
|
||||
@@ -307,7 +306,7 @@ public class DashboardSummary extends InstrumentedFragment
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void updateCategoryAndSuggestion(List<Tile> tiles) {
|
||||
void updateCategoryAndSuggestion(List<Tile> suggestions) {
|
||||
final Activity activity = getActivity();
|
||||
if (activity == null) {
|
||||
return;
|
||||
@@ -319,10 +318,14 @@ public class DashboardSummary extends InstrumentedFragment
|
||||
List<DashboardCategory> categories = new ArrayList<>();
|
||||
categories.add(mDashboardFeatureProvider.getTilesForCategory(
|
||||
CategoryKey.CATEGORY_HOMEPAGE));
|
||||
mAdapter.setCategoriesAndSuggestions(categories, tiles);
|
||||
if (suggestions != null) {
|
||||
mAdapter.setCategoriesAndSuggestions(categories, suggestions);
|
||||
} else {
|
||||
mAdapter.setCategory(categories);
|
||||
}
|
||||
} else {
|
||||
mAdapter.setCategoriesAndSuggestions(
|
||||
((SettingsActivity) activity).getDashboardCategories(), tiles);
|
||||
((SettingsActivity) activity).getDashboardCategories(), suggestions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user