Elicit ItemsData class and add DiffUtil.Callback
In the previous version, when there is a minor change in data, we will refresh the whole screen(and data) by invoking "recountItems" and "notifyDataSetChanged", which did lots of unnecessary works. In this new cl, I elicit ItemsData class, which encapsulates the list data used in adapter. When data changed, I build another ItemsData and use the DiffUtil.Callback to calculate diffs between ItemsDatas. In this way we can only refresh the items that changed in adapter. Since I cannot find usage of see_all.xml anymore, I delete the relevant code as well as the resource files. Bug: 30319913 Test: make RunSettingsRoboTests Change-Id: I4f753a26f624affea6c6c35d49cfb9c43fb74fe6
This commit is contained in:
@@ -20,6 +20,7 @@ import android.content.pm.PackageManager;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.util.DiffUtil;
|
||||
import android.support.v7.widget.PopupMenu;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
@@ -34,7 +35,6 @@ import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.internal.logging.MetricsProto.MetricsEvent;
|
||||
import com.android.internal.util.ArrayUtils;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||
@@ -48,82 +48,92 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.DashboardItemHolder>
|
||||
implements View.OnClickListener, SummaryLoader.SummaryConsumer {
|
||||
implements SummaryLoader.SummaryConsumer {
|
||||
public static final String TAG = "DashboardAdapter";
|
||||
private static final String STATE_SUGGESTION_LIST = "suggestion_list";
|
||||
private static final String STATE_CATEGORY_LIST = "category_list";
|
||||
private static final String STATE_IS_SHOWING_ALL = "is_showing_all";
|
||||
private static final String STATE_SUGGESTION_MODE = "suggestion_mode";
|
||||
private static final int NS_SPACER = 0;
|
||||
private static final int NS_SUGGESTION = 1000;
|
||||
private static final int NS_ITEMS = 2000;
|
||||
private static final int NS_CONDITION = 3000;
|
||||
|
||||
private static int SUGGESTION_MODE_DEFAULT = 0;
|
||||
private static int SUGGESTION_MODE_COLLAPSED = 1;
|
||||
private static int SUGGESTION_MODE_EXPANDED = 2;
|
||||
|
||||
private static final int DEFAULT_SUGGESTION_COUNT = 2;
|
||||
|
||||
private final List<Object> mItems = new ArrayList<>();
|
||||
private final List<Integer> mTypes = new ArrayList<>();
|
||||
private final List<Integer> mIds = new ArrayList<>();
|
||||
private final IconCache mCache;
|
||||
|
||||
private final Context mContext;
|
||||
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
|
||||
private List<DashboardCategory> mCategories;
|
||||
private List<Condition> mConditions;
|
||||
private List<Tile> mSuggestions;
|
||||
|
||||
private boolean mIsShowingAll;
|
||||
// Used for counting items;
|
||||
private int mId;
|
||||
|
||||
private int mSuggestionMode = SUGGESTION_MODE_DEFAULT;
|
||||
|
||||
private Condition mExpandedCondition = null;
|
||||
private DashboardData mDashboardData;
|
||||
private SuggestionParser mSuggestionParser;
|
||||
|
||||
private View.OnClickListener mTileClickListener = new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
//TODO: get rid of setTag/getTag
|
||||
final Tile tile = (Tile) mDashboardData.getItemEntityByPosition((int) v.getTag());
|
||||
((SettingsActivity) mContext).openTile(tile);
|
||||
}
|
||||
};
|
||||
|
||||
private View.OnClickListener mConditionClickListener = new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Condition expandedCondition = mDashboardData.getExpandedCondition();
|
||||
|
||||
//TODO: get rid of setTag/getTag
|
||||
if (v.getTag() == expandedCondition) {
|
||||
mMetricsFeatureProvider.action(mContext,
|
||||
MetricsEvent.ACTION_SETTINGS_CONDITION_CLICK,
|
||||
expandedCondition.getMetricsConstant());
|
||||
expandedCondition.onPrimaryClick();
|
||||
} else {
|
||||
expandedCondition = (Condition) v.getTag();
|
||||
mMetricsFeatureProvider.action(mContext,
|
||||
MetricsEvent.ACTION_SETTINGS_CONDITION_EXPAND,
|
||||
expandedCondition.getMetricsConstant());
|
||||
|
||||
updateExpandedCondition(expandedCondition);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public DashboardAdapter(Context context, SuggestionParser parser,
|
||||
MetricsFeatureProvider metricsFeatureProvider, Bundle savedInstanceState,
|
||||
List<Condition> conditions) {
|
||||
List<Tile> suggestions = null;
|
||||
List<DashboardCategory> categories = null;
|
||||
int suggestionMode = DashboardData.SUGGESTION_MODE_DEFAULT;
|
||||
|
||||
mContext = context;
|
||||
mMetricsFeatureProvider = metricsFeatureProvider;
|
||||
mCache = new IconCache(context);
|
||||
mSuggestionParser = parser;
|
||||
mConditions = conditions;
|
||||
|
||||
setHasStableIds(true);
|
||||
|
||||
boolean showAll = true;
|
||||
if (savedInstanceState != null) {
|
||||
mSuggestions = savedInstanceState.getParcelableArrayList(STATE_SUGGESTION_LIST);
|
||||
mCategories = savedInstanceState.getParcelableArrayList(STATE_CATEGORY_LIST);
|
||||
showAll = savedInstanceState.getBoolean(STATE_IS_SHOWING_ALL, true);
|
||||
mSuggestionMode = savedInstanceState.getInt(
|
||||
STATE_SUGGESTION_MODE, SUGGESTION_MODE_DEFAULT);
|
||||
suggestions = savedInstanceState.getParcelableArrayList(STATE_SUGGESTION_LIST);
|
||||
categories = savedInstanceState.getParcelableArrayList(STATE_CATEGORY_LIST);
|
||||
suggestionMode = savedInstanceState.getInt(
|
||||
STATE_SUGGESTION_MODE, DashboardData.SUGGESTION_MODE_DEFAULT);
|
||||
}
|
||||
setShowingAll(showAll);
|
||||
|
||||
mDashboardData = new DashboardData.Builder()
|
||||
.setConditions(conditions)
|
||||
.setSuggestions(suggestions)
|
||||
.setCategories(categories)
|
||||
.setSuggestionMode(suggestionMode)
|
||||
.build();
|
||||
}
|
||||
|
||||
public List<Tile> getSuggestions() {
|
||||
return mSuggestions;
|
||||
return mDashboardData.getSuggestions();
|
||||
}
|
||||
|
||||
public void setCategoriesAndSuggestions(List<DashboardCategory> categories,
|
||||
List<Tile> suggestions) {
|
||||
mSuggestions = suggestions;
|
||||
mCategories = categories;
|
||||
|
||||
// TODO: Better place for tinting?
|
||||
TypedValue tintColor = new TypedValue();
|
||||
mContext.getTheme().resolveAttribute(com.android.internal.R.attr.colorAccent,
|
||||
tintColor, true);
|
||||
for (int i = 0; i < categories.size(); i++) {
|
||||
for (int j = 0; j < categories.get(i).tiles.size(); j++) {
|
||||
Tile tile = categories.get(i).tiles.get(j);
|
||||
final Tile tile = categories.get(i).tiles.get(j);
|
||||
|
||||
if (!mContext.getPackageName().equals(
|
||||
tile.intent.getComponent().getPackageName())) {
|
||||
@@ -133,85 +143,49 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
}
|
||||
}
|
||||
}
|
||||
recountItems();
|
||||
|
||||
final DashboardData prevData = mDashboardData;
|
||||
mDashboardData = new DashboardData.Builder(prevData)
|
||||
.setSuggestions(suggestions)
|
||||
.setCategories(categories)
|
||||
.build();
|
||||
notifyDashboardDataChanged(prevData);
|
||||
}
|
||||
|
||||
public void setConditions(List<Condition> conditions) {
|
||||
mConditions = conditions;
|
||||
recountItems();
|
||||
final DashboardData prevData = mDashboardData;
|
||||
mDashboardData = new DashboardData.Builder(prevData)
|
||||
.setConditions(conditions)
|
||||
.build();
|
||||
notifyDashboardDataChanged(prevData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifySummaryChanged(Tile tile) {
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
final int position = mDashboardData.getPositionByTile(tile);
|
||||
if (position != DashboardData.POSITION_NOT_FOUND) {
|
||||
final Tile targetTile = (Tile) mDashboardData.getItemEntityByPosition(position);
|
||||
if (!TextUtils.equals(tile.summary, targetTile.summary)) {
|
||||
|
||||
public void setShowingAll(boolean showingAll) {
|
||||
mIsShowingAll = showingAll;
|
||||
recountItems();
|
||||
}
|
||||
|
||||
private void recountItems() {
|
||||
reset();
|
||||
boolean hasConditions = false;
|
||||
for (int i = 0; mConditions != null && i < mConditions.size(); i++) {
|
||||
boolean shouldShow = mConditions.get(i).shouldShow();
|
||||
hasConditions |= shouldShow;
|
||||
countItem(mConditions.get(i), R.layout.condition_card, shouldShow, NS_CONDITION);
|
||||
}
|
||||
boolean hasSuggestions = mSuggestions != null && mSuggestions.size() != 0;
|
||||
countItem(null, R.layout.dashboard_spacer, hasConditions && hasSuggestions, NS_SPACER);
|
||||
countItem(null, R.layout.suggestion_header, hasSuggestions, NS_SPACER);
|
||||
resetCount();
|
||||
if (mSuggestions != null) {
|
||||
int maxSuggestions = getDisplayableSuggestionCount();
|
||||
for (int i = 0; i < mSuggestions.size(); i++) {
|
||||
countItem(mSuggestions.get(i), R.layout.suggestion_tile, i < maxSuggestions,
|
||||
NS_SUGGESTION);
|
||||
// Since usually tile in parameter and tile in mCategories are same instance,
|
||||
// which is hard to be detected by DiffUtil, so we notifyItemChanged directly.
|
||||
notifyItemChanged(position);
|
||||
}
|
||||
}
|
||||
resetCount();
|
||||
for (int i = 0; mCategories != null && i < mCategories.size(); i++) {
|
||||
DashboardCategory category = mCategories.get(i);
|
||||
countItem(category, R.layout.dashboard_category, mIsShowingAll
|
||||
&& !TextUtils.isEmpty(category.title), NS_ITEMS);
|
||||
for (int j = 0; j < category.tiles.size(); j++) {
|
||||
Tile tile = category.tiles.get(j);
|
||||
countItem(tile, R.layout.dashboard_tile, mIsShowingAll
|
||||
|| ArrayUtils.contains(DashboardSummary.INITIAL_ITEMS,
|
||||
tile.intent.getComponent().getClassName()), NS_ITEMS);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: move this method to SuggestionParser or some other util class
|
||||
public void disableSuggestion(Tile suggestion) {
|
||||
if (mSuggestionParser == null) {
|
||||
return;
|
||||
}
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private void resetCount() {
|
||||
mId = 0;
|
||||
}
|
||||
|
||||
private void reset() {
|
||||
mItems.clear();
|
||||
mTypes.clear();
|
||||
mIds.clear();
|
||||
mId = 0;
|
||||
}
|
||||
|
||||
private void countItem(Object object, int type, boolean add, int nameSpace) {
|
||||
if (add) {
|
||||
mItems.add(object);
|
||||
mTypes.add(type);
|
||||
// TODO: Counting namespaces for handling of suggestions/conds appearing/disappearing.
|
||||
mIds.add(mId + nameSpace);
|
||||
if (mSuggestionParser.dismissSuggestion(suggestion)) {
|
||||
mContext.getPackageManager().setComponentEnabledSetting(
|
||||
suggestion.intent.getComponent(),
|
||||
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
|
||||
PackageManager.DONT_KILL_APP);
|
||||
mSuggestionParser.markCategoryDone(suggestion.category);
|
||||
}
|
||||
mId++;
|
||||
}
|
||||
|
||||
private int getDisplayableSuggestionCount() {
|
||||
final int suggestionSize = mSuggestions.size();
|
||||
return mSuggestionMode == SUGGESTION_MODE_DEFAULT
|
||||
? Math.min(DEFAULT_SUGGESTION_COUNT, suggestionSize)
|
||||
: mSuggestionMode == SUGGESTION_MODE_EXPANDED
|
||||
? suggestionSize : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -222,21 +196,24 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(DashboardItemHolder holder, int position) {
|
||||
switch (mTypes.get(position)) {
|
||||
final int type = mDashboardData.getItemTypeByPosition(position);
|
||||
switch (type) {
|
||||
case R.layout.dashboard_category:
|
||||
onBindCategory(holder, (DashboardCategory) mItems.get(position));
|
||||
onBindCategory(holder,
|
||||
(DashboardCategory) mDashboardData.getItemEntityByPosition(position));
|
||||
break;
|
||||
case R.layout.dashboard_tile:
|
||||
final Tile tile = (Tile) mItems.get(position);
|
||||
final Tile tile = (Tile) mDashboardData.getItemEntityByPosition(position);
|
||||
onBindTile(holder, tile);
|
||||
holder.itemView.setTag(tile);
|
||||
holder.itemView.setOnClickListener(this);
|
||||
holder.itemView.setTag(position);
|
||||
holder.itemView.setOnClickListener(mTileClickListener);
|
||||
break;
|
||||
case R.layout.suggestion_header:
|
||||
onBindSuggestionHeader(holder);
|
||||
onBindSuggestionHeader(holder, (DashboardData.SuggestionHeaderData)
|
||||
mDashboardData.getItemEntityByPosition(position));
|
||||
break;
|
||||
case R.layout.suggestion_tile:
|
||||
final Tile suggestion = (Tile) mItems.get(position);
|
||||
final Tile suggestion = (Tile) mDashboardData.getItemEntityByPosition(position);
|
||||
onBindTile(holder, suggestion);
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
@@ -255,12 +232,12 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
}
|
||||
});
|
||||
break;
|
||||
case R.layout.see_all:
|
||||
onBindSeeAll(holder);
|
||||
break;
|
||||
case R.layout.condition_card:
|
||||
ConditionAdapterUtils.bindViews((Condition) mItems.get(position), holder,
|
||||
mItems.get(position) == mExpandedCondition, this,
|
||||
final boolean isExpanded = mDashboardData.getItemEntityByPosition(position)
|
||||
== mDashboardData.getExpandedCondition();
|
||||
ConditionAdapterUtils.bindViews(
|
||||
(Condition) mDashboardData.getItemEntityByPosition(position),
|
||||
holder, isExpanded, mConditionClickListener,
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
@@ -271,45 +248,103 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return mDashboardData.getItemIdByPosition(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
return mDashboardData.getItemTypeByPosition(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mDashboardData.size();
|
||||
}
|
||||
|
||||
public void onExpandClick(View v) {
|
||||
Condition expandedCondition = mDashboardData.getExpandedCondition();
|
||||
if (v.getTag() == expandedCondition) {
|
||||
mMetricsFeatureProvider.action(mContext,
|
||||
MetricsEvent.ACTION_SETTINGS_CONDITION_COLLAPSE,
|
||||
expandedCondition.getMetricsConstant());
|
||||
expandedCondition = null;
|
||||
} else {
|
||||
expandedCondition = (Condition) v.getTag();
|
||||
mMetricsFeatureProvider.action(mContext, MetricsEvent.ACTION_SETTINGS_CONDITION_EXPAND,
|
||||
expandedCondition.getMetricsConstant());
|
||||
}
|
||||
|
||||
updateExpandedCondition(expandedCondition);
|
||||
}
|
||||
|
||||
public Object getItem(long itemId) {
|
||||
return mDashboardData.getItemEntityById(itemId);
|
||||
}
|
||||
|
||||
public static String getSuggestionIdentifier(Context context, Tile suggestion) {
|
||||
String packageName = suggestion.intent.getComponent().getPackageName();
|
||||
if (packageName.equals(context.getPackageName())) {
|
||||
// Since Settings provides several suggestions, fill in the class instead of the
|
||||
// package for these.
|
||||
packageName = suggestion.intent.getComponent().getClassName();
|
||||
}
|
||||
return packageName;
|
||||
}
|
||||
|
||||
private void notifyDashboardDataChanged(DashboardData prevData) {
|
||||
if (prevData != null) {
|
||||
final DiffUtil.DiffResult diffResult = DiffUtil.calculateDiff(new DashboardData
|
||||
.ItemsDataDiffCallback(prevData.getItemList(), mDashboardData.getItemList()));
|
||||
diffResult.dispatchUpdatesTo(this);
|
||||
} else {
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateExpandedCondition(Condition condition) {
|
||||
final DashboardData prevData = mDashboardData;
|
||||
mDashboardData = new DashboardData.Builder(prevData)
|
||||
.setExpandedCondition(condition)
|
||||
.build();
|
||||
notifyDashboardDataChanged(prevData);
|
||||
}
|
||||
|
||||
private void showRemoveOption(View v, final Tile suggestion) {
|
||||
PopupMenu popup = new PopupMenu(
|
||||
final PopupMenu popup = new PopupMenu(
|
||||
new ContextThemeWrapper(mContext, R.style.Theme_AppCompat_DayNight), v);
|
||||
popup.getMenu().add(R.string.suggestion_remove).setOnMenuItemClickListener(
|
||||
new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
mMetricsFeatureProvider.action(
|
||||
mContext, MetricsEvent.ACTION_SETTINGS_DISMISS_SUGGESTION,
|
||||
DashboardAdapter.getSuggestionIdentifier(mContext, suggestion));
|
||||
disableSuggestion(suggestion);
|
||||
mSuggestions.remove(suggestion);
|
||||
recountItems();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
mMetricsFeatureProvider.action(
|
||||
mContext, MetricsEvent.ACTION_SETTINGS_DISMISS_SUGGESTION,
|
||||
DashboardAdapter.getSuggestionIdentifier(mContext, suggestion));
|
||||
disableSuggestion(suggestion);
|
||||
List<Tile> suggestions = mDashboardData.getSuggestions();
|
||||
suggestions.remove(suggestion);
|
||||
|
||||
DashboardData prevData = mDashboardData;
|
||||
mDashboardData = new DashboardData.Builder(prevData)
|
||||
.setSuggestions(suggestions)
|
||||
.build();
|
||||
notifyDashboardDataChanged(prevData);
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
popup.show();
|
||||
}
|
||||
|
||||
public void disableSuggestion(Tile suggestion) {
|
||||
if (mSuggestionParser == null) {
|
||||
return;
|
||||
}
|
||||
if (mSuggestionParser.dismissSuggestion(suggestion)) {
|
||||
mContext.getPackageManager().setComponentEnabledSetting(
|
||||
suggestion.intent.getComponent(),
|
||||
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
|
||||
PackageManager.DONT_KILL_APP);
|
||||
mSuggestionParser.markCategoryDone(suggestion.category);
|
||||
}
|
||||
}
|
||||
private void onBindSuggestionHeader(final DashboardItemHolder holder, DashboardData
|
||||
.SuggestionHeaderData data) {
|
||||
final boolean moreSuggestions = data.hasMoreSuggestions;
|
||||
final int undisplayedSuggestionCount = data.undisplayedSuggestionCount;
|
||||
|
||||
private void onBindSuggestionHeader(final DashboardItemHolder holder) {
|
||||
final boolean moreSuggestions = hasMoreSuggestions();
|
||||
final int undisplayedSuggestionCount =
|
||||
mSuggestions.size() - getDisplayableSuggestionCount();
|
||||
holder.icon.setImageResource(moreSuggestions ? R.drawable.ic_expand_more
|
||||
: R.drawable.ic_expand_less);
|
||||
holder.title.setText(mContext.getString(R.string.suggestions_title, mSuggestions.size()));
|
||||
holder.title.setText(mContext.getString(R.string.suggestions_title, data.suggestionSize));
|
||||
String summaryContentDescription;
|
||||
if (moreSuggestions) {
|
||||
summaryContentDescription = mContext.getResources().getQuantityString(
|
||||
@@ -329,22 +364,22 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (hasMoreSuggestions()) {
|
||||
mSuggestionMode = SUGGESTION_MODE_EXPANDED;
|
||||
final int suggestionMode;
|
||||
if (moreSuggestions) {
|
||||
suggestionMode = DashboardData.SUGGESTION_MODE_EXPANDED;
|
||||
} else {
|
||||
mSuggestionMode = SUGGESTION_MODE_COLLAPSED;
|
||||
suggestionMode = DashboardData.SUGGESTION_MODE_COLLAPSED;
|
||||
}
|
||||
recountItems();
|
||||
|
||||
DashboardData prevData = mDashboardData;
|
||||
mDashboardData = new DashboardData.Builder(prevData)
|
||||
.setSuggestionMode(suggestionMode)
|
||||
.build();
|
||||
notifyDashboardDataChanged(prevData);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean hasMoreSuggestions() {
|
||||
return mSuggestionMode == SUGGESTION_MODE_COLLAPSED
|
||||
|| (mSuggestionMode == SUGGESTION_MODE_DEFAULT
|
||||
&& mSuggestions.size() > DEFAULT_SUGGESTION_COUNT);
|
||||
}
|
||||
|
||||
private void onBindTile(DashboardItemHolder holder, Tile tile) {
|
||||
holder.icon.setImageDrawable(mCache.getIcon(tile.icon));
|
||||
holder.title.setText(tile.title);
|
||||
@@ -360,98 +395,21 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
holder.title.setText(category.title);
|
||||
}
|
||||
|
||||
private void onBindSeeAll(DashboardItemHolder holder) {
|
||||
holder.title.setText(mIsShowingAll ? R.string.see_less
|
||||
: R.string.see_all);
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
setShowingAll(!mIsShowingAll);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return mIds.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
return mTypes.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mIds.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v.getId() == R.id.dashboard_tile) {
|
||||
((SettingsActivity) mContext).openTile((Tile) v.getTag());
|
||||
return;
|
||||
}
|
||||
if (v.getTag() == mExpandedCondition) {
|
||||
mMetricsFeatureProvider.action(mContext, MetricsEvent.ACTION_SETTINGS_CONDITION_CLICK,
|
||||
mExpandedCondition.getMetricsConstant());
|
||||
mExpandedCondition.onPrimaryClick();
|
||||
} else {
|
||||
mExpandedCondition = (Condition) v.getTag();
|
||||
mMetricsFeatureProvider.action(mContext, MetricsEvent.ACTION_SETTINGS_CONDITION_EXPAND,
|
||||
mExpandedCondition.getMetricsConstant());
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public void onExpandClick(View v) {
|
||||
if (v.getTag() == mExpandedCondition) {
|
||||
mMetricsFeatureProvider.action(mContext,
|
||||
MetricsEvent.ACTION_SETTINGS_CONDITION_COLLAPSE,
|
||||
mExpandedCondition.getMetricsConstant());
|
||||
mExpandedCondition = null;
|
||||
} else {
|
||||
mExpandedCondition = (Condition) v.getTag();
|
||||
mMetricsFeatureProvider.action(mContext, MetricsEvent.ACTION_SETTINGS_CONDITION_EXPAND,
|
||||
mExpandedCondition.getMetricsConstant());
|
||||
}
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public Object getItem(long itemId) {
|
||||
for (int i = 0; i < mIds.size(); i++) {
|
||||
if (mIds.get(i) == itemId) {
|
||||
return mItems.get(i);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getSuggestionIdentifier(Context context, Tile suggestion) {
|
||||
String packageName = suggestion.intent.getComponent().getPackageName();
|
||||
if (packageName.equals(context.getPackageName())) {
|
||||
// Since Settings provides several suggestions, fill in the class instead of the
|
||||
// package for these.
|
||||
packageName = suggestion.intent.getComponent().getClassName();
|
||||
}
|
||||
return packageName;
|
||||
}
|
||||
|
||||
void onSaveInstanceState(Bundle outState) {
|
||||
if (mSuggestions != null) {
|
||||
final List<Tile> suggestions = mDashboardData.getSuggestions();
|
||||
final List<DashboardCategory> categories = mDashboardData.getCategories();
|
||||
if (suggestions != null) {
|
||||
outState.putParcelableArrayList(STATE_SUGGESTION_LIST,
|
||||
new ArrayList<Tile>(mSuggestions));
|
||||
new ArrayList<Tile>(suggestions));
|
||||
}
|
||||
if (mCategories != null) {
|
||||
if (categories != null) {
|
||||
outState.putParcelableArrayList(STATE_CATEGORY_LIST,
|
||||
new ArrayList<DashboardCategory>(mCategories));
|
||||
new ArrayList<DashboardCategory>(categories));
|
||||
}
|
||||
outState.putBoolean(STATE_IS_SHOWING_ALL, mIsShowingAll);
|
||||
outState.putInt(STATE_SUGGESTION_MODE, mSuggestionMode);
|
||||
outState.putInt(STATE_SUGGESTION_MODE, mDashboardData.getSuggestionMode());
|
||||
}
|
||||
|
||||
private static class IconCache {
|
||||
|
||||
private final Context mContext;
|
||||
private final ArrayMap<Icon, Drawable> mMap = new ArrayMap<>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user