Remove Suggestion v1 code.
Change-Id: Ie6e9c8f2b1b5b609d44e287accb9fbbef9054d34 Fixes: 68719093 Test: robotests
This commit is contained in:
@@ -27,12 +27,10 @@ import android.view.ViewGroup;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
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;
|
||||
@@ -42,26 +40,20 @@ public class SuggestionAdapter extends RecyclerView.Adapter<DashboardItemHolder>
|
||||
|
||||
private final Context mContext;
|
||||
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
private final SuggestionFeatureProvider mSuggestionFeatureProvider;
|
||||
@Deprecated // in favor of mSuggestionsV2
|
||||
private final List<Tile> mSuggestions;
|
||||
private final List<Suggestion> mSuggestionsV2;
|
||||
private final List<Suggestion> mSuggestions;
|
||||
private final IconCache mCache;
|
||||
private final List<String> mSuggestionsShownLogged;
|
||||
private final SuggestionControllerMixin mSuggestionControllerMixin;
|
||||
|
||||
public SuggestionAdapter(Context context, SuggestionControllerMixin suggestionControllerMixin,
|
||||
List<Tile> suggestions, List<Suggestion> suggestionsV2,
|
||||
List<String> suggestionsShownLogged) {
|
||||
List<Suggestion> suggestions, List<String> suggestionsShownLogged) {
|
||||
mContext = context;
|
||||
mSuggestionControllerMixin = suggestionControllerMixin;
|
||||
mSuggestions = suggestions;
|
||||
mSuggestionsV2 = suggestionsV2;
|
||||
mSuggestionsShownLogged = suggestionsShownLogged;
|
||||
mCache = new IconCache(context);
|
||||
final FeatureFactory factory = FeatureFactory.getFactory(context);
|
||||
mMetricsFeatureProvider = factory.getMetricsFeatureProvider();
|
||||
mSuggestionFeatureProvider = factory.getSuggestionFeatureProvider(context);
|
||||
|
||||
setHasStableIds(true);
|
||||
}
|
||||
@@ -74,15 +66,11 @@ public class SuggestionAdapter extends RecyclerView.Adapter<DashboardItemHolder>
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(DashboardItemHolder holder, int position) {
|
||||
if (mSuggestions != null) {
|
||||
bindSuggestionTile(holder, position);
|
||||
} else {
|
||||
bindSuggestion(holder, position);
|
||||
}
|
||||
bindSuggestion(holder, position);
|
||||
}
|
||||
|
||||
private void bindSuggestion(DashboardItemHolder holder, int position) {
|
||||
final Suggestion suggestion = mSuggestionsV2.get(position);
|
||||
final Suggestion suggestion = mSuggestions.get(position);
|
||||
final String id = suggestion.getId();
|
||||
if (!mSuggestionsShownLogged.contains(id)) {
|
||||
mMetricsFeatureProvider.action(
|
||||
@@ -101,7 +89,7 @@ public class SuggestionAdapter extends RecyclerView.Adapter<DashboardItemHolder>
|
||||
}
|
||||
final View divider = holder.itemView.findViewById(R.id.divider);
|
||||
if (divider != null) {
|
||||
divider.setVisibility(position < mSuggestionsV2.size() - 1 ? View.VISIBLE : View.GONE);
|
||||
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
|
||||
@@ -121,110 +109,32 @@ public class SuggestionAdapter extends RecyclerView.Adapter<DashboardItemHolder>
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated in favor {@link #bindSuggestion(DashboardItemHolder, int)}.
|
||||
*/
|
||||
@Deprecated
|
||||
private void bindSuggestionTile(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,
|
||||
mSuggestionFeatureProvider.getLoggingTaggedData(mContext));
|
||||
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;
|
||||
}
|
||||
|
||||
clickHandler.setOnClickListener(v -> {
|
||||
mMetricsFeatureProvider.action(mContext,
|
||||
MetricsEvent.ACTION_SETTINGS_SUGGESTION, suggestionId,
|
||||
mSuggestionFeatureProvider.getLoggingTaggedData(mContext));
|
||||
((SettingsActivity) mContext).startSuggestion(suggestion.intent);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
if (mSuggestions != null) {
|
||||
return Objects.hash(mSuggestions.get(position).title);
|
||||
} else {
|
||||
return Objects.hash(mSuggestionsV2.get(position).getId());
|
||||
}
|
||||
return Objects.hash(mSuggestions.get(position).getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
if (mSuggestions != null) {
|
||||
Tile suggestion = getSuggestion(position);
|
||||
|
||||
return suggestion.remoteViews != null
|
||||
? R.layout.suggestion_tile_remote_container
|
||||
: R.layout.suggestion_tile;
|
||||
final Suggestion suggestion = getSuggestion(position);
|
||||
if ((suggestion.getFlags() & Suggestion.FLAG_HAS_BUTTON) != 0) {
|
||||
return R.layout.suggestion_tile_with_button;
|
||||
} else {
|
||||
final Suggestion suggestion = getSuggestionsV2(position);
|
||||
if ((suggestion.getFlags() & Suggestion.FLAG_HAS_BUTTON) != 0) {
|
||||
return R.layout.suggestion_tile_with_button;
|
||||
} else {
|
||||
return R.layout.suggestion_tile;
|
||||
}
|
||||
return R.layout.suggestion_tile;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
if (mSuggestions != null) {
|
||||
return mSuggestions.size();
|
||||
} else {
|
||||
return mSuggestionsV2.size();
|
||||
}
|
||||
return mSuggestions.size();
|
||||
}
|
||||
|
||||
public Tile getSuggestion(int position) {
|
||||
public Suggestion getSuggestion(int position) {
|
||||
final long itemId = getItemId(position);
|
||||
if (mSuggestions == null) {
|
||||
return null;
|
||||
}
|
||||
for (Tile tile : mSuggestions) {
|
||||
if (Objects.hash(tile.title) == itemId) {
|
||||
return tile;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Suggestion getSuggestionsV2(int position) {
|
||||
final long itemId = getItemId(position);
|
||||
if (mSuggestionsV2 == null) {
|
||||
return null;
|
||||
}
|
||||
for (Suggestion suggestion : mSuggestionsV2) {
|
||||
for (Suggestion suggestion : mSuggestions) {
|
||||
if (Objects.hash(suggestion.getId()) == itemId) {
|
||||
return suggestion;
|
||||
}
|
||||
@@ -232,13 +142,8 @@ public class SuggestionAdapter extends RecyclerView.Adapter<DashboardItemHolder>
|
||||
return null;
|
||||
}
|
||||
|
||||
public void removeSuggestion(Tile suggestion) {
|
||||
public void removeSuggestion(Suggestion suggestion) {
|
||||
mSuggestions.remove(suggestion);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void removeSuggestion(Suggestion suggestion) {
|
||||
mSuggestionsV2.remove(suggestion);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user