Exemple #1
0
        private async Task ValidateChannelLink()
        {
            var    reg  = new Regex(@"(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]");
            string link = ChannelLinkTextBox.Text.Trim();

            if (string.IsNullOrEmpty(link))
            {
                new PopupToast(AppTools.GetReswLanguage("Tip_FieldEmpty"), AppTools.GetThemeSolidColorBrush(ColorType.ErrorColor)).ShowPopup();
            }
            else
            {
                TryLinkButton.IsEnabled = false;
                LoadingRing.IsActive    = true;
                if (!reg.IsMatch(link))
                {
                    var results = await FeedlyResult.GetFeedlyResultFromText(link);

                    TryLinkButton.IsEnabled = true;
                    LoadingRing.IsActive    = false;
                    if (results.Count > 0)
                    {
                        SearchResultContainer.Visibility = Visibility.Visible;
                        FeedlyResults.Clear();
                        foreach (var item in results)
                        {
                            FeedlyResults.Add(item);
                        }
                    }
                    else
                    {
                        SearchResultContainer.Visibility = Visibility.Collapsed;
                        FeedlyResults.Clear();
                        new PopupToast(AppTools.GetReswLanguage("Tip_NoData"), AppTools.GetThemeSolidColorBrush(ColorType.ErrorColor)).ShowPopup();
                    }
                }
                else
                {
                    var channel = await AppTools.GetChannelFromUrl(link);

                    if (channel != null && !string.IsNullOrEmpty(channel.Name))
                    {
                        _sourceChannel             = channel;
                        LoadingRing.IsActive       = false;
                        TryLinkButton.IsEnabled    = true;
                        DetailContainer.Visibility = Visibility.Visible;
                        if (string.IsNullOrEmpty(ChannelNameTextBox.Text) && string.IsNullOrEmpty(ChannelDescriptionTextBox.Text))
                        {
                            ChannelNameTextBox.Text        = channel.Name;
                            ChannelDescriptionTextBox.Text = channel.Description;
                        }
                    }
                    else
                    {
                        LoadingRing.IsActive    = false;
                        TryLinkButton.IsEnabled = true;
                        new PopupToast(AppTools.GetReswLanguage("App_InvalidUrl"), AppTools.GetThemeSolidColorBrush(ColorType.ErrorColor)).ShowPopup();
                    }
                }
            }
        }