Ejemplo n.º 1
0
  public void generateChildContentViews(
      DataItem item, TiUIView parentContent, TiBaseListViewItem rootItem, boolean root) {

    ArrayList<DataItem> childrenItem = item.getChildren();
    for (int i = 0; i < childrenItem.size(); i++) {
      DataItem child = childrenItem.get(i);
      TiViewProxy proxy = child.getViewProxy();
      TiUIView view = proxy.createView(proxy.getActivity());
      view.registerForTouch();
      generateChildContentViews(child, view, rootItem, false);
      // Bind view to root.

      ViewItem viewItem = new ViewItem(view, new KrollDict());
      rootItem.bindView(child.getBindingId(), viewItem);
      // Add it to view hierarchy
      if (root) {
        rootItem.addView(view.getNativeView(), view.getLayoutParams());
      } else {
        parentContent.add(view);
      }
    }
  }
Ejemplo n.º 2
0
  public void populateViews(
      KrollDict data,
      TiBaseListViewItem cellContent,
      TiListViewTemplate template,
      int itemIndex,
      int sectionIndex,
      View item_layout) {
    Object cell = cellContent.getTag();
    // Handling root item, since that is not in the views map.
    if (!(cell instanceof TiListItem)) {
      Log.e(TAG, "Cell is not TiListItem. Something is wrong..", Log.DEBUG_MODE);
      return;
    }

    TiListItem listItem = (TiListItem) cell;
    KrollDict listItemProperties;
    String itemId = null;

    if (data.containsKey(TiC.PROPERTY_PROPERTIES)) {
      listItemProperties = new KrollDict((HashMap) data.get(TiC.PROPERTY_PROPERTIES));
    } else {
      listItemProperties = template.getRootItem().getDefaultProperties();
    }

    // find out if we need to update itemId
    if (listItemProperties.containsKey(TiC.PROPERTY_ITEM_ID)) {
      itemId = TiConvert.toString(listItemProperties.get(TiC.PROPERTY_ITEM_ID));
    }

    // update extra event data for list item
    appendExtraEventData(listItem, itemIndex, sectionIndex, TiC.PROPERTY_PROPERTIES, itemId);

    HashMap<String, ViewItem> views = (HashMap<String, ViewItem>) cellContent.getViewsMap();
    // Loop through all our views and apply default properties
    for (String binding : views.keySet()) {
      DataItem dataItem = template.getDataItem(binding);
      ViewItem viewItem = views.get(binding);
      TiUIView view = viewItem.getView();
      // update extra event data for views
      if (view != null) {
        appendExtraEventData(view, itemIndex, sectionIndex, binding, itemId);
      }
      // if binding is contain in data given to us, process that data, otherwise
      // apply default properties.
      if (data.containsKey(binding) && view != null) {
        KrollDict properties = new KrollDict((HashMap) data.get(binding));
        KrollDict diffProperties = viewItem.generateDiffProperties(properties);
        if (!diffProperties.isEmpty()) {
          view.processProperties(diffProperties);
        }

      } else if (dataItem != null && view != null) {
        KrollDict diffProperties = viewItem.generateDiffProperties(dataItem.getDefaultProperties());
        if (!diffProperties.isEmpty()) {
          view.processProperties(diffProperties);
        }
      } else {
        Log.w(
            TAG,
            "Sorry, " + binding + " isn't a valid binding. Perhaps you made a typo?",
            Log.DEBUG_MODE);
      }
    }

    // process listItem properties
    KrollDict listItemDiff = cellContent.getViewItem().generateDiffProperties(listItemProperties);
    if (!listItemDiff.isEmpty()) {
      listItem.processProperties(listItemDiff);
    }
  }