private async Task<IEnumerable> GetUpdatesDataCore(string userID)
        {
            //Get all updates
            var updates = await ParseObject.GetQuery("Update").Include("User").FindAsync();

            var updatesModel = from c in updates select new UpdateModel(c);

            var groupedData = from u in updatesModel
                              group u by u.Date.Date into groupData
                              select new
                              {
                                  Name = groupData.Key,
                                  Items = groupData
                              };

            ObservableCollection<GroupedData<UpdateModel>> data = new ObservableCollection<GroupedData<UpdateModel>>();
            foreach (var item in groupedData)
            {
                GroupedData<UpdateModel> list = new GroupedData<UpdateModel>();
                list.Key = item.Name;
                foreach (var itemInGroup in item.Items)
                {
                    list.Add(itemInGroup);
                }
                data.Add(list);
            }

            return data;
        }
        List <GroupedData> GetGroups()
        {
            List <GroupedData> groups = new List <GroupedData>();

            for (int i = 1; i < 100; i++)
            {
                var group = new GroupedData {
                    GroupName = $"Group {i}"
                };

                group.Add(new GroupItem {
                    DisplayText = $"Item {i}"
                });

                groups.Add(group);
            }

            return(groups);
        }
Exemplo n.º 3
0
        protected override void Init()
        {
            BackgroundColor = Color.Yellow;

            var list = new ObservableCollection <GroupedData>();

            for (int i = 1; i <= 2; i++)
            {
                var group = new GroupedData {
                    GroupName = $"Group #{i}"
                };

                for (int j = 1; j < 30; j++)
                {
                    var item = new MyItem {
                        Title = $"Item: #{i}-{j}", Color = (j % 2 == 0) ? Color.Blue : Color.Red
                    };

                    group.Add(item);
                }
                list.Add(group);
            }

            ListItems = list;

            BindingContext = this;
            var lst = new ListView(ListViewCachingStrategy.RecycleElement)
            {
                BackgroundColor       = Color.Transparent,
                ItemTemplate          = new DataTemplate(typeof(ItemTemplate)),
                GroupHeaderTemplate   = new DataTemplate(typeof(GroupHeaderTemplate)),
                IsGroupingEnabled     = true,
                GroupDisplayBinding   = new Binding(nameof(GroupedData.GroupName)),
                GroupShortNameBinding = new Binding(nameof(GroupedData.GroupName)),
            };

            lst.SeparatorVisibility = SeparatorVisibility.None;
            lst.SeparatorColor      = Color.Green;
            lst.SetBinding(ListView.ItemsSourceProperty, nameof(ListItems));
            Content = lst;
        }
Exemplo n.º 4
0
        async void FillResults(GroupedData results, int items, bool clear)
        {
            results.Clear();

            await Task.Delay(200);

            for (int i = 0; i < items; i++)
            {
                results.Add(new GroupItem {
                    DisplayText = $"Text for ListView item {i}"
                });
            }

            if (!clear)
            {
                return;
            }

            await Task.Delay(1000);

            results.Clear();
        }
Exemplo n.º 5
0
        private async Task <IEnumerable> GetUpdatesDataCore()
        {
            //Get all updates
            StorageFolder sf = await ApplicationData.Current.LocalFolder.CreateFolderAsync("Data", CreationCollisionOption.OpenIfExists);

            StorageFile st = await sf.CreateFileAsync("Data.xml", CreationCollisionOption.OpenIfExists);

            var updates = new List <PersonModel>();

            XmlDocument doc = new XmlDocument();

            var content = await FileIO.ReadTextAsync(st);

            if (!string.IsNullOrEmpty(content))
            {
                doc.LoadXml(content);

                var items = doc.GetElementsByTagName("person");

                foreach (var item in items)
                {
                    var person = new PersonModel();

                    foreach (var itemChild in item.ChildNodes)
                    {
                        switch (itemChild.NodeName)
                        {
                        case "Initials":
                            person.Initials = itemChild.InnerText;
                            break;

                        case "Height":
                            person.Height = double.Parse(itemChild.InnerText);
                            break;

                        case "Age":
                            person.Age = int.Parse(itemChild.InnerText);
                            break;

                        case "Bmi":
                            person.Bmi = double.Parse(itemChild.InnerText);
                            break;

                        case "Weight":
                            person.Weight = double.Parse(itemChild.InnerText);
                            break;

                        case "Sex":
                            person.SelectedSex = (SexType)Enum.Parse(typeof(SexType), itemChild.InnerText);
                            break;

                        default:
                            break;
                        }
                    }

                    updates.Add(person);
                }
            }

            var updatesModel = from c in updates
                               select new PersonModel()
            {
                Initials    = c.Initials,
                Height      = c.Height,
                Weight      = c.Weight,
                Age         = c.Age,
                Bmi         = c.Bmi,
                SelectedSex = c.SelectedSex
            };

            var groupedData = from u in updatesModel
                              group u by u.Initials into groupData
                              select new
            {
                Name  = groupData.Key,
                Items = groupData
            };

            ObservableCollection <GroupedData <PersonModel> > data = new ObservableCollection <GroupedData <PersonModel> >();

            foreach (var item in groupedData)
            {
                GroupedData <PersonModel> list = new GroupedData <PersonModel>();
                list.Key = item.Name;
                foreach (var itemInGroup in item.Items)
                {
                    list.Add(itemInGroup);
                }
                data.Add(list);
            }

            return(data);
        }
Exemplo n.º 6
0
        private IEnumerable GetUpdatesCategoriesDataCore()
        {
            var updates = new List <CategoryModel>();

            var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;

            if (localSettings.Values.ContainsKey("countCategories"))
            {
                var countCat = int.Parse(localSettings.Values["countCategories"].ToString());
                for (int i = 0; i < countCat; i++)
                {
                    if (localSettings.Values.ContainsKey("category" + i))
                    {
                        ApplicationDataCompositeValue composite = (ApplicationDataCompositeValue)localSettings.Values["category" + i];
                        var cat = new CategoryModel();
                        cat.Title = composite["title"].ToString();
                        cat.From  = double.Parse(composite["from"].ToString());
                        cat.To    = double.Parse(composite["to"].ToString());

                        updates.Add(cat);
                    }
                }
            }


            //var categories = localSettings.Values["category"];
            //var cat = new CategoryModel();
            //if (localSettings.Values["category"])
            //cat.Title = categories["title"];
            //cat.From = categories["from"];
            //cat.To = categories["to"];



            var categoriesModel = from c in updates
                                  select new CategoryModel()
            {
                Title = c.Title,
                From  = c.From,
                To    = c.To,
            };

            var groupedData = from u in categoriesModel
                              group u by u.Title into groupData
                              select new
            {
                Name  = groupData.Key,
                Items = groupData
            };

            ObservableCollection <GroupedData <CategoryModel> > data = new ObservableCollection <GroupedData <CategoryModel> >();

            foreach (var item in groupedData)
            {
                GroupedData <CategoryModel> list = new GroupedData <CategoryModel>();
                list.Key = item.Name;
                foreach (var itemInGroup in item.Items)
                {
                    list.Add(itemInGroup);
                }
                data.Add(list);
            }

            return(data);
        }
Exemplo n.º 7
0
        protected override void Init()
        {
            List <GroupedData> groups = new List <GroupedData>();

            var group1 = new GroupedData {
                GroupName = "Group #1"
            };

            group1.Add(new GroupItem {
                DisplayText = "Text for ListView item 1.1"
            });
            group1.Add(new GroupItem {
                DisplayText = "Text for ListView item 1.2"
            });
            groups.Add(group1);

            var group2 = new GroupedData {
                GroupName = "Group #2"
            };

            group2.Add(new GroupItem {
                DisplayText = "Text for ListVIew item 2.1"
            });
            group2.Add(new GroupItem {
                DisplayText = "Text for ListView item 2.2"
            });
            groups.Add(group2);

            var itemTemplate = new DataTemplate(typeof(GroupItemTemplate));

            itemTemplate.CreateContent();

            var groupHeaderTemplate = new DataTemplate(typeof(GroupHeaderTemplate));

            groupHeaderTemplate.CreateContent();

            var listView = new ListView
            {
                IsGroupingEnabled     = true,
                GroupDisplayBinding   = new Binding("GroupName"),
                GroupShortNameBinding = new Binding("GroupName"),
                HasUnevenRows         = Device.RuntimePlatform == Device.Android,

                ItemTemplate        = itemTemplate,
                GroupHeaderTemplate = groupHeaderTemplate,

                ItemsSource = groups
            };

            Content = new StackLayout
            {
                VerticalOptions = LayoutOptions.Center,
                Children        =
                {
                    new Label       {
                        Text = "The group headers below should extend to the width of the screen. If they aren't the width of the screen, this test has failed."
                    },
                    new ContentView {
                        Content           = listView,
                        HorizontalOptions = LayoutOptions.FillAndExpand,
                        Padding           = 0
                    }
                }
            };
        }