public MainPageViewModel(INavigationService navigationService)
            : base(navigationService)
        {
            Title = "Main Page";

            LotteryNumbers = new ObservableCollection <int>(Enumerable.Range(1, Persons.Count));

            AddCommand.Subscribe(() =>
            {
                var temp = new Person
                {
                    Name = "Hoge",
                    Age  = 50,
                };
                Persons.Add(temp);
            });

            DeleteCommand.Subscribe(() =>
            {
                if (Persons.Count > 0)
                {
                    Persons.Remove(Persons.FirstOrDefault());
                }
            });

            Persons.ObserveAddChanged().Subscribe(list =>
            {
                LotteryNumbers.Add(Persons.Count);
            });

            Persons.ObserveRemoveChanged().Subscribe(list =>
            {
                LotteryNumbers.Remove(Persons.Count + 1);
            });
        }
        public MainPageViewModel(TodoUsecase todoUsecase)
        {
            TodoItems = todoUsecase.TodoItems.ToReadOnlyReactiveCollection();

            IsVisibleDone = todoUsecase.IsVisibleDone;
            FilterLabel   = IsVisibleDone.Select(x => x ? "Hide Done" : "Show Done").ToReadOnlyReactiveProperty();

            ToggleShowDoneCommand.Subscribe(async _ =>
            {
                await todoUsecase.ToggleShowDone();
            });

            AddCommand.Subscribe(async _ =>
            {
                var newItem = await todoUsecase.Add();
                OpenNewTodoPageRequest?.Invoke(this, newItem);
            });

            DeleteCommand.Subscribe(async item =>
            {
                await todoUsecase.Delete(item);
            });

            UndoneCommand.Subscribe(async item =>
            {
                await todoUsecase.Undone(item);
            });


            todoUsecase.LoadItems();
        }
        public MainWindowViewModel(IMainWindowModel model)
        {
            if (model is null)
            {
                return;
            }

            _disposables = new CompositeDisposable();
            _model       = model;
            if (_model is IDisposable disposableModel)
            {
                _disposables.Add(disposableModel);
            }

            StartupShortcuts = _model.StartupShortcuts
                               .Select(x => x?.Select(i => new ShortcutForDisplay(i)).ToList())
                               .ToReadOnlyReactivePropertySlim(new List <ShortcutForDisplay>())
                               .AddTo(_disposables);

            AddCommand
            .Subscribe(AddShortcut)
            .AddTo(_disposables);

            RemoveCommand
            .Subscribe(RemoveShortcut)
            .AddTo(_disposables);

            OpenExplorerCommand
            .Subscribe(OpenExplorer)
            .AddTo(_disposables);
        }
 public PalettePartsListViewModel()
 {
     _palettePartsRepository = new PalettePartsSQLServer();
     GetPalettes();
     UpdateCommand.Subscribe(_ => Update());
     DeleteCommand.Subscribe(_ => Delete());
     AddCommand.Subscribe(_ => AddCommandExecute());
     SelectedPalette.Subscribe(_ => SelectedPaletteChangeExecute());
 }
        public RepeatableFlexPageViewModel(INavigationService navigationService, IPageDialogService pageDlg)
        {
            FlexDirection.Value   = Xamarin.Forms.FlexDirection.Row;
            FlexAlignItems.Value  = Xamarin.Forms.FlexAlignItems.Start;
            FlexJustify.Value     = Xamarin.Forms.FlexJustify.Start;
            FlexWrap.Value        = Xamarin.Forms.FlexWrap.NoWrap;
            ScrollDirection.Value = ScrollOrientation.Horizontal;

            SetColors(DirectionColor, 0);
            SetColors(AColor, 3);
            SetColors(JColor, 3);
            SetColors(WrapColor, 0);

            DirectionCommand.Subscribe(x => {
                var idx             = int.Parse(x);
                FlexDirection.Value = (Xamarin.Forms.FlexDirection)idx;
                SetScrollDirection();
                SetColors(DirectionColor, idx);
            });
            AlignItemsCommand.Subscribe(x => {
                var idx = int.Parse(x);
                FlexAlignItems.Value = (Xamarin.Forms.FlexAlignItems)idx;
                SetColors(AColor, idx);
            });
            JustifyContentCommand.Subscribe(x => {
                var idx           = int.Parse(x);
                FlexJustify.Value = (Xamarin.Forms.FlexJustify)idx;
                SetColors(JColor, idx);
            });
            WrapCommand.Subscribe(x => {
                var idx        = int.Parse(x);
                FlexWrap.Value = (Xamarin.Forms.FlexWrap)idx;
                SetScrollDirection();
                SetColors(WrapColor, idx);
            });


            BoxList = new ObservableCollection <Hoge>(Shuffle());

            AddCommand.Subscribe(_ => {
                BoxList.Add(GetNextItem());
            });

            DeleteCommand.Subscribe(_ => {
                BoxList.Remove(BoxList.Last());
            });

            ReplaceCommand.Subscribe(__ => {
                BoxList[0] = GetNextItem();
            });

            ClearCommand.Subscribe(__ => {
                BoxList.Clear();
            });
        }
        public DataTemplateTestViewModel(IPageDialogService pageDlg)
        {
            ItemsSource = new ObservableCollection <Person>(
                new List <Person>
            {
                new Person {
                    Name = "ABC", Days = "1,2,3,4"
                },
                new Person {
                    Name = "DEF", Days = "5,6,7,8"
                },
            }
                );

            DoCommand.Subscribe(async _ => {
                await pageDlg.DisplayAlertAsync("", "Command", "OK");
            });

            AddCommand.Subscribe(_ => {
                ItemsSource.Add(new Person {
                    Name = "Add", Days = "9,9,9,9"
                });
            });

            DelCommand.Subscribe(_ => {
                ItemsSource.Remove(ItemsSource.Last());
            });

            RepCommand.Subscribe(_ => {
                ItemsSource[0] = new Person {
                    Name = "Rep", Days = "1,1,1,1"
                };
            });

            ClrCommand.Subscribe(_ => {
                ItemsSource.Clear();
            });

            BtmCommand.Subscribe(_ => {
                ScrollToBottom.Value = true;
            });

            TopCommand.Subscribe(_ => {
                ScrollToTop.Value = true;
            });
        }
Example #7
0
        public RepeatableStackPageViewModel(INavigationService navigationService, IPageDialogService pageDlg)
        {
            BoxList = new ObservableCollection <Hoge>(Shuffle());

            AddCommand.Subscribe(_ => {
                BoxList.Add(GetNextItem());
            });

            DeleteCommand.Subscribe(_ => {
                BoxList.Remove(BoxList.Last());
            });

            ReplaceCommand.Subscribe(__ => {
                BoxList[0] = GetNextItem();
            });

            ClearCommand.Subscribe(__ => {
                BoxList.Clear();
            });
        }
Example #8
0
        private void ConfigureAddCommand()
        {
            var canAdd = this.WhenAny(x => x.Adding, x => x.Complete, (a, c) => !a.Value && !c.Value);

            AddCommand = ReactiveCommand.CreateFromObservable(_cacheService.LoadNextPullRequests, canAdd);
            AddCommand.IsExecuting.ToPropertyEx(this, x => x.Adding);
            AddCommand.ThrownExceptions.SelectMany(ex => ExceptionInteraction.Handle(ex)).Subscribe();
            AddCommand.Subscribe(x =>
            {
                //Check if there are more pull request
                if (x.Any())
                {
                    _pullRequestData.AddRange(x);
                }

                //Check if response has result per page configured on IGitHubApi
                if (!x.Any() || x.Count() < 50)
                {
                    Complete = true;
                }
            });
        }
Example #9
0
        public MainWindowViewModel()
        {
            Countries = CountriesSource.ToReadOnlyReactiveCollection();

            AddCommand.Subscribe(async _ =>
            {
                await Task.Run(() =>
                {
                    CountriesSource.Add(new CountryViewModel());
                });
            });

            DelCommand.Subscribe(async _ =>
            {
                await Task.Run(() =>
                {
                    if (CountriesSource.Count > 0)
                    {
                        CountriesSource.RemoveAt(CountriesSource.Count - 1);
                    }
                });
            });
        }
Example #10
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);
            });
        }
 /// <summary>
 /// コンストラクタ
 /// </summary>
 public MainWindowViewModel()
 {
     AddCommand.Subscribe(addData).AddTo(Disposable);
     DeleteCommand.Subscribe(deleteData).AddTo(Disposable);
     ClosedCommand.Subscribe(Close).AddTo(Disposable);
 }
        public CollectionViewModel(TProperty property, ViewModelFactory factory) : base(property)
        {
            Collection = property.Collection.ToReadOnlyReactiveCollection(x =>
            {
                IPropertyViewModel vm = null;
                try
                {
                    vm = factory.Create(x);
                }
                catch (Exception e)
                {
                    OnErrorSubject.OnNext(e);
                    return(null);
                }
                vm.OnChanged.Subscribe(y => OnChangedSubject.OnNext(Unit.Default));
                vm.OnError.Subscribe(e => OnErrorSubject.OnNext(e));
                return(vm);
            });

            FormatedString = Property.Count.Select(x => $"Count = {x}")
                             .ToReactiveProperty(mode: ReactivePropertyMode.RaiseLatestValueOnSubscribe);

            AddCommand.Subscribe(x =>
            {
                try
                {
                    Property.AddNewElement();
                }
                catch (Exception e)
                {
                    OnErrorSubject.OnNext(e);
                }
                OnChangedSubject.OnNext(Unit.Default);
            });
            RemoveCommand.Subscribe(x =>
            {
                try
                {
                    Property.RemoveElementAt(x);
                }
                catch (Exception e)
                {
                    OnErrorSubject.OnNext(e);
                }
                OnChangedSubject.OnNext(Unit.Default);
            });
            EditCommand.Subscribe(x => ShowDetailSubject.OnNext(this));

            UpCommand.Subscribe(x =>
            {
                Property.Move(x - 1, x);
                SelectedIndex.Value = x - 1;
            });
            DownCommand.Subscribe(x =>
            {
                Property.Move(x + 1, x);
                SelectedIndex.Value = x;
            });

            DuplicateCommand.Subscribe(x =>
            {
                Property.Duplicate(x, x + 1);
            });
        }