protected override void PostResetList() { AddSortDescription( new Microsoft.Toolkit.Uwp.UI.SortDescription("NowLive", Microsoft.Toolkit.Uwp.UI.SortDirection.Descending) ); AddSortDescription( new Microsoft.Toolkit.Uwp.UI.SortDescription("IsTimedOut", Microsoft.Toolkit.Uwp.UI.SortDirection.Ascending) ); AddSortDescription( new Microsoft.Toolkit.Uwp.UI.SortDescription("IsReserved", Microsoft.Toolkit.Uwp.UI.SortDirection.Ascending) ); AddSortDescription( new Microsoft.Toolkit.Uwp.UI.SortDescription("ExpiredAt", Microsoft.Toolkit.Uwp.UI.SortDirection.Ascending) ); IncrementalLoadingItems.ObserveElementPropertyChanged() .Where(x => x.EventArgs.PropertyName == nameof(x.Sender.Reservation) && x.Sender.Reservation == null) .Subscribe(x => { ItemsView.Remove(x.Sender); }); base.PostResetList(); }
protected override void OnDispose() { if (IncrementalLoadingItems.Source is HohoemaIncrementalSourceBase <ITEM_VM> ) { (IncrementalLoadingItems.Source as HohoemaIncrementalSourceBase <ITEM_VM>).Error -= HohoemaIncrementalSource_Error; } IncrementalLoadingItems?.Dispose(); }
internal async Task RemoveHistory(string videoId) { await HohoemaApp.NiconicoContext.Video.RemoveHistoryAsync(_HistoriesResponse.Token, videoId); var item = IncrementalLoadingItems.SingleOrDefault(x => x.RawVideoId == videoId); IncrementalLoadingItems.Remove(item); // await UpdateList(); }
public override void OnNavigatedTo(NavigatedToEventArgs e, Dictionary <string, object> viewModelState) { if (CheckNeedUpdateOnNavigateTo(e.NavigationMode)) { IncrementalLoadingItems?.Clear(); IncrementalLoadingItems = null; } else { ChangeCanIncmentalLoading(true); } base.OnNavigatedTo(e, viewModelState); }
protected override void OnDispose() { if (IncrementalLoadingItems != null) { IncrementalLoadingItems.BeginLoading -= BeginLoadingItems; IncrementalLoadingItems.DoneLoading -= CompleteLoadingItems; if (IncrementalLoadingItems.Source is HohoemaIncrementalSourceBase <ITEM_VM> ) { (IncrementalLoadingItems.Source as HohoemaIncrementalSourceBase <ITEM_VM>).Error -= HohoemaIncrementalSource_Error; } IncrementalLoadingItems.Dispose(); IncrementalLoadingItems = null; } }
private async void CacheManager_VideoCacheStateChanged(object sender, VideoCacheStateChangedEventArgs e) { if (e.CacheState != NicoVideoCacheState.Cached) { var video = IncrementalLoadingItems?.FirstOrDefault(x => x.RawVideoId == e.Request.RawVideoId); if (video != null) { await HohoemaApp.UIDispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() => { await video.RefrechCacheState(); }); } } }
protected async Task ResetList() { HasItem.Value = true; LoadedItemsCount.Value = 0; IsSelectionModeEnable.Value = false; SelectedItems.Clear(); if (IncrementalLoadingItems != null) { if (IncrementalLoadingItems.Source is HohoemaIncrementalSourceBase <ITEM_VM> ) { (IncrementalLoadingItems.Source as HohoemaIncrementalSourceBase <ITEM_VM>).Error -= HohoemaIncrementalSource_Error; } IncrementalLoadingItems.BeginLoading -= BeginLoadingItems; IncrementalLoadingItems.DoneLoading -= CompleteLoadingItems; IncrementalLoadingItems.Dispose(); IncrementalLoadingItems = null; } try { var source = GenerateIncrementalSource(); MaxItemsCount.Value = await source.ResetSource(); IncrementalLoadingItems = new IncrementalLoadingCollection <IIncrementalSource <ITEM_VM>, ITEM_VM>(source); OnPropertyChanged(nameof(IncrementalLoadingItems)); IncrementalLoadingItems.BeginLoading += BeginLoadingItems; IncrementalLoadingItems.DoneLoading += CompleteLoadingItems; if (IncrementalLoadingItems.Source is HohoemaIncrementalSourceBase <ITEM_VM> ) { (IncrementalLoadingItems.Source as HohoemaIncrementalSourceBase <ITEM_VM>).Error += HohoemaIncrementalSource_Error; } PostResetList(); } catch { IncrementalLoadingItems = null; NowLoadingItems.Value = false; HasItem.Value = true; HasError.Value = true; Debug.WriteLine("failed GenerateIncrementalSource."); } }
public MylistPageViewModel( HohoemaApp hohoemaApp , PageManager pageManager , Views.Service.MylistRegistrationDialogService mylistDialogService , Views.Service.ContentSelectDialogService contentSelectDialogService ) : base(hohoemaApp, pageManager, mylistDialogService, isRequireSignIn: true) { _ContentSelectDialogService = contentSelectDialogService; PlayableList = new ReactiveProperty <IPlayableList>(); MylistOrigin = new ReactiveProperty <Models.PlaylistOrigin>(); IsFavoriteMylist = new ReactiveProperty <bool>(mode: ReactivePropertyMode.DistinctUntilChanged) .AddTo(_CompositeDisposable); CanChangeFavoriteMylistState = new ReactiveProperty <bool>() .AddTo(_CompositeDisposable); IsFavoriteMylist .Where(x => PlayableList.Value.Id != null) .Subscribe(async x => { if (PlayableList.Value.Origin != PlaylistOrigin.OtherUser) { return; } if (_NowProcessFavorite) { return; } _NowProcessFavorite = true; CanChangeFavoriteMylistState.Value = false; if (x) { if (await FavoriteMylist()) { Debug.WriteLine(_MylistTitle + "のマイリストをお気に入り登録しました."); } else { // お気に入り登録に失敗した場合は状態を差し戻し Debug.WriteLine(_MylistTitle + "のマイリストをお気に入り登録に失敗"); IsFavoriteMylist.Value = false; } } else { if (await UnfavoriteMylist()) { Debug.WriteLine(_MylistTitle + "のマイリストをお気に入り解除しました."); } else { // お気に入り解除に失敗した場合は状態を差し戻し Debug.WriteLine(_MylistTitle + "のマイリストをお気に入り解除に失敗"); IsFavoriteMylist.Value = true; } } CanChangeFavoriteMylistState.Value = IsFavoriteMylist.Value == true || HohoemaApp.FollowManager.CanMoreAddFollow(FollowItemType.Mylist); _NowProcessFavorite = false; }) .AddTo(_CompositeDisposable); UnregistrationMylistCommand = SelectedItems.ObserveProperty(x => x.Count) .Where(_ => this.CanEditMylist) .Select(x => x > 0) .ToReactiveCommand(false); UnregistrationMylistCommand.Subscribe(async _ => { var mylistGroup = HohoemaApp.UserMylistManager.GetMylistGroup(PlayableList.Value.Id); var items = SelectedItems.ToArray(); var action = AsyncInfo.Run <uint>(async(cancelToken, progress) => { uint progressCount = 0; int successCount = 0; int failedCount = 0; Debug.WriteLine($"マイリストに追加解除を開始..."); foreach (var video in items) { var unregistrationResult = await mylistGroup.Unregistration( video.RawVideoId , withRefresh: false /* あとでまとめてリフレッシュするのでここでは OFF */); if (unregistrationResult == ContentManageResult.Success) { successCount++; } else { failedCount++; } progressCount++; progress.Report(progressCount); Debug.WriteLine($"{video.Title}[{video.RawVideoId}]:{unregistrationResult.ToString()}"); } // 登録解除結果を得るためリフレッシュ await mylistGroup.Refresh(); // ユーザーに結果を通知 var titleText = $"「{mylistGroup.Name}」から {successCount}件 の動画が登録解除されました"; var toastService = App.Current.Container.Resolve <ToastNotificationService>(); var resultText = $""; if (failedCount > 0) { resultText += $"\n登録解除に失敗した {failedCount}件 は選択されたままです"; } toastService.ShowText(titleText, resultText); // 登録解除に失敗したアイテムだけを残すように // マイリストから除外された動画を選択アイテムリストから削除 foreach (var item in SelectedItems.ToArray()) { if (false == mylistGroup.CheckRegistratedVideoId(item.RawVideoId)) { SelectedItems.Remove(item); IncrementalLoadingItems.Remove(item); } } Debug.WriteLine($"マイリストに追加解除完了---------------"); }); await PageManager.StartNoUIWork("マイリストに追加解除", items.Length, () => action); }); CopyMylistCommand = SelectedItems.ObserveProperty(x => x.Count) .Where(_ => this.CanEditMylist) .Select(x => x > 0) .ToReactiveCommand(false); CopyMylistCommand.Subscribe(async _ => { var mylistGroup = HohoemaApp.UserMylistManager.GetMylistGroup(PlayableList.Value.Id); // ターゲットのマイリストを選択する var targetMylist = await MylistDialogService .ShowSelectSingleMylistDialog( SelectedItems.Count , hideMylistGroupId: mylistGroup.GroupId ); if (targetMylist == null) { return; } // すでにターゲットのマイリストに登録されている動画を除外してコピーする var items = SelectedItems .Where(x => !targetMylist.CheckRegistratedVideoId(x.RawVideoId)) .ToList(); var action = AsyncInfo.Run <uint>(async(cancelToken, progress) => { Debug.WriteLine($"マイリストのコピーを開始..."); var result = await mylistGroup.CopyMylistTo( targetMylist , items.Select(video => video.RawVideoId).ToArray() ); Debug.WriteLine($"copy mylist {items.Count} item from {mylistGroup.Name} to {targetMylist.Name} : {result.ToString()}"); // ユーザーに結果を通知 var toastService = App.Current.Container.Resolve <ToastNotificationService>(); string titleText; string contentText; if (result == ContentManageResult.Success) { titleText = $"「{targetMylist.Name}」に {SelectedItems.Count}件 コピーしました"; contentText = $" {SelectedItems.Count}件 の動画をコピーしました"; progress.Report((uint)items.Count); } else { titleText = $"マイリストコピーに失敗"; contentText = $"時間を置いてからやり直してみてください"; } toastService.ShowText(titleText, contentText); // 成功した場合は選択状態を解除 if (result == ContentManageResult.Success) { ClearSelection(); } Debug.WriteLine($"マイリストのコピー完了..."); }); await PageManager.StartNoUIWork("マイリストのコピー", items.Count, () => action); }); MoveMylistCommand = SelectedItems.ObserveProperty(x => x.Count) .Where(_ => this.CanEditMylist) .Select(x => x > 0) .ToReactiveCommand(false); MoveMylistCommand.Subscribe(async _ => { var mylistGroup = HohoemaApp.UserMylistManager.GetMylistGroup(PlayableList.Value.Id); // ターゲットのマイリストを選択する var targetMylist = await MylistDialogService .ShowSelectSingleMylistDialog( SelectedItems.Count , hideMylistGroupId: mylistGroup.GroupId ); if (targetMylist == null) { return; } // すでにターゲットのマイリストに登録されている動画を除外してコピーする var items = SelectedItems .Where(x => !targetMylist.CheckRegistratedVideoId(x.RawVideoId)) .ToList(); Debug.WriteLine($"マイリストの移動を開始..."); var result = await mylistGroup.MoveMylistTo( targetMylist , items.Select(video => video.RawVideoId).ToArray() ); Debug.WriteLine($"move mylist {items.Count} item from {mylistGroup.Name} to {targetMylist.Name} : {result.ToString()}"); // ユーザーに結果を通知 var toastService = App.Current.Container.Resolve <ToastNotificationService>(); string titleText; string contentText; if (result == ContentManageResult.Success) { titleText = $"「{targetMylist.Name}」に {SelectedItems.Count}件 移動しました"; contentText = $" {SelectedItems.Count}件 の動画を移動しました"; } else { titleText = $"マイリスト移動に失敗"; contentText = $"時間を置いてからやり直してみてください"; } toastService.ShowText(titleText, contentText); // 成功した場合は選択状態を解除 if (result == ContentManageResult.Success) { // 移動元のマイリストからは削除されているはず foreach (var item in SelectedItems) { if (!mylistGroup.CheckRegistratedVideoId(item.RawVideoId)) { IncrementalLoadingItems.Remove(item); } else { throw new Exception(); } } ClearSelection(); } Debug.WriteLine($"マイリストの移動完了..."); }); }