public void Should_raise_changed_event_when_adding_deleting_and_manual()
        {
            var changedEvents = new List <NotifyCollectionChangedEventArgs>();
            var collection    = new CustomObservableCollection <string>();

            collection.CollectionChanged += (s, e) => changedEvents.Add(e);

            collection.Add("one");
            collection.Add("two");
            collection.Remove("one");
            collection.RaiseCollectionChanged();

            Assert.AreEqual(4, changedEvents.Count);

            Assert.AreEqual(NotifyCollectionChangedAction.Add, changedEvents[0].Action);
            Assert.AreEqual("one", changedEvents[0].NewItems.OfType <string>().FirstOrDefault());

            Assert.AreEqual(NotifyCollectionChangedAction.Add, changedEvents[1].Action);
            Assert.AreEqual("two", changedEvents[1].NewItems.OfType <string>().FirstOrDefault());

            Assert.AreEqual(NotifyCollectionChangedAction.Remove, changedEvents[2].Action);
            Assert.AreEqual("one", changedEvents[2].OldItems.OfType <string>().FirstOrDefault());

            Assert.AreEqual(NotifyCollectionChangedAction.Reset, changedEvents[3].Action);
        }
 /// <summary>
 /// When the Add Affected organ is clicked, the selected organ is added to affected organs
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void AddAffectedOrganClicked(object sender, EventArgs e)
 {
     if (NewAffectedOrganPicker.SelectedItem == null)
     {
         // List is empty
         return;
     }
     organsAffected.Add(NewAffectedOrganPicker.SelectedItem.ToString());
     organsAvailable.Remove(NewAffectedOrganPicker.SelectedItem.ToString());
 }
 private void RemoveClients(IList list)
 {
     foreach (object item in list)
     {
         if (item is XMPPClient client)
         {
             foreach (AccountDataTemplate account in ACCOUNTS)
             {
                 if (account.Client == client)
                 {
                     ACCOUNTS.Remove(account);
                     break;
                 }
             }
         }
     }
 }
Exemplo n.º 4
0
        public void replaceOmemoPreKey(uint preKeyId, IOmemoStore omemoStore)
        {
            // Remove key:
            foreach (PreKeyRecord key in OMEMO_PRE_KEYS)
            {
                if (key.getId() == preKeyId)
                {
                    OMEMO_PRE_KEYS.Remove(key);
                    omemoStore.RemovePreKey(preKeyId);
                    break;
                }
            }

            // Generate new key:
            PreKeyRecord newKey = KeyHelper.generatePreKeys(preKeyId, 1)[0];

            OMEMO_PRE_KEYS.Add(newKey);
            omemoStore.StorePreKey(newKey.getId(), newKey);
            omemoBundleInfoAnnounced = false;
        }
        public void Should_raise_changed_event_when_adding_deleting_and_manual()
        {
            var changedEvents = new List<NotifyCollectionChangedEventArgs>();
            var collection = new CustomObservableCollection<string>();
            collection.CollectionChanged += (s, e) => changedEvents.Add(e);

            collection.Add("one");
            collection.Add("two");
            collection.Remove("one");
            collection.RaiseCollectionChanged();

            Assert.AreEqual(4, changedEvents.Count);

            Assert.AreEqual(NotifyCollectionChangedAction.Add, changedEvents[0].Action);
            Assert.AreEqual("one", changedEvents[0].NewItems.OfType<string>().FirstOrDefault());

            Assert.AreEqual(NotifyCollectionChangedAction.Add, changedEvents[1].Action);
            Assert.AreEqual("two", changedEvents[1].NewItems.OfType<string>().FirstOrDefault());

            Assert.AreEqual(NotifyCollectionChangedAction.Remove, changedEvents[2].Action);
            Assert.AreEqual("one", changedEvents[2].OldItems.OfType<string>().FirstOrDefault());

            Assert.AreEqual(NotifyCollectionChangedAction.Reset, changedEvents[3].Action);
        }
Exemplo n.º 6
0
 public void Delete(Feed item)
 {
     feeds.Remove(item);
     Save();
 }
Exemplo n.º 7
0
 private void DeleteUser(ObservableUser obj)
 {
     _observableUsers.Remove(obj);
     _users.Remove(obj.Source);
 }
        public EditFilmPageViewModel(Film film)
        {
            ResourceManager manager = new ResourceManager("BetterThanIMDB.Resources.locale", typeof(FilmsPageViewModel).GetTypeInfo().Assembly);

            _film       = film;
            ReleaseDate = film.ReleaseDate;
            Duration    = film.Duration;
            Title       = film.Title;
            Poster      = film.Poster;
            Description = film.Description;
            foreach (var a in _film.Actors)
            {
                _tempActors.Add(a);
            }
            foreach (var p in _film.Producers)
            {
                _tempProducers.Add(p);
            }
            foreach (var g in _film.GenresList)
            {
                _tempGenres.Add(g);
            }
            foreach (var g in Enum.GetValues(typeof(Genres)))
            {
                _allGenres.Add((Genres)g);
            }

            ApplyCommand = new Command(async() =>
            {
                var col1 = _film.Actors.Except(_tempActors).ToList();
                var col2 = _tempActors.Except(_film.Actors).ToList();

                for (int i = 0; i < col1.Count(); i++)
                {
                    col1.ElementAt(i).RemoveFilm(_film);
                }
                for (int i = 0; i < col2.Count(); i++)
                {
                    col2.ElementAt(i).AddFilm(_film);
                }

                var col3 = _film.Producers.Except(_tempProducers).ToList();
                var col4 = _tempProducers.Except(_film.Producers).ToList();

                for (int i = 0; i < col3.Count(); i++)
                {
                    col3.ElementAt(i).RemoveFilm(_film);
                }
                for (int i = 0; i < col4.Count(); i++)
                {
                    col4.ElementAt(i).AddFilm(_film);
                }

                _film.Title       = Title;
                _film.ReleaseDate = ReleaseDate;
                _film.Duration    = Duration;
                _film.GenresList  = _tempGenres;
                _film.Poster      = Poster;

                await App.NavigationService.GoBackAsync();
            });

            RemoveActorCommand = new Command(() =>
            {
                ActionSheetConfig config = new ActionSheetConfig();
                foreach (var actor in _tempActors)
                {
                    config.Add(actor.Name, () =>
                    {
                        _tempActors.Remove(actor);
                    });
                }
                config.SetCancel();
                config.Title = manager.GetString("removeActor", CustomSettings.Settings.Instance.Culture);
                UserDialogs.Instance.ActionSheet(config);
            });

            AddActorCommand = new Command(() =>
            {
                ActionSheetConfig config     = new ActionSheetConfig();
                var actorsExceptAlreadyAdded = _allActors.Except(_tempActors);
                foreach (var actor in actorsExceptAlreadyAdded)
                {
                    config.Add(actor.Name, () => _tempActors.Add(actor));
                }
                config.SetCancel();
                config.Title = manager.GetString("addActor", CustomSettings.Settings.Instance.Culture);
                UserDialogs.Instance.ActionSheet(config);
            });

            AddProducerCommand = new Command(() =>
            {
                ActionSheetConfig config        = new ActionSheetConfig();
                var producersExceptAlreadyAdded = _allProducers.Except(_tempProducers);
                foreach (var producer in producersExceptAlreadyAdded)
                {
                    config.Add(producer.Name, () => _tempProducers.Add(producer));
                }
                config.SetCancel();
                config.Title = manager.GetString("addProducer", CustomSettings.Settings.Instance.Culture);
                UserDialogs.Instance.ActionSheet(config);
            });

            RemoveProducerCommand = new Command(() =>
            {
                ActionSheetConfig config = new ActionSheetConfig();
                foreach (var producer in _tempProducers)
                {
                    config.Add(producer.Name, () => _tempProducers.Remove(producer));
                }
                config.SetCancel();
                config.Title = manager.GetString("removeProducer", CustomSettings.Settings.Instance.Culture);
                UserDialogs.Instance.ActionSheet(config);
            });

            AddGenreCommand = new Command(() =>
            {
                ActionSheetConfig config     = new ActionSheetConfig();
                var genresExceptAlreadyAdded = _allGenres.Except(_tempGenres);
                foreach (var genre in genresExceptAlreadyAdded)
                {
                    config.Add(genre.ToString(), () => _tempGenres.Add(genre));
                }
                config.SetCancel();
                config.Title = manager.GetString("addGenre", CustomSettings.Settings.Instance.Culture);
                UserDialogs.Instance.ActionSheet(config);
            });

            RemoveGenreCommand = new Command(() =>
            {
                ActionSheetConfig config = new ActionSheetConfig();
                foreach (var genre in _tempGenres)
                {
                    config.Add(genre.ToString(), () => _tempGenres.Remove(genre));
                }
                config.SetCancel();
                config.Title = manager.GetString("removeGenre", CustomSettings.Settings.Instance.Culture);
                UserDialogs.Instance.ActionSheet(config);
            });

            SelectDateCommand = new Command(async() =>
            {
                DateTime.TryParse(ReleaseDate, out DateTime currentDate);
                var result = await UserDialogs.Instance.DatePromptAsync(new DatePromptConfig()
                {
                    SelectedDate = currentDate
                });
                if (result.Ok)
                {
                    ReleaseDate = result.SelectedDate.ToString("dd.MM.yyyy");
                }
            });

            SelectImageCommand = new Command(async() =>
            {
                await CrossMedia.Current.Initialize();
                var selectedImageFile = await CrossMedia.Current.PickPhotoAsync(new Plugin.Media.Abstractions.PickMediaOptions()
                {
                    CompressionQuality = 92,
                    PhotoSize          = Plugin.Media.Abstractions.PhotoSize.Medium
                });

                /*string fileName = Title + "_poster.jpeg";
                 * string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), fileName);
                 *
                 * using (var memoryStream = new MemoryStream())
                 * {
                 *  selectedImageFile.GetStream().CopyTo(memoryStream);
                 *  selectedImageFile.Dispose();
                 *
                 *  byte[] arr = memoryStream.ToArray();
                 *
                 *  using (FileStream file = File.Create(path))
                 *  {
                 *      await file.WriteAsync(arr, 0, arr.Length);
                 *  }
                 * }*/
                if (selectedImageFile != null)
                {
                    Poster = selectedImageFile.Path;
                }
            });
        }
        public SearchActorsPageViewModel(ActorsPageViewModel vm)
        {
            ResourceManager manager = new ResourceManager("BetterThanIMDB.Resources.locale", typeof(FilmsPageViewModel).GetTypeInfo().Assembly);

            PickMinDateCommand = new Command(async() =>
            {
                DateTime.TryParse(MinDate, out DateTime currentDate);
                var result = await UserDialogs.Instance.DatePromptAsync(new DatePromptConfig()
                {
                    SelectedDate = currentDate
                });
                if (result.Ok)
                {
                    MinDate = result.SelectedDate.ToString("dd.MM.yyyy");
                }
            });
            PickMaxDateCommand = new Command(async() =>
            {
                DateTime.TryParse(MaxDate, out DateTime currentDate);
                var result = await UserDialogs.Instance.DatePromptAsync(new DatePromptConfig()
                {
                    SelectedDate = currentDate
                });
                if (result.Ok)
                {
                    MaxDate = result.SelectedDate.ToString("dd.MM.yyyy");
                }
            });
            AddFilmCommand = new Command(() =>
            {
                ActionSheetConfig config    = new ActionSheetConfig();
                var filmsExceptAlreadyAdded = _allFilms.Except(_films);
                foreach (var film in filmsExceptAlreadyAdded)
                {
                    config.Add(film.Title, () => _films.Add(film));
                }
                config.SetCancel();
                config.Title = manager.GetString("addFilm", CustomSettings.Settings.Instance.Culture);
                UserDialogs.Instance.ActionSheet(config);
            });
            RemoveFilmCommand = new Command(() =>
            {
                ActionSheetConfig config = new ActionSheetConfig();
                foreach (var film in _films)
                {
                    config.Add(film.Title, () => _films.Remove(film));
                }
                config.SetCancel();
                config.Title = manager.GetString("removeFilm", CustomSettings.Settings.Instance.Culture);
                UserDialogs.Instance.ActionSheet(config);
            });
            ApplyCommand = new Command(async() =>
            {
                DateTime minDate = DateTime.Parse(MinDate);
                DateTime maxDate = DateTime.Parse(MaxDate);
                if (minDate > maxDate)
                {
                    UserDialogs.Instance.Toast("Check your date preferences");
                }
                else
                {
                    vm.Actors = new CustomObservableCollection <Actor>(ActorCollection.Instance.Actors.Where(a => a.Name.ToLower().Contains(Name.ToLower())).
                                                                       Where(a => DateTime.Parse(a.DateOfBirth) <= maxDate && DateTime.Parse(a.DateOfBirth) >= minDate).
                                                                       Where(a => a.Films.Intersect(_films).Count() == _films.Count));
                    await App.NavigationService.GoBackAsync();
                }
            });
        }
Exemplo n.º 10
0
        public SearchFilmsPageViewModel(FilmsPageViewModel vm)
        {
            ResourceManager manager = new ResourceManager("BetterThanIMDB.Resources.locale", typeof(FilmsPageViewModel).GetTypeInfo().Assembly);

            PickMinDateCommand = new Command(async() =>
            {
                DateTime.TryParse(MinDate, out DateTime currentDate);
                var result = await UserDialogs.Instance.DatePromptAsync(new DatePromptConfig()
                {
                    SelectedDate = currentDate
                });
                if (result.Ok)
                {
                    MinDate = result.SelectedDate.ToString("dd.MM.yyyy");
                }
            });
            PickMaxDateCommand = new Command(async() =>
            {
                DateTime.TryParse(MaxDate, out DateTime currentDate);
                var result = await UserDialogs.Instance.DatePromptAsync(new DatePromptConfig()
                {
                    SelectedDate = currentDate
                });
                if (result.Ok)
                {
                    MaxDate = result.SelectedDate.ToString("dd.MM.yyyy");
                }
            });
            AddActorCommand = new Command(() =>
            {
                ActionSheetConfig config     = new ActionSheetConfig();
                var actorsExceptAlreadyAdded = _allActors.Except(_actors);
                foreach (var actor in actorsExceptAlreadyAdded)
                {
                    config.Add(actor.Name, () => _actors.Add(actor));
                }
                config.SetCancel();
                config.Title = manager.GetString("addActor", CustomSettings.Settings.Instance.Culture);
                UserDialogs.Instance.ActionSheet(config);
            });
            AddProducerCommand = new Command(() =>
            {
                ActionSheetConfig config        = new ActionSheetConfig();
                var producersExceptAlreadyAdded = _allProducers.Except(_producers);
                foreach (var producer in producersExceptAlreadyAdded)
                {
                    config.Add(producer.Name, () => _producers.Add(producer));
                }
                config.SetCancel();
                config.Title = manager.GetString("addProducer", CustomSettings.Settings.Instance.Culture);
                UserDialogs.Instance.ActionSheet(config);
            });
            AddGenreCommand = new Command(() =>
            {
                ActionSheetConfig config = new ActionSheetConfig();
                List <Genres> allGenres  = new List <Genres>();
                foreach (var g in Enum.GetValues(typeof(Genres)))
                {
                    allGenres.Add((Genres)g);
                }
                foreach (var genre in allGenres.Except(_genres))
                {
                    config.Add(genre.ToString(), () => _genres.Add(genre));
                }
                config.SetCancel();
                config.Title = manager.GetString("addGenre", CustomSettings.Settings.Instance.Culture);
                UserDialogs.Instance.ActionSheet(config);
            });
            RemoveActorCommand = new Command(() =>
            {
                ActionSheetConfig config = new ActionSheetConfig();
                foreach (var actor in _actors)
                {
                    config.Add(actor.Name, () => _actors.Remove(actor));
                }
                config.SetCancel();
                config.Title = manager.GetString("removeActor", CustomSettings.Settings.Instance.Culture);
                UserDialogs.Instance.ActionSheet(config);
            });
            RemoveProducerCommand = new Command(() =>
            {
                ActionSheetConfig config = new ActionSheetConfig();
                foreach (var producer in _producers)
                {
                    config.Add(producer.Name, () => _producers.Remove(producer));
                }
                config.SetCancel();
                config.Title = manager.GetString("removeProducer", CustomSettings.Settings.Instance.Culture);
                UserDialogs.Instance.ActionSheet(config);
            });
            RemoveGenreCommand = new Command(() =>
            {
                ActionSheetConfig config = new ActionSheetConfig();
                foreach (var genre in _genres)
                {
                    config.Add(genre.ToString(), () => _genres.Remove(genre));
                }
                config.SetCancel();
                config.Title = manager.GetString("removeGenre", CustomSettings.Settings.Instance.Culture);
                UserDialogs.Instance.ActionSheet(config);
            });

            ApplyCommand = new Command(async() =>
            {
                DateTime minDate = DateTime.Parse(MinDate);
                DateTime maxDate = DateTime.Parse(MaxDate);
                if (MinDuration > MaxDuration || MaxDuration == 0)
                {
                    UserDialogs.Instance.Toast("Check your duration preferences");
                }
                else if (minDate > maxDate)
                {
                    UserDialogs.Instance.Toast("Check your date preferences");
                }
                else
                {
                    vm.Films = new CustomObservableCollection <Film>(FilmCollection.Instance.Films.
                                                                     Where(f => f.Title.ToLower().Contains(Title.ToLower())).
                                                                     Where(f => f.Duration <= MaxDuration && f.Duration >= MinDuration).
                                                                     Where(f => DateTime.Parse(f.ReleaseDate) <= maxDate && DateTime.Parse(f.ReleaseDate) >= minDate).
                                                                     Where(f => f.Actors.Intersect(_actors).Count() == _actors.Count).
                                                                     Where(f => f.Producers.Intersect(_producers).Count() == _producers.Count).
                                                                     Where(f => f.GenresList.Intersect(_genres).Count() == _genres.Count));
                    await App.NavigationService.GoBackAsync();
                }
            });
        }
Exemplo n.º 11
0
        public EditActorPageViewModel(Actor actor)
        {
            ResourceManager manager = new ResourceManager("BetterThanIMDB.Resources.locale", typeof(FilmsPageViewModel).GetTypeInfo().Assembly);

            _actor      = actor;
            Name        = actor.Name;
            DateOfBirth = actor.DateOfBirth;
            Photo       = actor.Photo;

            foreach (var film in actor.Films)
            {
                _tempFilms.Add(film);
            }

            ApplyCommand = new Command(async() =>
            {
                var col1 = _actor.Films.Except(_tempFilms).ToList();
                var col2 = _tempFilms.Except(_actor.Films).ToList();

                for (int i = 0; i < col1.Count(); i++)
                {
                    col1.ElementAt(i).RemoveActor(_actor);
                }
                for (int i = 0; i < col2.Count(); i++)
                {
                    col2.ElementAt(i).AddActor(_actor);
                }

                _actor.Name        = Name;
                _actor.DateOfBirth = DateOfBirth;
                _actor.Photo       = Photo;

                await App.NavigationService.GoBackAsync();
            });
            SelectDateCommand = new Command(async() =>
            {
                DateTime.TryParse(DateOfBirth, out DateTime currentDate);
                var result = await UserDialogs.Instance.DatePromptAsync(new DatePromptConfig()
                {
                    SelectedDate = currentDate
                });
                if (result.Ok)
                {
                    DateOfBirth = result.SelectedDate.ToString("dd.MM.yyyy");
                }
            });
            SelectImageCommand = new Command(async() =>
            {
                await CrossMedia.Current.Initialize();
                var selectedImageFile = await CrossMedia.Current.PickPhotoAsync(new Plugin.Media.Abstractions.PickMediaOptions()
                {
                    CompressionQuality = 92,
                    PhotoSize          = Plugin.Media.Abstractions.PhotoSize.Medium
                });

                if (selectedImageFile != null)
                {
                    Photo = selectedImageFile.Path;
                }
            });
            AddFilmCommand = new Command(() =>
            {
                ActionSheetConfig config = new ActionSheetConfig();
                foreach (var film in _allFilms.Except(_tempFilms))
                {
                    config.Add(film.Title, () => _tempFilms.Add(film));
                }
                config.SetCancel();
                config.Title = manager.GetString("addFilm", CustomSettings.Settings.Instance.Culture);
                UserDialogs.Instance.ActionSheet(config);
            });
            RemoveFilmCommand = new Command(() =>
            {
                ActionSheetConfig config = new ActionSheetConfig();
                foreach (var film in _tempFilms)
                {
                    config.Add(film.Title, () => _tempFilms.Remove(film));
                }
                config.SetCancel();
                config.Title = manager.GetString("removeFilm", CustomSettings.Settings.Instance.Culture);
                UserDialogs.Instance.ActionSheet(config);
            });
        }