Пример #1
0
  @Override
  public BindingHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
    int layout = mv.getLayout(viewType);

    ViewDataBinding binding =
        DataBindingUtil.inflate(
            LayoutInflater.from(viewGroup.getContext()), layout, viewGroup, false);
    BindingHolder holder = new BindingHolder(binding.getRoot());
    holder.setBinding(binding);
    return holder;
  }
Пример #2
0
  @Override
  public void onBindViewHolder(BindingHolder holder, final int position) {
    try {
      try {
        holder
            .getBinding()
            .setVariable(
                getBRClass().getDeclaredField("data").getInt(getBRClass().newInstance()),
                deals.get(position));
        ;
      } catch (IllegalAccessException e) {
        e.printStackTrace();
      } catch (InstantiationException e) {
        e.printStackTrace();
      }
    } catch (NoSuchFieldException e) {
      e.printStackTrace();
    }

    holder.getBinding().executePendingBindings();

    // add footer
    if (holder.getBinding() instanceof LceLoadingFooterBinding && recycle != null) {
      RecyclerView.LayoutManager manager = recycle.getLayoutManager();
      if (manager instanceof StaggeredGridLayoutManager) {
        StaggeredGridLayoutManager.LayoutParams layoutParams =
            new StaggeredGridLayoutManager.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        layoutParams.setFullSpan(true);
        holder.getBinding().getRoot().setLayoutParams(layoutParams);
      } else if (manager instanceof LinearLayoutManager) {
      } else if (manager instanceof GridLayoutManager) {
        final GridLayoutManager gridLayoutManager = (GridLayoutManager) manager;
        final GridLayoutManager.SpanSizeLookup lookup = gridLayoutManager.getSpanSizeLookup();
        gridLayoutManager.setSpanSizeLookup(
            new GridLayoutManager.SpanSizeLookup() {
              @Override
              public int getSpanSize(int inner_position) {
                if (position == inner_position) {
                  return gridLayoutManager.getSpanCount();
                } else {
                  return lookup.getSpanSize(inner_position);
                }
              }
            });
      }
    } else {
      onBind(holder, deals.get(position), mv.getModel(getItemViewType(position)), position);
    }
  }