public async Task <bool> PerformChannelLogin(IContentItem item) { var result = false; if ((item == null) || !(item is ChannelEx)) { return(result); } try { IsLoading = true; accountViewModel.IsLoading = true; var channel = item as ChannelEx; if ((channel != null) && (channel.LoginInfo != null)) { try { var validation = await SettingsClient.ValidateCredentials(channel.ID, channel.LoginInfo); if (validation != null) { channel.LoginInfo.LoginPerformed = validation.Success; channel.LoginInfo.ValidationSuccessful = validation.Success; result = validation.Success; if (!validation.Success) { Device.BeginInvokeOnMainThread(() => AlertViewService.Instance.ShowAlert(validation.Message)); } if (validation.Success) { UserStoreService.Instance.StoreRecordInKeychain(getAccountEmail() + "channel-" + item.ID, JsonConvert.SerializeObject(channel.LoginInfo)); } } } finally { accountViewModel.IsLoading = false; } channel.RefreshIsSearchVisible(); accountViewModel.RefreshSelectedChannel(); if (channel.LoginInfo.LoginPerformed) { if (SelectedChannel == channel) { selectedItem = channel; OnPropertyChanged("SelectedItem"); selectedItem.Children = null; SelectedFolder = selectedItem; updateBreadcrumbs(); await TaskQueue.EnqueueAsync(async() => await loadChildrenAsync(selectedItem, false)); OnPropertyChanged("SelectedChannel"); } } } } finally { IsLoading = false; } return(result); }
private async Task <IEnumerable <IContentItem> > getItemChildren(IContentItem item, bool silent) { if (item.IsRoot) { lastChannelsLoaded = DateTime.Now; var result = await ContentClient.GetChannels(); canRefresh = true; if ((result != null) && result.Any()) { return(result); } else { var isConnected = await RestService.Instance.GetIsConnected(); if (!silent && isConnected) { Device.BeginInvokeOnMainThread(() => Application.Current.MainPage.DisplayAlert("Error", "Unable to get channel list. Please make sure you are online, and try again.", "OK")); } return(null); } } else { if (item.IsChannel) { var channel = item as ChannelEx; if (!channel.IsAvailable) { return(null); } if ((channel.LoginInfo != null) && channel.LoginInfo.HasCredentials) { channel.LoginInfo.LoginPerformed = true; var result = await ContentClient.LoginAndGetChildren(item.ID, channel.LoginInfo); if (result == null) { var validation = await SettingsClient.ValidateCredentials(channel.ID, channel.LoginInfo); if ((validation != null) && !validation.Success) { channel.LoginInfo.ValidationSuccessful = false; Device.BeginInvokeOnMainThread(() => AlertViewService.Instance.ShowAlert(validation.Message)); } } else { channel.LoginInfo.ValidationSuccessful = true; UserStoreService.Instance.StoreRecordInKeychain(getAccountEmail() + "channel-" + item.ID, JsonConvert.SerializeObject((item as ChannelEx).LoginInfo)); } channel.RefreshIsSearchVisible(); return(result); } else if (channel.CredentialsType != ChannelCredentialsType.Anonymous) { return(await ContentClient.LoginAndGetChildren(item.ID, new ChannelLoginInfo())); } } return(await ContentClient.GetChildren(item.ID)); } }