Refactor DashboardFragment.

Merged refreshAllPreferences into DashboardFragment. This hopefully
makes it more modular to manage preference display logic in each
dashboardFragment, and makes it more efficient to monitor category
changes.

Now subclasses needs to implement 2 methods:
- displayResourceTiles(): for 'static' preferences from xml
- getDashboardTiles(): returns a list of dashboard tiles and superclass
  will wire it up to preference screen.

If getDashboardTiles() return null (aka no dashboardCategory available),
the fragment will not attempt to monitor category change. The edge case
is that if a package starts to provide a tile for this category, we will
not be notified. I have not seen this case coming up. If we indeed need
to handle this case, the category listener needs to have a way to
monitor specific category rather than globally.

Bug: 31781480
Test: make RunSettingsRoboTests -j40
Change-Id: Ia9f9541b95816214df0d0bb27e3e41078c36c5ca
This commit is contained in:
Fan Zhang
2016-10-07 08:38:48 -07:00
parent cb054fff54
commit 36924659f5
5 changed files with 117 additions and 61 deletions

View File

@@ -17,16 +17,14 @@
package com.android.settings.deviceinfo;
import android.content.Context;
import android.os.Bundle;
import android.os.UserManager;
import android.provider.SearchIndexableResource;
import android.support.v7.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
import com.android.settingslib.drawer.DashboardCategory;
import java.util.ArrayList;
import java.util.Arrays;
@@ -41,6 +39,11 @@ public class StorageDashboardFragment extends DashboardFragment {
return STORAGE_CATEGORY_FRAGMENT;
}
@Override
protected String getLogTag() {
return TAG;
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
@@ -48,28 +51,16 @@ public class StorageDashboardFragment extends DashboardFragment {
}
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
super.onCreatePreferences(savedInstanceState, rootKey);
refreshAllPreferences();
protected DashboardCategory getDashboardTiles() {
return mDashboardFeatureProvider.getTilesForStorageCategory();
}
@Override
public void onCategoriesChanged() {
refreshAllPreferences();
}
private void refreshAllPreferences() {
PreferenceScreen screen = getPreferenceScreen();
if (screen != null) {
screen.removeAll();
}
protected void displayResourceTiles() {
addPreferencesFromResource(R.xml.storage_dashboard_fragment);
getPreferenceController(ManageStoragePreferenceController.class)
.displayPreference(getPreferenceScreen());
displayTilesAsPreference(TAG, getPreferenceScreen(),
mDashboardFeatureProvider.getTilesForStorageCategory());
}
/**