internal RvAdapter(Context context, IVirtualListViewAdapter adapter) { Context = context; this.adapter = adapter; templates = new List <Xamarin.Forms.DataTemplate>(); }
public (int realSectionIndex, int realItemIndex) GetRealIndexPath(IVirtualListViewAdapter adapter, int sectionIndex, int itemIndex) { var realSectionIndex = sectionIndex; if (HasGlobalHeader) { if (sectionIndex == 0) { return(-1, -1); } // Global header takes up a section, real adapter is 1 less realSectionIndex--; } var realNumberOfSections = adapter.Sections; if (HasGlobalFooter) { if (realSectionIndex >= realNumberOfSections) { return(-1, -1); } } var realItemsInSection = adapter.ItemsForSection(realSectionIndex); var realItemIndex = itemIndex; if (HasSectionHeader) { realItemIndex--; if (itemIndex == 0) { return(-1, -1); } } if (HasSectionFooter) { if (realItemIndex >= realItemsInSection) { return(-1, -1); } } return(realSectionIndex, realItemIndex); }
protected override void OnElementChanged(ElementChangedEventArgs <VirtualListView> e) { base.OnElementChanged(e); // Clean up old if (e.OldElement != null) { } // Setup new if (e.NewElement != null) { TemplateSelector = CreateTemplateSelector(); Adapter = e.NewElement.Adapter; // Create the native control if (Control == null) { layout = new CvLayout(); layout.EstimatedItemSize = UICollectionViewFlowLayout.AutomaticSize; layout.SectionInset = new UIEdgeInsets(0, 0, 0, 0); layout.MinimumInteritemSpacing = 0f; layout.MinimumLineSpacing = 0f; DataSource = new CvDataSource(this); DataSource.IsSelectedHandler = (realSection, realIndex) => e?.NewElement?.IsItemSelected(realSection, realIndex) ?? false; cvdelegate = new CvDelegate(this); collectionView = new UICollectionView(this.Frame, layout); collectionView.AllowsSelection = e.NewElement.SelectionMode != SelectionMode.None; collectionView.AllowsMultipleSelection = e.NewElement.SelectionMode == SelectionMode.Multiple; collectionView.DataSource = DataSource; collectionView.ContentInset = new UIEdgeInsets(0, 0, 0, 0); collectionView.Delegate = cvdelegate; SetNativeControl(collectionView); collectionView.ReloadData(); } } }
public int GetTotalCount(IVirtualListViewAdapter adapter) { if (adapter == null) { return(0); } var sum = 0; if (HeaderTemplate != null) { sum += 1; } if (adapter != null) { for (int i = 0; i < adapter.Sections; i++) { if (SectionHeaderTemplate != null || SectionHeaderTemplateSelector != null) { sum += 1; } sum += adapter.ItemsForSection(i); if (SectionFooterTemplate != null || SectionFooterTemplateSelector != null) { sum += 1; } } } if (FooterTemplate != null) { sum += 1; } return(sum); }
public override DataTemplate SelectItemTemplate(IVirtualListViewAdapter adapter, int sectionIndex, int itemIndex) { var item = adapter.Item(sectionIndex, itemIndex); if (item is TrackInfo trackInfo) { var genreId = trackInfo.GenreId; if (genreId == 9) { return(PopTemplate); } //if (genreId == 1 || genreId == 3 || genreId == 4 || genreId == 5 || genreId == 13) // return HeavyTemplate; else if (genreId == 10 || genreId == 19 || genreId == 18 || genreId == 21 || genreId == 22) { return(FilmTemplate); } } return(GenericTemplate); }
public PositionInfo GetInfo(IVirtualListViewAdapter adapter, int position) { if (adapter == null) { return(null); } var linear = 0; var numberSections = adapter.Sections; if (HeaderTemplate != null) { if (position == 0) { return new PositionInfo { Position = position, Kind = PositionKind.Header } } ; linear++; } for (int s = 0; s < numberSections; s++) { if (SectionHeaderTemplate != null || SectionHeaderTemplateSelector != null) { if (position == linear) { return new PositionInfo { SectionIndex = s, Position = position, BindingContext = adapter.Section(s), Kind = PositionKind.SectionHeader } } ; linear++; } var itemsInSection = adapter.ItemsForSection(s); // It's an item in the section, return it for this item if (position < linear + itemsInSection) { var itemIndex = position - linear; return(new PositionInfo { SectionIndex = s, NumberOfSections = numberSections, ItemIndex = itemIndex, ItemsInSection = itemsInSection, Position = position, BindingContext = adapter.Item(s, itemIndex), Kind = PositionKind.Item }); } linear += itemsInSection; if (SectionFooterTemplate != null || SectionFooterTemplateSelector != null) { if (position == linear) { return new PositionInfo { SectionIndex = s, Position = position, BindingContext = adapter.Section(s), Kind = PositionKind.SectionFooter } } ; linear++; } } return(new PositionInfo { Position = position, Kind = PositionKind.Footer }); }
public DataTemplate GetTemplate(IVirtualListViewAdapter adapter, int position) { if (position == 0) { if (HeaderTemplate != null) { return(HeaderTemplate); } if (SectionHeaderTemplateSelector != null) { return(SectionHeaderTemplateSelector.SelectGroupTemplate(adapter, 0)); } if (SectionHeaderTemplate != null) { return(SectionHeaderTemplate); } } var linear = 0; if (HeaderTemplate != null) { linear++; } for (int s = 0; s < adapter.Sections; s++) { if (HasSectionHeader) { if (position == linear) { return(SectionHeaderTemplateSelector?.SelectGroupTemplate(adapter, s) ?? SectionHeaderTemplate); } linear++; } var itemsInSection = adapter.ItemsForSection(s); // It's an item in the section, return it for this item if (position < linear + itemsInSection) { var itemIndex = position - linear; return(ItemTemplateSelector?.SelectItemTemplate(adapter, s, itemIndex) ?? ItemTemplate); } linear += itemsInSection; if (HasSectionFooter) { if (position == linear) { return(SectionFooterTemplateSelector?.SelectGroupTemplate(adapter, s) ?? SectionFooterTemplate); } linear++; } } return(FooterTemplate); }
public (DataTemplate template, PositionInfo info) GetTemplateAndInfo(IVirtualListViewAdapter adapter, int sectionIndex, int itemIndex) { var realSectionIndex = sectionIndex; if (HasGlobalHeader) { if (sectionIndex == 0) { return(HeaderTemplate, new PositionInfo { Kind = PositionKind.Header }); } // Global header takes up a section, real adapter is 1 less realSectionIndex--; } var realNumberOfSections = adapter.Sections; if (HasGlobalFooter) { if (realSectionIndex >= realNumberOfSections) { return(FooterTemplate, new PositionInfo { Kind = PositionKind.Footer }); } } var realItemsInSection = adapter.ItemsForSection(realSectionIndex); var realItemIndex = itemIndex; var itemsAdded = 0; if (HasSectionHeader) { itemsAdded++; realItemIndex--; if (itemIndex == 0) { return(SectionHeaderTemplateSelector?.SelectGroupTemplate(adapter, realSectionIndex) ?? SectionHeaderTemplate, new PositionInfo { Kind = PositionKind.SectionHeader, ItemsInSection = realItemsInSection, SectionIndex = realSectionIndex, BindingContext = adapter.Section(realSectionIndex), NumberOfSections = realNumberOfSections }); } } if (HasSectionFooter) { itemsAdded++; if (itemIndex >= realItemsInSection + itemsAdded - 1) { return(SectionFooterTemplateSelector?.SelectGroupTemplate(adapter, realSectionIndex) ?? SectionFooterTemplate, new PositionInfo { Kind = PositionKind.SectionFooter, ItemsInSection = realItemsInSection, SectionIndex = realSectionIndex, BindingContext = adapter.Section(realSectionIndex), NumberOfSections = realNumberOfSections }); } } return(ItemTemplateSelector?.SelectItemTemplate(adapter, realSectionIndex, realItemIndex) ?? ItemTemplate, new PositionInfo { Kind = PositionKind.Item, ItemsInSection = realItemsInSection, SectionIndex = realSectionIndex, ItemIndex = realItemIndex, BindingContext = adapter.Item(realSectionIndex, realItemIndex), NumberOfSections = realNumberOfSections, }); }
public abstract DataTemplate SelectItemTemplate(IVirtualListViewAdapter adapter, int sectionIndex, int itemIndex);
public abstract DataTemplate SelectGroupTemplate(IVirtualListViewAdapter adapter, int sectionIndex);
public static object DataFor(this IVirtualListViewAdapter vlva, PositionKind kind, int sectionIndex, int itemIndex) => kind switch {