Merge "Refactor SummaryLoader to set summary on subsetting pages."
This commit is contained in:
committed by
Android (Google) Code Review
commit
36a6cb0370
@@ -48,7 +48,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.DashboardItemHolder>
|
public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.DashboardItemHolder>
|
||||||
implements View.OnClickListener {
|
implements View.OnClickListener, SummaryLoader.SummaryConsumer {
|
||||||
public static final String TAG = "DashboardAdapter";
|
public static final String TAG = "DashboardAdapter";
|
||||||
private static final String STATE_SUGGESTION_LIST = "suggestion_list";
|
private static final String STATE_SUGGESTION_LIST = "suggestion_list";
|
||||||
private static final String STATE_CATEGORY_LIST = "category_list";
|
private static final String STATE_CATEGORY_LIST = "category_list";
|
||||||
@@ -141,11 +141,8 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
|||||||
recountItems();
|
recountItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isShowingAll() {
|
@Override
|
||||||
return mIsShowingAll;
|
public void notifySummaryChanged(Tile tile) {
|
||||||
}
|
|
||||||
|
|
||||||
public void notifyChanged(Tile tile) {
|
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -31,19 +31,9 @@ public interface DashboardFeatureProvider {
|
|||||||
boolean isEnabled();
|
boolean isEnabled();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get tiles (wrapped in {@link DashboardCategory}) for homepage.
|
* Get tiles (wrapped in {@link DashboardCategory}) for key defined in CategoryKey.
|
||||||
*/
|
*/
|
||||||
DashboardCategory getTilesForHomepage();
|
DashboardCategory getTilesForCategory(String key);
|
||||||
|
|
||||||
/**
|
|
||||||
* Get tiles (wrapped in {@link DashboardCategory}) for storage category.
|
|
||||||
*/
|
|
||||||
DashboardCategory getTilesForStorageCategory();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get tiles (wrapped in {@link DashboardCategory}) for system category.
|
|
||||||
*/
|
|
||||||
DashboardCategory getTilesForSystemCategory();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all tiles, grouped by category.
|
* Get all tiles, grouped by category.
|
||||||
|
@@ -48,18 +48,8 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DashboardCategory getTilesForHomepage() {
|
public DashboardCategory getTilesForCategory(String key) {
|
||||||
return mCategoryManager.getTilesByCategory(mContext, CategoryKey.CATEGORY_HOMEPAGE);
|
return mCategoryManager.getTilesByCategory(mContext, key);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public DashboardCategory getTilesForStorageCategory() {
|
|
||||||
return mCategoryManager.getTilesByCategory(mContext, CategoryKey.CATEGORY_STORAGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public DashboardCategory getTilesForSystemCategory() {
|
|
||||||
return mCategoryManager.getTilesByCategory(mContext, CategoryKey.CATEGORY_SYSTEM);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -40,13 +40,15 @@ import java.util.Map;
|
|||||||
* Base fragment for dashboard style UI containing a list of static and dynamic setting items.
|
* Base fragment for dashboard style UI containing a list of static and dynamic setting items.
|
||||||
*/
|
*/
|
||||||
public abstract class DashboardFragment extends SettingsPreferenceFragment
|
public abstract class DashboardFragment extends SettingsPreferenceFragment
|
||||||
implements SettingsDrawerActivity.CategoryListener, Indexable {
|
implements SettingsDrawerActivity.CategoryListener, Indexable,
|
||||||
|
SummaryLoader.SummaryConsumer {
|
||||||
|
|
||||||
private final Map<Class, PreferenceController> mPreferenceControllers =
|
private final Map<Class, PreferenceController> mPreferenceControllers =
|
||||||
new ArrayMap<>();
|
new ArrayMap<>();
|
||||||
|
|
||||||
protected DashboardFeatureProvider mDashboardFeatureProvider;
|
protected DashboardFeatureProvider mDashboardFeatureProvider;
|
||||||
private boolean mListeningToCategoryChange;
|
private boolean mListeningToCategoryChange;
|
||||||
|
private SummaryLoader mSummaryLoader;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Context context) {
|
public void onAttach(Context context) {
|
||||||
@@ -57,7 +59,8 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCategoriesChanged() {
|
public void onCategoriesChanged() {
|
||||||
final DashboardCategory category = getDashboardTiles();
|
final DashboardCategory category =
|
||||||
|
mDashboardFeatureProvider.getTilesForCategory(getCategoryKey());
|
||||||
if (category == null) {
|
if (category == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -73,11 +76,12 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
|
|||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
final DashboardCategory category = getDashboardTiles();
|
final DashboardCategory category =
|
||||||
|
mDashboardFeatureProvider.getTilesForCategory(getCategoryKey());
|
||||||
if (category == null) {
|
if (category == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
mSummaryLoader.setListening(true);
|
||||||
final Activity activity = getActivity();
|
final Activity activity = getActivity();
|
||||||
if (activity instanceof SettingsDrawerActivity) {
|
if (activity instanceof SettingsDrawerActivity) {
|
||||||
mListeningToCategoryChange = true;
|
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
|
@Override
|
||||||
public boolean onPreferenceTreeClick(Preference preference) {
|
public boolean onPreferenceTreeClick(Preference preference) {
|
||||||
Collection<PreferenceController> controllers = mPreferenceControllers.values();
|
Collection<PreferenceController> controllers = mPreferenceControllers.values();
|
||||||
@@ -100,6 +117,7 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
|
|||||||
@Override
|
@Override
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
|
mSummaryLoader.setListening(false);
|
||||||
if (mListeningToCategoryChange) {
|
if (mListeningToCategoryChange) {
|
||||||
final Activity activity = getActivity();
|
final Activity activity = getActivity();
|
||||||
if (activity instanceof SettingsDrawerActivity) {
|
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.
|
* Displays resource based tiles.
|
||||||
@@ -135,7 +153,8 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
|
|||||||
*/
|
*/
|
||||||
private final void displayDashboardTiles(final String TAG, PreferenceScreen screen) {
|
private final void displayDashboardTiles(final String TAG, PreferenceScreen screen) {
|
||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
final DashboardCategory category = getDashboardTiles();
|
final DashboardCategory category =
|
||||||
|
mDashboardFeatureProvider.getTilesForCategory(getCategoryKey());
|
||||||
if (category == null) {
|
if (category == null) {
|
||||||
Log.d(TAG, "NO dynamic tiles for " + TAG);
|
Log.d(TAG, "NO dynamic tiles for " + TAG);
|
||||||
return;
|
return;
|
||||||
@@ -145,6 +164,13 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
|
|||||||
Log.d(TAG, "tile list is empty, skipping category " + category.title);
|
Log.d(TAG, "tile list is empty, skipping category " + category.title);
|
||||||
return;
|
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) {
|
for (Tile tile : tiles) {
|
||||||
final String key = mDashboardFeatureProvider.getDashboardKeyForTile(tile);
|
final String key = mDashboardFeatureProvider.getDashboardKeyForTile(tile);
|
||||||
if (TextUtils.isEmpty(key)) {
|
if (TextUtils.isEmpty(key)) {
|
||||||
|
@@ -38,6 +38,7 @@ import com.android.settings.dashboard.conditional.ConditionManager;
|
|||||||
import com.android.settings.dashboard.conditional.FocusRecyclerView;
|
import com.android.settings.dashboard.conditional.FocusRecyclerView;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settingslib.SuggestionParser;
|
import com.android.settingslib.SuggestionParser;
|
||||||
|
import com.android.settingslib.drawer.CategoryKey;
|
||||||
import com.android.settingslib.drawer.DashboardCategory;
|
import com.android.settingslib.drawer.DashboardCategory;
|
||||||
import com.android.settingslib.drawer.SettingsDrawerActivity;
|
import com.android.settingslib.drawer.SettingsDrawerActivity;
|
||||||
import com.android.settingslib.drawer.Tile;
|
import com.android.settingslib.drawer.Tile;
|
||||||
@@ -95,8 +96,7 @@ public class DashboardSummary extends InstrumentedFragment
|
|||||||
.getDashboardFeatureProvider(activity);
|
.getDashboardFeatureProvider(activity);
|
||||||
|
|
||||||
if (mDashboardFeatureProvider.isEnabled()) {
|
if (mDashboardFeatureProvider.isEnabled()) {
|
||||||
mSummaryLoader = new SummaryLoader(activity,
|
mSummaryLoader = new SummaryLoader(activity, CategoryKey.CATEGORY_HOMEPAGE);
|
||||||
mDashboardFeatureProvider.getTilesForHomepage());
|
|
||||||
} else {
|
} else {
|
||||||
mSummaryLoader = new SummaryLoader(activity,
|
mSummaryLoader = new SummaryLoader(activity,
|
||||||
((SettingsActivity) getActivity()).getDashboardCategories());
|
((SettingsActivity) getActivity()).getDashboardCategories());
|
||||||
@@ -222,7 +222,7 @@ public class DashboardSummary extends InstrumentedFragment
|
|||||||
mAdapter = new DashboardAdapter(getContext(), mSuggestionParser, mMetricsFeatureProvider,
|
mAdapter = new DashboardAdapter(getContext(), mSuggestionParser, mMetricsFeatureProvider,
|
||||||
bundle, mConditionManager.getConditions());
|
bundle, mConditionManager.getConditions());
|
||||||
mDashboard.setAdapter(mAdapter);
|
mDashboard.setAdapter(mAdapter);
|
||||||
mSummaryLoader.setAdapter(mAdapter);
|
mSummaryLoader.setSummaryConsumer(mAdapter);
|
||||||
ConditionAdapterUtils.addDismiss(mDashboard);
|
ConditionAdapterUtils.addDismiss(mDashboard);
|
||||||
if (DEBUG_TIMING) {
|
if (DEBUG_TIMING) {
|
||||||
Log.d(TAG, "onViewCreated took "
|
Log.d(TAG, "onViewCreated took "
|
||||||
@@ -297,13 +297,13 @@ public class DashboardSummary extends InstrumentedFragment
|
|||||||
// Temporary hack to wrap homepage category into a list. Soon we will create adapter
|
// Temporary hack to wrap homepage category into a list. Soon we will create adapter
|
||||||
// API that takes a single category.
|
// API that takes a single category.
|
||||||
List<DashboardCategory> categories = new ArrayList<>();
|
List<DashboardCategory> categories = new ArrayList<>();
|
||||||
categories.add(mDashboardFeatureProvider.getTilesForHomepage());
|
categories.add(mDashboardFeatureProvider.getTilesForCategory(
|
||||||
|
CategoryKey.CATEGORY_HOMEPAGE));
|
||||||
mAdapter.setCategoriesAndSuggestions(categories, tiles);
|
mAdapter.setCategoriesAndSuggestions(categories, tiles);
|
||||||
} else {
|
} else {
|
||||||
mAdapter.setCategoriesAndSuggestions(
|
mAdapter.setCategoriesAndSuggestions(
|
||||||
((SettingsActivity) activity).getDashboardCategories(), tiles);
|
((SettingsActivity) activity).getDashboardCategories(), tiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -36,7 +36,6 @@ import com.android.settingslib.drawer.SettingsDrawerActivity;
|
|||||||
import com.android.settingslib.drawer.Tile;
|
import com.android.settingslib.drawer.Tile;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class SummaryLoader {
|
public class SummaryLoader {
|
||||||
@@ -47,18 +46,22 @@ public class SummaryLoader {
|
|||||||
|
|
||||||
private final Activity mActivity;
|
private final Activity mActivity;
|
||||||
private final ArrayMap<SummaryProvider, ComponentName> mSummaryMap = new ArrayMap<>();
|
private final ArrayMap<SummaryProvider, ComponentName> mSummaryMap = new ArrayMap<>();
|
||||||
private final List<Tile> mTiles = new ArrayList<>();
|
private final DashboardFeatureProvider mDashboardFeatureProvider;
|
||||||
|
private final String mCategoryKey;
|
||||||
|
|
||||||
private final Worker mWorker;
|
private final Worker mWorker;
|
||||||
private final Handler mHandler;
|
private final Handler mHandler;
|
||||||
private final HandlerThread mWorkerThread;
|
private final HandlerThread mWorkerThread;
|
||||||
|
|
||||||
private DashboardAdapter mAdapter;
|
private SummaryConsumer mSummaryConsumer;
|
||||||
private boolean mListening;
|
private boolean mListening;
|
||||||
private boolean mWorkerListening;
|
private boolean mWorkerListening;
|
||||||
private ArraySet<BroadcastReceiver> mReceivers = new ArraySet<>();
|
private ArraySet<BroadcastReceiver> mReceivers = new ArraySet<>();
|
||||||
|
|
||||||
public SummaryLoader(Activity activity, List<DashboardCategory> categories) {
|
public SummaryLoader(Activity activity, List<DashboardCategory> categories) {
|
||||||
|
mDashboardFeatureProvider = FeatureFactory.getFactory(activity)
|
||||||
|
.getDashboardFeatureProvider(activity);
|
||||||
|
mCategoryKey = null;
|
||||||
mHandler = new Handler();
|
mHandler = new Handler();
|
||||||
mWorkerThread = new HandlerThread("SummaryLoader", Process.THREAD_PRIORITY_BACKGROUND);
|
mWorkerThread = new HandlerThread("SummaryLoader", Process.THREAD_PRIORITY_BACKGROUND);
|
||||||
mWorkerThread.start();
|
mWorkerThread.start();
|
||||||
@@ -73,14 +76,18 @@ public class SummaryLoader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public SummaryLoader(Activity activity, DashboardCategory categories) {
|
public SummaryLoader(Activity activity, String categoryKey) {
|
||||||
|
mDashboardFeatureProvider = FeatureFactory.getFactory(activity)
|
||||||
|
.getDashboardFeatureProvider(activity);
|
||||||
|
mCategoryKey = categoryKey;
|
||||||
mHandler = new Handler();
|
mHandler = new Handler();
|
||||||
mWorkerThread = new HandlerThread("SummaryLoader", Process.THREAD_PRIORITY_BACKGROUND);
|
mWorkerThread = new HandlerThread("SummaryLoader", Process.THREAD_PRIORITY_BACKGROUND);
|
||||||
mWorkerThread.start();
|
mWorkerThread.start();
|
||||||
mWorker = new Worker(mWorkerThread.getLooper());
|
mWorker = new Worker(mWorkerThread.getLooper());
|
||||||
mActivity = activity;
|
mActivity = activity;
|
||||||
List<Tile> tiles = categories.tiles;
|
|
||||||
for (Tile tile :tiles) {
|
List<Tile> tiles = mDashboardFeatureProvider.getTilesForCategory(categoryKey).tiles;
|
||||||
|
for (Tile tile : tiles) {
|
||||||
mWorker.obtainMessage(Worker.MSG_GET_PROVIDER, tile).sendToTarget();
|
mWorker.obtainMessage(Worker.MSG_GET_PROVIDER, tile).sendToTarget();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -91,8 +98,8 @@ public class SummaryLoader {
|
|||||||
setListeningW(false);
|
setListeningW(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAdapter(DashboardAdapter adapter) {
|
public void setSummaryConsumer(SummaryConsumer summaryConsumer) {
|
||||||
mAdapter = adapter;
|
mSummaryConsumer = summaryConsumer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSummary(SummaryProvider provider, final CharSequence summary) {
|
public void setSummary(SummaryProvider provider, final CharSequence summary) {
|
||||||
@@ -100,21 +107,20 @@ public class SummaryLoader {
|
|||||||
mHandler.post(new Runnable() {
|
mHandler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
// Since tiles are not always cached (like on locale change for instance),
|
|
||||||
// we need to always get the latest one.
|
|
||||||
if (!(mActivity instanceof SettingsDrawerActivity)) {
|
|
||||||
if (DEBUG) {
|
|
||||||
Log.d(TAG, "Can't get category list.");
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final Tile tile;
|
final Tile tile;
|
||||||
final DashboardFeatureProvider dashboardFeatureProvider =
|
if (mDashboardFeatureProvider.isEnabled()) {
|
||||||
FeatureFactory.getFactory(mActivity).getDashboardFeatureProvider(mActivity);
|
tile = getTileFromCategory(
|
||||||
if (dashboardFeatureProvider.isEnabled()) {
|
mDashboardFeatureProvider.getTilesForCategory(mCategoryKey), component);
|
||||||
tile = getTileFromCategory(dashboardFeatureProvider.getTilesForHomepage(),
|
|
||||||
component);
|
|
||||||
} else {
|
} else {
|
||||||
|
// Since tiles are not always cached (like on locale change for instance),
|
||||||
|
// we need to always get the latest one.
|
||||||
|
if (!(mActivity instanceof SettingsDrawerActivity)) {
|
||||||
|
if (DEBUG) {
|
||||||
|
Log.d(TAG, "Can't get category list.");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
tile = getTileFromCategory(
|
tile = getTileFromCategory(
|
||||||
((SettingsDrawerActivity) mActivity).getDashboardCategories(),
|
((SettingsDrawerActivity) mActivity).getDashboardCategories(),
|
||||||
component);
|
component);
|
||||||
@@ -130,7 +136,14 @@ public class SummaryLoader {
|
|||||||
Log.d(TAG, "setSummary " + tile.title + " - " + summary);
|
Log.d(TAG, "setSummary " + tile.title + " - " + summary);
|
||||||
}
|
}
|
||||||
tile.summary = summary;
|
tile.summary = summary;
|
||||||
mAdapter.notifyChanged(tile);
|
if (mSummaryConsumer != null) {
|
||||||
|
mSummaryConsumer.notifySummaryChanged(tile);
|
||||||
|
} else {
|
||||||
|
if (DEBUG) {
|
||||||
|
Log.d(TAG, "SummaryConsumer is null, skipping summary update for "
|
||||||
|
+ tile.title);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -259,6 +272,10 @@ public class SummaryLoader {
|
|||||||
void setListening(boolean listening);
|
void setListening(boolean listening);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface SummaryConsumer {
|
||||||
|
void notifySummaryChanged(Tile tile);
|
||||||
|
}
|
||||||
|
|
||||||
public interface SummaryProviderFactory {
|
public interface SummaryProviderFactory {
|
||||||
SummaryProvider createSummaryProvider(Activity activity, SummaryLoader summaryLoader);
|
SummaryProvider createSummaryProvider(Activity activity, SummaryLoader summaryLoader);
|
||||||
}
|
}
|
||||||
|
@@ -24,7 +24,7 @@ import com.android.settings.dashboard.DashboardFragment;
|
|||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
import com.android.settings.search.Indexable;
|
import com.android.settings.search.Indexable;
|
||||||
import com.android.settingslib.drawer.DashboardCategory;
|
import com.android.settingslib.drawer.CategoryKey;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -51,8 +51,8 @@ public class StorageDashboardFragment extends DashboardFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected DashboardCategory getDashboardTiles() {
|
protected String getCategoryKey() {
|
||||||
return mDashboardFeatureProvider.getTilesForStorageCategory();
|
return CategoryKey.CATEGORY_STORAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -25,7 +25,7 @@ import com.android.settings.deviceinfo.SystemUpdatePreferenceController;
|
|||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
import com.android.settings.search.Indexable;
|
import com.android.settings.search.Indexable;
|
||||||
import com.android.settingslib.drawer.DashboardCategory;
|
import com.android.settingslib.drawer.CategoryKey;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -62,8 +62,8 @@ public class SystemDashboardFragment extends DashboardFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected DashboardCategory getDashboardTiles() {
|
protected String getCategoryKey() {
|
||||||
return mDashboardFeatureProvider.getTilesForSystemCategory();
|
return CategoryKey.CATEGORY_SYSTEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -24,6 +24,7 @@ import com.android.settings.TestConfig;
|
|||||||
import com.android.settings.core.PreferenceController;
|
import com.android.settings.core.PreferenceController;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settings.testutils.FakeFeatureFactory;
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
|
import com.android.settingslib.drawer.CategoryKey;
|
||||||
import com.android.settingslib.drawer.DashboardCategory;
|
import com.android.settingslib.drawer.DashboardCategory;
|
||||||
import com.android.settingslib.drawer.Tile;
|
import com.android.settingslib.drawer.Tile;
|
||||||
|
|
||||||
@@ -42,6 +43,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
|
import static org.mockito.Matchers.anyString;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
@@ -68,7 +70,8 @@ public class DashboardFragmentTest {
|
|||||||
mDashboardCategory.tiles.add(new Tile());
|
mDashboardCategory.tiles.add(new Tile());
|
||||||
mTestFragment = new TestFragment(ShadowApplication.getInstance().getApplicationContext());
|
mTestFragment = new TestFragment(ShadowApplication.getInstance().getApplicationContext());
|
||||||
mTestFragment.onAttach(mContext);
|
mTestFragment.onAttach(mContext);
|
||||||
mTestFragment.mCategory = mDashboardCategory;
|
when(mFakeFeatureFactory.dashboardFeatureProvider.getTilesForCategory(anyString()))
|
||||||
|
.thenReturn(mDashboardCategory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -100,7 +103,7 @@ public class DashboardFragmentTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void displayTilesAsPreference_withEmptyCategory_shouldNotAddTiles() {
|
public void displayTilesAsPreference_withEmptyCategory_shouldNotAddTiles() {
|
||||||
mTestFragment.mCategory.tiles = null;
|
mDashboardCategory.tiles = null;
|
||||||
mTestFragment.onCreatePreferences(new Bundle(), "rootKey");
|
mTestFragment.onCreatePreferences(new Bundle(), "rootKey");
|
||||||
|
|
||||||
verify(mTestFragment.mScreen, never()).addPreference(any(DashboardTilePreference.class));
|
verify(mTestFragment.mScreen, never()).addPreference(any(DashboardTilePreference.class));
|
||||||
@@ -133,8 +136,6 @@ public class DashboardFragmentTest {
|
|||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
@Mock
|
@Mock
|
||||||
public PreferenceScreen mScreen;
|
public PreferenceScreen mScreen;
|
||||||
public DashboardCategory mCategory;
|
|
||||||
|
|
||||||
|
|
||||||
public TestFragment(Context context) {
|
public TestFragment(Context context) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
@@ -152,8 +153,8 @@ public class DashboardFragmentTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected DashboardCategory getDashboardTiles() {
|
protected String getCategoryKey() {
|
||||||
return mCategory;
|
return CategoryKey.CATEGORY_HOMEPAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Reference in New Issue
Block a user