Refactor SummaryLoader to set summary on subsetting pages.
- Make a SummaryConsumer interface. Things that needs latest summary should implement this interface (DashboardAdapter for homepage, DashboardFragment for subsettings). This also decouples SummaryLoader from relying on SettingsDrawerActivity. - Make DashboardFeatureProvider more generic to load DashboardCategory by key. Bug: 31781480 Test: RunSettingsRoboTests Change-Id: I9c65456fb433a74c352498251e0ccf65da0be1f0
This commit is contained in:
@@ -40,13 +40,15 @@ import java.util.Map;
|
||||
* Base fragment for dashboard style UI containing a list of static and dynamic setting items.
|
||||
*/
|
||||
public abstract class DashboardFragment extends SettingsPreferenceFragment
|
||||
implements SettingsDrawerActivity.CategoryListener, Indexable {
|
||||
implements SettingsDrawerActivity.CategoryListener, Indexable,
|
||||
SummaryLoader.SummaryConsumer {
|
||||
|
||||
private final Map<Class, PreferenceController> mPreferenceControllers =
|
||||
new ArrayMap<>();
|
||||
|
||||
protected DashboardFeatureProvider mDashboardFeatureProvider;
|
||||
private boolean mListeningToCategoryChange;
|
||||
private SummaryLoader mSummaryLoader;
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
@@ -57,7 +59,8 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
|
||||
|
||||
@Override
|
||||
public void onCategoriesChanged() {
|
||||
final DashboardCategory category = getDashboardTiles();
|
||||
final DashboardCategory category =
|
||||
mDashboardFeatureProvider.getTilesForCategory(getCategoryKey());
|
||||
if (category == null) {
|
||||
return;
|
||||
}
|
||||
@@ -73,11 +76,12 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
final DashboardCategory category = getDashboardTiles();
|
||||
final DashboardCategory category =
|
||||
mDashboardFeatureProvider.getTilesForCategory(getCategoryKey());
|
||||
if (category == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
mSummaryLoader.setListening(true);
|
||||
final Activity activity = getActivity();
|
||||
if (activity instanceof SettingsDrawerActivity) {
|
||||
mListeningToCategoryChange = true;
|
||||
@@ -85,6 +89,19 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifySummaryChanged(Tile tile) {
|
||||
final String key = mDashboardFeatureProvider.getDashboardKeyForTile(tile);
|
||||
final Preference pref = findPreference(key);
|
||||
if (pref == null) {
|
||||
Log.d(getLogTag(),
|
||||
String.format("Can't find pref by key %s, skipping update summary %s/%s",
|
||||
key, tile.title, tile.summary));
|
||||
return;
|
||||
}
|
||||
pref.setSummary(tile.summary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceTreeClick(Preference preference) {
|
||||
Collection<PreferenceController> controllers = mPreferenceControllers.values();
|
||||
@@ -100,6 +117,7 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
mSummaryLoader.setListening(false);
|
||||
if (mListeningToCategoryChange) {
|
||||
final Activity activity = getActivity();
|
||||
if (activity instanceof SettingsDrawerActivity) {
|
||||
@@ -119,9 +137,9 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@link DashboardCategory} for this fragment.
|
||||
* Returns the CategoryKey for loading {@link DashboardCategory} for this fragment.
|
||||
*/
|
||||
protected abstract DashboardCategory getDashboardTiles();
|
||||
protected abstract String getCategoryKey();
|
||||
|
||||
/**
|
||||
* Displays resource based tiles.
|
||||
@@ -135,7 +153,8 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
|
||||
*/
|
||||
private final void displayDashboardTiles(final String TAG, PreferenceScreen screen) {
|
||||
final Context context = getContext();
|
||||
final DashboardCategory category = getDashboardTiles();
|
||||
final DashboardCategory category =
|
||||
mDashboardFeatureProvider.getTilesForCategory(getCategoryKey());
|
||||
if (category == null) {
|
||||
Log.d(TAG, "NO dynamic tiles for " + TAG);
|
||||
return;
|
||||
@@ -145,6 +164,13 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
|
||||
Log.d(TAG, "tile list is empty, skipping category " + category.title);
|
||||
return;
|
||||
}
|
||||
// There are dashboard tiles, so we need to install SummaryLoader.
|
||||
if (mSummaryLoader != null) {
|
||||
mSummaryLoader.release();
|
||||
}
|
||||
mSummaryLoader = new SummaryLoader(getActivity(), getCategoryKey());
|
||||
mSummaryLoader.setSummaryConsumer(this);
|
||||
// Install dashboard tiles.
|
||||
for (Tile tile : tiles) {
|
||||
final String key = mDashboardFeatureProvider.getDashboardKeyForTile(tile);
|
||||
if (TextUtils.isEmpty(key)) {
|
||||
|
Reference in New Issue
Block a user