Reduce the number of times that dataset changed is triggerd in DashboardAdapter

1. Save the suggestion list and the category list into the instance
state so that it will be available on warm start, and avoid the need
to reload the data.
2. Add the condition list to the constructor parameters for
DashboardAdapter, so that it does not need to setConditions()
separately which will trigger notifyDataSetChanged()

Bug: 30055644
Change-Id: Ia04fa3a25b13d2dacf6baf5f412d662a595fb6dd
This commit is contained in:
Doris Ling
2016-07-11 18:09:15 -07:00
parent 8dc1a7340b
commit b76de265a2
2 changed files with 34 additions and 8 deletions

View File

@@ -165,6 +165,9 @@ public class DashboardSummary extends InstrumentedFragment
super.onSaveInstanceState(outState);
if (mLayoutManager == null) return;
outState.putInt(EXTRA_SCROLL_POSITION, mLayoutManager.findFirstVisibleItemPosition());
if (mAdapter != null) {
mAdapter.onSaveInstanceState(outState);
}
}
@Override
@@ -181,14 +184,13 @@ public class DashboardSummary extends InstrumentedFragment
mDashboard.setHasFixedSize(true);
mDashboard.setListener(this);
mDashboard.addItemDecoration(new DashboardDecorator(getContext()));
mAdapter = new DashboardAdapter(getContext(), mSuggestionParser);
mAdapter.setConditions(mConditionManager.getConditions());
mAdapter = new DashboardAdapter(getContext(), mSuggestionParser, bundle,
mConditionManager.getConditions());
mDashboard.setAdapter(mAdapter);
mSummaryLoader.setAdapter(mAdapter);
ConditionAdapterUtils.addDismiss(mDashboard);
if (DEBUG_TIMING) Log.d(TAG, "onViewCreated took "
+ (System.currentTimeMillis() - startTime) + " ms");
rebuildUI();
}