Fix suggested action custom view binding
Remove all the views before adding the remote views again, so the card will not have multiple custom views on top of each other. Test: cd tests/robotests && mma Change-Id: Id41bfb962c08e8d1ee6534e0cf44d173a1f1910f
This commit is contained in:
@@ -417,6 +417,7 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
private void onBindTile(DashboardItemHolder holder, Tile tile) {
|
||||
if (tile.remoteViews != null) {
|
||||
final ViewGroup itemView = (ViewGroup) holder.itemView;
|
||||
itemView.removeAllViews();
|
||||
itemView.addView(tile.remoteViews.apply(itemView.getContext(), itemView));
|
||||
} else {
|
||||
holder.icon.setImageDrawable(mCache.getIcon(tile.icon));
|
||||
|
@@ -373,6 +373,30 @@ public class DashboardAdapterTest {
|
||||
verify(mContext).startSuggestion(any(Intent.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindViewHolder_viewsClearedOnRebind() {
|
||||
Context context = new ContextThemeWrapper(application, R.style.Theme_Settings);
|
||||
|
||||
List<Tile> packages = makeSuggestions("pkg1");
|
||||
RemoteViews remoteViews = mock(RemoteViews.class);
|
||||
FrameLayout layout = new FrameLayout(context);
|
||||
Button primary = new Button(context);
|
||||
primary.setId(android.R.id.primary);
|
||||
layout.addView(primary);
|
||||
doReturn(layout).when(remoteViews).apply(any(Context.class), any(ViewGroup.class));
|
||||
packages.get(0).remoteViews = remoteViews;
|
||||
mDashboardAdapter.setCategoriesAndSuggestions(Collections.emptyList(), packages);
|
||||
mSuggestionHolder = mDashboardAdapter.onCreateViewHolder(
|
||||
new FrameLayout(context),
|
||||
R.layout.suggestion_tile_card);
|
||||
|
||||
mDashboardAdapter.onBindViewHolder(mSuggestionHolder, 1);
|
||||
mDashboardAdapter.onBindViewHolder(mSuggestionHolder, 1);
|
||||
|
||||
ViewGroup itemView = (ViewGroup) mSuggestionHolder.itemView;
|
||||
assertThat(itemView.getChildCount()).isEqualTo(1);
|
||||
}
|
||||
|
||||
private List<Tile> makeSuggestions(String... pkgNames) {
|
||||
final List<Tile> suggestions = new ArrayList<>();
|
||||
for (String pkgName : pkgNames) {
|
||||
|
Reference in New Issue
Block a user