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

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: Fix initialisation with no MV Data, move back to array 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..131a04040efb0e9053afbc97a61fad303a69049b 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,11 +6,11 @@
import android.content.Context;
import android.util.AttributeSet;
-import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
+import org.chromium.base.Log;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ntp.TitleUtil;
@@ -19,10 +19,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,33 +33,59 @@ 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.
- * @param tile The tile that holds the data to populate this view.
* @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);
+ 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 maybeUpdateView(Tile tile) {
+ if (!isUpToDate(tile)) renderTile(tile);
+ }
+
+ private boolean isUpToDate(Tile tile) {
+ if (!tile.getUrl().equals(mUrl)) return false;
+ if (tile.getIcon() != mIconView.getDrawable()) {
+ Log.d("DGN", "isUpToDate: Drawable has changed");
+ return false;
+ } else {
+ Log.d("DGN", "isUpToDate: Drawable didn't change.");
+ }
+ 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) {
+ mUrl = tile.getUrl();
+ mTitleView.setText(TitleUtil.getTitleForDisplay(tile.getTitle(), tile.getUrl()));
+ mBadgeView.setVisibility(tile.isOfflineAvailable() ? VISIBLE : GONE);
+ renderIcon(tile);
}
}

Powered by Google App Engine
This is Rietveld 408576698