예제 #1
0
        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();
        }
예제 #2
0
        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);
            }
        }