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 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, }); }