public override async Task OnNavigatedToAsync(INavigationParameters parameters) { if (parameters.TryGetValue("id", out string id)) { RawChannelId = id; try { var channelInfo = await ChannelProvider.GetChannelInfo(RawChannelId); ChannelId = channelInfo.ChannelId; ChannelName = channelInfo.Name; ChannelScreenName = channelInfo.ScreenName; ChannelOpenTime = channelInfo.ParseOpenTime(); ChannelUpdateTime = channelInfo.ParseUpdateTime(); } catch { ChannelName = RawChannelId; } FollowToggleButtonService.SetFollowTarget(this); } await base.OnNavigatedToAsync(parameters); }
protected override async Task NavigatedToAsync(CancellationToken cancelToken, NavigatedToEventArgs e, Dictionary <string, object> viewModelState) { if (e.Parameter is string) { RawChannelId = e.Parameter as string; } if (RawChannelId == null) { return; } try { var channelInfo = await ChannelProvider.GetChannelInfo(RawChannelId); ChannelId = channelInfo.ChannelId; ChannelName = channelInfo.Name; ChannelScreenName = channelInfo.ScreenName; ChannelOpenTime = channelInfo.ParseOpenTime(); ChannelUpdateTime = channelInfo.ParseUpdateTime(); } catch { ChannelName = RawChannelId; } FollowToggleButtonService.SetFollowTarget(this); PageManager.PageTitle = ChannelName; await base.NavigatedToAsync(cancelToken, e, viewModelState); }
protected override async Task NavigatedToAsync(CancellationToken cancelToken, NavigatedToEventArgs e, Dictionary <string, object> viewModelState) { if (e.Parameter is string) { var payload = MylistPagePayload.FromParameterString <MylistPagePayload>(e.Parameter as string); var playableList = await MylistHelper.FindMylist(payload.Id, payload.Origin); Mylist.Value = playableList; MylistOrigin.Value = playableList.ToMylistOrigin().Value; } if (Mylist.Value != null) { MylistBookmark = Database.BookmarkDb.Get(Database.BookmarkType.Mylist, Mylist.Value.Id) ?? new Database.Bookmark() { Label = Mylist.Value.Label, Content = Mylist.Value.Id, BookmarkType = Database.BookmarkType.Mylist, }; FollowToggleButtonService.SetFollowTarget(Mylist.Value as Interfaces.IFollowable); RaisePropertyChanged(nameof(MylistBookmark)); } await Reset(); await base.NavigatedToAsync(cancelToken, e, viewModelState); }
/* * * private async Task<bool> FavoriteMylist() * { * if (PlayableList.Value == null) { return false; } * if (PlayableList.Value.Origin != PlaylistOrigin.OtherUser) { return false; } * * var favManager = HohoemaApp.FollowManager; * var result = await favManager.AddFollow(FollowItemType.Mylist, PlayableList.Value.Id, PlayableList.Value.Label); * * return result == ContentManageResult.Success || result == ContentManageResult.Exist; * } * * private async Task<bool> UnfavoriteMylist() * { * if (PlayableList.Value == null) { return false; } * if (PlayableList.Value.Origin != PlaylistOrigin.OtherUser) { return false; } * * var favManager = HohoemaApp.FollowManager; * var result = await favManager.RemoveFollow(FollowItemType.Mylist, PlayableList.Value.Id); * * return result == ContentManageResult.Success; * * } * */ public async Task OnNavigatedToAsync(INavigationParameters parameters) { string mylistId = null; PlaylistOrigin?origin = null; if (parameters.TryGetValue <string>("id", out var idString)) { mylistId = idString; } else if (parameters.TryGetValue <int>("id", out var idInt)) { mylistId = idInt.ToString(); } if (parameters.TryGetValue <PlaylistOrigin>("origin", out var mylistOrigin)) { origin = mylistOrigin; } else if (parameters.TryGetValue("origin", out string mylistOriginString)) { if (Enum.TryParse(mylistOriginString, out mylistOrigin)) { origin = mylistOrigin; } } var playableList = await MylistHelper.FindMylist(mylistId, origin); if (playableList == null) { return; } Mylist.Value = playableList; MylistOrigin.Value = playableList.ToMylistOrigin().Value; if (Mylist.Value != null) { MylistBookmark = Database.BookmarkDb.Get(Database.BookmarkType.Mylist, Mylist.Value.Id) ?? new Database.Bookmark() { Label = Mylist.Value.Label, Content = Mylist.Value.Id, BookmarkType = Database.BookmarkType.Mylist, }; FollowToggleButtonService.SetFollowTarget(Mylist.Value as Interfaces.IFollowable); RaisePropertyChanged(nameof(MylistBookmark)); } PageManager.PageTitle = playableList.Label; await Reset(); }
public ChannelFavItemVM( FollowItemInfo follow, Services.NiconicoFollowToggleButtonService followToggleButtonService, Models.Subscription.SubscriptionManager subscriptionManager, Commands.Subscriptions.CreateSubscriptionGroupCommand createSubscriptionGroupCommand ) : base(follow, followToggleButtonService, subscriptionManager, createSubscriptionGroupCommand) { FollowToggleButtonService.SetFollowTarget(this); }
protected override async Task NavigatedToAsync(CancellationToken cancelToken, NavigatedToEventArgs e, Dictionary <string, object> viewModelState) { NowLoading = true; string userId = null; if (e.Parameter is string) { userId = e.Parameter as string; } else if (e.Parameter is uint) { userId = ((uint)e.Parameter).ToString(); } else { userId = NiconicoSession.UserId.ToString(); } if (userId == UserId) { NowLoading = false; return; } UserId = userId; // ログインユーザーと同じ場合、お気に入り表示をOFFに IsLoginUser = NiconicoSession.UserId.ToString() == userId; IsLoadFailed = false; MylistGroups.Clear(); VideoInfoItems.Clear(); try { var userInfo = await UserProvider.GetUserDetail(UserId); var user = userInfo; UserName = user.Nickname; UserIconUri = user.ThumbnailUri; FollowerCount = user.FollowerCount; StampCount = user.StampCount; VideoCount = user.TotalVideoCount; IsVideoPrivate = user.IsOwnerVideoPrivate; } catch { IsLoadFailed = true; NowLoading = false; } if (UserId == null) { return; } // NGユーザーの設定 if (!IsLoginUser) { var ngResult = NgSettings.IsNgVideoOwnerId(UserId); IsNGVideoOwner.Value = ngResult != null; } else { IsNGVideoOwner.Value = false; } try { await Task.Delay(500); var userVideos = await UserProvider.GetUserVideos(uint.Parse(UserId), 1); foreach (var item in userVideos.Items.Take(5)) { var vm = new VideoInfoControlViewModel(item.VideoId); vm.SetTitle(item.Title); vm.SetThumbnailImage(item.ThumbnailUrl.OriginalString); VideoInfoItems.Add(vm); } RaisePropertyChanged(nameof(VideoInfoItems)); } catch (Exception ex) { IsLoadFailed = true; NowLoading = false; Debug.WriteLine(ex.Message); } HasOwnerVideo = VideoInfoItems.Count != 0; if (NiconicoSession.IsLoginUserId(UserId)) { foreach (var item in UserMylistManager.Mylists) { MylistGroups.Add(new MylistGroupListItem(item)); } } else { try { // await Task.Delay(500); var mylistGroups = await UserProvider.GetUserMylistGroups(UserId); foreach (var item in mylistGroups) { MylistGroups.Add(new MylistGroupListItem(item)); } } catch (Exception ex) { IsLoadFailed = true; Debug.WriteLine(ex.Message); } } RaisePropertyChanged(nameof(MylistGroups)); UserBookmark = Database.BookmarkDb.Get(Database.BookmarkType.User, UserId) ?? new Database.Bookmark() { Content = UserId, Label = UserName, BookmarkType = Database.BookmarkType.User }; RaisePropertyChanged(nameof(UserBookmark)); FollowToggleButtonService.SetFollowTarget(this); NowLoading = false; }
public async Task OnNavigatedToAsync(INavigationParameters parameters) { // ナビゲーションパラメータからコミュニティIDを取得 IsFailed = false; try { NowLoading = true; if (parameters.TryGetValue("id", out string id)) { CommunityId = id; var res = await CommunityProvider.GetCommunityInfo(CommunityId); if (res == null || !res.IsStatusOK) { return; } CommunityInfo = res.Community; RaisePropertyChanged(nameof(CommunityName)); RaisePropertyChanged(nameof(IsPublic)); RaisePropertyChanged(nameof(CommunityDescription)); RaisePropertyChanged(nameof(IsOfficial)); RaisePropertyChanged(nameof(MaxUserCount)); RaisePropertyChanged(nameof(UserCount)); RaisePropertyChanged(nameof(CommunityLevel)); RaisePropertyChanged(nameof(CreatedAt)); RaisePropertyChanged(nameof(ThumbnailUrl)); RaisePropertyChanged(nameof(TopUrl)); var detail = await CommunityProvider.GetCommunityDetail(CommunityId); if (detail == null && !detail.IsStatusOK) { return; } CommunityDetail = detail.CommunitySammary.CommunityDetail; ApplicationTheme appTheme; if (_appearanceSettings.Theme == ElementTheme.Dark) { appTheme = ApplicationTheme.Dark; } else if (_appearanceSettings.Theme == ElementTheme.Light) { appTheme = ApplicationTheme.Light; } else { appTheme = Views.Helpers.SystemThemeHelper.GetSystemTheme(); } var profileHtmlId = $"{CommunityId}_profile"; ProfileHtmlFileUri = await Models.Helpers.HtmlFileHelper.PartHtmlOutputToCompletlyHtml(profileHtmlId, CommunityDetail.ProfielHtml, appTheme); OwnerUserInfo = new UserInfoViewModel( CommunityDetail.OwnerUserName, CommunityDetail.OwnerUserId ); IsOwnedCommunity = NiconicoSession.UserId.ToString() == OwnerUserInfo.Id; Tags = CommunityDetail.Tags.Select(x => new NicoVideoTag(x)) .ToList(); FutureLiveList = CommunityDetail.FutureLiveList.Select(x => new CommunityLiveInfoViewModel(x)) .ToList(); RecentLiveList = CommunityDetail.RecentLiveList.Select(x => new CommunityLiveInfoViewModel(x)) .ToList(); NewsList = new List <CommunityNewsViewModel>(); foreach (var news in CommunityDetail.NewsList) { var newsVM = await CommunityNewsViewModel.Create(CommunityId, news.Title, news.PostAuthor, news.PostDate, news.ContentHtml, PageManager, _appearanceSettings); NewsList.Add(newsVM); } HasNews = NewsList.Count > 0; CurrentLiveInfoList = CommunityDetail.CurrentLiveList.Select(x => new CurrentLiveInfoViewModel(x, CommunityDetail)) .ToList(); HasCurrentLiveInfo = CurrentLiveInfoList.Count > 0; CommunityVideoSamples = new List <CommunityVideoInfoViewModel>(); foreach (var sampleVideo in CommunityDetail.VideoList) { var videoInfoVM = new CommunityVideoInfoViewModel(sampleVideo); CommunityVideoSamples.Add(videoInfoVM); } RaisePropertyChanged(nameof(CommunityOwnerName)); RaisePropertyChanged(nameof(VideoCount)); RaisePropertyChanged(nameof(PrivilegeDescription)); // RaisePropertyChanged(nameof(IsJoinAutoAccept)); // RaisePropertyChanged(nameof(IsJoinWithoutPrivacyInfo)); // RaisePropertyChanged(nameof(IsCanLiveOnlyPrivilege)); // RaisePropertyChanged(nameof(IsCanAcceptJoinOnlyPrivilege)); // RaisePropertyChanged(nameof(IsCanSubmitVideoOnlyPrivilege)); RaisePropertyChanged(nameof(ProfileHtmlFileUri)); RaisePropertyChanged(nameof(OwnerUserInfo)); RaisePropertyChanged(nameof(Tags)); RaisePropertyChanged(nameof(FutureLiveList)); RaisePropertyChanged(nameof(NewsList)); RaisePropertyChanged(nameof(HasNews)); RaisePropertyChanged(nameof(CurrentLiveInfoList)); RaisePropertyChanged(nameof(HasCurrentLiveInfo)); RaisePropertyChanged(nameof(CommunityVideoSamples)); // フォロー表示・操作の準備 // Note: オーナーコミュニティのフォローを解除=コミュニティの解散操作となるため注意が必要 // 安全管理上、アプリ上でコミュニティの解散は不可の方向に倒して対応したい if (!IsOwnedCommunity) { FollowToggleButtonService.SetFollowTarget(this); } else { FollowToggleButtonService.SetFollowTarget(null); } UpdateCanNotFollowReason(); } } catch (Exception ex) { Debug.WriteLine(ex.ToString()); IsFailed = true; } finally { NowLoading = false; } }
/* * * private async Task<bool> FavoriteMylist() * { * if (PlayableList.Value == null) { return false; } * if (PlayableList.Value.Origin != PlaylistOrigin.OtherUser) { return false; } * * var favManager = HohoemaApp.FollowManager; * var result = await favManager.AddFollow(FollowItemType.Mylist, PlayableList.Value.Id, PlayableList.Value.Label); * * return result == ContentManageResult.Success || result == ContentManageResult.Exist; * } * * private async Task<bool> UnfavoriteMylist() * { * if (PlayableList.Value == null) { return false; } * if (PlayableList.Value.Origin != PlaylistOrigin.OtherUser) { return false; } * * var favManager = HohoemaApp.FollowManager; * var result = await favManager.RemoveFollow(FollowItemType.Mylist, PlayableList.Value.Id); * * return result == ContentManageResult.Success; * * } * */ public async Task OnNavigatedToAsync(INavigationParameters parameters) { string mylistId = null; if (parameters.TryGetValue <string>("id", out var idString)) { mylistId = idString; } else if (parameters.TryGetValue <int>("id", out var idInt)) { mylistId = idInt.ToString(); } var mylist = await _playlistAggregate.FindPlaylistAsync(mylistId) as MylistPlaylist; if (mylist == null) { return; } Mylist.Value = mylist; IsUserOwnerdMylist = _mylistRepository.IsLoginUserMylistId(mylist.Id); IsLoginUserDeflist = mylist.IsDefaultMylist(); IsWatchAfterLocalMylist = false; IsLocalMylist = false; if (mylist is LoginUserMylistPlaylist loginMylist) { Observable.FromEventPattern <MylistItemAddedEventArgs>( h => loginMylist.MylistItemAdded += h, h => loginMylist.MylistItemAdded -= h ) .Subscribe(e => { var args = e.EventArgs; if (args.MylistId == Mylist.Value.Id) { RefreshCommand.Execute(); } }) .AddTo(_NavigatingCompositeDisposable); Observable.FromEventPattern <MylistItemRemovedEventArgs>( h => loginMylist.MylistItemRemoved += h, h => loginMylist.MylistItemRemoved -= h ) .Subscribe(e => { var args = e.EventArgs; if (args.MylistId == Mylist.Value.Id) { foreach (var removed in args.SuccessedItems) { var removedItem = MylistItems.FirstOrDefault(x => x.Id == removed); if (removedItem != null) { MylistItems.Remove(removedItem); } } } }) .AddTo(_NavigatingCompositeDisposable); } MylistItems = await CreateItemsSourceAsync(mylist); MaxItemsCount = Mylist.Value.Count; if (Mylist.Value != null) { MylistBookmark = Database.BookmarkDb.Get(Database.BookmarkType.Mylist, Mylist.Value.Id) ?? new Database.Bookmark() { Label = Mylist.Value.Label, Content = Mylist.Value.Id, BookmarkType = Database.BookmarkType.Mylist, }; FollowToggleButtonService.SetFollowTarget(Mylist.Value as Interfaces.IFollowable); RaisePropertyChanged(nameof(MylistBookmark)); } EditMylistGroupCommand.RaiseCanExecuteChanged(); DeleteMylistCommand.RaiseCanExecuteChanged(); }
public async Task OnNavigatedToAsync(INavigationParameters parameters) { string userId = null; if (parameters.TryGetValue <string>("id", out var id)) { userId = id; } if (userId == UserId) { return; } UserId = userId; // ログインユーザーと同じ場合、お気に入り表示をOFFに IsLoginUser = NiconicoSession.UserId.ToString() == userId; IsLoadFailed = false; VideoInfoItems.Clear(); try { var userInfo = await UserProvider.GetUserDetail(UserId); var user = userInfo; UserName = user.Nickname; UserIconUri = user.ThumbnailUri; FollowerCount = user.FollowerCount; StampCount = user.StampCount; VideoCount = user.TotalVideoCount; IsVideoPrivate = user.IsOwnerVideoPrivate; } catch { IsLoadFailed = true; } if (UserId == null) { return; } // NGユーザーの設定 if (!IsLoginUser) { var ngResult = NgSettings.IsNgVideoOwnerId(UserId); IsNGVideoOwner.Value = ngResult != null; } else { IsNGVideoOwner.Value = false; } try { await Task.Delay(500); var userVideos = await UserProvider.GetUserVideos(uint.Parse(UserId), 1); foreach (var item in userVideos.Items.Take(5)) { var vm = new VideoInfoControlViewModel(item.VideoId); vm.SetTitle(item.Title); vm.SetThumbnailImage(item.ThumbnailUrl.OriginalString); VideoInfoItems.Add(vm); } RaisePropertyChanged(nameof(VideoInfoItems)); } catch (Exception ex) { IsLoadFailed = true; Debug.WriteLine(ex.Message); } HasOwnerVideo = VideoInfoItems.Count != 0; if (NiconicoSession.IsLoginUserId(UserId)) { MylistGroups = UserMylistManager.Mylists; } else { try { // await Task.Delay(500); MylistGroups = await _mylistRepository.GetUserMylistsAsync(UserId); } catch (Exception ex) { IsLoadFailed = true; Debug.WriteLine(ex.Message); } } RaisePropertyChanged(nameof(MylistGroups)); UserBookmark = Database.BookmarkDb.Get(Database.BookmarkType.User, UserId) ?? new Database.Bookmark() { Content = UserId, Label = UserName, BookmarkType = Database.BookmarkType.User }; RaisePropertyChanged(nameof(UserBookmark)); FollowToggleButtonService.SetFollowTarget(this); }
protected override async Task NavigatedToAsync(CancellationToken cancelToken, NavigatedToEventArgs e, Dictionary <string, object> viewModelState) { // ナビゲーションパラメータからコミュニティIDを取得 IsFailed = false; try { NowLoading = true; CommunityId = null; if (e.Parameter is string) { CommunityId = e.Parameter as string; } // コミュニティ情報の取得 if (!string.IsNullOrEmpty(CommunityId)) { var res = await CommunityProvider.GetCommunityInfo(CommunityId); if (res == null || !res.IsStatusOK) { return; } CommunityInfo = res.Community; RaisePropertyChanged(nameof(CommunityName)); RaisePropertyChanged(nameof(IsPublic)); RaisePropertyChanged(nameof(CommunityDescription)); RaisePropertyChanged(nameof(IsOfficial)); RaisePropertyChanged(nameof(MaxUserCount)); RaisePropertyChanged(nameof(UserCount)); RaisePropertyChanged(nameof(CommunityLevel)); RaisePropertyChanged(nameof(CreatedAt)); RaisePropertyChanged(nameof(ThumbnailUrl)); RaisePropertyChanged(nameof(TopUrl)); var detail = await CommunityProvider.GetCommunityDetail(CommunityId); if (detail == null && !detail.IsStatusOK) { return; } CommunityDetail = detail.CommunitySammary.CommunityDetail; var profileHtmlId = $"{CommunityId}_profile"; ProfileHtmlFileUri = await Models.Helpers.HtmlFileHelper.PartHtmlOutputToCompletlyHtml(profileHtmlId, CommunityDetail.ProfielHtml); OwnerUserInfo = new UserInfoViewModel( CommunityDetail.OwnerUserName, CommunityDetail.OwnerUserId ); IsOwnedCommunity = NiconicoSession.UserId.ToString() == OwnerUserInfo.Id; Tags = CommunityDetail.Tags.Select(x => new TagViewModel(x)) .ToList(); FutureLiveList = CommunityDetail.FutureLiveList.Select(x => new CommunityLiveInfoViewModel(x)) .ToList(); RecentLiveList = CommunityDetail.RecentLiveList.Select(x => new CommunityLiveInfoViewModel(x)) .ToList(); NewsList = new List <CommunityNewsViewModel>(); foreach (var news in CommunityDetail.NewsList) { var newsVM = await CommunityNewsViewModel.Create(CommunityId, news.Title, news.PostAuthor, news.PostDate, news.ContentHtml, PageManager); NewsList.Add(newsVM); } HasNews = NewsList.Count > 0; CurrentLiveInfoList = CommunityDetail.CurrentLiveList.Select(x => new CurrentLiveInfoViewModel(x, CommunityDetail)) .ToList(); HasCurrentLiveInfo = CurrentLiveInfoList.Count > 0; CommunityVideoSamples = new List <CommunityVideoInfoViewModel>(); foreach (var sampleVideo in CommunityDetail.VideoList) { var videoInfoVM = new CommunityVideoInfoViewModel(sampleVideo); CommunityVideoSamples.Add(videoInfoVM); } RaisePropertyChanged(nameof(CommunityOwnerName)); RaisePropertyChanged(nameof(VideoCount)); RaisePropertyChanged(nameof(PrivilegeDescription)); // RaisePropertyChanged(nameof(IsJoinAutoAccept)); // RaisePropertyChanged(nameof(IsJoinWithoutPrivacyInfo)); // RaisePropertyChanged(nameof(IsCanLiveOnlyPrivilege)); // RaisePropertyChanged(nameof(IsCanAcceptJoinOnlyPrivilege)); // RaisePropertyChanged(nameof(IsCanSubmitVideoOnlyPrivilege)); RaisePropertyChanged(nameof(ProfileHtmlFileUri)); RaisePropertyChanged(nameof(OwnerUserInfo)); RaisePropertyChanged(nameof(Tags)); RaisePropertyChanged(nameof(FutureLiveList)); RaisePropertyChanged(nameof(NewsList)); RaisePropertyChanged(nameof(HasNews)); RaisePropertyChanged(nameof(CurrentLiveInfoList)); RaisePropertyChanged(nameof(HasCurrentLiveInfo)); RaisePropertyChanged(nameof(CommunityVideoSamples)); // フォロー表示・操作の準備 // Note: オーナーコミュニティのフォローを解除=コミュニティの解散操作となるため注意が必要 // 安全管理上、アプリ上でコミュニティの解散は不可の方向に倒して対応したい if (!IsOwnedCommunity) { FollowToggleButtonService.SetFollowTarget(this); } else { FollowToggleButtonService.SetFollowTarget(null); } UpdateCanNotFollowReason(); } } catch (Exception ex) { Debug.WriteLine(ex.ToString()); IsFailed = true; } finally { NowLoading = false; } }