public override void RetrieveBiblePassage(string bibleAddress, OnBibleResult onResult) { // I normally hate returning from places other than the bottom, but to prevent // wrapping the ENTIRE function, we will. if (RetrievingVerse == true) { onResult(string.Empty); return; } RetrievingVerse = true; RestRequest request = new RestRequest(Method.GET); // We expect the Bible URL to be written in the format "bible://[Translation]/[Book]/[Chapter]". string translation, book, chapter; FriendlyBibleUrlToParts(bibleAddress, out translation, out book, out chapter); // now based on the translation, get the correct book abbreviations that the API expects GetBookAbbreviation(translation, book, delegate(string bookAbbrev) { if (bookAbbrev != null) { // Build the URI for the Bible Searches API request. string BibleSearchesAddress = String.Format(BiblesOrg_Chapter_URL, translation, bookAbbrev, chapter); HttpRequest webRequest = new HttpRequest( ); webRequest.ExecuteAsync <RestResponse>(BibleSearchesAddress, request, SecuredValues.Bible_Searches_API_Key, string.Empty, delegate(System.Net.HttpStatusCode statusCode, string statusDescription, RestResponse response) { string htmlStream = null; if (Util.StatusInSuccessRange(statusCode) == true) { string text, copyright; if (TryParseChapter(response.Content, out text, out copyright)) { string titleHTML = "<h2>" + book + " " + chapter + " (" + translation + ")" + "</h2><br/>"; string styleHeader = "<head>" + "<style type=\"text/css\">" + "html {-webkit-text-size-adjust:none}" + "body {" + "font-family: Arial;" + "color: white;" + "background-color: #1C1C1C;" + "}" + "</style>" + "</head>"; string copyrightHtml = "<small>" + copyright + "</small>"; // adds the CSS header to the HTML string htmlStream = "<html>" + styleHeader + "<body>" + titleHTML + text + copyright + "</body></html>"; // get rid of <a href> tags in the copyright because the WebView // is not set up aesthetically to show any other pages but this HTML response htmlStream = Regex.Replace(htmlStream, "<a href=.*?>", String.Empty); htmlStream = Regex.Replace(htmlStream, "</a>", String.Empty); } } // return the htmlStream we built RetrievingVerse = false; onResult(htmlStream); }); } // Book Abbreviation Request failed else { RetrievingVerse = false; onResult(string.Empty); } }); }
public override void RetrieveBiblePassage(string bibleAddress, OnBibleResult onResult) { string htmlStream = string.Empty; // first, convert what the user typed in into fragments string bookStr, chapterStr; if (FriendlyBibleUrlToParts(bibleAddress, out bookStr, out chapterStr)) { Book book = new Book( ); #if __IOS__ using (StreamReader sr = new StreamReader(Foundation.NSBundle.MainBundle.BundlePath + "/" + "bible_niv_xml.xml")) #elif __ANDROID__ using (StreamReader sr = new StreamReader(Rock.Mobile.PlatformSpecific.Android.Core.Context.Assets.Open("bible_niv_xml.xml"))) #elif __WIN__ //NOTE: Not supported or needed on Windows platform using (StreamReader sr = new StreamReader("")) #endif { using (XmlTextReader reader = new XmlTextReader(sr)) { while (reader.Read( )) { switch (reader.NodeType) { case XmlNodeType.Element: { if (reader.Name == "b") { string bookName = reader.GetAttribute("n"); // if this is the book we want, parse it. if (bookName.ToLower( ) == bookStr.ToLower( )) { List <Chapter> chapterList = ParseBook(reader); book.Name = bookName; book.Chapters = chapterList; } } break; } } } if (book.IsValid( )) { // get the chapter they want int chapterNum = int.Parse(chapterStr); string textBody = book.GetHTML(chapterNum); // cool, build html string titleHTML = "<h2>" + book.Name + " " + chapterStr + " (" + "NIV" + ")" + "</h2>"; string styleHeader = "<head>" + "<style type=\"text/css\">" + "html {-webkit-text-size-adjust:none}" + "body {" + "font-family: Arial;" + "color: white;" + "background-color: #1C1C1C;" + "}" + "</style>" + "</head>"; string copyrightHtml = "<p style=\"text-align: center\"><small>" + CopyrightText + "</small></p>"; // adds the CSS header to the HTML string htmlStream = "<html>" + styleHeader + "<body>" + titleHTML + textBody + copyrightHtml + "</body></html>"; } } } } onResult(htmlStream); }
public abstract void RetrieveBiblePassage(string bibleAddress, OnBibleResult onResult);