Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1387)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/suggestions/TileView.java

Issue 2710473003: 📰 Ensure NTP Tiles keep tracking recent data (Closed)
Patch Set: Add OWNERS file for new test folder Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/suggestions/TileView.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/suggestions/TileView.java b/chrome/android/java/src/org/chromium/chrome/browser/suggestions/TileView.java
index 535489c8a532fe7009ca20d5fa0eab408fc33050..0b4982393994c07521df7496b4fb515a1ba58469 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/suggestions/TileView.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/suggestions/TileView.java
@@ -6,7 +6,6 @@
import android.content.Context;
import android.util.AttributeSet;
-import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
@@ -19,10 +18,12 @@
* large icon isn't available, displays a rounded rectangle with a single letter in its place.
*/
public class TileView extends FrameLayout {
- /**
- * The tile that holds the data to populate this view.
- */
- private Tile mTile;
+ /** The url currently associated to this tile. */
+ private String mUrl;
+
+ private TextView mTitleView;
+ private ImageView mIconView;
+ private ImageView mBadgeView;
/**
* Constructor for inflating from XML.
@@ -31,6 +32,15 @@ public TileView(Context context, AttributeSet attrs) {
super(context, attrs);
}
+ @Override
+ protected void onFinishInflate() {
+ super.onFinishInflate();
+
+ mTitleView = (TextView) findViewById(R.id.tile_view_title);
+ mIconView = (ImageView) findViewById(R.id.tile_view_icon);
+ mBadgeView = (ImageView) findViewById(R.id.offline_badge);
+ }
+
/**
* Initializes the view using the data held by {@code tile}. This should be called immediately
* after inflation.
@@ -38,26 +48,43 @@ public TileView(Context context, AttributeSet attrs) {
* @param titleLines The number of text lines to use for the tile title.
*/
public void initialize(Tile tile, int titleLines) {
- mTile = tile;
- TextView titleView = (TextView) findViewById(R.id.tile_view_title);
- titleView.setLines(titleLines);
- titleView.setText(TitleUtil.getTitleForDisplay(mTile.getTitle(), mTile.getUrl()));
- renderIcon();
- findViewById(R.id.offline_badge)
- .setVisibility(mTile.isOfflineAvailable() ? View.VISIBLE : View.GONE);
+ mTitleView.setLines(titleLines);
+ mUrl = tile.getUrl();
+ renderTile(tile);
}
- /**
- * @return The tile that holds the data to populate this view.
- */
- public Tile getTile() {
- return mTile;
+ /** @return The url associated to this view. */
+ public String getUrl() {
+ return mUrl;
}
/**
* Renders the icon held by the {@link Tile} or clears it from the view if the icon is null.
*/
- public void renderIcon() {
- ((ImageView) findViewById(R.id.tile_view_icon)).setImageDrawable(mTile.getIcon());
+ public void renderIcon(Tile tile) {
+ mIconView.setImageDrawable(tile.getIcon());
+ }
+
+ /** Updates the view if there have been changes since the last time. */
+ public void updateIfDataChanged(Tile tile) {
+ if (!isUpToDate(tile)) renderTile(tile);
+ }
+
+ private boolean isUpToDate(Tile tile) {
+ assert mUrl.equals(tile.getUrl());
+
+ if (tile.getIcon() != mIconView.getDrawable()) return false;
+ if (tile.isOfflineAvailable() != (mBadgeView.getVisibility() == VISIBLE)) return false;
+ // We don't check the title since it's not likely to change, but that could also be done.
+ return true;
+ }
+
+ private void renderTile(Tile tile) {
+ // A TileView should not be reused across tiles having different urls, as registered
+ // callbacks and handlers use it to look up the data and notify the rest of the system.
+ assert mUrl.equals(tile.getUrl());
+ mTitleView.setText(TitleUtil.getTitleForDisplay(tile.getTitle(), tile.getUrl()));
+ mBadgeView.setVisibility(tile.isOfflineAvailable() ? VISIBLE : GONE);
+ renderIcon(tile);
}
}
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/suggestions/TileGroup.java ('k') | chrome/android/java_sources.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698