Beispiel #1
0
        public Playlist Get(Data.Playlist model)
        {
            var result = new Playlist(_container, _validator, _dialogViewModel, model);

            result.AddRange(_mediaItemMapper.GetMany(model.MediaItems));
            return(result);
        }
Beispiel #2
0
        private async Task LoadFromUrl()
        {
            using (_busyStack.GetToken())
            {
                var items = await _dialogViewModel.ShowUrlParseDialog();

                Items.AddRange(_mediaItemMapper.GetMany(items, Id));
            }
        }
        private async Task Parse()
        {
            Result = await _dataParsingService.Parse(Source, ParseResultType.MediaItems)
                     .ConfigureAwait(true);

            if (Result.Count > 0 && Result.MediaItems?.Count > 0)
            {
                AddRange(_mapper.GetMany(Result.MediaItems));
            }
        }
Beispiel #4
0
        public Playlist(ViewModelServiceContainer container, IValidator <Playlist> validator, IDialogViewModel dialogViewModel, IMediaItemMapper mediaItemMapper, PlaylistModel model)
            : base(model, validator, container?.Messenger)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container), $"{nameof(container)} {Resources.IsRequired}");
            }

            SkipChangeTracking = true;
            using (BusyStack.GetToken())
            {
                _itemsLock = new object();

                _mediaItemMapper  = mediaItemMapper ?? throw new ArgumentNullException(nameof(mediaItemMapper), $"{nameof(mediaItemMapper)} {Resources.IsRequired}");
                _dialogViewModel  = dialogViewModel ?? throw new ArgumentNullException(nameof(dialogViewModel), $"{nameof(dialogViewModel)} {Resources.IsRequired}");
                _sequenceProvider = container.SequenceService;

                _translator   = container.LocalizationService;
                _title        = model.Title;
                _description  = model.Description;
                _repeatMode   = (RepeatMode)model.RepeatMode;
                _isShuffeling = model.IsShuffeling;
                _sequence     = model.Sequence;

                RepeatModes = new RangeObservableCollection <RepeatMode>(Enum.GetValues(typeof(RepeatMode)).Cast <RepeatMode>().ToList());
                _history    = new Stack <int>();

                Items = new RangeObservableCollection <MediaItem>();
                _items.CollectionChanged += (o, e) => OnPropertyChanged(nameof(Count));

                BindingOperations.EnableCollectionSynchronization(Items, _itemsLock);
                View = CollectionViewSource.GetDefaultView(Items); // TODO add sorting by sequence
                OnPropertyChanged(nameof(Count));

                LoadFromFileCommand   = AsyncCommand.Create(LoadFromFile, () => CanLoadFromFile());
                LoadFromFolderCommand = AsyncCommand.Create(LoadFromFolder, () => CanLoadFromFolder());
                LoadFromUrlCommand    = AsyncCommand.Create(LoadFromUrl, () => CanLoadFromUrl());

                RemoveCommand      = new RelayCommand <object>(Remove, CanRemove);
                RemoveRangeCommand = new RelayCommand <IList>(RemoveRange, CanRemoveRange);
                ClearCommand       = new RelayCommand(() => Clear(), CanClear);

                AddRange(_mediaItemMapper.GetMany(model.MediaItems));

                MessageTokens.Add(Messenger.Subscribe <PlayingMediaItemMessage>(OnPlaybackItemChanged, m => m.PlaylistId == Id && _items.Contains(m.Content)));

                Validate();
            }
            SkipChangeTracking = false;
        }
Beispiel #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Playlist" /> class.
        /// </summary>
        /// <param name="translator">The translator.</param>
        /// <param name="mediaItemMapper">The media item mapper.</param>
        /// <param name="dialogViewModel">The dialog view model.</param>
        /// <param name="model">The model.</param>
        /// <exception cref="System.ArgumentNullException">dialogViewModel</exception>
        /// <exception cref="System.ArgumentException"></exception>
        public Playlist(ILocalizationService translator, IMediaItemMapper mediaItemMapper, ISequenceProvider sequenceProvider, IValidator <Playlist> validator, DialogViewModel dialogViewModel, Data.Playlist model)
            : base(model, validator)
        {
            using (_busyStack.GetToken())
            {
                _itemsLock        = new object();
                _sequenceProvider = sequenceProvider ?? throw new ArgumentNullException(nameof(sequenceProvider));
                _dialogViewModel  = dialogViewModel ?? throw new ArgumentNullException(nameof(dialogViewModel));
                _translator       = translator ?? throw new ArgumentNullException(nameof(translator));
                _mediaItemMapper  = mediaItemMapper ?? throw new ArgumentNullException(nameof(mediaItemMapper));

                Items       = new RangeObservableCollection <MediaItem>();
                RepeatModes = new ObservableCollection <RepeatMode>(Enum.GetValues(typeof(RepeatMode)).Cast <RepeatMode>().ToList());
                History     = new Stack <int>();

                BindingOperations.EnableCollectionSynchronization(Items, _itemsLock);

                _title        = model.Title;
                _description  = model.Description;
                _id           = model.Id;
                _repeatMode   = (RepeatMode)model.RepeatMode;
                _isShuffeling = model.IsShuffeling;
                _sequence     = model.Sequence;
                _createdBy    = model.CreatedBy;
                _createdOn    = model.CreatedOn;
                _updatedBy    = model.UpdatedBy;
                _updatedOn    = model.UpdatedOn;

                if (model.MediaItems == null)
                {
                    throw new ArgumentException($"{model.MediaItems} cannot be null");
                }

                Items.AddRange(_mediaItemMapper.GetMany(model.MediaItems));

                Items.CollectionChanged += (o, e) =>
                {
                    OnPropertyChanged(nameof(Count));
                };

                View = CollectionViewSource.GetDefaultView(Items);
                OnPropertyChanged(nameof(Count));

                InitializeCommands();
                IntializeValidation();

                Validate();
            }
        }
Beispiel #6
0
        private void InitializeCommands()
        {
            ParseCommand = new RelayCommand(async() =>
            {
                using (_busyStack.GetToken())
                {
                    Result = await _dataParsingService.Parse(Source, ParseResultType.MediaItems);

                    if (Result.Count > 0 && Result.MediaItems?.Count > 0)
                    {
                        Items.AddRange(_mapper.GetMany(Result.MediaItems));
                    }
                }
            }, () => !string.IsNullOrWhiteSpace(Source));
        }
Beispiel #7
0
        /// <summary>
        /// Shows the URL parse dialog.
        /// </summary>
        /// <returns></returns>
        public async Task <List <MediaItem> > ShowUrlParseDialog()
        {
            var result    = new List <MediaItem>();
            var viewmodel = new CreateMediaItem(_service, _mediaItemMapper, _messenger);

            TitleDetail = string.Empty;
            Context     = viewmodel;
            Title       = _translator.Translate(nameof(Resources.VideoAdd));

            AcceptAction = () =>
            {
                if (viewmodel.Result?.MediaItems?.Any() == true)
                {
                    var items = _mediaItemMapper.GetMany(viewmodel.Result.MediaItems);
                    result.AddRange(items);
                }
            };

            await Open().ConfigureAwait(false);

            return(result);
        }