//Search feed for Fragments
 public void DisplayResults(DocumentList sourcedocumentList, ViewPager view, SearchAdapter search, string searchTerm, int count, bool truncate)
 {
     //Syncs the document List objects together
     documentList = sourcedocumentList;
     //Calls GetItem Method from Search Adapter for Display. Required for fragments to display in viewPager
     search.GetItem(count);
     // index = count;
     shareList = "";
     //Saves current Adapter state
     search.SaveState();
     //Displays results
     view.Adapter = search;
 }
Exemple #2
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();
        }