示例#1
0
        void InitializeProperties()
        {
            var list1 = new List <PhotoItem>();

            for (var i = 0; i < 20; i++)
            {
                list1.Add(new PhotoItem
                {
                    PhotoUrl = $"https://kamusoft.jp/openimage/nativecell/{i + 1}.jpg",
                    Title    = $"Title {i + 1}",
                    Category = "AAA",
                });
            }
            var list2 = new List <PhotoItem>();

            for (var i = 10; i < 15; i++)
            {
                list2.Add(new PhotoItem
                {
                    PhotoUrl = $"https://kamusoft.jp/openimage/nativecell/{i + 1}.jpg",
                    Title    = $"Title {i + 1}",
                    Category = "BBB",
                });
            }
            var list3 = new List <PhotoItem>();

            for (var i = 5; i < 20; i++)
            {
                list3.Add(new PhotoItem
                {
                    PhotoUrl = $"https://kamusoft.jp/openimage/nativecell/{i + 1}.jpg",
                    Title    = $"Title {i + 1}",
                    Category = "CCC",
                });
            }
            var list4 = new List <PhotoItem>();

            for (var i = 1; i < 10; i++)
            {
                list4.Add(new PhotoItem
                {
                    PhotoUrl = $"https://kamusoft.jp/openimage/nativecell/{i + 1}.jpg",
                    Title    = $"Title {i + 1}",
                    Category = "DDD",
                });
            }

            var noGroupList = new List <PhotoItem>();

            for (var i = 0; i < 20; i++)
            {
                noGroupList.Add(new PhotoItem
                {
                    PhotoUrl = $"https://kamusoft.jp/openimage/nativecell/{i + 1}.jpg",
                    Title    = $"Title {i + 1}",
                    Category = "AAA",
                });
            }
            ItemsSource2 = new PhotoGroup(noGroupList);

            var group1 = new PhotoGroup(list1)
            {
                Head = "SecA"
            };
            var group2 = new PhotoGroup(list2)
            {
                Head = "SecB"
            };
            var group3 = new PhotoGroup(list3)
            {
                Head = "SecC"
            };

            ItemsSource.Add(group1);
            ItemsSource.Add(group2);
            ItemsSource.Add(group3);
            _additionalGroup = new PhotoGroup(list4)
            {
                Head = "SEC4"
            };

            TapCommand.Subscribe(async item =>
            {
                var photo = item as PhotoItem;
                await _pageDlg.DisplayAlertAsync("", $"Tap {photo.Title}", "OK");
            });

            LongTapCommand.Subscribe(async item =>
            {
                var photo = item as PhotoItem;
                await _pageDlg.DisplayAlertAsync("", $"LongTap {photo.Title}", "OK");
            });

            var addItem = new PhotoItem
            {
                PhotoUrl = $"https://kamusoft.jp/openimage/nativecell/1.jpg",
                Title    = $"AddItem",
                Category = "AAA"
            };

            var addPtn = 0;

            AddCommand.Subscribe(_ =>
            {
                switch (addPtn)
                {
                case 0:
                    group1.Add(addItem);
                    break;

                case 1:
                    group1.Insert(0, addItem);
                    break;

                case 2:
                    group1.Insert(group1.Count / 2, addItem);
                    break;
                }

                addPtn++;
                if (addPtn > 2)
                {
                    addPtn = 0;
                }
            });

            var delPtn = 0;

            DelCommand.Subscribe(_ =>
            {
                switch (delPtn)
                {
                case 0:
                    group1.RemoveAt(0);
                    break;

                case 1:
                    group1.RemoveAt(group1.Count / 2);
                    break;

                case 2:
                    group1.RemoveAt(group1.Count - 1);
                    break;
                }
                delPtn++;
                if (delPtn > 2)
                {
                    delPtn = 0;
                }
            });

            RepCommand.Subscribe(_ =>
            {
                group1[0] = addItem;
            });

            MoveCommand.Subscribe(_ =>
            {
                group1.Move(0, 3);
            });


            AddSecCommand.Subscribe(_ =>
            {
                ItemsSource.Add(_additionalGroup);
            });

            DelSecCommand.Subscribe(_ =>
            {
                ItemsSource.RemoveAt(ItemsSource.Count - 1);
            });
        }
示例#2
0
        public DemoPageViewModel(IPageDialogService pageDialog, IToast toast)
        {
            _toast   = toast;
            _pageDlg = pageDialog;

            var list1 = new List <PhotoItem>();

            for (var i = 0; i < 20; i++)
            {
                list1.Add(new PhotoItem
                {
                    PhotoUrl = $"https://kamusoft.jp/openimage/nativecell/{i + 1}.jpg",
                    Title    = $"Title {i + 1}",
                    Category = "AAA",
                });
            }
            var list2 = new List <PhotoItem>();

            for (var i = 10; i < 15; i++)
            {
                list2.Add(new PhotoItem
                {
                    PhotoUrl = $"https://kamusoft.jp/openimage/nativecell/{i + 1}.jpg",
                    Title    = $"Title {i + 1}",
                    Category = "BBB",
                });
            }
            var list3 = new List <PhotoItem>();

            for (var i = 5; i < 20; i++)
            {
                list3.Add(new PhotoItem
                {
                    PhotoUrl = $"https://kamusoft.jp/openimage/nativecell/{i + 1}.jpg",
                    Title    = $"Title {i + 1}",
                    Category = "CCC",
                });
            }

            var group1 = new PhotoGroup(list1)
            {
                Head = "SectionA"
            };
            var group2 = new PhotoGroup(list2)
            {
                Head = "SectionB"
            };
            var group3 = new PhotoGroup(list3)
            {
                Head = "SectionC"
            };

            ItemsSource.Add(group1);
            ItemsSource.Add(group2);
            ItemsSource.Add(group3);
            ItemsSourceH.Add(group1);
            ItemsSourceH.Add(group2);

            TapCommand.Subscribe(async item => {
                var photo = item as PhotoItem;
                await _pageDlg.DisplayAlertAsync("", $"Tap {photo.Title}", "OK");
            });

            LongTapCommand.Subscribe(async item => {
                var photo = item as PhotoItem;
                await _pageDlg.DisplayAlertAsync("", $"LongTap {photo.Title}", "OK");
            });

            RefreshCommand.Subscribe(async _ => {
                await Task.Delay(3000);
                IsRefreshing.Value = false;
            });

            NextCommand.Subscribe(NextAction);

            var loadCount = 1;

            LoadMoreCommand.Subscribe(_ =>
            {
                if (loadCount == 10)
                {
                    SetEndLoadMore(true);
                    return;
                }
                var list = new List <PhotoItem>();
                for (var i = 5; i < 20; i++)
                {
                    list.Add(new PhotoItem
                    {
                        PhotoUrl = $"https://kamusoft.jp/openimage/nativecell/{i + 1}.jpg",
                        Title    = $"Title {i + 1}",
                        Category = "XXX",
                    });
                }

                var group = new PhotoGroup(list)
                {
                    Head = $"SectionX{loadCount}"
                };
                ItemsSource.Add(group);
                SetEndLoadMore(false);
                loadCount++;
            });

            var loadHCount = 1;

            LoadMoreHCommand.Subscribe(_ =>
            {
                if (loadHCount == 10)
                {
                    SetEndLoadMoreH(true);
                    return;
                }
                var list = new List <PhotoItem>();
                for (var i = 5; i < 20; i++)
                {
                    list.Add(new PhotoItem
                    {
                        PhotoUrl = $"https://kamusoft.jp/openimage/nativecell/{i + 1}.jpg",
                        Title    = $"Title {i + 1}",
                        Category = "XXX",
                    });
                }

                var group = new PhotoGroup(list)
                {
                    Head = $"SectionX{loadHCount}"
                };
                ItemsSourceH.Add(group);
                SetEndLoadMoreH(false);
                loadHCount++;
            });

            SetDemoItems();
        }