コード例 #1
0
        private void VideoItemFlyout_Opening(object sender, object e)
        {
            object dataContext = Target.DataContext ?? (Target as SelectorItem)?.Content;
            var    content     = (dataContext as Interfaces.IVideoContent);

            if (content == null || (VideoItems?.Any() ?? false))
            {
                content     = VideoItems?.First();
                dataContext = VideoItems;
            }

            bool isMultipleSelection = VideoItems?.Count >= 2;

            var playlist = Playlist;


            // 視聴履歴
            RemoveWatchHisotryItem.Visibility = (content is IWatchHistory).ToVisibility();

            // ローカルプレイリスト
            if (playlist is LocalPlaylist localPlaylist)
            {
                RemoveLocalPlaylistItem.CommandParameter = dataContext;
                RemoveLocalPlaylistItem.Command          = localPlaylist.ItemsRemoveCommand;
                RemoveLocalPlaylistItem.Visibility       = Visibility.Visible;
            }
            else
            {
                RemoveLocalPlaylistItem.Visibility = Visibility.Collapsed;
            }

            // マイリスト
            if (playlist is LoginUserMylistPlaylist mylistPlaylist)
            {
                RemoveMylistItem.CommandParameter = dataContext;
                RemoveMylistItem.Command          = mylistPlaylist.ItemsRemoveCommand;
                RemoveMylistItem.Visibility       = Visibility.Visible;
            }
            else
            {
                RemoveMylistItem.Visibility = Visibility.Collapsed;
            }

            // キュー
            AddQueue.CommandParameter    = dataContext;
            RemoveQueue.CommandParameter = dataContext;
            if (isMultipleSelection)
            {
                AddQueue.Visibility    = VideoItems.All(x => HohoemaPlaylist.QueuePlaylist.Contains(x)).ToInvisibility();
                RemoveQueue.Visibility = VideoItems.Any(x => HohoemaPlaylist.QueuePlaylist.Contains(x)).ToVisibility();
            }
            else if (HohoemaPlaylist.QueuePlaylist.Contains(content))
            {
                AddQueue.Visibility    = Visibility.Collapsed;
                RemoveQueue.Visibility = Visibility.Visible;
            }
            else
            {
                AddQueue.Visibility    = Visibility.Visible;
                RemoveQueue.Visibility = Visibility.Collapsed;
            }

            // あとで見る
            AddWatchAfter.CommandParameter    = dataContext;
            RemoveWatchAfter.CommandParameter = dataContext;
            if (isMultipleSelection)
            {
                AddWatchAfter.Visibility    = VideoItems.All(x => HohoemaPlaylist.WatchAfterPlaylist.Contains(x)).ToInvisibility();
                RemoveWatchAfter.Visibility = VideoItems.Any(x => HohoemaPlaylist.WatchAfterPlaylist.Contains(x)).ToVisibility();
            }
            else if (HohoemaPlaylist.WatchAfterPlaylist.Contains(content))
            {
                AddWatchAfter.Visibility    = Visibility.Collapsed;
                RemoveWatchAfter.Visibility = Visibility.Visible;
            }
            else
            {
                AddWatchAfter.Visibility    = Visibility.Visible;
                RemoveWatchAfter.Visibility = Visibility.Collapsed;
            }


            // マイリスト
            AddToMylistSubItem.Items.Clear();
            AddToMylistSubItem.Visibility = UserMylistManager.IsLoginUserMylistReady ? Visibility.Visible : Visibility.Collapsed;
            if (UserMylistManager.IsLoginUserMylistReady)
            {
                AddToMylistSubItem.Items.Add(new MenuFlyoutItem()
                {
                    Text             = _localizedText_CreateNew,
                    Command          = CreateMylistCommand,
                    CommandParameter = dataContext
                });

                foreach (var mylist in UserMylistManager.Mylists)
                {
                    AddToMylistSubItem.Items.Add(new MenuFlyoutItem()
                    {
                        Text             = mylist.Label,
                        Command          = mylist.ItemsAddCommand,
                        CommandParameter = dataContext
                    });
                }
            }

            var visibleSingleSelectionItem = isMultipleSelection.ToInvisibility();

            OpenVideoInfoPage.Visibility      = visibleSingleSelectionItem;
            OpenOwnerVideosPage.Visibility    = visibleSingleSelectionItem;
            AddNgUser.Visibility              = visibleSingleSelectionItem;
            VideoInfoItemSeparator.Visibility = visibleSingleSelectionItem;


            //OpenOwnerSeriesPage.Visibility = (content?.ProviderType == Database.NicoVideoUserType.User && content?.ProviderId != null).ToVisibility();
            //OpenOwnerSeriesPage.CommandParameter = content?.ProviderId;

            Share.Visibility       = visibleSingleSelectionItem;
            CopySubItem.Visibility = visibleSingleSelectionItem;

            SusbcriptionSubItem.Visibility = visibleSingleSelectionItem;


            // プレイリスト
            LocalMylistSubItem.Items.Clear();
            LocalMylistSubItem.Items.Add(new MenuFlyoutItem()
            {
                Text             = _localizedText_CreateNew,
                Command          = CreateLocalMylistCommand,
                CommandParameter = dataContext
            });

            foreach (var localMylist in LocalMylistManager.LocalPlaylists)
            {
                LocalMylistSubItem.Items.Add(new MenuFlyoutItem()
                {
                    Text             = localMylist.Label,
                    Command          = localMylist.ItemsAddCommand,
                    CommandParameter = dataContext
                });
            }

            // 購読
            var susbcSourceConverter = new Subscriptions.SubscriptionSourceConverter();
            var subscSource          = susbcSourceConverter.Convert(content, typeof(SubscriptionSource), null, null);

            SusbcriptionSubItem.Items.Clear();
            SusbcriptionSubItem.Items.Add(new MenuFlyoutItem()
            {
                Text             = _localizedText_CreateNew,
                Command          = CreateSubscriptionGroupCommand,
                CommandParameter = subscSource
            });

            foreach (var subsc in SubscriptionManager.Subscriptions)
            {
                SusbcriptionSubItem.Items.Add(new MenuFlyoutItem()
                {
                    Text             = subsc.Label,
                    Command          = subsc.AddSource,
                    CommandParameter = subscSource
                });
            }

            // NG投稿者
            AddNgUser.Visibility    = AddNgUser.Command.CanExecute(content).ToVisibility();
            RemoveNgUser.Visibility = RemoveNgUser.Command.CanExecute(content).ToVisibility();


            // キャッシュ
            var isCacheEnabled          = VideoCacheManager.CacheSettings.IsEnableCache && VideoCacheManager.CacheSettings.IsUserAcceptedCache;
            var cacheEnableToVisibility = isCacheEnabled.ToVisibility();

            if (isMultipleSelection && isCacheEnabled)
            {
                // 一つでもキャッシュ済みがあれば削除ボタンを表示
                // 一つでも未キャッシュがあれば取得ボタンを表示
                var anyItemsCached    = VideoItems.Any(x => VideoCacheManager.IsCacheRequested(x.Id));
                var anyItemsNotCached = VideoItems.Any(x => !VideoCacheManager.CheckCachedAsyncUnsafe(x.Id));

                var notCachedToVisible = (anyItemsNotCached).ToVisibility();
                CacheRequest.Visibility             = notCachedToVisible;
                CacheRequest.CommandParameter       = dataContext;
                CacheRequestWithQuality.Visibility  = notCachedToVisible;
                DeleteCacheRequest.CommandParameter = dataContext;

                CacheSeparator.Visibility = Visibility.Visible;

                var cachedToVisible = (anyItemsCached).ToVisibility();
                DeleteCacheRequest.Visibility = cachedToVisible;
            }
            else if (isCacheEnabled)
            {
                var itemCached    = VideoCacheManager.IsCacheRequested(content.Id);
                var itemNotCached = !VideoCacheManager.CheckCachedAsyncUnsafe(content.Id);

                var notCachedToVisible = (itemNotCached).ToVisibility();
                CacheRequest.Visibility             = notCachedToVisible;
                CacheRequest.CommandParameter       = dataContext;
                CacheRequestWithQuality.Visibility  = notCachedToVisible;
                DeleteCacheRequest.CommandParameter = dataContext;

                CacheSeparator.Visibility = Visibility.Visible;

                var cachedToVisible = (itemCached).ToVisibility();
                DeleteCacheRequest.Visibility = cachedToVisible;
            }
            else
            {
                CacheRequest.Visibility            = Visibility.Collapsed;
                CacheRequestWithQuality.Visibility = Visibility.Collapsed;
                CacheSeparator.Visibility          = Visibility.Collapsed;
                DeleteCacheRequest.Visibility      = Visibility.Collapsed;
            }


            if (CacheRequestWithQuality.Items.Count == 0)
            {
                foreach (var quality in Enum.GetValues(typeof(NicoVideoQuality)).Cast <NicoVideoQuality>().Where(x => x.IsDmc() && x != NicoVideoQuality.Unknown))
                {
                    var command = App.Current.Container.Resolve <CacheAddRequestCommand>();
                    command.VideoQuality = quality;
                    var cacheRequestMenuItem = new MenuFlyoutItem()
                    {
                        Text    = quality.Translate(),
                        Command = command,
                    };
                    CacheRequestWithQuality.Items.Add(cacheRequestMenuItem);
                }
            }

            foreach (var qualityCacheRequest in CacheRequestWithQuality.Items)
            {
                (qualityCacheRequest as MenuFlyoutItem).CommandParameter = dataContext;
            }


            // 選択
            if (!VideoItemsSelectionContext.IsSelectionEnabled)
            {
                SelectionStart.Visibility = Visibility.Visible;
                SelectionEnd.Visibility   = Visibility.Collapsed;
                SelectionAll.Visibility   = Visibility.Collapsed;
            }
            else
            {
                SelectionStart.Visibility = Visibility.Collapsed;
                SelectionEnd.Visibility   = Visibility.Visible;
                SelectionAll.Visibility   = Visibility.Visible;
            }
        }
コード例 #2
0
ファイル: Location.cs プロジェクト: retslig/ANDP
        public bool Validate(CustomValidationService service)
        {
            ValidationErrors = new SerializableDictionary <string, string>();

            if ((PhoneItems == null || PhoneItems.Count < 1) &&
                (InternetItems == null || InternetItems.Count < 1) &&
                (VideoItems == null || VideoItems.Count < 1))
            {
                ValidationErrors.Add(LambdaHelper <Location> .GetPropertyName(x => x.PhoneItems), "Location.PhoneItems is a mandatory field.");
                ValidationErrors.Add(LambdaHelper <Location> .GetPropertyName(x => x.InternetItems), "Location.InternetItems is a mandatory field.");
                ValidationErrors.Add(LambdaHelper <Location> .GetPropertyName(x => x.VideoItems), "Location.VideoItems is a mandatory field.");
            }

            if (PhoneItems != null && PhoneItems.Any())
            {
                foreach (var item in PhoneItems)
                {
                    if (item.Validate(service))
                    {
                        foreach (var validationError in item.ValidationErrors)
                        {
                            if (!ValidationErrors.ContainsKey(validationError.Key))
                            {
                                ValidationErrors.Add(validationError.Key, validationError.Value);
                            }
                        }
                    }
                }
            }

            if (InternetItems != null)
            {
                if (InternetItems != null && InternetItems.Any())
                {
                    foreach (var item in InternetItems)
                    {
                        if (item.Validate(service))
                        {
                            foreach (var validationError in item.ValidationErrors)
                            {
                                if (!ValidationErrors.ContainsKey(validationError.Key))
                                {
                                    ValidationErrors.Add(validationError.Key, validationError.Value);
                                }
                            }
                        }
                    }
                }
            }

            if (VideoItems != null)
            {
                if (VideoItems != null && VideoItems.Any())
                {
                    foreach (var item in VideoItems)
                    {
                        if (item.Validate(service))
                        {
                            foreach (var validationError in item.ValidationErrors)
                            {
                                if (!ValidationErrors.ContainsKey(validationError.Key))
                                {
                                    ValidationErrors.Add(validationError.Key, validationError.Value);
                                }
                            }
                        }
                    }
                }
            }

            if (Address == null)
            {
                ValidationErrors.Add(LambdaHelper <Location> .GetPropertyName(x => x.Address), "Location.Address is a mandatory field.");
            }
            else
            {
                if (Address.Validate())
                {
                    foreach (var validationError in Address.ValidationErrors)
                    {
                        if (!ValidationErrors.ContainsKey(validationError.Key))
                        {
                            ValidationErrors.Add(validationError.Key, validationError.Value);
                        }
                    }
                }
            }

            return(ValidationErrors.Count > 0);
        }