void RemoveHandleMylistItemsChanged(Interfaces.IUserOwnedMylist ownedMylist) { if (mylistItemsSubscriberMap.TryGetValue(ownedMylist, out var disposer)) { disposer.Dispose(); mylistItemsSubscriberMap.Remove(ownedMylist); } }
void AddHandleMylistItemsChanged(Interfaces.IUserOwnedMylist ownedMylist) { if (mylistItemsSubscriberMap.ContainsKey(ownedMylist)) { return; } var disposable = ownedMylist.CollectionChangedAsObservable() .Subscribe(e => { // ログイン直後の同期に反応しないように if (ownedMylist is UserOwnedMylist && !UserMylistManager.IsLoginUserMylistReady) { return; } if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add) { var item = e.NewItems.Cast <string>().First(); var video = Database.NicoVideoDb.Get(item); if (video != null) { var text = $"「{ownedMylist.Label}」に\n「{video.Title ?? video.RawVideoId}」を追加しました"; NotificationService.ShowInAppNotification(new InAppNotificationPayload() { Content = text, }); } } else if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove) { var item = e.OldItems.Cast <string>().First(); var video = Database.NicoVideoDb.Get(item); if (video != null) { var text = $"「{ownedMylist.Label}」から\n「{video.Title ?? video.RawVideoId}」を削除しました"; NotificationService.ShowInAppNotification(new InAppNotificationPayload() { Content = text, }); } } }); mylistItemsSubscriberMap.Add(ownedMylist, disposable); }
public async Task <Interfaces.IUserOwnedMylist> ChoiceMylist( params string[] ignoreMylistId ) { const string CreateNewContextLabel = @"@create_new"; var mylists = UserMylistManager.Mylists; var localMylists = LocalMylistManager.Mylists; List <ISelectableContainer> selectDialogContent; if (false) { selectDialogContent = new List <ISelectableContainer>() { new ChoiceFromListSelectableContainer("マイリスト", mylists.Where(x => ignoreMylistId.All(y => x.Id != y)) .Select(x => new SelectDialogPayload() { Label = x.Label, Id = x.Id, Context = x }) ), new ChoiceFromListSelectableContainer("ローカルマイリスト", localMylists.Where(x => ignoreMylistId.All(y => x.Id != y)) .Select(x => new SelectDialogPayload() { Label = x.Label, Id = x.Id, Context = x }) ), new ChoiceFromListSelectableContainer("新規作成", new [] { new SelectDialogPayload() { Label = "マイリストを作成", Id = "mylist", Context = CreateNewContextLabel }, new SelectDialogPayload() { Label = "ローカルマイリストを作成", Id = "local", Context = CreateNewContextLabel }, } ) }; } else { selectDialogContent = new List <ISelectableContainer>() { new ChoiceFromListSelectableContainer("ローカルマイリスト", localMylists.Where(x => ignoreMylistId.All(y => x.Id != y)) .Select(x => new SelectDialogPayload() { Label = x.Label, Id = x.Id, Context = x }) ), new ChoiceFromListSelectableContainer("新規作成", new [] { new SelectDialogPayload() { Label = "ローカルマイリストを作成", Id = "local", Context = CreateNewContextLabel }, } ) }; } Interfaces.IUserOwnedMylist resultList = null; while (resultList == null) { var result = await ShowContentSelectDialogAsync( "追加先マイリストを選択", selectDialogContent ); if (result == null) { break; } if (result?.Context as string == CreateNewContextLabel) { var mylistTypeLabel = result.Id == "mylist" ? "マイリスト" : "ローカルマイリスト"; var title = await GetTextAsync( $"{mylistTypeLabel}を作成", $"{mylistTypeLabel}名", validater : (str) => !string.IsNullOrWhiteSpace(str) ); if (title == null) { continue; } if (result.Id == "mylist") { await UserMylistManager.AddMylist(title, "", false, Mntone.Nico2.Mylist.MylistDefaultSort.FirstRetrieve_Descending, Mntone.Nico2.Mylist.IconType.Default); resultList = UserMylistManager.Mylists.FirstOrDefault(x => x.Label == title); } else //if (result.Id == "local") { var localMylist = new LocalMylistGroup(Guid.NewGuid().ToString(), title); LocalMylistManager.Mylists.Add(localMylist); resultList = localMylist; } } else { resultList = result?.Context as Interfaces.IUserOwnedMylist; } } return(resultList); }