예제 #1
0
 //Search by topic
 public void FilterResults(DocumentList documentList, bool truncate, bool answers, bool proofs, bool allDocs, string searchTerm)
 {
     resultList.Clear();
     Log.Info("Filter Results", "Filter has begun processing");
     //for (int y = 1; y <= documentList.Count; y++)
     foreach (Document document in documentList)
     {
         if (document.Type == "CONFESSION")
         {
             Confession confession = (Confession)document;
             confession.Filter(searchTerm, truncate);
             if (confession.Matches >= 1)
             {
                 resultList.Add(confession);
             }
         }
         else if (document.Type == "CATECHISM")
         {
             Catechism catechism = (Catechism)document;
             catechism.Filter(searchTerm, truncate);
             if (catechism.Matches >= 1)
             {
                 resultList.Add(catechism);
             }
         }
     }
     this.documentList = resultList;
     this.documentList.MergeSort(DocumentList.OrderEnum.MatchOrder);
 }
        private string ShareListBuilder(string shares, Document document)
        {
            string        qHeader = "", aHeader = "Answer:", pHeader = "Proofs:", chHeader = "";
            List <string> listBuilder = new List <string>();

            if (document.Type == "CREED")
            {
                Creed creed = (Creed)document;
                shares += creed.Title;
                shares += "\r\n";
                shares += creed.CreedText;
            }
            else if (document.Type == "CATECHISM")
            {
                Catechism catechism = (Catechism)document;

                qHeader = String.Format("QUESTION {0}:", catechism.IDNumber.ToString("d3"));
                listBuilder.Add(catechism.DocTitle);
                listBuilder.Add(qHeader);
                listBuilder.Add(catechism.Question);
                listBuilder.Add(aHeader);
                listBuilder.Add(catechism.Answer);
                listBuilder.Add(pHeader);
                listBuilder.Add(catechism.Proofs);
                shares = "";
                foreach (string shareElement in listBuilder)
                {
                    shares += shareElement + "\r\n";
                }
            }
            else if (document.Type == "CONFESSION")
            {
                Confession confession = (Confession)document;
                chHeader = String.Format("Chapter {0}: {1}", confession.IDNumber, confession.DocTitle);
                listBuilder.Add(confession.DocTitle); listBuilder.Add(chHeader);
                listBuilder.Add(confession.Chapter); listBuilder.Add(pHeader);
                listBuilder.Add(confession.Proofs); shares = "";
                foreach (string element in listBuilder)
                {
                    shares += element + "\r\n";
                }
            }
            return(shares);
        }
        //Fetches the fragment for display
        public override Android.Support.V4.App.Fragment GetItem(int position)
        {
            Android.Support.V4.App.Fragment frg;
            if (docPosition > 0)
            {
                position = position + 1;
            }
            string docTitle = "";

            if (documentList.Title == "Results" || documentList.Title == "")
            {
                docTitle = documentList[position].DocTitle;
            }
            else
            {
                docTitle = documentList.Title;
            }
            if (documentList[position].Type == "CONFESSION")
            {
                docPosition++;
                Confession confession = (Confession)documentList[position];
                frg = (Android.Support.V4.App.Fragment)SearchResultFragment.NewResult(confession.Chapter, confession.Proofs, confession.Title, confession.IDNumber, docTitle, documentList.Truncate, confession.Matches);
            }
            else if (documentList[position].Type == "CATECHISM")
            {
                docPosition++;
                Catechism catechism = (Catechism)documentList[position];
                frg = (Android.Support.V4.App.Fragment)SearchResultFragment.NewResult(catechism.Question, catechism.Answer, catechism.Proofs, catechism.Title, catechism.IDNumber, docTitle, catechism.Matches, documentList.Truncate);
            }
            else if (documentList[position].Type == "CREED")
            {
                docPosition++;
                Creed creed = (Creed)documentList[position];
                frg = (Android.Support.V4.App.Fragment)SearchResultFragment.NewResult(creed.DocTitle, documentList.Title, truncate, creed.CreedText, creed.IDNumber, creed.Proofs, creed.Matches);
            }
            else
            {
                frg = GetItem(position + 1);
            }
            Log.Info("Search Adapter", String.Format("{0} Panel Loaded", position));
            return(frg);
        }
예제 #4
0
        /// <summary>
        /// Search Method
        /// </summary>
        /// <param name="query"> Search Term</param>
        //281 lines of code
        private void Search(string query)
        {
            #region Variable Declaration

            int  docCount = 1;
            bool truncate = false;
            Log.Info("Search()", String.Format(Resource.String.search_execution_begins + ""));
            documentList = new DocumentList();
            RadioButton radio = FindViewById <RadioButton>(Resource.Id.viewAllRadio);
            this.searchFragmentActivity = new SearchFragmentActivity();
            AssetManager asset = this.Assets;
            //string searchTerm = "";
            bool     proofs = true, answers = true, searchAll = false;
            string[] fileNames = new string[10];
            CheckBox answerCheck = FindViewById <CheckBox>(Resource.Id.AnswerBox), proofCheck = FindViewById <CheckBox>(Resource.Id.proofBox),
                     searchCheck = FindViewById <CheckBox>(Resource.Id.searchAllCheckBox);
            Spinner spinner      = FindViewById <Spinner>(Resource.Id.spinner1);
            #endregion
            Spinner spinner2 = FindViewById <Spinner>(Resource.Id.spinner2);
            spinner.ItemSelected  += new EventHandler <AdapterView.ItemSelectedEventArgs>(Spinner1_ItemSelected);
            spinner2.ItemSelected += new EventHandler <AdapterView.ItemSelectedEventArgs>(Spinner2_ItemSelected);
            //Search Options
            #region Search Options
            // Modify This section
            if (allOpen)
            {
                if (radio.Checked == false)
                {
                    if (answerCheck.Checked)
                    {
                        answers = false;
                    }
                    else
                    {
                        answers = true;
                    }
                    if (proofCheck.Checked)
                    {
                        proofs = false;
                    }
                    else
                    {
                        proofs = true;
                    }
                    if (searchCheck.Checked)
                    {
                        searchAll = true;
                        fileNames = new[] { "Westminster Confession of Faith 1646.txt", "2nd London Baptist Confession of Faith.txt", "1618 Belgic Confession Of Faith.txt",
                                            "1658 Savoy Declaration.txt", "Westminster Larger Catechism.txt", "Westminster Shorter Catechism.txt", "Heidelberg Catechism.txt", "Apostle\'s Creed.txt",
                                            "Nicene Creed.txt", "Athanasian Creed.txt" };
                        docCount = 10;
                    }
                    else
                    {
                        searchAll = false;
                    }
                }
                else
                {
                    answers   = true;
                    searchAll = false;
                    docCount  = 1; proofs = true;
                }
            }
            else if (catechismOpen)
            {
                if (radio.Checked == false)
                {
                    if (answerCheck.Checked)
                    {
                        answers = false;
                    }
                    else
                    {
                        answers = true;
                    }
                    if (proofCheck.Checked)
                    {
                        proofs = false;
                    }
                    else
                    {
                        proofs = true;
                    }
                    if (searchCheck.Checked)
                    {
                        searchAll = true;
                        fileNames = new[] { "Westminster Larger Catechism.txt", "Westminster Shorter Catechism.txt", "Heidelberg Catechism.txt" };
                        docCount  = 3;
                    }
                    else
                    {
                        searchAll = false;
                    }
                }
                else
                {
                    answers   = true;
                    searchAll = false;
                    docCount  = 1; proofs = true;
                }
            }
            else if (confessionOpen)
            {
                if (radio.Checked != true)
                {
                    if (proofCheck.Checked)
                    {
                        proofs = false;
                    }
                    else
                    {
                        proofs = true;
                    }
                    if (searchCheck.Checked)
                    {
                        searchAll = true;
                        fileNames = new[] { "Westminster Confession of Faith 1646.txt", "2nd London Baptist Confession of Faith.txt", "1618 Belgic Confession Of Faith.txt", "1658 Savoy Declaration.txt" };
                        docCount  = 4;
                    }
                    else
                    {
                        searchAll = false;
                    }
                    docCount = 1;
                }
                else
                {
                    proofs   = true; searchAll = false;
                    docCount = 1;
                }
            }
            else if (creedOpen)
            {
                if (searchCheck.Checked)
                {
                    searchAll = true;
                    docCount  = 3;
                    fileNames = new[] { "Apostle\'s Creed.txt", "Nicene Creed.txt", "Athanasian Creed.txt" };
                }
                else
                {
                    proofs   = false; searchAll = false; truncate = false;
                    docCount = 1;
                }
                answers = false;
            }
            Fill(this.documentList, 1, fileNames, answers, proofs, asset, searchAll);
            this.documentList.Truncate = truncate;

            search = query;
            //Results are truncated to the term if true
            if (FindViewById <CheckBox>(Resource.Id.truncateCheck).Checked)
            {
                truncate = true;
            }
            #endregion
            Log.Info("Search()", String.Format(Resource.String.search_status_sorting + ""));
            //If topic is filled
            if (radio.Checked != true && query != "" && FindViewById <RadioButton>(Resource.Id.topicRadio).Checked)
            {
                if (FindViewById <RadioButton>(Resource.Id.topicRadio).Checked)
                {
                    stopwatch.Start();
                    FilterResults(this.documentList, truncate, answers, proofs, searchAll, query);
                    this.documentList.Reverse();
                    stopwatch.Stop();
                }
            }
            //if Chapter is filled
            else if (FindViewById <RadioButton>(Resource.Id.chapterRadio).Checked & query != "")
            {
                int searchInt = Int32.Parse(query);
                FilterResults(this.documentList, truncate, answers, proofs, searchAll, searchInt);
            }
            //if View Document is checked
            else if (FindViewById <RadioButton>(Resource.Id.viewAllRadio).Checked)
            {
                if (!FindViewById <CheckBox>(Resource.Id.searchAllCheckBox).Checked)
                {
                    query = this.documentList.Title;
                }
                else
                {
                    query = "View All";
                }
            }
            //Display Results
            Log.Info("Search Method", "Displaying Results");
            if (documentList.Count > 1)
            {
                SetContentView(Resource.Layout.search_results);
                ViewPager     viewPager = FindViewById <ViewPager>(Resource.Id.viewpager);
                SearchAdapter adapter   = new SearchAdapter(SupportFragmentManager, this.documentList, query, truncate);
                //Sets the final state of application
                this.searchFragmentActivity.DisplayResults(this.documentList, viewPager, adapter, query, 1, truncate);
                SetTitle(Resource.String.search_results_title);
            }
            //Single result or no results found
            else
            {
                stopwatch.Stop();
                //If There are no Search Results
                if (this.documentList.Empty)
                {
                    #region Error Logging
                    Log.Info("Search()", String.Format("No Results were found for {0}", query));
                    Toast.MakeText(this, String.Format("No results were found for  {0}", query), ToastLength.Long).Show();
                    #endregion
                    #region Variable Declaration and Assignment

                    SetContentView(Resource.Layout.errorLayout);
                    TextView errorMsg = FindViewById <TextView>(Resource.Id.errorTV);
                    errorMsg.Text = String.Format("No Search Results were found for {0}\r\n\r\n" +
                                                  "Go back to home page to search for another topic", query);


                    #endregion
                    #region Dialog Box
                    Android.App.AlertDialog.Builder alert = new Android.App.AlertDialog.Builder(this);
                    alert.SetTitle(Resource.String.zero_results_title);
                    alert.SetMessage(String.Format("No Results were found for {0}.\r\n\r\n" +
                                                   "Do you want to go back and search for another topic?", query));
                    alert.SetPositiveButton("Yes", (senderAlert, args) =>
                    {
                        intent = new Intent(this, Class);
                        searchFragmentActivity = null;
                        this.OnStop();
                        this.Finish();
                        StartActivity(intent);
                    });
                    alert.SetNegativeButton("No", (senderAlert, args) => { alert.Dispose(); });

                    Dialog dialog = alert.Create();
                    dialog.Show();
                    #endregion
                    SetTitle(Resource.String.error_results);
                }
                //If there is only 1 search result
                else
                {
                    SetTitle(Resource.String.search_results_title);
                    Document document = this.documentList[this.documentList.Count];
                    //Display Catechism Results
                    if (document.Type == "CATECHISM")
                    {
                        this.SetContentView(Resource.Layout.catechism_Results);
                        TextView  questionBox = FindViewById <TextView>(Resource.Id.chapterText);
                        TextView  answerBox   = FindViewById <TextView>(Resource.Id.answerText);
                        TextView  numberBox   = FindViewById <TextView>(Resource.Id.confessionChLabel);
                        TextView  proofBox    = FindViewById <TextView>(Resource.Id.proofText);
                        TextView  proofView   = FindViewById <TextView>(Resource.Id.proofLabel);
                        TextView  docTitleBox = FindViewById <TextView>(Resource.Id.documentTitleLabel);
                        Catechism catechism   = (Catechism)document;
                        questionBox.Text = catechism.Question;
                        answerBox.Text   = catechism.Answer;
                        numberBox.Text   = String.Format("Question {0}: {1}", catechism.IDNumber.ToString(), catechism.Title);
                        proofBox.Text    = catechism.Proofs;
                        docTitleBox.Text = catechism.DocTitle;
                        ChangeColor(true, Android.Graphics.Color.Black, questionBox, answerBox, proofBox, numberBox, docTitleBox);
                        ChangeColor(false, Android.Graphics.Color.Black, proofView, FindViewById <TextView>(Resource.Id.catechismAnswerLabel));
                        shareList = docTitleBox.Text + newLine + String.Format("Question {0}:", catechism.IDNumber.ToString("d3")) + newLine + questionBox.Text + newLine + "Answer:" + newLine +
                                    answerBox.Text + newLine + "Proofs:" + newLine + proofBox.Text;
                        FloatingActionButton fab = FindViewById <FloatingActionButton>(Resource.Id.shareActionButton);
                        ChangeColor(fab, Android.Graphics.Color.Black);
                        fab.Click += ShareContent;
                    }
                    //Display Confession Results
                    else if (document.Type == "CONFESSION")
                    {
                        SetContentView(Resource.Layout.confession_results);
                        TextView   chapterBox  = FindViewById <TextView>(Resource.Id.chapterText);
                        TextView   proofBox    = FindViewById <TextView>(Resource.Id.proofText);
                        TextView   chNumbBox   = FindViewById <TextView>(Resource.Id.confessionChLabel);
                        TextView   docTitleBox = FindViewById <TextView>(Resource.Id.documentTitleLabel);
                        Confession confession  = (Confession)document;
                        chapterBox.Text  = confession.Chapter;
                        chNumbBox.Text   = String.Format("Chapter {0} : {1}", confession.IDNumber.ToString(), confession.Title);
                        proofBox.Text    = confession.Proofs;
                        docTitleBox.Text = confession.DocTitle;
                        TextView proofView = FindViewById <TextView>(Resource.Id.proofLabel);
                        ChangeColor(true, Android.Graphics.Color.Black, chapterBox, proofBox, chNumbBox, docTitleBox);
                        ChangeColor(proofView, false, Android.Graphics.Color.Black);
                        shareList = docTitleBox.Text + newLine + chNumbBox.Text + newLine + chapterBox.Text + newLine + "Proofs" + newLine + proofBox.Text;
                        FloatingActionButton fab = FindViewById <FloatingActionButton>(Resource.Id.shareActionButton);
                        ChangeColor(fab, Android.Graphics.Color.Black);

                        fab.Click += ShareContent;
                    }
                    //Display Creed Results
                    else if (document.Type == "CREED")
                    {
                        SetContentView(Resource.Layout.creed_Results);
                        Creed    creed    = (Creed)document;
                        TextView creedBox = FindViewById <TextView>(Resource.Id.chapterText);
                        TextView titleBox = FindViewById <TextView>(Resource.Id.documentTitleLabel);
                        SetTitle(Resource.String.search_results_title);
                        creedBox.Text = creed.CreedText; titleBox.Text = documentList.Title;
                        shareList     = titleBox.Text + newLine + creed.CreedText;
                        FloatingActionButton fab = FindViewById <FloatingActionButton>(Resource.Id.shareActionButton);
                        ChangeColor(fab, Android.Graphics.Color.Black);
                        ChangeColor(true, Android.Graphics.Color.Black, creedBox, titleBox);
                        fab.Click += ShareContent;
                    }
                }
            }
            Toast.MakeText(this, String.Format("Search Completed for {0}" + "\r\n" + "{1} ms Passed", query, stopwatch.ElapsedMilliseconds.ToString()), ToastLength.Long).Show();
        }