Ejemplo n.º 1
0
 @Override
 public int getCount() {
   int count = 0;
   for (int i = 0; i < sections.size(); i++) {
     ListSectionProxy section = sections.get(i);
     count += section.getItemCount();
   }
   return count;
 }
Ejemplo n.º 2
0
 private void reFilter(String searchText) {
   if (searchText != null) {
     for (int i = 0; i < sections.size(); ++i) {
       ListSectionProxy section = sections.get(i);
       section.applyFilter(searchText);
     }
   }
   if (adapter != null) {
     adapter.notifyDataSetChanged();
   }
 }
Ejemplo n.º 3
0
  protected Pair<ListSectionProxy, Pair<Integer, Integer>> getSectionInfoByEntryIndex(int index) {
    if (index < 0) {
      return null;
    }
    for (int i = 0; i < sections.size(); i++) {
      ListSectionProxy section = sections.get(i);
      int sectionItemCount = section.getItemCount();
      if (index <= sectionItemCount - 1) {
        return new Pair<ListSectionProxy, Pair<Integer, Integer>>(
            section, new Pair<Integer, Integer>(i, index));
      } else {
        index -= sectionItemCount;
      }
    }

    return null;
  }
Ejemplo n.º 4
0
 private int findItemPosition(int sectionIndex, int sectionItemIndex) {
   int position = 0;
   for (int i = 0; i < sections.size(); i++) {
     ListSectionProxy section = sections.get(i);
     if (i == sectionIndex) {
       if (sectionItemIndex >= section.getContentCount()) {
         Log.e(TAG, "Invalid item index");
         return -1;
       }
       position += sectionItemIndex;
       if (section.getHeaderTitle() != null) {
         position += 1;
       }
       break;
     } else {
       position += section.getItemCount();
     }
   }
   return position;
 }
Ejemplo n.º 5
0
 @Override
 public int getItemViewType(int position) {
   Pair<ListSectionProxy, Pair<Integer, Integer>> info = getSectionInfoByEntryIndex(position);
   ListSectionProxy section = info.first;
   int sectionItemIndex = info.second.second;
   if (section.isHeaderTitle(sectionItemIndex) || section.isFooterTitle(sectionItemIndex))
     return HEADER_FOOTER_TITLE_TYPE;
   if (section.isHeaderView(sectionItemIndex) || section.isFooterView(sectionItemIndex)) {
     return HEADER_FOOTER_VIEW_TYPE;
   }
   return section.getTemplateByIndex(sectionItemIndex).getType();
 }
Ejemplo n.º 6
0
 protected void processSection(Object sec, int index) {
   if (sec instanceof ListSectionProxy) {
     ListSectionProxy section = (ListSectionProxy) sec;
     if (this.sections.contains(section)) {
       return;
     }
     if (index == -1 || index >= sections.size()) {
       this.sections.add(section);
     } else {
       this.sections.add(index, section);
     }
     section.setAdapter(adapter);
     section.setListView(this);
     // Attempts to set type for existing templates.
     section.setTemplateType();
     // Process preload data if any
     section.processPreloadData();
     // Apply filter if necessary
     if (searchText != null) {
       section.applyFilter(searchText);
     }
   }
 }
Ejemplo n.º 7
0
 private void refreshItems() {
   for (int i = 0; i < sections.size(); i++) {
     ListSectionProxy section = sections.get(i);
     section.refreshItems();
   }
 }
Ejemplo n.º 8
0
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      // Get section info from index
      Pair<ListSectionProxy, Pair<Integer, Integer>> info = getSectionInfoByEntryIndex(position);
      ListSectionProxy section = info.first;
      int sectionItemIndex = info.second.second;
      int sectionIndex = info.second.first;
      // check marker
      if (sectionIndex > marker[0]
          || (sectionIndex == marker[0] && sectionItemIndex >= marker[1])) {
        proxy.fireEvent(TiC.EVENT_MARKER, null, false);
        resetMarker();
      }

      View content = convertView;

      // Handles header/footer views and titles.
      if (section.isHeaderView(sectionItemIndex) || section.isFooterView(sectionItemIndex)) {
        return section.getHeaderOrFooterView(sectionItemIndex);
      } else if (section.isHeaderTitle(sectionItemIndex)
          || section.isFooterTitle(sectionItemIndex)) {
        // No content to reuse, so we create a new view
        if (content == null) {
          content = inflater.inflate(headerFooterId, null);
        }
        TextView title = (TextView) content.findViewById(titleId);
        title.setText(section.getHeaderOrFooterTitle(sectionItemIndex));
        return content;
      }

      // Handling templates
      KrollDict data = section.getListItemData(sectionItemIndex);
      TiListViewTemplate template = section.getTemplateByIndex(sectionItemIndex);

      if (content != null) {
        TiBaseListViewItem itemContent = (TiBaseListViewItem) content.findViewById(listContentId);
        section.populateViews(data, itemContent, template, sectionItemIndex, sectionIndex, content);
      } else {
        content = inflater.inflate(listItemId, null);
        TiBaseListViewItem itemContent = (TiBaseListViewItem) content.findViewById(listContentId);
        LayoutParams params = new LayoutParams();
        params.autoFillsWidth = true;
        itemContent.setLayoutParams(params);
        section.generateCellContent(
            sectionIndex, data, template, itemContent, sectionItemIndex, content);
      }
      return content;
    }