Last active
August 29, 2015 14:27
-
-
Save ScottIsAFool/9f81ac757e0625de1574 to your computer and use it in GitHub Desktop.
Files needed to do inline ads/reviews/whatever
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace ScottIsAFool.Windows.Core.ViewModel | |
{ | |
public interface IListType | |
{ | |
ListType ListType { get; } | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Windows.UI.Xaml; | |
using Windows.UI.Xaml.Controls; | |
using ScottIsAFool.Windows.Core.ViewModel; | |
namespace ScottIsAFool.Windows.Data | |
{ | |
public class ItemTypeDataTemplateSelector : DataTemplateSelector | |
{ | |
public DataTemplate NormalTemplate { get; set; } | |
public DataTemplate AdTemplate { get; set; } | |
public DataTemplate ReviewTemplate { get; set; } | |
protected override DataTemplate SelectTemplateCore(object item) | |
{ | |
var listType = item as IListType; | |
if (listType == null) | |
{ | |
return base.SelectTemplateCore(item); | |
} | |
switch (listType.ListType) | |
{ | |
case ListType.Normal: | |
return NormalTemplate; | |
case ListType.Ad: | |
return AdTemplate; | |
case ListType.Review: | |
return ReviewTemplate; | |
default: | |
return base.SelectTemplateCore(item); | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace ScottIsAFool.Windows.Core.ViewModel | |
{ | |
public enum ListType | |
{ | |
Normal, | |
Review, | |
Ad | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using ScottIsAFool.Windows.Core.ViewModel; | |
namespace ScottIsAFool.Windows.Core.Extensions | |
{ | |
public static class ListTypeExtensions | |
{ | |
public static List<IListType> AddEveryOften(this IEnumerable<IListType> collectionList, int everyOften, int maxNumberToShow, IListType itemToAdd, int startAt = 0, bool addAsFirstItem = false) | |
{ | |
var list = collectionList.ToList(); | |
if (list == null || !list.Any()) | |
{ | |
return new List<IListType>(); | |
} | |
var itemsAdded = 0; | |
var numberOfItemsToAdd = Math.Floor((decimal)list.Count / everyOften); | |
for (var i = 0; i < numberOfItemsToAdd; i++) | |
{ | |
var multiplyValue = addAsFirstItem && startAt > 0 ? i : i + 1; | |
var addAt = addAsFirstItem && i == 0 ? startAt : (multiplyValue * everyOften) + startAt; | |
if (addAt > list.Count) | |
{ | |
break; | |
} | |
list.Insert(addAt, itemToAdd); | |
itemsAdded++; | |
if (itemsAdded == maxNumberToShow) | |
{ | |
break; | |
} | |
} | |
return list; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment