Combine settings suggestion and condition.
- Add a flag in dashboard feature provider to specify whether to use the combined UI for suggestions and conditions. - Move Conditions below Suggestions. - Add dashboard entity for condition and suggestion container, and wrap the condition and suggestion list inside the container. The container itself will be a single dashboard item, and within it will be the list of suggestion or condition. - Add suggestion/condition header that will show the combined info for the conditions and suggestion data, and have the expand button to control expanding both the suggestion and condition list. - Change the individual condition card to be always expanded, and remove the logic to collapse/expand individual condition card. - Remove the divider between the action button and condition detail within each condition card. - Add suggestion/condition footer for collapsing the whole suggestion and condition list. Bug: 37645754 Test: make RunSettingsRoboTests Change-Id: I86df75f7e4551778f79d730851c03121fd0dcbdf
This commit is contained in:
@@ -20,11 +20,13 @@ import android.annotation.ColorInt;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v7.util.DiffUtil;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.util.ArrayMap;
|
||||
@@ -33,19 +35,28 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.R.id;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settings.dashboard.DashboardData.SuggestionConditionHeaderData;
|
||||
import com.android.settings.dashboard.conditional.Condition;
|
||||
import com.android.settings.dashboard.conditional.ConditionAdapter;
|
||||
import com.android.settings.dashboard.conditional.ConditionAdapterUtils;
|
||||
import com.android.settings.dashboard.conditional.FocusRecyclerView;
|
||||
import com.android.settings.dashboard.suggestions.SuggestionAdapter;
|
||||
import com.android.settings.dashboard.suggestions.SuggestionDismissController;
|
||||
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.Utils;
|
||||
import com.android.settingslib.drawer.DashboardCategory;
|
||||
import com.android.settingslib.drawer.Tile;
|
||||
|
||||
import com.android.settingslib.suggestions.SuggestionParser;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -57,6 +68,7 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
private static final String STATE_SUGGESTION_MODE = "suggestion_mode";
|
||||
private static final String STATE_SUGGESTIONS_SHOWN_LOGGED = "suggestions_shown_logged";
|
||||
private static final int DONT_SET_BACKGROUND_ATTR = -1;
|
||||
private static final String STATE_SUGGESTION_CONDITION_MODE = "suggestion_condition_mode";
|
||||
|
||||
private final IconCache mCache;
|
||||
private final Context mContext;
|
||||
@@ -65,6 +77,12 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
private final SuggestionFeatureProvider mSuggestionFeatureProvider;
|
||||
private final ArrayList<String> mSuggestionsShownLogged;
|
||||
private boolean mFirstFrameDrawn;
|
||||
private boolean mCombineSuggestionAndCondition;
|
||||
private RecyclerView mRecyclerView;
|
||||
private SuggestionParser mSuggestionParser;
|
||||
private SuggestionAdapter mSuggestionAdapter;
|
||||
private SuggestionDismissController mSuggestionDismissHandler;
|
||||
private SuggestionDismissController.Callback mCallback;
|
||||
|
||||
@VisibleForTesting
|
||||
DashboardData mDashboardData;
|
||||
@@ -81,43 +99,65 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Condition expandedCondition = mDashboardData.getExpandedCondition();
|
||||
|
||||
//TODO: get rid of setTag/getTag
|
||||
if (v.getTag() == expandedCondition) {
|
||||
if (mCombineSuggestionAndCondition) {
|
||||
Condition condition = (Condition) v.getTag();
|
||||
//TODO: get rid of setTag/getTag
|
||||
mMetricsFeatureProvider.action(mContext,
|
||||
MetricsEvent.ACTION_SETTINGS_CONDITION_CLICK,
|
||||
condition.getMetricsConstant());
|
||||
condition.onPrimaryClick();
|
||||
} else {
|
||||
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,
|
||||
expandedCondition.onPrimaryClick();
|
||||
} else {
|
||||
expandedCondition = (Condition) v.getTag();
|
||||
mMetricsFeatureProvider.action(mContext,
|
||||
MetricsEvent.ACTION_SETTINGS_CONDITION_EXPAND,
|
||||
expandedCondition.getMetricsConstant());
|
||||
|
||||
updateExpandedCondition(expandedCondition);
|
||||
updateExpandedCondition(expandedCondition);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Deprecated
|
||||
public DashboardAdapter(Context context, Bundle savedInstanceState,
|
||||
List<Condition> conditions) {
|
||||
List<Condition> conditions) {
|
||||
this(context, savedInstanceState, conditions, null, null);
|
||||
}
|
||||
|
||||
public DashboardAdapter(Context context, Bundle savedInstanceState,
|
||||
List<Condition> conditions, SuggestionParser suggestionParser,
|
||||
SuggestionDismissController.Callback callback) {
|
||||
List<Tile> suggestions = null;
|
||||
List<DashboardCategory> categories = null;
|
||||
int suggestionMode = DashboardData.SUGGESTION_MODE_DEFAULT;
|
||||
int suggestionConditionMode = DashboardData.HEADER_MODE_DEFAULT;
|
||||
|
||||
mContext = context;
|
||||
final FeatureFactory factory = FeatureFactory.getFactory(context);
|
||||
mMetricsFeatureProvider = factory.getMetricsFeatureProvider();
|
||||
mDashboardFeatureProvider = factory.getDashboardFeatureProvider(context);
|
||||
mSuggestionFeatureProvider = factory.getSuggestionFeatureProvider(context);
|
||||
mCombineSuggestionAndCondition = mDashboardFeatureProvider.combineSuggestionAndCondition();
|
||||
mCache = new IconCache(context);
|
||||
mSuggestionParser = suggestionParser;
|
||||
mCallback = callback;
|
||||
|
||||
setHasStableIds(true);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
suggestions = savedInstanceState.getParcelableArrayList(STATE_SUGGESTION_LIST);
|
||||
categories = savedInstanceState.getParcelableArrayList(STATE_CATEGORY_LIST);
|
||||
suggestionConditionMode = savedInstanceState.getInt(
|
||||
STATE_SUGGESTION_CONDITION_MODE, suggestionConditionMode);
|
||||
suggestionMode = savedInstanceState.getInt(
|
||||
STATE_SUGGESTION_MODE, DashboardData.SUGGESTION_MODE_DEFAULT);
|
||||
mSuggestionsShownLogged = savedInstanceState.getStringArrayList(
|
||||
@@ -131,6 +171,8 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
.setSuggestions(suggestions)
|
||||
.setCategories(categories)
|
||||
.setSuggestionMode(suggestionMode)
|
||||
.setCombineSuggestionAndCondition(mCombineSuggestionAndCondition)
|
||||
.setSuggestionConditionMode(suggestionConditionMode)
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -167,14 +209,24 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
.build();
|
||||
notifyDashboardDataChanged(prevData);
|
||||
List<Tile> shownSuggestions = null;
|
||||
switch (mDashboardData.getSuggestionMode()) {
|
||||
case DashboardData.SUGGESTION_MODE_DEFAULT:
|
||||
if (mCombineSuggestionAndCondition) {
|
||||
final int mode = mDashboardData.getSuggestionConditionMode();
|
||||
if (mode == DashboardData.HEADER_MODE_DEFAULT) {
|
||||
shownSuggestions = suggestions.subList(0,
|
||||
Math.min(suggestions.size(), DashboardData.DEFAULT_SUGGESTION_COUNT));
|
||||
break;
|
||||
case DashboardData.SUGGESTION_MODE_EXPANDED:
|
||||
Math.min(suggestions.size(), DashboardData.DEFAULT_SUGGESTION_COUNT));
|
||||
} else if (mode != DashboardData.HEADER_MODE_COLLAPSED) {
|
||||
shownSuggestions = suggestions;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch (mDashboardData.getSuggestionMode()) {
|
||||
case DashboardData.SUGGESTION_MODE_DEFAULT:
|
||||
shownSuggestions = suggestions.subList(0,
|
||||
Math.min(suggestions.size(), DashboardData.DEFAULT_SUGGESTION_COUNT));
|
||||
break;
|
||||
case DashboardData.SUGGESTION_MODE_EXPANDED:
|
||||
shownSuggestions = suggestions;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (shownSuggestions != null) {
|
||||
for (Tile suggestion : shownSuggestions) {
|
||||
@@ -199,10 +251,16 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
public void setConditions(List<Condition> conditions) {
|
||||
final DashboardData prevData = mDashboardData;
|
||||
Log.d(TAG, "adapter setConditions called");
|
||||
mDashboardData = new DashboardData.Builder(prevData)
|
||||
if (mCombineSuggestionAndCondition) {
|
||||
mDashboardData = new DashboardData.Builder(prevData)
|
||||
.setConditions(conditions)
|
||||
.build();
|
||||
} else {
|
||||
mDashboardData = new DashboardData.Builder(prevData)
|
||||
.setConditions(conditions)
|
||||
.setExpandedCondition(null)
|
||||
.build();
|
||||
}
|
||||
notifyDashboardDataChanged(prevData);
|
||||
}
|
||||
|
||||
@@ -218,8 +276,14 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
|
||||
@Override
|
||||
public DashboardItemHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
return new DashboardItemHolder(LayoutInflater.from(parent.getContext()).inflate(
|
||||
viewType, parent, false));
|
||||
final View view = LayoutInflater.from(parent.getContext()).inflate(viewType, parent, false);
|
||||
if (viewType == R.layout.suggestion_condition_header) {
|
||||
return new SuggestionAndConditionHeaderHolder(view);
|
||||
}
|
||||
if (viewType == R.layout.suggestion_condition_container) {
|
||||
return new SuggestionAndConditionContainerHolder(view);
|
||||
}
|
||||
return new DashboardItemHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -277,6 +341,43 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
(Condition) mDashboardData.getItemEntityByPosition(position),
|
||||
holder, isExpanded, mConditionClickListener, v -> onExpandClick(v));
|
||||
break;
|
||||
case R.layout.suggestion_condition_container:
|
||||
onBindConditionAndSuggestion(
|
||||
(SuggestionAndConditionContainerHolder) holder, position);
|
||||
break;
|
||||
case R.layout.suggestion_condition_header:
|
||||
/* There are 2 different headers for the suggestions/conditions section. To minimize
|
||||
visual animation when expanding and collapsing the suggestions/conditions, we are
|
||||
using the same layout to represent the 2 headers:
|
||||
1. Suggestion header - when there is any suggestion shown, the suggestion header
|
||||
will be the first item on the section. It only has the text "Suggestion", and
|
||||
do nothing when clicked. This header will not be shown when the section is
|
||||
collapsed, in which case, the SuggestionCondition header will be
|
||||
shown instead to show the summary info.
|
||||
2. SuggestionCondition header - the header that shows the summary info for the
|
||||
suggestion/condition that is currently hidden. It has the expand button to
|
||||
expand the section. */
|
||||
if (mDashboardData.getDisplayableSuggestionCount() > 0 && position == 1
|
||||
&& mDashboardData.getSuggestionConditionMode()
|
||||
!= DashboardData.HEADER_MODE_COLLAPSED) {
|
||||
onBindSuggestionHeader((SuggestionAndConditionHeaderHolder) holder);
|
||||
} else {
|
||||
onBindSuggestionConditionHeader((SuggestionAndConditionHeaderHolder) holder,
|
||||
(SuggestionConditionHeaderData)
|
||||
mDashboardData.getItemEntityByPosition(position));
|
||||
}
|
||||
break;
|
||||
case R.layout.suggestion_condition_footer:
|
||||
holder.itemView.setOnClickListener(v -> {
|
||||
mMetricsFeatureProvider.action(mContext,
|
||||
MetricsEvent.ACTION_SETTINGS_CONDITION_EXPAND, false);
|
||||
DashboardData prevData = mDashboardData;
|
||||
mDashboardData = new DashboardData.Builder(prevData).setSuggestionConditionMode(
|
||||
DashboardData.HEADER_MODE_COLLAPSED).build();
|
||||
notifyDashboardDataChanged(prevData);
|
||||
mRecyclerView.scrollToPosition(1);
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -295,6 +396,14 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
return mDashboardData.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
|
||||
super.onAttachedToRecyclerView(recyclerView);
|
||||
// save the view so that we can scroll it when expanding/collapsing the suggestion and
|
||||
// conditions.
|
||||
mRecyclerView = recyclerView;
|
||||
}
|
||||
|
||||
public void onPause() {
|
||||
if (mDashboardData.getSuggestions() == null) {
|
||||
return;
|
||||
@@ -310,6 +419,9 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
mSuggestionsShownLogged.clear();
|
||||
}
|
||||
|
||||
// condition card is always expanded in new suggestion/condition UI.
|
||||
// TODO: Remove when completely move to new suggestion/condition UI
|
||||
@Deprecated
|
||||
public void onExpandClick(View v) {
|
||||
Condition expandedCondition = mDashboardData.getExpandedCondition();
|
||||
if (v.getTag() == expandedCondition) {
|
||||
@@ -330,6 +442,13 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
return mDashboardData.getItemEntityById(itemId);
|
||||
}
|
||||
|
||||
public Tile getSuggestion(int position) {
|
||||
if (mCombineSuggestionAndCondition) {
|
||||
return mSuggestionAdapter.getSuggestion(position);
|
||||
}
|
||||
return (Tile) getItem(getItemId(position));
|
||||
}
|
||||
|
||||
private void notifyDashboardDataChanged(DashboardData prevData) {
|
||||
if (mFirstFrameDrawn && prevData != null) {
|
||||
final DiffUtil.DiffResult diffResult = DiffUtil.calculateDiff(new DashboardData
|
||||
@@ -405,17 +524,7 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
final int suggestionMode;
|
||||
if (moreSuggestions) {
|
||||
suggestionMode = DashboardData.SUGGESTION_MODE_EXPANDED;
|
||||
|
||||
for (Tile suggestion : mDashboardData.getSuggestions()) {
|
||||
final String suggestionId = mSuggestionFeatureProvider.getSuggestionIdentifier(
|
||||
mContext, suggestion);
|
||||
if (!mSuggestionsShownLogged.contains(suggestionId)) {
|
||||
mMetricsFeatureProvider.action(
|
||||
mContext, MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
|
||||
suggestionId);
|
||||
mSuggestionsShownLogged.add(suggestionId);
|
||||
}
|
||||
}
|
||||
logSuggestions();
|
||||
} else {
|
||||
suggestionMode = DashboardData.SUGGESTION_MODE_COLLAPSED;
|
||||
}
|
||||
@@ -428,6 +537,130 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
});
|
||||
}
|
||||
|
||||
private void logSuggestions() {
|
||||
for (Tile suggestion : mDashboardData.getSuggestions()) {
|
||||
final String suggestionId = mSuggestionFeatureProvider.getSuggestionIdentifier(
|
||||
mContext, suggestion);
|
||||
if (!mSuggestionsShownLogged.contains(suggestionId)) {
|
||||
mMetricsFeatureProvider.action(
|
||||
mContext, MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION,
|
||||
suggestionId);
|
||||
mSuggestionsShownLogged.add(suggestionId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void onBindSuggestionHeader(final SuggestionAndConditionHeaderHolder holder) {
|
||||
holder.title.setText(R.string.suggestions_title);
|
||||
holder.title.setTextColor(Color.BLACK);
|
||||
holder.icon.setVisibility(View.INVISIBLE);
|
||||
holder.icons.removeAllViews();
|
||||
holder.icons.setVisibility(View.INVISIBLE);
|
||||
holder.summary.setVisibility(View.INVISIBLE);
|
||||
holder.expandIndicator.setVisibility(View.INVISIBLE);
|
||||
holder.itemView.setOnClickListener(null);
|
||||
}
|
||||
|
||||
private void onBindSuggestionConditionHeader(final SuggestionAndConditionHeaderHolder holder,
|
||||
SuggestionConditionHeaderData data) {
|
||||
final int curMode = mDashboardData.getSuggestionConditionMode();
|
||||
final int nextMode = data.hiddenSuggestionCount > 0 && data.conditionCount > 0
|
||||
&& curMode != DashboardData.HEADER_MODE_SUGGESTION_EXPANDED
|
||||
? DashboardData.HEADER_MODE_SUGGESTION_EXPANDED
|
||||
: DashboardData.HEADER_MODE_FULLY_EXPANDED;
|
||||
final boolean moreSuggestions = data.hiddenSuggestionCount > 0;
|
||||
final boolean hasConditions = data.conditionCount > 0;
|
||||
if (data.conditionCount > 0) {
|
||||
holder.icon.setImageIcon(data.conditionIcons.get(0));
|
||||
holder.icon.setVisibility(View.VISIBLE);
|
||||
if (data.conditionCount == 1) {
|
||||
holder.title.setText(data.title);
|
||||
holder.title.setTextColor(Utils.getColorAccent(mContext));
|
||||
holder.icons.setVisibility(View.INVISIBLE);
|
||||
} else {
|
||||
holder.title.setText(null);
|
||||
updateConditionIcons(data.conditionIcons, holder.icons);
|
||||
holder.icons.setVisibility(View.VISIBLE);
|
||||
}
|
||||
} else {
|
||||
holder.icon.setVisibility(View.INVISIBLE);
|
||||
holder.icons.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
|
||||
if (data.hiddenSuggestionCount > 0) {
|
||||
holder.summary.setTextColor(Color.BLACK);
|
||||
if (curMode == DashboardData.HEADER_MODE_COLLAPSED) {
|
||||
if (data.conditionCount > 0) {
|
||||
holder.summary.setText(mContext.getResources().getQuantityString(
|
||||
R.plurals.suggestions_collapsed_summary,
|
||||
data.hiddenSuggestionCount, data.hiddenSuggestionCount));
|
||||
} else {
|
||||
holder.title.setText(mContext.getResources().getQuantityString(
|
||||
R.plurals.suggestions_collapsed_title,
|
||||
data.hiddenSuggestionCount, data.hiddenSuggestionCount));
|
||||
holder.title.setTextColor(Color.BLACK);
|
||||
holder.summary.setText(null);
|
||||
}
|
||||
} else if (curMode == DashboardData.HEADER_MODE_DEFAULT) {
|
||||
if (data.conditionCount > 0) {
|
||||
holder.summary.setText(mContext.getString(
|
||||
R.string.suggestions_summary, data.hiddenSuggestionCount));
|
||||
} else {
|
||||
holder.title.setText(mContext.getString(
|
||||
R.string.suggestions_more_title, data.hiddenSuggestionCount));
|
||||
holder.title.setTextColor(Color.BLACK);
|
||||
holder.summary.setText(null);
|
||||
}
|
||||
}
|
||||
} else if (data.conditionCount > 1) {
|
||||
holder.summary.setTextColor(Utils.getColorAccent(mContext));
|
||||
holder.summary.setText(
|
||||
mContext.getString(R.string.condition_summary, data.conditionCount));
|
||||
} else {
|
||||
holder.summary.setText(null);
|
||||
}
|
||||
holder.summary.setVisibility(View.VISIBLE);
|
||||
holder.expandIndicator.setVisibility(View.VISIBLE);
|
||||
|
||||
holder.itemView.setOnClickListener(v -> {
|
||||
if (moreSuggestions ) {
|
||||
logSuggestions();
|
||||
} else if (hasConditions) {
|
||||
mMetricsFeatureProvider.action(mContext,
|
||||
MetricsEvent.ACTION_SETTINGS_CONDITION_EXPAND, true);
|
||||
}
|
||||
DashboardData prevData = mDashboardData;
|
||||
final boolean wasCollapsed = curMode == DashboardData.HEADER_MODE_COLLAPSED;
|
||||
mDashboardData = new DashboardData.Builder(prevData)
|
||||
.setSuggestionConditionMode(nextMode).build();
|
||||
notifyDashboardDataChanged(prevData);
|
||||
if (wasCollapsed) {
|
||||
mRecyclerView.scrollToPosition(1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void onBindConditionAndSuggestion(final SuggestionAndConditionContainerHolder holder,
|
||||
int position) {
|
||||
RecyclerView.Adapter<DashboardItemHolder> adapter;
|
||||
// If there is suggestions to show, it will be at position 2 (position 0 = header spacer,
|
||||
// position 1 is suggestion header.
|
||||
if (position == 2 && mDashboardData.getSuggestions() != null) {
|
||||
mSuggestionAdapter = new SuggestionAdapter(mContext, (List<Tile>)
|
||||
mDashboardData.getItemEntityByPosition(position), mSuggestionsShownLogged);
|
||||
adapter = mSuggestionAdapter;
|
||||
mSuggestionDismissHandler = new SuggestionDismissController(mContext,
|
||||
holder.data, mSuggestionParser, mCallback);
|
||||
} else {
|
||||
ConditionAdapterUtils.addDismiss(holder.data);
|
||||
adapter = new ConditionAdapter(mContext,
|
||||
(List<Condition>) mDashboardData.getItemEntityByPosition(position),
|
||||
mDashboardData.getSuggestionConditionMode());
|
||||
}
|
||||
holder.data.setLayoutManager(new LinearLayoutManager(mContext));
|
||||
holder.data.setAdapter(adapter);
|
||||
}
|
||||
|
||||
private void onBindTile(DashboardItemHolder holder, Tile tile) {
|
||||
if (tile.remoteViews != null) {
|
||||
final ViewGroup itemView = (ViewGroup) holder.itemView;
|
||||
@@ -460,9 +693,27 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
}
|
||||
outState.putInt(STATE_SUGGESTION_MODE, mDashboardData.getSuggestionMode());
|
||||
outState.putStringArrayList(STATE_SUGGESTIONS_SHOWN_LOGGED, mSuggestionsShownLogged);
|
||||
outState.putInt(STATE_SUGGESTION_CONDITION_MODE,
|
||||
mDashboardData.getSuggestionConditionMode());
|
||||
}
|
||||
|
||||
private static class IconCache {
|
||||
private void updateConditionIcons(List<Icon> icons, ViewGroup parent) {
|
||||
if (icons == null || icons.size() < 2) {
|
||||
parent.setVisibility(View.INVISIBLE);
|
||||
return;
|
||||
}
|
||||
final LayoutInflater inflater = LayoutInflater.from(parent.getContext());
|
||||
parent.removeAllViews();
|
||||
for (int i = 1, size = icons.size(); i < size; i++) {
|
||||
ImageView icon = (ImageView) inflater.inflate(
|
||||
R.layout.condition_header_icon, parent, false);
|
||||
icon.setImageIcon(icons.get(i));
|
||||
parent.addView(icon);
|
||||
}
|
||||
parent.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
public static class IconCache {
|
||||
private final Context mContext;
|
||||
private final ArrayMap<Icon, Drawable> mMap = new ArrayMap<>();
|
||||
|
||||
@@ -492,4 +743,25 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
summary = itemView.findViewById(android.R.id.summary);
|
||||
}
|
||||
}
|
||||
|
||||
public static class SuggestionAndConditionHeaderHolder extends DashboardItemHolder {
|
||||
public final LinearLayout icons;
|
||||
public final ImageView expandIndicator;
|
||||
|
||||
public SuggestionAndConditionHeaderHolder(View itemView) {
|
||||
super(itemView);
|
||||
icons = itemView.findViewById(id.additional_icons);
|
||||
expandIndicator = itemView.findViewById(id.expand_indicator);
|
||||
}
|
||||
}
|
||||
|
||||
public static class SuggestionAndConditionContainerHolder extends DashboardItemHolder {
|
||||
public final RecyclerView data;
|
||||
|
||||
public SuggestionAndConditionContainerHolder(View itemView) {
|
||||
super(itemView);
|
||||
data = itemView.findViewById(id.data);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,9 @@
|
||||
package com.android.settings.dashboard;
|
||||
|
||||
import android.annotation.IntDef;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v7.util.DiffUtil;
|
||||
import android.text.TextUtils;
|
||||
|
||||
@@ -38,9 +40,22 @@ import java.util.Objects;
|
||||
* ItemsData has inner class Item, which represents the Item in data list.
|
||||
*/
|
||||
public class DashboardData {
|
||||
@Deprecated
|
||||
public static final int SUGGESTION_MODE_DEFAULT = 0;
|
||||
@Deprecated
|
||||
public static final int SUGGESTION_MODE_COLLAPSED = 1;
|
||||
@Deprecated
|
||||
public static final int SUGGESTION_MODE_EXPANDED = 2;
|
||||
|
||||
public static final int HEADER_MODE_DEFAULT = 0;
|
||||
public static final int HEADER_MODE_SUGGESTION_EXPANDED = 1;
|
||||
public static final int HEADER_MODE_FULLY_EXPANDED = 2;
|
||||
public static final int HEADER_MODE_COLLAPSED = 3;
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@IntDef({HEADER_MODE_DEFAULT, HEADER_MODE_SUGGESTION_EXPANDED, HEADER_MODE_FULLY_EXPANDED,
|
||||
HEADER_MODE_COLLAPSED})
|
||||
public @interface HeaderMode{}
|
||||
|
||||
public static final int POSITION_NOT_FOUND = -1;
|
||||
public static final int DEFAULT_SUGGESTION_COUNT = 2;
|
||||
|
||||
@@ -49,14 +64,19 @@ public class DashboardData {
|
||||
private static final int NS_SPACER = 1000;
|
||||
private static final int NS_ITEMS = 2000;
|
||||
private static final int NS_CONDITION = 3000;
|
||||
private static final int NS_SUGGESTION_CONDITION = 4000;
|
||||
|
||||
private final List<Item> mItems;
|
||||
private final List<DashboardCategory> mCategories;
|
||||
private final List<Condition> mConditions;
|
||||
private final List<Tile> mSuggestions;
|
||||
@Deprecated
|
||||
private final int mSuggestionMode;
|
||||
@Deprecated
|
||||
private final Condition mExpandedCondition;
|
||||
private final @HeaderMode int mSuggestionConditionMode;
|
||||
private int mId;
|
||||
private boolean mCombineSuggestionAndCondition;
|
||||
|
||||
private DashboardData(Builder builder) {
|
||||
mCategories = builder.mCategories;
|
||||
@@ -64,6 +84,8 @@ public class DashboardData {
|
||||
mSuggestions = builder.mSuggestions;
|
||||
mSuggestionMode = builder.mSuggestionMode;
|
||||
mExpandedCondition = builder.mExpandedCondition;
|
||||
mSuggestionConditionMode = builder.mSuggestionConditionMode;
|
||||
mCombineSuggestionAndCondition = builder.mCombineSuggestionAndCondition;
|
||||
|
||||
mItems = new ArrayList<>();
|
||||
mId = 0;
|
||||
@@ -116,6 +138,11 @@ public class DashboardData {
|
||||
return mSuggestionMode;
|
||||
}
|
||||
|
||||
public int getSuggestionConditionMode() {
|
||||
return mSuggestionConditionMode;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Condition getExpandedCondition() {
|
||||
return mExpandedCondition;
|
||||
}
|
||||
@@ -177,14 +204,31 @@ public class DashboardData {
|
||||
* @return the count of suggestions to display
|
||||
*/
|
||||
public int getDisplayableSuggestionCount() {
|
||||
final int suggestionSize = mSuggestions.size();
|
||||
return mSuggestionMode == SUGGESTION_MODE_DEFAULT
|
||||
? Math.min(DEFAULT_SUGGESTION_COUNT, suggestionSize)
|
||||
: mSuggestionMode == SUGGESTION_MODE_EXPANDED
|
||||
? suggestionSize : 0;
|
||||
final int suggestionSize = sizeOf(mSuggestions);
|
||||
if (mCombineSuggestionAndCondition) {
|
||||
if (mSuggestionConditionMode == HEADER_MODE_COLLAPSED) {
|
||||
return 0;
|
||||
}
|
||||
if (mSuggestionConditionMode == HEADER_MODE_DEFAULT) {
|
||||
return Math.min(DEFAULT_SUGGESTION_COUNT, suggestionSize);
|
||||
}
|
||||
return suggestionSize;
|
||||
}
|
||||
if (mSuggestionMode == SUGGESTION_MODE_DEFAULT) {
|
||||
return Math.min(DEFAULT_SUGGESTION_COUNT, suggestionSize);
|
||||
}
|
||||
if (mSuggestionMode == SUGGESTION_MODE_EXPANDED) {
|
||||
return suggestionSize;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean hasMoreSuggestions() {
|
||||
if (mCombineSuggestionAndCondition) {
|
||||
return mSuggestionConditionMode == HEADER_MODE_COLLAPSED && mSuggestions.size() > 0
|
||||
|| mSuggestionConditionMode == HEADER_MODE_DEFAULT
|
||||
&& mSuggestions.size() > DEFAULT_SUGGESTION_COUNT;
|
||||
}
|
||||
return mSuggestionMode == SUGGESTION_MODE_COLLAPSED
|
||||
|| (mSuggestionMode == SUGGESTION_MODE_DEFAULT
|
||||
&& mSuggestions.size() > DEFAULT_SUGGESTION_COUNT);
|
||||
@@ -208,7 +252,11 @@ public class DashboardData {
|
||||
*/
|
||||
private void countItem(Object object, int type, boolean add, int nameSpace) {
|
||||
if (add) {
|
||||
mItems.add(new Item(object, type, mId + nameSpace, object == mExpandedCondition));
|
||||
if (mCombineSuggestionAndCondition) {
|
||||
mItems.add(new Item(object, type, mId + nameSpace));
|
||||
} else {
|
||||
mItems.add(new Item(object, type, mId + nameSpace, object == mExpandedCondition));
|
||||
}
|
||||
}
|
||||
mId++;
|
||||
}
|
||||
@@ -238,26 +286,75 @@ public class DashboardData {
|
||||
// add the view that goes under the search bar
|
||||
countItem(null, R.layout.dashboard_header_spacer, true, NS_HEADER_SPACER);
|
||||
resetCount();
|
||||
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);
|
||||
}
|
||||
final boolean hasSuggestions = sizeOf(mSuggestions) > 0;
|
||||
if (!mCombineSuggestionAndCondition) {
|
||||
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);
|
||||
}
|
||||
|
||||
resetCount();
|
||||
final boolean hasSuggestions = mSuggestions != null && mSuggestions.size() != 0;
|
||||
countItem(null, R.layout.dashboard_spacer, hasConditions && hasSuggestions, NS_SPACER);
|
||||
countItem(buildSuggestionHeaderData(), R.layout.suggestion_header, hasSuggestions,
|
||||
resetCount();
|
||||
countItem(null, R.layout.dashboard_spacer, hasConditions && hasSuggestions, NS_SPACER);
|
||||
countItem(buildSuggestionHeaderData(), R.layout.suggestion_header, hasSuggestions,
|
||||
NS_SPACER);
|
||||
|
||||
resetCount();
|
||||
if (mSuggestions != null) {
|
||||
int maxSuggestions = getDisplayableSuggestionCount();
|
||||
for (int i = 0; i < mSuggestions.size(); i++) {
|
||||
countSuggestion(mSuggestions.get(i), i < maxSuggestions);
|
||||
resetCount();
|
||||
if (mSuggestions != null) {
|
||||
int maxSuggestions = getDisplayableSuggestionCount();
|
||||
for (int i = 0; i < mSuggestions.size(); i++) {
|
||||
countSuggestion(mSuggestions.get(i), i < maxSuggestions);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
final List<Condition> conditions = getConditionsToShow(mConditions);
|
||||
final boolean hasConditions = sizeOf(conditions) > 0;
|
||||
|
||||
final List<Tile> suggestions = getSuggestionsToShow(mSuggestions);
|
||||
final int hiddenSuggestion =
|
||||
hasSuggestions ? sizeOf(mSuggestions) - sizeOf(suggestions) : 0;
|
||||
|
||||
resetCount();
|
||||
/* Top suggestion/condition header. This will be present when there is any suggestion or
|
||||
* condition to show, except in the case that there is only conditions to show and the
|
||||
* mode is fully expanded. */
|
||||
countItem(new SuggestionConditionHeaderData(conditions, hiddenSuggestion),
|
||||
R.layout.suggestion_condition_header, hasSuggestions
|
||||
|| hasConditions && mSuggestionConditionMode != HEADER_MODE_FULLY_EXPANDED,
|
||||
NS_SUGGESTION_CONDITION);
|
||||
|
||||
/* Suggestion container. This is the card view that contains the list of suggestions.
|
||||
* This will be added whenever the suggestion list is not empty */
|
||||
countItem(suggestions, R.layout.suggestion_condition_container, sizeOf(suggestions) > 0,
|
||||
NS_SUGGESTION_CONDITION);
|
||||
|
||||
/* Second suggestion/condition header. This will be added when there is at least one
|
||||
* suggestion or condition that is not currently displayed, and the user can expand the
|
||||
* section to view more items. */
|
||||
countItem(new SuggestionConditionHeaderData(conditions, hiddenSuggestion),
|
||||
R.layout.suggestion_condition_header,
|
||||
mSuggestionConditionMode != HEADER_MODE_COLLAPSED
|
||||
&& mSuggestionConditionMode != HEADER_MODE_FULLY_EXPANDED
|
||||
&& (hiddenSuggestion > 0
|
||||
|| hasConditions && hasSuggestions),
|
||||
NS_SUGGESTION_CONDITION);
|
||||
|
||||
/* Condition container. This is the card view that contains the list of conditions.
|
||||
* This will be added whenever the condition list is not empty */
|
||||
countItem(conditions, R.layout.suggestion_condition_container,
|
||||
hasConditions && mSuggestionConditionMode == HEADER_MODE_FULLY_EXPANDED,
|
||||
NS_SUGGESTION_CONDITION);
|
||||
|
||||
/* Suggestion/condition footer. This will be present when the section is fully expanded
|
||||
* or when there is no conditions and no hidden suggestions */
|
||||
countItem(null, R.layout.suggestion_condition_footer,
|
||||
(hasConditions || hasSuggestions) &&
|
||||
mSuggestionConditionMode == HEADER_MODE_FULLY_EXPANDED
|
||||
|| hasSuggestions && !hasConditions && hiddenSuggestion == 0,
|
||||
NS_SUGGESTION_CONDITION);
|
||||
}
|
||||
|
||||
resetCount();
|
||||
for (int i = 0; mCategories != null && i < mCategories.size(); i++) {
|
||||
DashboardCategory category = mCategories.get(i);
|
||||
@@ -270,6 +367,10 @@ public class DashboardData {
|
||||
}
|
||||
}
|
||||
|
||||
private static int sizeOf(List<?> list) {
|
||||
return list == null ? 0 : list.size();
|
||||
}
|
||||
|
||||
private SuggestionHeaderData buildSuggestionHeaderData() {
|
||||
SuggestionHeaderData data;
|
||||
if (mSuggestions == null) {
|
||||
@@ -285,19 +386,49 @@ public class DashboardData {
|
||||
return data;
|
||||
}
|
||||
|
||||
private List<Condition> getConditionsToShow(List<Condition> conditions) {
|
||||
if (conditions == null) {
|
||||
return null;
|
||||
}
|
||||
List<Condition> result = new ArrayList<Condition>();
|
||||
final int size = conditions == null ? 0 : conditions.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
final Condition condition = conditions.get(i);
|
||||
if (condition.shouldShow()) {
|
||||
result.add(condition);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<Tile> getSuggestionsToShow(List<Tile> suggestions) {
|
||||
if (suggestions == null || mSuggestionConditionMode == HEADER_MODE_COLLAPSED) {
|
||||
return null;
|
||||
}
|
||||
if (mSuggestionConditionMode != HEADER_MODE_DEFAULT
|
||||
|| suggestions.size() <= DEFAULT_SUGGESTION_COUNT) {
|
||||
return suggestions;
|
||||
}
|
||||
return suggestions.subList(0, DEFAULT_SUGGESTION_COUNT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builder used to build the ItemsData
|
||||
* <p>
|
||||
* {@link #mExpandedCondition} and {@link #mSuggestionMode} have default value
|
||||
* while others are not.
|
||||
* {@link #mExpandedCondition}, {@link #mSuggestionConditionMode} and {@link #mSuggestionMode}
|
||||
* have default value while others are not.
|
||||
*/
|
||||
public static class Builder {
|
||||
@Deprecated
|
||||
private int mSuggestionMode = SUGGESTION_MODE_DEFAULT;
|
||||
@Deprecated
|
||||
private Condition mExpandedCondition = null;
|
||||
private @HeaderMode int mSuggestionConditionMode = HEADER_MODE_DEFAULT;
|
||||
|
||||
private List<DashboardCategory> mCategories;
|
||||
private List<Condition> mConditions;
|
||||
private List<Tile> mSuggestions;
|
||||
private boolean mCombineSuggestionAndCondition;
|
||||
|
||||
public Builder() {
|
||||
}
|
||||
@@ -308,6 +439,8 @@ public class DashboardData {
|
||||
mSuggestions = dashboardData.mSuggestions;
|
||||
mSuggestionMode = dashboardData.mSuggestionMode;
|
||||
mExpandedCondition = dashboardData.mExpandedCondition;
|
||||
mSuggestionConditionMode = dashboardData.mSuggestionConditionMode;
|
||||
mCombineSuggestionAndCondition = dashboardData.mCombineSuggestionAndCondition;
|
||||
}
|
||||
|
||||
public Builder setCategories(List<DashboardCategory> categories) {
|
||||
@@ -330,11 +463,22 @@ public class DashboardData {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Builder setExpandedCondition(Condition expandedCondition) {
|
||||
this.mExpandedCondition = expandedCondition;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setSuggestionConditionMode(@HeaderMode int mode) {
|
||||
this.mSuggestionConditionMode = mode;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setCombineSuggestionAndCondition(boolean combine) {
|
||||
this.mCombineSuggestionAndCondition = combine;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DashboardData build() {
|
||||
return new DashboardData(this);
|
||||
}
|
||||
@@ -373,6 +517,8 @@ public class DashboardData {
|
||||
return mOldItems.get(oldItemPosition).equals(mNewItems.get(newItemPosition));
|
||||
}
|
||||
|
||||
// not needed in combined UI
|
||||
@Deprecated
|
||||
@Nullable
|
||||
@Override
|
||||
public Object getChangePayload(int oldItemPosition, int newItemPosition) {
|
||||
@@ -390,13 +536,24 @@ public class DashboardData {
|
||||
// valid types in field type
|
||||
private static final int TYPE_DASHBOARD_CATEGORY = R.layout.dashboard_category;
|
||||
private static final int TYPE_DASHBOARD_TILE = R.layout.dashboard_tile;
|
||||
@Deprecated
|
||||
private static final int TYPE_SUGGESTION_HEADER = R.layout.suggestion_header;
|
||||
@Deprecated
|
||||
private static final int TYPE_SUGGESTION_TILE = R.layout.suggestion_tile;
|
||||
private static final int TYPE_SUGGESTION_CONDITION_CONTAINER =
|
||||
R.layout.suggestion_condition_container;
|
||||
private static final int TYPE_SUGGESTION_CONDITION_HEADER =
|
||||
R.layout.suggestion_condition_header;
|
||||
@Deprecated
|
||||
private static final int TYPE_CONDITION_CARD = R.layout.condition_card;
|
||||
private static final int TYPE_SUGGESTION_CONDITION_FOOTER =
|
||||
R.layout.suggestion_condition_footer;
|
||||
private static final int TYPE_DASHBOARD_SPACER = R.layout.dashboard_spacer;
|
||||
|
||||
@IntDef({TYPE_DASHBOARD_CATEGORY, TYPE_DASHBOARD_TILE, TYPE_SUGGESTION_HEADER,
|
||||
TYPE_SUGGESTION_TILE, TYPE_CONDITION_CARD, TYPE_DASHBOARD_SPACER})
|
||||
TYPE_SUGGESTION_TILE, TYPE_SUGGESTION_CONDITION_CONTAINER,
|
||||
TYPE_SUGGESTION_CONDITION_HEADER, TYPE_CONDITION_CARD,
|
||||
TYPE_SUGGESTION_CONDITION_FOOTER, TYPE_DASHBOARD_SPACER})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface ItemTypes{}
|
||||
|
||||
@@ -422,8 +579,10 @@ public class DashboardData {
|
||||
* To store whether the condition is expanded, useless when {@link #type} is not
|
||||
* {@link #TYPE_CONDITION_CARD}
|
||||
*/
|
||||
@Deprecated
|
||||
public final boolean conditionExpanded;
|
||||
|
||||
@Deprecated
|
||||
public Item(Object entity, @ItemTypes int type, int id, boolean conditionExpanded) {
|
||||
this.entity = entity;
|
||||
this.type = type;
|
||||
@@ -431,6 +590,10 @@ public class DashboardData {
|
||||
this.conditionExpanded = conditionExpanded;
|
||||
}
|
||||
|
||||
public Item(Object entity, @ItemTypes int type, int id) {
|
||||
this(entity, type, id, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override it to make comparision in the {@link ItemsDataDiffCallback}
|
||||
* @param obj object to compared with
|
||||
@@ -516,4 +679,27 @@ public class DashboardData {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This class contains the data needed to build the suggestion/condition header. The data can
|
||||
* also be used to check the diff in DiffUtil.Callback
|
||||
*/
|
||||
public static class SuggestionConditionHeaderData {
|
||||
public final List<Icon> conditionIcons;
|
||||
public final CharSequence title;
|
||||
public final int conditionCount;
|
||||
public final int hiddenSuggestionCount;
|
||||
|
||||
public SuggestionConditionHeaderData(List<Condition> conditions,
|
||||
int hiddenSuggestionCount) {
|
||||
conditionCount = sizeOf(conditions);
|
||||
this.hiddenSuggestionCount = hiddenSuggestionCount;
|
||||
title = conditionCount > 0 ? conditions.get(0).getTitle() : null;
|
||||
conditionIcons = new ArrayList<Icon>();
|
||||
for (int i = 0; conditions != null && i < conditions.size(); i++) {
|
||||
final Condition condition = conditions.get(i);
|
||||
conditionIcons.add(condition.getIcon());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -95,4 +95,9 @@ public interface DashboardFeatureProvider {
|
||||
*/
|
||||
void openTileIntent(Activity activity, Tile tile);
|
||||
|
||||
/**
|
||||
* Whether or not we should use new UI that combines the settings suggestions and conditions.
|
||||
*/
|
||||
boolean combineSuggestionAndCondition();
|
||||
|
||||
}
|
||||
|
||||
@@ -206,6 +206,11 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
|
||||
launchIntentOrSelectProfile(activity, tile, intent, MetricsEvent.DASHBOARD_SUMMARY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean combineSuggestionAndCondition() {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void launchIntentOrSelectProfile(Activity activity, Tile tile, Intent intent,
|
||||
int sourceMetricCategory) {
|
||||
if (!isIntentResolvable(intent)) {
|
||||
|
||||
@@ -196,13 +196,16 @@ public class DashboardSummary extends InstrumentedFragment
|
||||
mDashboard.addItemDecoration(new DashboardDecorator(getContext()));
|
||||
mDashboard.setListener(this);
|
||||
Log.d(TAG, "adapter created");
|
||||
mAdapter = new DashboardAdapter(getContext(), bundle, mConditionManager.getConditions());
|
||||
mAdapter = new DashboardAdapter(getContext(), bundle, mConditionManager.getConditions(),
|
||||
mSuggestionParser, this /* SuggestionDismissController.Callback */);
|
||||
mDashboard.setAdapter(mAdapter);
|
||||
mSuggestionDismissHandler = new SuggestionDismissController(
|
||||
if (!mDashboardFeatureProvider.combineSuggestionAndCondition()) {
|
||||
mSuggestionDismissHandler = new SuggestionDismissController(
|
||||
getContext(), mDashboard, mSuggestionParser, this);
|
||||
ConditionAdapterUtils.addDismiss(mDashboard);
|
||||
}
|
||||
mDashboard.setItemAnimator(new DashboardItemAnimator());
|
||||
mSummaryLoader.setSummaryConsumer(mAdapter);
|
||||
ConditionAdapterUtils.addDismiss(mDashboard);
|
||||
if (DEBUG_TIMING) {
|
||||
Log.d(TAG, "onViewCreated took "
|
||||
+ (System.currentTimeMillis() - startTime) + " ms");
|
||||
@@ -242,7 +245,7 @@ public class DashboardSummary extends InstrumentedFragment
|
||||
|
||||
@Override
|
||||
public Tile getSuggestionForPosition(int position) {
|
||||
return (Tile) mAdapter.getItem(mAdapter.getItemId(position));
|
||||
return mAdapter.getSuggestion(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.settings.dashboard.conditional;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settings.dashboard.DashboardAdapter.DashboardItemHolder;
|
||||
import com.android.settings.dashboard.DashboardData;
|
||||
import com.android.settings.dashboard.DashboardData.HeaderMode;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ConditionAdapter extends RecyclerView.Adapter<DashboardItemHolder> {
|
||||
public static final String TAG = "ConditionAdapter";
|
||||
|
||||
private final Context mContext;
|
||||
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
private List<Condition> mConditions;
|
||||
private @HeaderMode int mMode;
|
||||
|
||||
private View.OnClickListener mConditionClickListener = new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
//TODO: get rid of setTag/getTag
|
||||
Condition condition = (Condition) v.getTag();
|
||||
mMetricsFeatureProvider.action(mContext,
|
||||
MetricsEvent.ACTION_SETTINGS_CONDITION_CLICK,
|
||||
condition.getMetricsConstant());
|
||||
condition.onPrimaryClick();
|
||||
}
|
||||
};
|
||||
|
||||
public ConditionAdapter(Context context, List<Condition> conditions, @HeaderMode int mode) {
|
||||
mContext = context;
|
||||
mConditions = conditions;
|
||||
mMode = mode;
|
||||
mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
|
||||
|
||||
setHasStableIds(true);
|
||||
}
|
||||
|
||||
public Object getItem(long itemId) {
|
||||
for (Condition condition : mConditions) {
|
||||
if (Objects.hash(condition.getTitle()) == itemId) {
|
||||
return condition;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DashboardItemHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
return new DashboardItemHolder(LayoutInflater.from(parent.getContext()).inflate(
|
||||
viewType, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(DashboardItemHolder holder, int position) {
|
||||
// TODO: merge methods from ConditionAdapterUtils into this class
|
||||
ConditionAdapterUtils.bindViews(mConditions.get(position), holder,
|
||||
position == mConditions.size() - 1, mConditionClickListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return Objects.hash(mConditions.get(position).getTitle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
return R.layout.condition_tile_new_ui;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
if (mMode == DashboardData.HEADER_MODE_FULLY_EXPANDED) {
|
||||
return mConditions.size();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -44,22 +44,28 @@ public class ConditionAdapterUtils {
|
||||
@Override
|
||||
public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
|
||||
return viewHolder.getItemViewType() == R.layout.condition_card
|
||||
|| viewHolder.getItemViewType() == R.layout.condition_tile_new_ui
|
||||
? super.getSwipeDirs(recyclerView, viewHolder) : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
|
||||
DashboardAdapter adapter = (DashboardAdapter) recyclerView.getAdapter();
|
||||
Object item = adapter.getItem(viewHolder.getItemId());
|
||||
if (item instanceof Condition) {
|
||||
((Condition) item).silence();
|
||||
Object item;
|
||||
if (viewHolder.getItemViewType() == R.layout.condition_card) {
|
||||
DashboardAdapter adapter = (DashboardAdapter) recyclerView.getAdapter();
|
||||
item = adapter.getItem(viewHolder.getItemId());
|
||||
} else {
|
||||
ConditionAdapter adapter = (ConditionAdapter) recyclerView.getAdapter();
|
||||
item = adapter.getItem(viewHolder.getItemId());
|
||||
}
|
||||
((Condition) item).silence();
|
||||
}
|
||||
};
|
||||
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(callback);
|
||||
itemTouchHelper.attachToRecyclerView(recyclerView);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void bindViews(final Condition condition,
|
||||
DashboardAdapter.DashboardItemHolder view, boolean isExpanded,
|
||||
View.OnClickListener onClickListener, View.OnClickListener onExpandListener) {
|
||||
@@ -121,6 +127,49 @@ public class ConditionAdapterUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static void bindViews(final Condition condition,
|
||||
DashboardAdapter.DashboardItemHolder view, boolean isLastItem,
|
||||
View.OnClickListener onClickListener) {
|
||||
if (condition instanceof AirplaneModeCondition) {
|
||||
Log.d(TAG, "Airplane mode condition has been bound with "
|
||||
+ "isActive=" + condition.isActive() + ". Airplane mode is currently " +
|
||||
WirelessUtils.isAirplaneModeOn(condition.mManager.getContext()));
|
||||
}
|
||||
View card = view.itemView.findViewById(R.id.content);
|
||||
card.setTag(condition);
|
||||
card.setOnClickListener(onClickListener);
|
||||
view.icon.setImageIcon(condition.getIcon());
|
||||
view.title.setText(condition.getTitle());
|
||||
|
||||
CharSequence[] actions = condition.getActions();
|
||||
final boolean hasButtons = actions.length > 0;
|
||||
setViewVisibility(view.itemView, R.id.buttonBar, hasButtons);
|
||||
|
||||
view.summary.setText(condition.getSummary());
|
||||
for (int i = 0; i < 2; i++) {
|
||||
Button button = (Button) view.itemView.findViewById(i == 0
|
||||
? R.id.first_action : R.id.second_action);
|
||||
if (actions.length > i) {
|
||||
button.setVisibility(View.VISIBLE);
|
||||
button.setText(actions[i]);
|
||||
final int index = i;
|
||||
button.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Context context = v.getContext();
|
||||
FeatureFactory.getFactory(context).getMetricsFeatureProvider()
|
||||
.action(context, MetricsEvent.ACTION_SETTINGS_CONDITION_BUTTON,
|
||||
condition.getMetricsConstant());
|
||||
condition.onActionClick(index);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
button.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
setViewVisibility(view.itemView, R.id.divider, !isLastItem);
|
||||
}
|
||||
|
||||
private static void setViewVisibility(View containerView, int viewId, boolean visible) {
|
||||
View view = containerView.findViewById(viewId);
|
||||
if (view != null) {
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.settings.dashboard.suggestions;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.R.layout;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settings.dashboard.DashboardAdapter.DashboardItemHolder;
|
||||
import com.android.settings.dashboard.DashboardAdapter.IconCache;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.drawer.Tile;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class SuggestionAdapter extends RecyclerView.Adapter<DashboardItemHolder> {
|
||||
public static final String TAG = "SuggestionAdapter";
|
||||
|
||||
private final Context mContext;
|
||||
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
private final SuggestionFeatureProvider mSuggestionFeatureProvider;
|
||||
private List<Tile> mSuggestions;
|
||||
private final IconCache mCache;
|
||||
private final List<String> mSuggestionsShownLogged;
|
||||
|
||||
public SuggestionAdapter(Context context, List<Tile> suggestions,
|
||||
List<String> suggestionsShownLogged) {
|
||||
mContext = context;
|
||||
mSuggestions = suggestions;
|
||||
mSuggestionsShownLogged = suggestionsShownLogged;
|
||||
mCache = new IconCache(context);
|
||||
final FeatureFactory factory = FeatureFactory.getFactory(context);
|
||||
mMetricsFeatureProvider = factory.getMetricsFeatureProvider();
|
||||
mSuggestionFeatureProvider = factory.getSuggestionFeatureProvider(context);
|
||||
|
||||
setHasStableIds(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DashboardItemHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
return new DashboardItemHolder(LayoutInflater.from(parent.getContext()).inflate(
|
||||
viewType, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(DashboardItemHolder holder, int position) {
|
||||
final Tile suggestion = (Tile) mSuggestions.get(position);
|
||||
final String suggestionId = mSuggestionFeatureProvider.getSuggestionIdentifier(
|
||||
mContext, suggestion);
|
||||
// This is for cases when a suggestion is dismissed and the next one comes to view
|
||||
if (!mSuggestionsShownLogged.contains(suggestionId)) {
|
||||
mMetricsFeatureProvider.action(
|
||||
mContext, MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION, suggestionId);
|
||||
mSuggestionsShownLogged.add(suggestionId);
|
||||
}
|
||||
if (suggestion.remoteViews != null) {
|
||||
final ViewGroup itemView = (ViewGroup) holder.itemView;
|
||||
itemView.removeAllViews();
|
||||
itemView.addView(suggestion.remoteViews.apply(itemView.getContext(), itemView));
|
||||
} else {
|
||||
holder.icon.setImageDrawable(mCache.getIcon(suggestion.icon));
|
||||
holder.title.setText(suggestion.title);
|
||||
if (!TextUtils.isEmpty(suggestion.summary)) {
|
||||
holder.summary.setText(suggestion.summary);
|
||||
holder.summary.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
holder.summary.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
final View divider = holder.itemView.findViewById(R.id.divider);
|
||||
if (divider != null) {
|
||||
divider.setVisibility(position < mSuggestions.size() - 1 ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
View clickHandler = holder.itemView;
|
||||
// If a view with @android:id/primary is defined, use that as the click handler
|
||||
// instead.
|
||||
final View primaryAction = holder.itemView.findViewById(android.R.id.primary);
|
||||
if (primaryAction != null) {
|
||||
clickHandler = primaryAction;
|
||||
// set the item view to disabled to remove any touch effects
|
||||
holder.itemView.setEnabled(false);
|
||||
}
|
||||
clickHandler.setOnClickListener(v -> {
|
||||
mMetricsFeatureProvider.action(mContext,
|
||||
MetricsEvent.ACTION_SETTINGS_SUGGESTION, suggestionId);
|
||||
((SettingsActivity) mContext).startSuggestion(suggestion.intent);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return Objects.hash(mSuggestions.get(position).title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
return layout.suggestion_tile_new_ui;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mSuggestions.size();
|
||||
}
|
||||
|
||||
public Tile getSuggestion(int position) {
|
||||
final long itemId = getItemId(position);
|
||||
for (Tile tile: mSuggestions) {
|
||||
if (Objects.hash(tile.title) == itemId) {
|
||||
return tile;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -67,6 +67,7 @@ public class SuggestionDismissController extends ItemTouchHelper.SimpleCallback
|
||||
public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
|
||||
final int layoutId = viewHolder.getItemViewType();
|
||||
if (layoutId == R.layout.suggestion_tile
|
||||
|| layoutId == R.layout.suggestion_tile_new_ui
|
||||
|| layoutId == R.layout.suggestion_tile_card) {
|
||||
// Only return swipe direction for suggestion tiles. All other types are not swipeable.
|
||||
return super.getSwipeDirs(recyclerView, viewHolder);
|
||||
|
||||
Reference in New Issue
Block a user