Beispiel #1
0
        public void ChangeArticle(int offset)
        {
            Console.WriteLine(Enum.GetName(typeof(Library), library));

            int currentIndex = Array.IndexOf(primaryArticles.Select(a => a.ArticleNumber).ToArray(), SelectedArticle.ToString());
            int index        = currentIndex + offset;
            int last         = primaryArticles.Count - 1;

            if (index > last)
            {
                index = 0;
            }
            else if (index < 0)
            {
                index = last;
            }

            NavStruct nav = NavStruct.Parse(primaryArticles[index].ArticleNumber);

            SelectedArticle = nav;

            DisplayArticles();
        }
        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();
        }
Beispiel #3
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();
        }
Beispiel #4
0
        public async override void Init(object initData)
        {
            Articles = new List <Article>(await StorehouseService.Instance.GetArticlesAsync("es"));

            string template = @"
                <html>
                    <head>
                        <link rel=""stylesheet"" type=""text/css"" href=""css/meps-styles.min.css"">
                        <link rel=""stylesheet"" type=""text/css"" href=""css/wol.min.css"">
                        <link rel=""stylesheet"" type=""text/css"" href=""css/wol.unified.fonts.min.css"">
                        <link rel=""stylesheet"" type=""text/css"" href=""css/pubs/nwt.min.css"">
                        <link rel=""stylesheet"" type=""text/css"" href=""css/today.min.css"">
                        <link rel=""stylesheet"" type=""text/css"" href=""css/print.min.css"" media=""print"">
                    </head>
                    <body>
                        |
                    </body> 
                </html>";

            string    date    = "es" + DateTime.Now.ToString(@"yy.M.d");
            NavStruct article = NavStruct.Parse(date);
            //Debug.WriteLine(article.ToString());

            string primaryHtml = template.Replace("|", Articles.Where(a => a.MepsID == article.ToString() && a.Library == Settings.PrimaryLanguage).First().Content);

            primaryHtml = primaryHtml.Replace(@"href=""/", @"href=""" + "http://wol.jw.org/").Replace(@"src=""/", @"src=""" + "http://wol.jw.org/");

            string secondaryHtml = template.Replace("|", Articles.Where(a => a.MepsID == article.ToString() && a.Library == Settings.SecondaryLanguage).First().Content);

            secondaryHtml = secondaryHtml.Replace(@"href=""/", @"href=""" + "http://wol.jw.org/").Replace(@"src=""/", @"src=""" + "http://wol.jw.org/");

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

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

            PrimaryWebViewSource = new HtmlWebViewSource
            {
                Html    = primaryHtml,
                BaseUrl = root
            };

            SecondaryWebViewSource = new HtmlWebViewSource
            {
                Html    = secondaryHtml,
                BaseUrl = root
            };
        }