Example #1
0
        private WOLArticle GetFirstArticle(string database)
        {
            WOLArticle article;

            if (database == "primary")
            {
                if (library == Library.DailyText)
                {
                    article = primaryArticles.First(a => a.ArticleNumber == SelectedArticle.ToString());
                }
                else
                {
                    article = primaryArticles.First(a => NavStruct.Parse(a.ArticleNumber).Chapter == SelectedArticle.Chapter);
                }
            }
            else
            {
                if (library == Library.DailyText)
                {
                    article = secondaryArticles.First(a => a.ArticleNumber == SelectedArticle.ToString());
                }
                else
                {
                    article = secondaryArticles.First(a => NavStruct.Parse(a.ArticleNumber).Chapter == SelectedArticle.Chapter);
                }
            }

            return(article);
        }
Example #2
0
        public App()
        {
            // If book, chapter, or verse is changed, store it in the navigation dictionary
            this.ArticleChanged  += App_ArticleChanged;
            this.LanguageChanged += App_LanguageChanged;
            this.PinyinChanged   += App_PinyinChanged;

            SelectedArticle = new NavStruct();
        }
Example #3
0
        private void SelectChapter(object sender, AdapterView.ItemClickEventArgs e)
        {
            if (library == App.STATE.CurrentLibrary)
            {
                NavStruct selected = NavStruct.Parse(primaryArticles[e.Position].ArticleNumber);

                SelectedArticle = selected;

                DisplayArticles();
            }
        }
Example #4
0
 public void UpdateArticleNavigation(string key, NavStruct value)
 {
     if (ArticleNavigation.ContainsKey(key))
     {
         ArticleNavigation[key] = value;
     }
     else
     {
         ArticleNavigation.Add(key, value);
     }
 }
Example #5
0
        private async Task UpdateMonthlyPublications()
        {
            List <string> meps = new List <string>((await StorehouseService.Instance.GetArticlesAsync())
                                                   .Where(a => NavStruct.Parse(a.MepsID).Publication.StartsWith("mwb-") || NavStruct.Parse(a.MepsID).Publication.StartsWith("w-") || NavStruct.Parse(a.MepsID).Publication.StartsWith("wp-") || NavStruct.Parse(a.MepsID).Publication.StartsWith("g-"))
                                                   .Select(a => a.MepsID));

            GemWriteLine("MEPS Count", meps.Count);

            // Meeting Workbook
            foreach (var article in await WolDownloader.WolDownloader.GenerateMonthlyPublicationAsync("mwb", ArticleType.Monthly, meps))
            {
                try
                {
                    await StorehouseService.Instance.AddArticleAsync(article.ToArticle());

                    WolDownloader.WolDownloader.DebugArticleOutput(article);
                }
                catch (Exception e) { Debug.WriteLine(e.Message); }
            }
            // Watchtower Study Edition
            foreach (var article in await WolDownloader.WolDownloader.GenerateMonthlyPublicationAsync("w", ArticleType.Monthly, meps))
            {
                try
                {
                    await StorehouseService.Instance.AddArticleAsync(article.ToArticle());

                    //WolDownloader.WolDownloader.DebugArticleOutput(article);
                }
                catch (Exception e) { Debug.WriteLine(e.Message); }
            }
            // Watchtower Public
            foreach (var article in await WolDownloader.WolDownloader.GenerateMonthlyPublicationAsync("wp", ArticleType.Monthly, meps))
            {
                try
                {
                    await StorehouseService.Instance.AddArticleAsync(article.ToArticle());

                    //WolDownloader.WolDownloader.DebugArticleOutput(article);
                }
                catch (Exception e) { Debug.WriteLine(e.Message); }
            }
            // Awake!
            foreach (var article in await WolDownloader.WolDownloader.GenerateMonthlyPublicationAsync("g", ArticleType.Monthly, meps))
            {
                try
                {
                    await StorehouseService.Instance.AddArticleAsync(article.ToArticle());

                    //WolDownloader.WolDownloader.DebugArticleOutput(article);
                }
                catch (Exception e) { Debug.WriteLine(e.Message); }
            }
        }
        private void SelectNewLibrary(Library library)
        {
            if (IsFinishing)
            {
                return;
            }

            // If there are fragments loaded, do nothing
            Stack <Fragment> stack = stacks[(int)App.STATE.CurrentLibrary];

            if (stack.Count > 0)
            {
                drawer.CloseDrawer(list);
                return;
            }

            Fragment fragment;

            App.STATE.CurrentLibrary = library;
            string tag = Enum.GetName(typeof(Library), library);

            FragmentManager     manager     = SupportFragmentManager;
            FragmentTransaction transaction = manager.BeginTransaction();

            transaction.SetTransition((int)FragmentTransit.FragmentFade);

            if (App.STATE.CurrentLibrary == Library.DailyText)
            {
                string date = App.FUNCTIONS.FormatDateTime(DateTime.Now);

                fragment = new ArticleFragment(NavStruct.Parse(date), library);
            }
            else
            {
                fragment = new LibraryFragment();
            }

            transaction.Replace(Resource.Id.content_frame, fragment);
            transaction.Commit();

            int index = App.STATE.Libraries.IndexOf(library);

            list.SetItemChecked(index, true);
            list.SetSelection(index);

            drawer.CloseDrawer(list);

            Console.WriteLine("Current LibraryMode is " + App.STATE.CurrentLibrary.ToString());
        }
Example #7
0
        private int GetNavigationIndex()
        {
            int index = 0;

            if (library == Library.DailyText)
            {
                index = Array.IndexOf(primaryArticles.Select(a => a.ArticleNumber).ToArray(), SelectedArticle.ToString());
            }
            else
            {
                index = Array.IndexOf(primaryArticles.Select(a => NavStruct.Parse(a.ArticleNumber).Chapter.ToString()).ToArray(), SelectedArticle.Chapter.ToString());
            }

            return(index);
        }
Example #8
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
            };
        }
        private void LoadArticle(NavStruct article)
        {
            Fragment fragment = new ArticleFragment(article, LibraryMode);

            fragment.RetainInstance = true;

            FragmentManager     manager     = Activity.SupportFragmentManager;
            FragmentTransaction transaction = manager.BeginTransaction();

            transaction.SetTransition((int)FragmentTransit.FragmentFade);
            transaction.Add(Resource.Id.content_frame, fragment, null);
            transaction.AddToBackStack(null);
            transaction.Commit();

            bool memorize = PreferenceManager.GetDefaultSharedPreferences(Activity.ApplicationContext).GetBoolean("memorizeLibraryArticle", true);

            if (memorize)
            {
                ((MainLibraryActivity)Activity).stacks[(int)LibraryMode].Push(fragment);
            }
        }
Example #10
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();
        }
Example #12
0
 public ArticleChangedArgs(NavStruct selectedArticle)
 {
     this.selectedArticle = selectedArticle;
 }
Example #13
0
        private void RefreshActionBar()
        {
            // Keep this try.catch UNTIL YOU GET THE PINYIN FOR INSIGHT!!!!!
            try
            {
                WOLArticle article         = GetFirstArticle("primary");
                string     publicationName = string.Empty;

                // Set Publication title
                int width = (int)(App.STATE.Activity.Resources.GetDimension(Resource.Dimension.bible_nav_bible_book_grid_width) / App.STATE.Activity.Resources.DisplayMetrics.Density);
                if (library == Library.Bible)
                {
                    publicationName = article.PublicationName;

                    string bibleBook = App.FUNCTIONS.GetAllBibleBooks(App.STATE.PrimaryLanguage.EnglishName).Single(b => b.Number.Equals((NavStruct.Parse(article.ArticleNumber).Book - 1).ToString())).Name;
                    gridViewTitle.SetText(Html.FromHtml("<center>" + bibleBook.Replace("\n", "<br/>") + "</center>"), TextView.BufferType.Normal);
                }
                else
                {
                    if (width > 100)
                    {
                        publicationName = App.FUNCTIONS.GetPublicationName(App.STATE.Language, article.PublicationCode);
                    }
                    else
                    {
                        publicationName = App.FUNCTIONS.GetPublicationName(App.STATE.Language, article.PublicationCode, true);
                    }
                    gridViewTitle.SetText(Html.FromHtml("<center>" + publicationName.Replace("\n", "<br/>") + "</center>"), TextView.BufferType.Normal);
                }

                // Set ActionBar type
                App.STATE.SetActionBarTitle(((MainLibraryActivity)Activity).SupportActionBar, article.ArticleTitle, publicationName);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Example #14
0
        public void InitializeLayoutParadigm(View view)
        {
            // Set views
            primaryWebview   = view.FindViewById <ObservableWebView>(Resource.Id.primaryWebView);
            secondaryWebview = view.FindViewById <ObservableWebView>(Resource.Id.secondaryWebView);
            flipper          = view.FindViewById <ViewFlipper>(Resource.Id.view_flipper);
            gridViewTitle    = view.FindViewById <TextView>(Resource.Id.chapterTitle);
            gridView         = view.FindViewById <HeaderFooterGridView>(Resource.Id.chapterGridView);

            LayoutInflater layoutInflater = LayoutInflater.From(Activity);
            View           footerView     = layoutInflater.Inflate(Resource.Layout.FooterWebView, null);

            gridViewFooterWebview = footerView.FindViewById <ObservableWebView>(Resource.Id.footerWebView);

            // ViewFlipper animations
            flipper.SetInAnimation(Activity, Resource.Animation.push_down_in_no_alpha);
            flipper.SetOutAnimation(Activity, Resource.Animation.push_down_out_no_alpha);

            // Style views
            Typeface face = Typeface.CreateFromAsset(Activity.Assets, "fonts/Roboto-Regular.ttf");

            gridViewTitle.SetTypeface(face, TypefaceStyle.Normal);

            // WebView setup
            InitializeWebView(primaryWebview);
            InitializeWebView(secondaryWebview);
            InitializeWebView(gridViewFooterWebview);

            primaryWebview.Tag   = "primary";
            secondaryWebview.Tag = "secondary";

            ((LinearLayout)primaryWebview.Parent).LayoutParameters = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MatchParent,
                LinearLayout.LayoutParams.MatchParent,
                App.STATE.WebviewWeights[0]);
            ((LinearLayout)secondaryWebview.Parent).LayoutParameters = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MatchParent,
                LinearLayout.LayoutParams.MatchParent,
                App.STATE.WebviewWeights[1]);

            if (App.STATE.WebviewWeights[0] == 0)
            {
                primaryWebview.IsDeflated = true;
            }
            if (App.STATE.WebviewWeights[1] == 0)
            {
                secondaryWebview.IsDeflated = true;
            }

            if (Build.VERSION.SdkInt >= BuildVersionCodes.Honeycomb)
            {
                gridView.ChoiceMode = ChoiceMode.Single;
            }

            gridView.ItemClick += SelectChapter;

            if (library == Library.Bible)
            {
                gridView.DoSetHeight = false;

                gridViewTitle.Click += text_Click;
                gridViewTitle.SetCompoundDrawablesWithIntrinsicBounds(Resource.Drawable.ic_outline, 0, 0, 0);

                // Set Bible book outline
                NavStruct outline = new NavStruct()
                {
                    Book    = 0,
                    Chapter = SelectedArticle.Book,
                    Verse   = 0
                };
                OutlineContents = JwStore.QueryArticle("outline", outline, LibraryStorehouse.English).ArticleContent;
                gridView.AddFooterView(footerView);
                gridViewFooterWebview.LoadDataWithBaseURL("file:///android_asset/", OutlineContents, "text/html", "utf-8", null);
            }
        }
        private void ShowChapterPrompt(string storehouse, WOLPublication pub, NavStruct article)
        {
            LayoutInflater       inflater = (LayoutInflater)Activity.GetSystemService(Context.LayoutInflaterService);
            View                 view     = inflater.Inflate(Resource.Layout.DialogChapterSelect, null);
            HeaderFooterGridView gridview = view.FindViewById <HeaderFooterGridView>(Resource.Id.chapterSelectGridView);

            gridview.SetSelector(Android.Resource.Color.Transparent);

            List <WOLArticle> articles;
            List <ISpanned>   titles;

            if (LibraryMode == Library.Bible)
            {
                gridview.NumColumns  = -1;
                gridview.StretchMode = StretchMode.NoStretch;

                string bookNumber = article.Book.ToString() + ".";

                articles = JwStore.QueryArticleChapterTitles(PublicationType.Bible, storehouse)
                           .Where(a => a.ArticleNumber.StartsWith(bookNumber)).ToList();

                titles = articles.Select(a => Html.FromHtml(a.ArticleTitle.ToString().Split(new[] { ' ' }).Last())).ToList();
                if (titles.Count == 1)
                {
                    LoadArticle(article);

                    return;
                }
            }
            else if (LibraryMode == Library.Insight)
            {
                gridview.NumColumns  = 2;
                gridview.StretchMode = StretchMode.StretchColumnWidth;

                articles = JwStore.QueryArticleChapterTitles(PublicationType.Insight, storehouse)
                           .Where(i => i.ArticleGroup.Equals(pub.Group))
                           .ToList();

                titles = articles.Select(a => Html.FromHtml(a.ArticleTitle.Replace("\n", "<br/>").Split('<')[0] + "<br/><i>" + a.ArticleLocation + "</i>")).ToList();
            }
            else
            {
                gridview.NumColumns  = 1;
                gridview.StretchMode = StretchMode.StretchColumnWidth;

                articles = JwStore.QueryArticleChapterTitles(pub.Code, storehouse)
                           .ToList();

                titles = articles.Select(a => Html.FromHtml(a.ArticleTitle.Replace("\n", "<br/>").Split('<')[0] + "<br/><i>" + a.ArticleLocation + "</i>")).ToList();
                if (titles.Count == 1)
                {
                    LoadArticle(article);

                    return;
                }
            }

            MaterialDialog dialog = null;

            gridview.Adapter    = new ArticleButtonAdapter(Activity, titles.ToArray());
            gridview.ItemClick += (s, args) =>
            {
                dialog.Dismiss();

                article = NavStruct.Parse(articles[args.Position].ArticleNumber);
                LoadArticle(article);
            };

            MaterialDialog.Builder popup = new MaterialDialog.Builder(Activity);
            popup.SetCustomView(view, false);
            popup.SetTitle(pub.Name.Replace("\n", "<br/>").Split('<')[0]);
            popup.SetNegativeText("X");

            dialog = popup.Show();
        }
        private void LibraryGridView_Click(object sender, AdapterView.ItemClickEventArgs e)
        {
            App.STATE.CurrentArticleGroup = e.Position;

            int    book         = 0;
            int    chapter      = 0;
            int    verse        = 0;
            string lang         = string.Empty;
            string mepsID       = string.Empty;
            string storehouse   = string.Empty;
            string insightGroup = "it-" + e.Position;
            string tag          = (string)((LibraryGridView)sender).Tag;
            bool   showPrompt   = PreferenceManager.GetDefaultSharedPreferences(Activity.ApplicationContext).GetBoolean("chapterSelectionFirst", true);
            //string title = ((LibraryGridView)sender).Adapter.GetItem(e.Position).ToString().Replace("\n", "<br/>").Split('<')[0];

            NavStruct      article = new NavStruct();
            WOLPublication pub     = new WOLPublication();

            if (tag.Contains("English"))
            {
                storehouse = LibraryStorehouse.English;
                lang       = "en-";
            }
            else if (tag.Contains("Simplified"))
            {
                storehouse = LibraryStorehouse.Chinese;
                lang       = "ch-";
            }
            else if (tag.Contains("Pinyin"))
            {
                storehouse = LibraryStorehouse.Pinyin;
                lang       = "ch-";
            }

            // Bible Book
            if (LibraryMode == Library.Bible)
            {
                pub.Code = PublicationType.Bible;

                book    = (tag.Contains("hebrew")) ? e.Position + 1 : e.Position + 40;
                mepsID  = LibraryMode.ToString() + book.ToString();
                chapter = (App.STATE.ArticleNavigation.TryGetValue(mepsID, out article)) ? App.STATE.ArticleNavigation[mepsID].Chapter : 1;
            }
            // Publication
            else if (LibraryMode == Library.Publications)
            {
                pub = App.FUNCTIONS.GetAllWOLPublications(true).ElementAt(e.Position);

                book    = int.Parse(pub.Number);
                mepsID  = LibraryMode.ToString() + book.ToString();
                chapter = (App.STATE.ArticleNavigation.TryGetValue(mepsID, out article)) ? App.STATE.ArticleNavigation[mepsID].Chapter : 1;
            }
            // Insight
            else if (LibraryMode == Library.Insight)
            {
                pub.Code = PublicationType.Insight;

                WOLArticle insight = new SQLiteConnection(storehouse).Query <WOLArticle>("select ArticleNumber from WOLArticle where ArticleGroup = ? limit 1", insightGroup).Single();

                book    = e.Position;
                chapter = (App.STATE.ArticleNavigation.TryGetValue(mepsID, out article)) ? App.STATE.ArticleNavigation[mepsID].Chapter : NavStruct.Parse(insight.ArticleNumber).Chapter;

                insight = new SQLiteConnection(storehouse).Query <WOLArticle>("select ArticleNumber from WOLArticle where ArticleNumber like ? limit 1", "%" + chapter.ToString() + "%").Single();
                verse   = NavStruct.Parse(insight.ArticleNumber).Verse;
            }

            // Set WOL article to load into ArticleFragment;
            article = new NavStruct()
            {
                Book    = book,
                Chapter = chapter,
                Verse   = verse
            };

            if (showPrompt)
            {
                //Set Publication attributes to load chapter titles into dialog for selection
                int width = (int)(App.STATE.Activity.Resources.GetDimension(Resource.Dimension.bible_nav_bible_book_grid_width) / App.STATE.Activity.Resources.DisplayMetrics.Density);
                if (LibraryMode == Library.Bible)
                {
                    pub.Name = App.FUNCTIONS.GetAllBibleBooks(App.STATE.PrimaryLanguage.EnglishName).Single(b => b.Number.Equals((book - 1).ToString())).Name;
                }
                else
                {
                    if (width > 100)
                    {
                        pub.Name = App.FUNCTIONS.GetPublicationName(App.STATE.Language, pub.Code);
                    }
                    else
                    {
                        pub.Name = App.FUNCTIONS.GetPublicationName(App.STATE.Language, pub.Code, true);
                    }
                }
                pub.Group = insightGroup;

                ShowChapterPrompt(storehouse, pub, article);
            }
            else
            {
                LoadArticle(article);
            }
        }
        private void SelectLibrary(Library library)
        {
            if (IsFinishing)
            {
                return;
            }

            //// If there are fragments loaded, do nothing
            //Stack<Fragment> stack = stacks[(int)App.STATE.CurrentLibrary];
            //if (stack.Count > 0)
            //{
            //    drawer.CloseDrawer(list);
            //    return;
            //}

            App.STATE.CurrentLibrary = library;
            string tag = Enum.GetName(typeof(Library), library);

            FragmentManager     manager     = SupportFragmentManager;
            FragmentTransaction transaction = manager.BeginTransaction();

            transaction.SetTransition((int)FragmentTransit.FragmentFade);
            Fragment fragment = SupportFragmentManager.FindFragmentByTag(tag);

            if (fragment == null)
            {
                if (App.STATE.CurrentLibrary == Library.DailyText)
                {
                    string date = App.FUNCTIONS.FormatDateTime(DateTime.Now);

                    fragment = new ArticleFragment(NavStruct.Parse(date), library);
                    fragment.RetainInstance = true;
                }
                else
                {
                    fragment = new LibraryFragment();
                    fragment.RetainInstance = true;
                }

                if (SelectedFragment != null)
                {
                    transaction.Detach(SelectedFragment);
                }
                transaction.Add(Resource.Id.content_frame, fragment, tag);
            }
            else
            {
                transaction.Detach(SelectedFragment);
                transaction.Attach(fragment);
            }

            // COMMIT TRANSACTION
            if (active)
            {
                transaction.Commit();
            }
            else
            {
                transaction.CommitAllowingStateLoss();
            }

            SelectedFragment = fragment;

            int index = App.STATE.Libraries.IndexOf(library);

            list.SetItemChecked(index, true);
            list.SetSelection(index);

            drawer.CloseDrawer(list);

            Console.WriteLine("Current LibraryMode is " + App.STATE.CurrentLibrary.ToString());
        }
Example #18
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();
        }
Example #19
0
 public ArticleFragment(NavStruct article, Library library)
 {
     this.SelectedArticle = article;
     this.library         = library;
 }