Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package org.chromium.chrome.browser.suggestions; | |
| 6 | |
| 7 import android.view.LayoutInflater; | |
| 8 import android.view.ViewGroup; | |
| 9 | |
| 10 import org.chromium.chrome.R; | |
| 11 import org.chromium.chrome.browser.ntp.ContextMenuManager; | |
| 12 import org.chromium.chrome.browser.ntp.MostVisitedLayout; | |
| 13 import org.chromium.chrome.browser.ntp.cards.ItemViewType; | |
| 14 import org.chromium.chrome.browser.ntp.cards.Leaf; | |
| 15 import org.chromium.chrome.browser.ntp.cards.NewTabPageViewHolder; | |
| 16 import org.chromium.chrome.browser.ntp.cards.NewTabPageViewHolder.PartialBindCal lback; | |
| 17 | |
| 18 /** | |
| 19 * The model and controller for a group of site suggestion tiles that will be re ndered in a grid. | |
| 20 */ | |
| 21 public class TileGrid extends Leaf implements TileGroup.Observer { | |
|
dgn
2017/01/31 18:21:35
what if the user removes all the tiles? do we stil
Michael van Ouwerkerk
2017/02/03 12:37:48
It was rendering with 0 height so the user wouldn'
| |
| 22 private static final int MAX_TILES = 4; | |
| 23 private static final int MAX_ROWS = 1; | |
| 24 | |
| 25 private final TileGroup mTileGroup; | |
| 26 | |
| 27 public TileGrid(SuggestionsUiDelegate uiDelegate, ContextMenuManager context MenuManager, | |
| 28 TileGroup.Delegate tileGroupDelegate) { | |
| 29 mTileGroup = new TileGroup( | |
| 30 uiDelegate, contextMenuManager, tileGroupDelegate, /* observer = */ this); | |
| 31 mTileGroup.startObserving(MAX_TILES); | |
| 32 } | |
| 33 | |
| 34 @Override | |
| 35 @ItemViewType | |
| 36 protected int getItemViewType() { | |
| 37 return ItemViewType.TILE_GRID; | |
| 38 } | |
| 39 | |
| 40 @Override | |
| 41 protected void onBindViewHolder(NewTabPageViewHolder holder) { | |
| 42 assert holder instanceof ViewHolder; | |
| 43 ((ViewHolder) holder).onBindViewHolder(mTileGroup); | |
| 44 } | |
| 45 | |
| 46 @Override | |
| 47 public void onInitialTileDataLoaded() { | |
| 48 notifyItemChanged(0); | |
| 49 } | |
| 50 | |
| 51 @Override | |
| 52 public void onTileDataChanged() { | |
| 53 notifyItemChanged(0); | |
| 54 } | |
| 55 | |
| 56 @Override | |
| 57 public void onTileCountChanged() {} | |
|
dgn
2017/01/31 18:21:35
why no notification here?
Michael van Ouwerkerk
2017/02/03 12:37:48
Done.
| |
| 58 | |
| 59 @Override | |
| 60 public void onTileIconChanged(final Tile tile) { | |
| 61 notifyItemChanged(0, new PartialBindCallback() { | |
| 62 @Override | |
| 63 public void onResult(NewTabPageViewHolder holder) { | |
| 64 assert holder instanceof ViewHolder; | |
| 65 ((ViewHolder) holder).updateIconView(tile); | |
| 66 } | |
| 67 }); | |
| 68 } | |
| 69 | |
| 70 @Override | |
| 71 public void onLoadTaskAdded() {} | |
| 72 | |
| 73 @Override | |
| 74 public void onLoadTaskCompleted() {} | |
| 75 | |
| 76 /** | |
| 77 * The {@code ViewHolder} for the {@link TileGrid}. | |
| 78 */ | |
| 79 public static class ViewHolder extends NewTabPageViewHolder { | |
| 80 private final MostVisitedLayout mLayout; | |
| 81 | |
| 82 public ViewHolder(ViewGroup parentView) { | |
| 83 super(LayoutInflater.from(parentView.getContext()) | |
| 84 .inflate(R.layout.suggestions_site_tile_grid, parent View, false)); | |
| 85 mLayout = (MostVisitedLayout) itemView; | |
| 86 } | |
| 87 | |
| 88 public void onBindViewHolder(TileGroup tileGroup) { | |
| 89 mLayout.setMaxRows(MAX_ROWS); | |
| 90 tileGroup.renderTileViews(mLayout, /* trackLoadTasks = */ false); | |
| 91 } | |
| 92 | |
| 93 public void updateIconView(Tile tile) { | |
| 94 mLayout.updateIconView(tile.getUrl(), tile.getIcon()); | |
| 95 } | |
| 96 } | |
| 97 } | |
| OLD | NEW |