/// <summary>
        /// Create a list of AlphaGroup{T} with keys set by a SortedLocaleGrouping.
        /// </summary>
        /// <param name="items">The items to place in the groups.</param>
        /// <param name="getKey">A delegate to get the key from an item.</param>
        /// <param name="getSortKey">A delegate to get the key for sorting from an item.</param>
        /// <param name="sort">Will sort the data if true.</param>
        /// <param name="itemClickCommand">The command to execute on a click.</param>
        /// <returns>An items source for a LongListSelector</returns>
        public static List <DateListGroupCollection <T> > CreateGroups(IEnumerable <T> items,
                                                                       GetKeyDelegate getKey,
                                                                       GetSortKeyDelegate getSortKey,
                                                                       bool sort = true,
                                                                       RelayCommand <T>?itemClickCommand = null)
        {
            ThrowIfNull(items);

            var list = new List <DateListGroupCollection <T> >();

            foreach (T item in items)
            {
                string index = getKey(item);

                if (list.All(a => a.Key != index))
                {
                    list.Add(new DateListGroupCollection <T>(index, itemClickCommand));
                }

                if (!string.IsNullOrEmpty(index))
                {
                    list.Find(a => a.Key == index).Add(item);
                }
            }

            if (sort)
            {
                foreach (DateListGroupCollection <T> group in list)
                {
                    group.Sort((c0, c1) => getSortKey(c1).Date.Day.CompareTo(getSortKey(c0).Date.Day));
                }
            }

            return(list);
        }
Esempio n. 2
0
        /// <summary>
        ///     Create a list of AlphaGroup<T> with keys set by a SortedLocaleGrouping.
        /// </summary>
        /// <param name="items">The items to place in the groups.</param>
        /// <param name="ci">The CultureInfo to group and sort by.</param>
        /// <param name="getKey">A delegate to get the key from an item.</param>
        /// <param name="getSortKey">A delegate to get the key for sorting from an item.</param>
        /// <param name="sort">Will sort the data if true.</param>
        /// <returns>An items source for a LongListSelector</returns>
        public static List <DateListGroup <T> > CreateGroups(IEnumerable <T> items, CultureInfo ci, GetKeyDelegate getKey,
                                                             GetSortKeyDelegate getSortKey, bool sort)
        {
            var list = new List <DateListGroup <T> >();

            foreach (var item in items)
            {
                var index = getKey(item);

                if (list.All(a => a.Key != index))
                {
                    list.Add(new DateListGroup <T>(index));
                }

                if (!string.IsNullOrEmpty(index))
                {
                    list.Find(a => a.Key == index).Add(item);
                }
            }

            if (sort)
            {
                foreach (var group in list)
                {
                    group.Sort((c0, c1) => getSortKey(c1).Date.Day.CompareTo(getSortKey(c0).Date.Day));
                }
            }

            return(list);
        }