private async void UpdateArticle()
        {
            ArticleWebViewSource = null;
            ArticleWebViewSources?.Clear();
            ArticleWebViewSources = null;

            FontSize = Settings.TextSettings.ToString();

            //ArticleTemplate = new ArticleTemplateSelector();

            string    date = "es." + DateTime.Now.ToString(@"M.d");
            NavStruct nav  = NavStruct.Parse(date);

            ArticleWebViewSources = new ObservableCollection <ArticlesDataModel>();

            //ObservableCollection<Article> articles = new ObservableCollection<Article>(await StorehouseService.Instance.GetArticlesAsync("es")).ToObservableCollection();
            ObservableCollection <Article> articles = new ObservableCollection <Article>(await StorehouseService.Instance.GetArticlesAsync("es")).Where(a => a.MepsID == nav.ToString()).ToObservableCollection();

            App.GemWriteLine(articles.Count());

            var root = DependencyService.Get <IBaseUrl>().Get();

            Url = $"{root}index.html";

            string[] meps = articles.Where(a => a.Library == App.PrimaryLanguageBase).Select(a => a.MepsID).ToArray();
            for (int index = 0; index < meps.Count(); index++)
            {
                // PRIMARY
                string primaryHtml = TEMPLATE.Replace("%|%", articles.Where(a => a.MepsID == meps[index] && a.Library == Settings.PrimaryLanguage).SingleOrDefault().Content);
                primaryHtml = primaryHtml.Replace("%||%", FontSize);
                primaryHtml = primaryHtml.Replace(@"href=""/", @"href=""" + "http://wol.jw.org/").Replace(@"src=""/", @"src=""" + "http://wol.jw.org/");

                // SECONDARY
                string secondaryHtml = TEMPLATE.Replace("%|%", articles.Where(a => a.MepsID == meps[index] && a.Library == Settings.SecondaryLanguage).SingleOrDefault().Content);
                secondaryHtml = secondaryHtml.Replace("%||%", FontSize);
                secondaryHtml = secondaryHtml.Replace(@"href=""/", @"href=""" + "http://wol.jw.org/").Replace(@"src=""/", @"src=""" + "http://wol.jw.org/");

                // Reference Symbols
                if (!Settings.ReferenceSymbols)
                {
                    primaryHtml = primaryHtml.Replace(@">*</a>", @" style=""display: none;"">*</a>")
                                  .Replace(@"class=""b"">+</a>", @"class=""b"" style=""display: none;"">*</a>");
                    secondaryHtml = secondaryHtml.Replace(@">*</a>", @" style=""display: none;"">*</a>")
                                    .Replace(@"class=""b"">+</a>", @"class=""b"" style=""display: none;"">*</a>");
                }

                // Choose Chinese WebView
                if (Settings.PrimaryLanguage == LPLanguage.Chinese.GetName())
                {
                    primaryHtml = primaryHtml.Replace(@"<title></title>", @"<title>Chinese</title>"); // IMPORTANT FOR ANNOTATIONS TO WORK ONLY ON CHINESE WEBVIEW
                }
                if (Settings.SecondaryLanguage == LPLanguage.Chinese.GetName())
                {
                    secondaryHtml = secondaryHtml.Replace(@"<title></title>", @"<title>Chinese</title>"); // IMPORTANT FOR ANNOTATIONS TO WORK ONLY ON CHINESE WEBVIEW
                }

                ArticlesDataModel dayArticleModel = new ArticlesDataModel()
                {
                    Primary = new HtmlWebViewSource
                    {
                        Html    = primaryHtml,
                        BaseUrl = root
                    },
                    Secondary = new HtmlWebViewSource
                    {
                        Html    = secondaryHtml,
                        BaseUrl = root
                    }
                };

                ArticleWebViewSources.Add(dayArticleModel);

                if (NavStruct.Parse(meps[index]).ToString() == nav.ToString())
                {
                    ArticleIndex = index;
                }
            }

            ArticleWebViewSource = ArticleWebViewSources.First();
        }
Exemple #2
0
        private async void GenerateArticles(Article article)
        {
            NavStruct nav = NavStruct.Parse(article.MepsID);

            // Loads all articles
            //ObservableCollection<Article> articles = new ObservableCollection<Article>(await StorehouseService.Instance.GetArticlesAsync(article.Symbol)).ToObservableCollection();

            // Loads only 1 article at a time
            //ObservableCollection<Article> articles = new ObservableCollection<Article>(await StorehouseService.Instance.GetArticlesAsync(article.Symbol)).Where(a => a.MepsID == nav.ToString()).ToObservableCollection();
            ObservableCollection <Article> articles = new ObservableCollection <Article>(await StorehouseService.Instance.GetArticlesAsync(article.Symbol)).Where(a => (article.Symbol != "es") ? a.MepsID.Contains("." + nav.MepsID + ".") : a.MepsID == nav.ToString()).ToObservableCollection();

            var root = DependencyService.Get <IBaseUrl>().Get();

            Url = $"{root}index.html";

            string[] meps = articles.Where(a => a.Library == App.PrimaryLanguageBase).Select(a => a.MepsID).ToArray();
            for (int index = 0; index < meps.Count(); index++)
            {
                // PRIMARY
                string primaryHtml = TEMPLATE.Replace("%|%", articles.Where(a => a.MepsID == meps[index] && a.Library == Settings.PrimaryLanguage).SingleOrDefault().Content);
                primaryHtml = primaryHtml.Replace("%||%", FontSize);
                primaryHtml = primaryHtml.Replace(@"href=""/", @"href=""" + "http://wol.jw.org/").Replace(@"src=""/", @"src=""" + "http://wol.jw.org/");

                // SECONDARY
                string secondaryHtml = (article.Symbol != "es") ? TEMPLATE.Replace("%|%", articles.Where(a => a.MepsID.Contains("." + NavStruct.Parse(meps[index]).MepsID + ".") && a.Library == Settings.SecondaryLanguage).SingleOrDefault().Content)
                                                                : TEMPLATE.Replace("%|%", articles.Where(a => a.MepsID == meps[index] && a.Library == Settings.SecondaryLanguage).SingleOrDefault().Content);
                secondaryHtml = secondaryHtml.Replace("%||%", FontSize);
                //string secondaryHtml = template.Replace("|", articles.Where(a => a.MepsID == meps[index] && a.Library == Settings.SecondaryLanguage).SingleOrDefault().Content);
                secondaryHtml = secondaryHtml.Replace(@"href=""/", @"href=""" + "http://wol.jw.org/").Replace(@"src=""/", @"src=""" + "http://wol.jw.org/");

                // Reference Symbols
                if (!Settings.ReferenceSymbols)
                {
                    primaryHtml = primaryHtml.Replace(@">*</a>", @" style=""display: none;"">*</a>")
                                  .Replace(@"class=""b"">+</a>", @"class=""b"" style=""display: none;"">*</a>");
                    secondaryHtml = secondaryHtml.Replace(@">*</a>", @" style=""display: none;"">*</a>")
                                    .Replace(@"class=""b"">+</a>", @"class=""b"" style=""display: none;"">*</a>");
                }

                // Choose Chinese WebView
                if (Settings.PrimaryLanguage == LPLanguage.Chinese.GetName())
                {
                    primaryHtml = primaryHtml.Replace(@"<title></title>", @"<title>Chinese</title>"); // IMPORTANT FOR ANNOTATIONS TO WORK ONLY ON CHINESE WEBVIEW
                }
                if (Settings.SecondaryLanguage == LPLanguage.Chinese.GetName())
                {
                    secondaryHtml = secondaryHtml.Replace(@"<title></title>", @"<title>Chinese</title>"); // IMPORTANT FOR ANNOTATIONS TO WORK ONLY ON CHINESE WEBVIEW
                }

                ArticlesDataModel publicationArticleModel = new ArticlesDataModel()
                {
                    Primary = new HtmlWebViewSource
                    {
                        Html    = primaryHtml,
                        BaseUrl = root
                    },
                    Secondary = new HtmlWebViewSource
                    {
                        Html    = secondaryHtml,
                        BaseUrl = root
                    }
                };

                ArticleWebViewSources.Add(publicationArticleModel);

                if (NavStruct.Parse(meps[index]).ToString() == nav.ToString())
                {
                    ArticleIndex = index;
                    //_articleTitle = articles.Where(a => a.MepsID == meps[index] && a.Library == Settings.PrimaryLanguage).SingleOrDefault().Title;
                }
            }

            ArticleWebViewSource = ArticleWebViewSources.First();
        }