Example #1
0
        public static List <ListGroup <T> > GroupList <T>(IEnumerable <T> listToGroup, GetNameDelegate <T> getName, bool sort)
        {
            List <ListGroup <T> > groupedList = new List <ListGroup <T> >();
            SortedLocaleGrouping  slg         = new SortedLocaleGrouping(CultureInfo.InvariantCulture);

            foreach (string key in slg.GroupDisplayNames)
            {
                groupedList.Add(new ListGroup <T>(key));
            }

            foreach (T item in listToGroup)
            {
                string itemName = GetTrimmedName(getName(item));

                int index = slg.GetGroupIndex(itemName);
                if (index >= 0 && index < groupedList.Count)
                {
                    groupedList[index].Add(item);
                }
            }

            if (sort)
            {
                foreach (ListGroup <T> group in groupedList)
                {
                    group.Sort((c0, c1) => { return(CultureInfo.InvariantCulture.CompareInfo.Compare(GetTrimmedName(getName(c0)), GetTrimmedName(getName(c1)))); });
                }
            }

            return(groupedList);
        }
Example #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="sort">Will sort the data if true.</param>
        /// <returns>An items source for a LongListSelector</returns>
        public static List <AlphaKeyGroup <T> > CreateGroups(IEnumerable <T> items, CultureInfo ci, GetKeyDelegate getKey, bool sort)
        {
            var slg  = new SortedLocaleGrouping(ci);
            var list = CreateGroups(slg);

            foreach (T item in items)
            {
                var index = 0;
                if (slg.SupportsPhonetics)
                {
                    //check if your database has yomi string for item
                    //if it does not, then do you want to generate Yomi or ask the user for this item.
                    //index = slg.GetGroupIndex(getKey(Yomiof(item)));
                }
                else
                {
                    index = slg.GetGroupIndex(getKey(item));
                }
                if (index >= 0 && index < list.Count)
                {
                    list[index].Add(item);
                }
            }

            if (sort)
            {
                foreach (var group in list)
                {
                    group.Sort((c0, c1) => { return(ci.CompareInfo.Compare(getKey(c0), getKey(c1))); });
                }
            }

            return(list);
        }
Example #3
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="sort">Will sort the data if true.</param>
        /// <returns>An items source for a LongListSelector</returns>
        public static List <AlphaKeyGroup <T> > CreateGroups(IEnumerable <T> items, CultureInfo ci, GetKeyDelegate getKey, bool sort)
        {
            SortedLocaleGrouping      slg  = new SortedLocaleGrouping(ci);
            List <AlphaKeyGroup <T> > list = CreateGroups(slg);

            foreach (T item in items)
            {
                int index = 0;
                if (slg != null && !slg.SupportsPhonetics)
                {
                    string key = getKey(item);
                    if (key != null && key.Length > 0)
                    {
                        index = slg.GetGroupIndex(key);
                    }
                }
                if (index >= 0 && index < list.Count)
                {
                    list[index].Add(item);
                }
            }

            if (sort)
            {
                foreach (AlphaKeyGroup <T> group in list)
                {
                    group.Sort((c0, c1) => { return(ci.CompareInfo.Compare(getKey(c0), getKey(c1))); });
                }
            }

            return(list);
        }
Example #4
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="sort">Will sort the data if true.</param>
        /// <returns>An items source for a LongListSelector</returns>
        public static List <AlphaKeyGroup <T> > CreateGroups(IEnumerable <T> items, CultureInfo ci, Func <T, string> keySelector, bool sort)
        {
            SortedLocaleGrouping      slg  = new SortedLocaleGrouping(ci);
            List <AlphaKeyGroup <T> > list = CreateDefaultGroups(slg);

            foreach (T item in items)
            {
                int index = 0;
                //if (slg.SupportsPhonetics)
                //{
                //check if your database has yomi string for item
                //if it does not, then do you want to generate Yomi or ask the user for this item.
                //index = slg.GetGroupIndex(getKey(Yomiof(item)));
                //}
                //else
                {
                    index = slg.GetGroupIndex(keySelector(item));
                }

                if (index >= 0 && index < list.Count)
                {
                    list[index].Add(item);
                }
            }

            if (sort)
            {
                foreach (AlphaKeyGroup <T> group in list)
                {
                    group.Sort((c0, c1) => { return(ci.CompareInfo.Compare(keySelector(c0), keySelector(c1))); });
                }
            }

            return(list);
        }
Example #5
0
        public static List <Agrupamento <T> > CriaGrupos(IEnumerable <T> items, CultureInfo ci, GetKeyDelegate getKey, bool sort)
        {
            SortedLocaleGrouping    slg  = new SortedLocaleGrouping(ci);
            List <Agrupamento <T> > list = CriaGrupos(slg);

            foreach (T item in items)
            {
                int index = slg.GetGroupIndex(getKey(item));

                if (index >= 0 && index < list.Count)
                {
                    list[index].Add(item);
                }
            }

            if (sort)
            {
                foreach (Agrupamento <T> group in list)
                {
                    group.Sort((c0, c1) => { return(ci.CompareInfo.Compare(getKey(c0), getKey(c1))); });
                }
            }

            return(list);
        }
Example #6
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="keySelector"></param>
        /// <param name="sort">Will sort the data if true.</param>
        /// <returns>An items source for a LongListSelector</returns>
        public static List <AlphaKeyGroup <T> > CreateGroups(IEnumerable <T> items, CultureInfo ci, Func <T, string> keySelector, bool sort)
        {
            var slg = new SortedLocaleGrouping(ci);
            List <AlphaKeyGroup <T> > list = CreateDefaultGroups(slg);

            foreach (T item in items)
            {
                int index;
                {
                    index = slg.GetGroupIndex(keySelector(item));
                }

                if (index >= 0 && index < list.Count)
                {
                    list[index].Add(item);
                }
            }

            if (sort)
            {
                foreach (AlphaKeyGroup <T> group in list)
                {
                    group.Sort((c0, c1) => ci.CompareInfo.Compare(keySelector(c0), keySelector(c1)));
                }
            }

            return(list);
        }
Example #7
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="sort">Will sort the data if true.</param>
        /// <returns>An items source for a LongListSelector</returns>
        public static List <AlphaKeyGroup <T> > CreateGroups(IEnumerable <T> items, CultureInfo ci, GetKeyDelegate getKey, bool sort)
        {
            SortedLocaleGrouping      slg  = new SortedLocaleGrouping(ci);
            List <AlphaKeyGroup <T> > list = new List <AlphaKeyGroup <T> >();

            foreach (string key in slg.GroupDisplayNames)
            {
                if (key == "...")
                {
                    list.Add(new AlphaKeyGroup <T>(GlobeGroupKey));
                }
                else
                {
                    list.Add(new AlphaKeyGroup <T>(key));
                }
            }

            foreach (T item in items)
            {
                int index = slg.GetGroupIndex(getKey(item));
                if (index >= 0 && index < list.Count)
                {
                    list[index].Add(item);
                }
            }

            if (sort)
            {
                foreach (AlphaKeyGroup <T> group in list)
                {
                    group.Sort((c0, c1) => { return(ci.CompareInfo.Compare(getKey(c0), getKey(c1))); });
                }
            }

            return(list);
        }