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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/CardItemDecoration.java

Issue 2024933002: [NTP Snippets] Show a status card when there are no available snippets (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased and address comments Created 4 years, 6 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/ntp/cards/CardItemDecoration.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/CardItemDecoration.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/CardItemDecoration.java
new file mode 100644
index 0000000000000000000000000000000000000000..1bfee572b2d1e7aa2583d547b4359b5551f3a517
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/CardItemDecoration.java
@@ -0,0 +1,44 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.ntp.cards;
+
+import android.content.Context;
+import android.graphics.Rect;
+import android.support.v7.widget.RecyclerView;
+import android.view.View;
+
+import org.chromium.chrome.R;
+
+/**
+ * A decorator that places separators between RecyclerView cards.
+ */
+public class CardItemDecoration extends RecyclerView.ItemDecoration {
+ private final int mCardsVerticalSpacing;
+
+ /**
+ * @param context used to retrieve resources.
+ */
+ public CardItemDecoration(Context context) {
+ mCardsVerticalSpacing =
+ context.getResources().getDimensionPixelSize(R.dimen.snippets_vertical_spacing);
+ }
+
+ @Override
+ public void getItemOffsets(
+ Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
+ int childPos = parent.getChildAdapterPosition(view);
+
+ // childPos can be NO_POSITION if the method is called with a view being removed from the
+ // RecyclerView, for example when dismissing an item.
+ if (childPos == RecyclerView.NO_POSITION) return;
+
+ // Add spacing if the current item and the next are cards.
+ if (parent.getChildViewHolder(view) instanceof CardViewHolder
+ && parent.findViewHolderForAdapterPosition(childPos + 1)
+ instanceof CardViewHolder) {
+ outRect.set(0, 0, 0, mCardsVerticalSpacing);
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698