diff options
author | Diego Perez <diegoperez@google.com> | 2017-05-20 08:40:58 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2017-05-20 08:41:01 +0000 |
commit | c56293b035c7a73188b709b7effc340a022e46f4 (patch) | |
tree | bf101c39f3a000faab5c87c58f5afb9c45797095 | |
parent | 52b0360b1a3af42893c35227992d5bd78d1a32c7 (diff) | |
parent | b1ae00e68fac4cb755d3d1b5ed66f0df4adf3fba (diff) | |
download | layoutlib-c56293b035c7a73188b709b7effc340a022e46f4.tar.gz |
Merge "Add itemCount to RecyclerView"
3 files changed, 12 insertions, 5 deletions
diff --git a/bridge/src/android/view/BridgeInflater.java b/bridge/src/android/view/BridgeInflater.java index b6e6ec0084..58d8c52746 100644 --- a/bridge/src/android/view/BridgeInflater.java +++ b/bridge/src/android/view/BridgeInflater.java @@ -370,10 +370,12 @@ public final class BridgeInflater extends LayoutInflater { } if (ReflectionUtils.isInstanceOf(view, RecyclerViewUtil.CN_RECYCLER_VIEW)) { Integer resourceId = null; - String attrVal = attrs.getAttributeValue(BridgeConstants.NS_TOOLS_URI, + String attrListItemValue = attrs.getAttributeValue(BridgeConstants.NS_TOOLS_URI, BridgeConstants.ATTR_LIST_ITEM); - if (attrVal != null && !attrVal.isEmpty()) { - ResourceValue resValue = bc.getRenderResources().findResValue(attrVal, false); + int attrItemCountValue = attrs.getAttributeIntValue(BridgeConstants.NS_TOOLS_URI, + BridgeConstants.ATTR_ITEM_COUNT, -1); + if (attrListItemValue != null && !attrListItemValue.isEmpty()) { + ResourceValue resValue = bc.getRenderResources().findResValue(attrListItemValue, false); if (resValue.isFramework()) { resourceId = Bridge.getResourceId(resValue.getResourceType(), resValue.getName()); @@ -385,7 +387,7 @@ public final class BridgeInflater extends LayoutInflater { if (resourceId == null) { resourceId = 0; } - RecyclerViewUtil.setAdapter(view, bc, mLayoutlibCallback, resourceId); + RecyclerViewUtil.setAdapter(view, bc, mLayoutlibCallback, resourceId, attrItemCountValue); } else if (ReflectionUtils.isInstanceOf(view, DrawerLayoutUtil.CN_DRAWER_LAYOUT)) { String attrVal = attrs.getAttributeValue(BridgeConstants.NS_TOOLS_URI, BridgeConstants.ATTR_OPEN_DRAWER); diff --git a/bridge/src/com/android/layoutlib/bridge/BridgeConstants.java b/bridge/src/com/android/layoutlib/bridge/BridgeConstants.java index 6228766957..d95c5088c9 100644 --- a/bridge/src/com/android/layoutlib/bridge/BridgeConstants.java +++ b/bridge/src/com/android/layoutlib/bridge/BridgeConstants.java @@ -55,4 +55,5 @@ public class BridgeConstants { @SuppressWarnings("SpellCheckingInspection") public static final String ATTR_LIST_ITEM = "listitem"; public static final String ATTR_OPEN_DRAWER = "openDrawer"; + public static final String ATTR_ITEM_COUNT = "itemCount"; } diff --git a/bridge/src/com/android/layoutlib/bridge/android/support/RecyclerViewUtil.java b/bridge/src/com/android/layoutlib/bridge/android/support/RecyclerViewUtil.java index ab278195f3..c6e034f4a4 100644 --- a/bridge/src/com/android/layoutlib/bridge/android/support/RecyclerViewUtil.java +++ b/bridge/src/com/android/layoutlib/bridge/android/support/RecyclerViewUtil.java @@ -55,13 +55,17 @@ public class RecyclerViewUtil { * Any exceptions thrown during the process are logged in {@link Bridge#getLog()} */ public static void setAdapter(@NonNull View recyclerView, @NonNull BridgeContext context, - @NonNull LayoutlibCallback layoutlibCallback, int adapterLayout) { + @NonNull LayoutlibCallback layoutlibCallback, int adapterLayout, int itemCount) { try { setLayoutManager(recyclerView, context, layoutlibCallback); Object adapter = createAdapter(layoutlibCallback); if (adapter != null) { setProperty(recyclerView, CN_ADAPTER, adapter, "setAdapter"); setProperty(adapter, int.class, adapterLayout, "setLayoutId"); + + if (itemCount != -1) { + setProperty(adapter, int.class, itemCount, "setItemCount"); + } } } catch (ReflectionException e) { Throwable cause = getCause(e); |