public DialogEditChannelViewModel() { this.useHoldingBay = true; _holdingBay = ContainerHelper.GetService <IHoldingBay>(); NewYtChannel = (YTChannel)_holdingBay.GetEntry("CHANNEL_NEW", false); // do not remove object from our repo }
/// <summary> /// Handler executed when SearchBoxCmd command is invoked /// </summary> private async void OnSearchBoxCmd() { // If we dont have anything we skip actions :) if (string.IsNullOrWhiteSpace(SearchBoxTerm)) { return; } string tmpChannelID; Channel tmpChannelStats = null; if (IsUrl(SearchBoxTerm)) { tmpChannelID = _ytManager.GetChannelIdFromUrl(SearchBoxTerm); if (tmpChannelID != null) { tmpChannelStats = _ytManager.GetChannelStatistcsByChannelId(tmpChannelID); } } else { tmpChannelID = await _ytManager.GetChannelIdForUserAsync(SearchBoxTerm); if (tmpChannelID != null) { tmpChannelStats = _ytManager.GetChannelStatistcsByUser(SearchBoxTerm); } } // bail out if we have not found anything if (tmpChannelStats == null) { return; } var chann = new YTChannel() { description = $"{tmpChannelStats.Snippet.Description.Substring(0, tmpChannelStats.Snippet.Description.Length < 100 ? tmpChannelStats.Snippet.Description.Length : 100).Trim()} ...", thumbnail = tmpChannelStats.Snippet.Thumbnails.High.Url, channelId = tmpChannelStats.Id, user = tmpChannelStats.Snippet.Title }; /* * At this stage we have channel so we can push it into our holding bay. * Probably there is a better way to do it - just havent discovered it yet :) */ _holdingbay.AddEntry("CHANNEL_NEW", chann); //let's set up a little MVVM, cos that's what the cool kids are doing: var view = new DialogEditChannel() { DataContext = new DialogEditChannelViewModel() }; //show the dialog bool result = (bool)await DialogHost.Show(view, "RootDialog"); if (!result) { return; // User cliked cancel - so we dont add this channel } chann = (YTChannel)_holdingbay.GetEntry("CHANNEL_NEW"); _yupRepository.AddChannel(chann); _yupRepository.SaveRepository(); YtChannels.Add(chann); _eventBus.RaiseEvent(EventOnBus.channelAdded, this, new EventBusArgs() { Item = chann }); // Clean up searchbox terms _searchBoxTerm = ""; SearchBoxTerm = ""; this.OnFilterChanged(); }