Exemple #1
0
        public ItemsViewModel()
        {
            Title            = "Badges";
            LoadItemsCommand = new Command(StartLoadItems);
            AddItemCommand   = new Command(() => Navigation.PushAsync(new EditorPage(new AddItemViewModel())),
                                           () => App.DataStore.IsAvailable);
            EditItemCommand = new Command((item) =>
            {
                var vm = new EditItemViewModel(((BadgeViewModel)item).Badge);
                Navigation.PushAsync(new EditorPage(vm));
            });

            MessagingCenter.Subscribe <EditorPageViewModel>(this, "ItemChanged", (sender) =>
            {
                StartLoadItems();
            });

            MessagingCenter.Subscribe <FilterViewModel, BadgeFilter>(this, FilterViewModel.FilterChangedMessage, (sender, filter) =>
            {
                _filter = filter;
                StartLoadItems();
            });

            App.DataStore.PropertyChanged += (sender, e) =>
            {
                if (e.PropertyName == nameof(App.DataStore.IsAvailable))
                {
                    StartLoadItems();
                    AddItemCommand?.ChangeCanExecute();
                }
            };
        }
Exemple #2
0
        public FilterViewModel()
        {
            Title    = "Фильтр";
            Sections = new ObservableCollection <Section>(App.DataStore.GetGroups());
            Sections.Insert(0, Section.All);

            Years = new List <int>();
            int currentYear = DateTime.Now.Year;

            for (int i = 0; i < 10; i++)
            {
                Years.Add(currentYear - i);
            }

            App.DataStore.PropertyChanged += (sender, e) =>
            {
                if (e.PropertyName == nameof(App.DataStore.IsAvailable) && App.DataStore.IsAvailable)
                {
                    Sections.Clear();
                    Sections.Add(Section.All);
                    foreach (var item in App.DataStore.GetGroups())
                    {
                        Sections.Add(item);
                    }
                }
            };

            PropertyChanged += (sender, e) =>
            {
                if (e.PropertyName == nameof(SelectedSection) || e.PropertyName == nameof(SelectedYearIndex))
                {
                    int year      = Years[SelectedYearIndex >= 0 ? SelectedYearIndex : 0];
                    int sectionId = (SelectedSection ?? Section.All).Id;
                    var filter    = new BadgeFilter(year, sectionId);
                    MessagingCenter.Send(this, FilterChangedMessage, filter);
                }
            };
        }