private async void OnAdd(ClipViewModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var count = await _clipboardRepository.CountAsync(); if (_appSettingsService.MaxSavedCopiesCount > 0 && (count >= _appSettingsService.MaxSavedCopiesCount)) { return; } var isDuplicate = _clips.Where(x => x.Format == model.Format).Any(x => { if (x.Format == DataFormats.Text) { return(((string)model.Data).Equals((string)x.Data)); } if (x.Format == DataFormats.Bitmap) { return(Utils.AreEqual((BitmapSource)model.Data, (BitmapSource)x.Data)); } return(true); }); if (isDuplicate) { return; } var clip = AppAutoMapper.Map(model); await _clipboardRepository.AddAsync(clip); model.Id = clip.Id; _clips.Insert(0, model); Refresh(); }
protected override async void OnInitialize() { var clipsInDb = await _clipboardRepository.FindAllAsync(); var clips = new ObservableCollection <ClipViewModel>(); foreach (var clip in clipsInDb) { var model = AppAutoMapper.Map(clip); clips.Add(model); } _clips = clips; Clips = CollectionViewSource.GetDefaultView(_clips); Clips.Filter += OnClipFilter; base.OnInitialize(); }
private async void OnSelect(ClipViewModel model) { if (model == null) { return; } model.LastUsedDate = DateTime.Now; var clipInDb = await _clipboardRepository.FindAsync(model.Id); AppAutoMapper.Map(model, clipInDb); await _clipboardRepository.UpdateAsync(clipInDb); // Moves the new clip to the top of the list and resets the list to re-arrange the index for each item _clips.Move(_clips.IndexOf(model), 0); Refresh(); ClipSelected?.Invoke(this, model); }