Пример #1
0
        public static List <AlphaKeyGroup <T> > CreateGroups(
            IEnumerable <T> items,
            CultureInfo cultureInfo,
            Func <T, string> keySelector,
            bool sort)
        {
            SortedLocaleGrouping      slg  = new SortedLocaleGrouping(cultureInfo);
            List <AlphaKeyGroup <T> > list = CreateDefaultGroups(slg);

            if (items == null)
            {
                return(null);
            }

            int index = 0;

            foreach (T item in items)
            {
                index++;

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

            return(list);
        }
Пример #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);
        }
Пример #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);
        }
Пример #4
0
 /// <summary>
 /// Create a list of AlphaGroup{T} with keys set by a SortedLocaleGrouping.
 /// </summary>
 /// <param name="slg">The </param>
 /// <returns>Theitems source for a LongListSelector</returns>
 private static List <AlphaKeyGroup <T> > CreateDefaultGroups(SortedLocaleGrouping slg)
 {
     return(slg.GroupDisplayNames
            .Select(key => key == "..." ? GlobeGroupKey : key)
            .Select(key => new AlphaKeyGroup <T>(key))
            .ToList());
 }
Пример #5
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);
        }
Пример #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="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);
        }
Пример #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="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);
        }
Пример #8
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);
        }
    /// <summary>
    /// Create a list of AlphaGroup<T> with keys set by a SortedLocaleGrouping.
    /// </summary>
    /// <param name="slg">The </param>
    /// <returns>Theitems source for a LongListSelector</returns>
    private static List <LonglistSelectorPivot1 <T> > CreateGroups(SortedLocaleGrouping slg)
    {
        List <LonglistSelectorPivot1 <T> > list = new List <LonglistSelectorPivot1 <T> >();

        foreach (string key in slg.GroupDisplayNames)
        {
            list.Add(new LonglistSelectorPivot1 <T>(key));
        }
        return(list);
    }
Пример #10
0
        /// <summary>
        /// Create a list of AlphaGroup<T> with keys set by a SortedLocaleGrouping.
        /// </summary>
        /// <param name="slg">The </param>
        /// <returns>Theitems source for a LongListSelector</returns>
        private static List <AlphaKeyGroup <T> > CreateGroups(SortedLocaleGrouping slg)
        {
            List <AlphaKeyGroup <T> > list = new List <AlphaKeyGroup <T> >();

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

            return(list);
        }
Пример #11
0
        /// <summary>
        /// Create a list of AlphaGroup<T> with keys set by a SortedLocaleGrouping.
        /// </summary>
        /// <param name="slg">The </param>
        /// <returns>Theitems source for a LongListSelector</returns>
        private static ObservableCollection <AlphaKeyGroup <T> > CreateGroups(SortedLocaleGrouping slg)
        {
            ObservableCollection <AlphaKeyGroup <T> > list = new ObservableCollection <AlphaKeyGroup <T> >();

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

            return(list);
        }
Пример #12
0
        private static List <Agrupamento <T> > CriaGrupos(SortedLocaleGrouping slg)
        {
            List <Agrupamento <T> > list = new List <Agrupamento <T> >();

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

            return(list);
        }
Пример #13
0
        /// <summary>
        /// Create a list of AlphaGroup<T> with keys set by a SortedLocaleGrouping.
        /// </summary>
        /// <param name="slg">The </param>
        /// <returns>The items source for a LongListSelector</returns>
        private static List <AlphaKeyGroup <T> > CreateGroups(SortedLocaleGrouping slg)
        {
            List <AlphaKeyGroup <T> > list = new List <AlphaKeyGroup <T> >();

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

            return(list);
        }
Пример #14
0
        private static List <AlphaKeyGroup <T> > CreateDefaultGroups(SortedLocaleGrouping slg)
        {
            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));
                }
            }

            return(list);
        }
Пример #15
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);
        }
Пример #16
0
 /// <summary>
 /// Create a list of AlphaGroup<T> with keys set by a SortedLocaleGrouping.
 /// </summary>
 /// <param name="slg">The </param>
 /// <returns>Theitems source for a LongListSelector</returns>
 private static List <AlphaKeyGroup <T> > CreateGroups(SortedLocaleGrouping slg)
 {
     return(slg.GroupDisplayNames.Select(key => new AlphaKeyGroup <T>(key)).ToList());
 }
 /// <summary>
 /// Create a list of AlphaGroup<T> with keys set by a SortedLocaleGrouping.
 /// </summary>
 /// <param name="slg">The </param>
 /// <returns>Theitems source for a LongListSelector</returns>
 private static ObservableCollection <AlphaKeyGroup <T> > CreateGroups(SortedLocaleGrouping slg)
 {
     return(new ObservableCollection <AlphaKeyGroup <T> >(slg.GroupDisplayNames.Select(key => new AlphaKeyGroup <T>(key)).ToList()));
 }