Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ca022e2b authored by Maurice Lam's avatar Maurice Lam Committed by Android (Google) Code Review
Browse files

Merge "Fix suggested action custom view binding"

parents 68d6bcd1 58c14f75
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -396,6 +396,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));
+24 −0
Original line number Diff line number Diff line
@@ -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) {