private async Task<List<MovieEntry>> BoxOfficeMoviesHelper (String Url) { MovieList Movie_List = new MovieList (); MovieEntry Movie_Entry = null; var Client = new HttpClient (); var Result = Client.GetStringAsync (@Url); var JsonDataStructure = JObject.Parse (Result.Result); int Count_Movies = JsonDataStructure.Count; int Temp_Count = 0; while (Temp_Count < Count_Movies) { Movie_Entry = new MovieEntry (); Movie_Entry.MovieTitle = (String)JsonDataStructure ["movies"] [Temp_Count] ["title"]; Movie_Entry.MPAA_Rating = (String)JsonDataStructure ["movies"] [Temp_Count] ["mpaa_rating"]; Movie_Entry.Synopsis = (String)JsonDataStructure ["movies"] [Temp_Count] ["synopsis"]; Movie_Entry.Runtime = getDateFormHHMM ((String)JsonDataStructure ["movies"] [Temp_Count] ["runtime"]); Movie_Entry.MovieThumbnail = (String)JsonDataStructure ["movies"] [Temp_Count] ["posters"] ["thumbnail"]; if (((String)JsonDataStructure ["movies"] [Temp_Count] ["ratings"] ["critics_rating"]).Equals ("Certified Fresh")) { Movie_Entry.FreshOrRotten = true; } else if (((String)JsonDataStructure ["movies"] [Temp_Count] ["ratings"] ["critics_rating"]).Equals ("Rotten")) { Movie_Entry.FreshOrRotten = false; } else { Movie_Entry.FreshOrRotten = null; } Movie_Entry.OverallCriticScore = (String)JsonDataStructure ["movies"] [Temp_Count] ["ratings"] ["critics_score"]; Movie_Entry.TheatreReleaseDate = (String)JsonDataStructure ["movies"] [Temp_Count] ["release_dates"] ["theater"]; var JsonTempObject = (JArray)JsonDataStructure ["movies"] [Temp_Count] ["abridged_cast"]; int Temp_Count1 = 0; while (Temp_Count1 < JsonTempObject.Count) { Cast Cast_Obj = new Cast (); IDictionary<string,JToken> dictionary =(JObject) JsonTempObject [Temp_Count1]; if (dictionary.ContainsKey("characters")) { int CharachterCount = (((JArray)JsonTempObject [Temp_Count1] ["characters"]).Count) - 1; while (CharachterCount >= 0) { Cast_Obj.Charachter = Cast_Obj.Charachter + JsonTempObject [Temp_Count1] ["characters"] [CharachterCount] + " "; CharachterCount--; } } else { Cast_Obj.Charachter = ""; } Cast_Obj.Name = (String)JsonTempObject [Temp_Count1] ["name"]; Movie_Entry.AbridgedCast.Add (Cast_Obj); Temp_Count1++; } //Would need a new HTTP call for filling the other data. // HTTP call for CriticReview String WebUrl = ((String)(JsonDataStructure ["movies"] [Temp_Count] ["links"] ["reviews"] + "?apikey=" + API_KEY)); HttpClient tempClient = new HttpClient (); var TempResults = tempClient.GetStringAsync (@WebUrl); // tempClient.Dispose (); var TempJsonDataStructure = JObject.Parse (TempResults.Result); Temp_Count1 = 0; Critics Critics_Obj = new Critics (); while (Temp_Count1 < ((JArray)TempJsonDataStructure ["reviews"]).Count) { CriticInfo Critic_Info = new CriticInfo (); Critic_Info.BriefCriticReview = (String)TempJsonDataStructure ["reviews"] [Temp_Count1] ["quote"]; Critic_Info.MediaSourceOfCritc = (String)TempJsonDataStructure ["reviews"] [Temp_Count1] ["publication"]; Critic_Info.NameOfCritic = (String)TempJsonDataStructure ["reviews"] [Temp_Count1] ["critic"]; if (((String)TempJsonDataStructure ["reviews"] [Temp_Count1] ["freshness"]).Equals ("fresh")) { Critic_Info.FreshOrRotten = true; } else if (((String)TempJsonDataStructure ["reviews"] [Temp_Count1] ["freshness"]).Equals ("rotten")) { Critic_Info.FreshOrRotten = false; } else { Critic_Info.FreshOrRotten = null; } Critics_Obj.Critic_Info.Add (Critic_Info); Temp_Count1++; } Link Link_Obj2 = new Link (); Link_Obj2.NameOfLink = "self"; Link_Obj2.WebUrl = (String)TempJsonDataStructure ["links"] ["self"]+ "?apikey=" + API_KEY; Critics_Obj.Links.Add (Link_Obj2); Link_Obj2 = new Link (); Link_Obj2.NameOfLink = "next"; Link_Obj2.WebUrl = (String)TempJsonDataStructure ["links"] ["next"]+ "?apikey=" + API_KEY; Critics_Obj.Links.Add (Link_Obj2); Link_Obj2 = new Link (); Link_Obj2.NameOfLink = "alternate"; Link_Obj2.WebUrl = (String)TempJsonDataStructure ["links"] ["alternate"]+ "?apikey=" + API_KEY; Critics_Obj.Links.Add (Link_Obj2); Link_Obj2 = new Link (); Link_Obj2.NameOfLink = "rel"; Link_Obj2.WebUrl = (String)TempJsonDataStructure ["links"] ["rel"]+ "?apikey=" + API_KEY; Critics_Obj.Links.Add (Link_Obj2); Movie_Entry.ListOfCritics = Critics_Obj; // HTTP call for Cast So call to main Cast page WebUrl = ""; TempJsonDataStructure = null; TempResults = null; @WebUrl = (String)JsonDataStructure ["movies"] [Temp_Count] ["links"] ["cast"] + "?apikey=" + API_KEY; tempClient = new HttpClient (); TempResults = tempClient.GetStringAsync (@WebUrl); //tempClient.Dispose (); TempJsonDataStructure = JObject.Parse (TempResults.Result); Temp_Count1 = 0; while (Temp_Count1 < TempJsonDataStructure.Count) { Cast Cast_Obj = new Cast (); IDictionary<string,JToken> dictionary =(JObject) TempJsonDataStructure ["cast"][Temp_Count1]; if (dictionary.ContainsKey ("characters")) { int CharachterCount = (((JArray)TempJsonDataStructure ["cast"] [Temp_Count1] ["characters"]).Count) - 1; while (CharachterCount >= 0) { Cast_Obj.Charachter = Cast_Obj.Charachter + TempJsonDataStructure ["cast"] [Temp_Count1] ["characters"] [CharachterCount] + " "; CharachterCount--; } } else { Cast_Obj.Charachter = ""; } Cast_Obj.Name = (String)TempJsonDataStructure["cast"] [Temp_Count1] ["name"]; Movie_Entry.CompleteCast.Add (Cast_Obj); Temp_Count1++; } // HTTP call for Directors and Genre's WebUrl = ""; TempJsonDataStructure = null; TempResults = null; @WebUrl = (String)JsonDataStructure ["movies"] [Temp_Count] ["links"] ["self"] + "?apikey=" + API_KEY; tempClient = new HttpClient (); TempResults = tempClient.GetStringAsync (@WebUrl); //tempClient.Dispose (); TempJsonDataStructure = JObject.Parse (TempResults.Result); int DirectorCount = ((JArray)TempJsonDataStructure ["abridged_directors"]).Count-1; while (DirectorCount >= 0) { Movie_Entry.Directors.Add ((String)TempJsonDataStructure ["abridged_directors"] [DirectorCount] ["name"]); DirectorCount--; } int GenreCount = ((JArray)TempJsonDataStructure ["genres"]).Count-1; while (GenreCount >= 0) { Movie_Entry.Genres.Add ((String)TempJsonDataStructure ["genres"] [GenreCount]); GenreCount--; } Link Link_Obj = new Link (); Link_Obj.NameOfLink = "self"; Link_Obj.WebUrl = (String)JsonDataStructure ["movies"] [Temp_Count] ["links"] ["self"] + "?apikey=" + API_KEY; Movie_Entry.Links.Add (Link_Obj); Link_Obj = new Link (); Link_Obj.NameOfLink = "alternate"; Link_Obj.WebUrl = (String)JsonDataStructure ["movies"] [Temp_Count] ["links"] ["alternate"] + "?apikey=" + API_KEY; Movie_Entry.Links.Add (Link_Obj); Link_Obj = new Link (); Link_Obj.NameOfLink = "cast"; Link_Obj.WebUrl = (String)JsonDataStructure ["movies"] [Temp_Count] ["links"] ["cast"] + "?apikey=" + API_KEY; Movie_Entry.Links.Add (Link_Obj); Link_Obj = new Link (); Link_Obj.NameOfLink = "clips"; Link_Obj.WebUrl = (String)JsonDataStructure ["movies"] [Temp_Count] ["links"] ["clips"] + "?apikey=" + API_KEY; Movie_Entry.Links.Add (Link_Obj); Link_Obj = new Link (); Link_Obj.NameOfLink = "reviews"; Link_Obj.WebUrl = (String)JsonDataStructure ["movies"] [Temp_Count] ["links"] ["reviews"] + "?apikey=" + API_KEY; Movie_Entry.Links.Add (Link_Obj); Link_Obj = new Link (); Link_Obj.NameOfLink = "similar"; Link_Obj.WebUrl = (String)JsonDataStructure ["movies"] [Temp_Count] ["links"] ["similar"] + "?apikey=" + API_KEY; Movie_Entry.Links.Add (Link_Obj); Movie_List.ListOfMovies.Add (Movie_Entry); Temp_Count++; } return Movie_List.ListOfMovies; }
private async Task <List <MovieEntry> > BoxOfficeMoviesHelper(String Url) { MovieList Movie_List = new MovieList(); MovieEntry Movie_Entry = null; var Client = new HttpClient(); var Result = Client.GetStringAsync(@Url); var JsonDataStructure = JObject.Parse(Result.Result); int Count_Movies = JsonDataStructure.Count; int Temp_Count = 0; while (Temp_Count < Count_Movies) { Movie_Entry = new MovieEntry(); Movie_Entry.MovieTitle = (String)JsonDataStructure ["movies"] [Temp_Count] ["title"]; Movie_Entry.MPAA_Rating = (String)JsonDataStructure ["movies"] [Temp_Count] ["mpaa_rating"]; Movie_Entry.Synopsis = (String)JsonDataStructure ["movies"] [Temp_Count] ["synopsis"]; Movie_Entry.Runtime = getDateFormHHMM((String)JsonDataStructure ["movies"] [Temp_Count] ["runtime"]); Movie_Entry.MovieThumbnail = (String)JsonDataStructure ["movies"] [Temp_Count] ["posters"] ["thumbnail"]; if (((String)JsonDataStructure ["movies"] [Temp_Count] ["ratings"] ["critics_rating"]).Equals("Certified Fresh")) { Movie_Entry.FreshOrRotten = true; } else if (((String)JsonDataStructure ["movies"] [Temp_Count] ["ratings"] ["critics_rating"]).Equals("Rotten")) { Movie_Entry.FreshOrRotten = false; } else { Movie_Entry.FreshOrRotten = null; } Movie_Entry.OverallCriticScore = (String)JsonDataStructure ["movies"] [Temp_Count] ["ratings"] ["critics_score"]; Movie_Entry.TheatreReleaseDate = (String)JsonDataStructure ["movies"] [Temp_Count] ["release_dates"] ["theater"]; var JsonTempObject = (JArray)JsonDataStructure ["movies"] [Temp_Count] ["abridged_cast"]; int Temp_Count1 = 0; while (Temp_Count1 < JsonTempObject.Count) { Cast Cast_Obj = new Cast(); IDictionary <string, JToken> dictionary = (JObject)JsonTempObject [Temp_Count1]; if (dictionary.ContainsKey("characters")) { int CharachterCount = (((JArray)JsonTempObject [Temp_Count1] ["characters"]).Count) - 1; while (CharachterCount >= 0) { Cast_Obj.Charachter = Cast_Obj.Charachter + JsonTempObject [Temp_Count1] ["characters"] [CharachterCount] + " "; CharachterCount--; } } else { Cast_Obj.Charachter = ""; } Cast_Obj.Name = (String)JsonTempObject [Temp_Count1] ["name"]; Movie_Entry.AbridgedCast.Add(Cast_Obj); Temp_Count1++; } //Would need a new HTTP call for filling the other data. // HTTP call for CriticReview String WebUrl = ((String)(JsonDataStructure ["movies"] [Temp_Count] ["links"] ["reviews"] + "?apikey=" + API_KEY)); HttpClient tempClient = new HttpClient(); var TempResults = tempClient.GetStringAsync(@WebUrl); // tempClient.Dispose (); var TempJsonDataStructure = JObject.Parse(TempResults.Result); Temp_Count1 = 0; Critics Critics_Obj = new Critics(); while (Temp_Count1 < ((JArray)TempJsonDataStructure ["reviews"]).Count) { CriticInfo Critic_Info = new CriticInfo(); Critic_Info.BriefCriticReview = (String)TempJsonDataStructure ["reviews"] [Temp_Count1] ["quote"]; Critic_Info.MediaSourceOfCritc = (String)TempJsonDataStructure ["reviews"] [Temp_Count1] ["publication"]; Critic_Info.NameOfCritic = (String)TempJsonDataStructure ["reviews"] [Temp_Count1] ["critic"]; if (((String)TempJsonDataStructure ["reviews"] [Temp_Count1] ["freshness"]).Equals("fresh")) { Critic_Info.FreshOrRotten = true; } else if (((String)TempJsonDataStructure ["reviews"] [Temp_Count1] ["freshness"]).Equals("rotten")) { Critic_Info.FreshOrRotten = false; } else { Critic_Info.FreshOrRotten = null; } Critics_Obj.Critic_Info.Add(Critic_Info); Temp_Count1++; } Link Link_Obj2 = new Link(); Link_Obj2.NameOfLink = "self"; Link_Obj2.WebUrl = (String)TempJsonDataStructure ["links"] ["self"] + "?apikey=" + API_KEY; Critics_Obj.Links.Add(Link_Obj2); Link_Obj2 = new Link(); Link_Obj2.NameOfLink = "next"; Link_Obj2.WebUrl = (String)TempJsonDataStructure ["links"] ["next"] + "?apikey=" + API_KEY; Critics_Obj.Links.Add(Link_Obj2); Link_Obj2 = new Link(); Link_Obj2.NameOfLink = "alternate"; Link_Obj2.WebUrl = (String)TempJsonDataStructure ["links"] ["alternate"] + "?apikey=" + API_KEY; Critics_Obj.Links.Add(Link_Obj2); Link_Obj2 = new Link(); Link_Obj2.NameOfLink = "rel"; Link_Obj2.WebUrl = (String)TempJsonDataStructure ["links"] ["rel"] + "?apikey=" + API_KEY; Critics_Obj.Links.Add(Link_Obj2); Movie_Entry.ListOfCritics = Critics_Obj; // HTTP call for Cast So call to main Cast page WebUrl = ""; TempJsonDataStructure = null; TempResults = null; @WebUrl = (String)JsonDataStructure ["movies"] [Temp_Count] ["links"] ["cast"] + "?apikey=" + API_KEY; tempClient = new HttpClient(); TempResults = tempClient.GetStringAsync(@WebUrl); //tempClient.Dispose (); TempJsonDataStructure = JObject.Parse(TempResults.Result); Temp_Count1 = 0; while (Temp_Count1 < TempJsonDataStructure.Count) { Cast Cast_Obj = new Cast(); IDictionary <string, JToken> dictionary = (JObject)TempJsonDataStructure ["cast"][Temp_Count1]; if (dictionary.ContainsKey("characters")) { int CharachterCount = (((JArray)TempJsonDataStructure ["cast"] [Temp_Count1] ["characters"]).Count) - 1; while (CharachterCount >= 0) { Cast_Obj.Charachter = Cast_Obj.Charachter + TempJsonDataStructure ["cast"] [Temp_Count1] ["characters"] [CharachterCount] + " "; CharachterCount--; } } else { Cast_Obj.Charachter = ""; } Cast_Obj.Name = (String)TempJsonDataStructure["cast"] [Temp_Count1] ["name"]; Movie_Entry.CompleteCast.Add(Cast_Obj); Temp_Count1++; } // HTTP call for Directors and Genre's WebUrl = ""; TempJsonDataStructure = null; TempResults = null; @WebUrl = (String)JsonDataStructure ["movies"] [Temp_Count] ["links"] ["self"] + "?apikey=" + API_KEY; tempClient = new HttpClient(); TempResults = tempClient.GetStringAsync(@WebUrl); //tempClient.Dispose (); TempJsonDataStructure = JObject.Parse(TempResults.Result); int DirectorCount = ((JArray)TempJsonDataStructure ["abridged_directors"]).Count - 1; while (DirectorCount >= 0) { Movie_Entry.Directors.Add((String)TempJsonDataStructure ["abridged_directors"] [DirectorCount] ["name"]); DirectorCount--; } int GenreCount = ((JArray)TempJsonDataStructure ["genres"]).Count - 1; while (GenreCount >= 0) { Movie_Entry.Genres.Add((String)TempJsonDataStructure ["genres"] [GenreCount]); GenreCount--; } Link Link_Obj = new Link(); Link_Obj.NameOfLink = "self"; Link_Obj.WebUrl = (String)JsonDataStructure ["movies"] [Temp_Count] ["links"] ["self"] + "?apikey=" + API_KEY; Movie_Entry.Links.Add(Link_Obj); Link_Obj = new Link(); Link_Obj.NameOfLink = "alternate"; Link_Obj.WebUrl = (String)JsonDataStructure ["movies"] [Temp_Count] ["links"] ["alternate"] + "?apikey=" + API_KEY; Movie_Entry.Links.Add(Link_Obj); Link_Obj = new Link(); Link_Obj.NameOfLink = "cast"; Link_Obj.WebUrl = (String)JsonDataStructure ["movies"] [Temp_Count] ["links"] ["cast"] + "?apikey=" + API_KEY; Movie_Entry.Links.Add(Link_Obj); Link_Obj = new Link(); Link_Obj.NameOfLink = "clips"; Link_Obj.WebUrl = (String)JsonDataStructure ["movies"] [Temp_Count] ["links"] ["clips"] + "?apikey=" + API_KEY; Movie_Entry.Links.Add(Link_Obj); Link_Obj = new Link(); Link_Obj.NameOfLink = "reviews"; Link_Obj.WebUrl = (String)JsonDataStructure ["movies"] [Temp_Count] ["links"] ["reviews"] + "?apikey=" + API_KEY; Movie_Entry.Links.Add(Link_Obj); Link_Obj = new Link(); Link_Obj.NameOfLink = "similar"; Link_Obj.WebUrl = (String)JsonDataStructure ["movies"] [Temp_Count] ["links"] ["similar"] + "?apikey=" + API_KEY; Movie_Entry.Links.Add(Link_Obj); Movie_List.ListOfMovies.Add(Movie_Entry); Temp_Count++; } return(Movie_List.ListOfMovies); }
public RootElement getUI(MovieEntry entry){ NSUrl url = new NSUrl(entry.MovieThumbnail); NSData data = NSData.FromUrl(url); UIImage MovieThumb = new UIImage (data); UIImage Rotten = UIImage.FromBundle ("rotten.png"); UIImage Fresh = UIImage.FromBundle ("fresh.png"); UIImage DontKnow = UIImage.FromBundle ("QuestionMark.png"); System.Drawing.SizeF size = new System.Drawing.SizeF (); size.Height = 3; size.Width = 3; Rotten.Scale (size); Fresh.Scale (size); DontKnow.Scale (size); String Director_String=""; String Genre_String = ""; foreach(var directors in entry.Directors){ Director_String = Director_String + +directors+" " ; } foreach (var genre in entry.Genres) { Genre_String = Genre_String +genre+" "; } var Actor_Section = new Section ("Actors"); Console.WriteLine ("CompleteCast count"+entry.CompleteCast.Count); Console.WriteLine ("Abridged Cast Count" + entry.AbridgedCast.Count); foreach (var actor in entry.AbridgedCast) { var elem = new StyledStringElement (actor.Name , actor.Charachter, UITableViewCellStyle.Subtitle); Actor_Section.Add (elem); } var Reviews_Section = new Section ("Reviews"); foreach (var review in entry.ListOfCritics.Critic_Info) { BadgeElement elem = null; if(review.FreshOrRotten==true){ elem = new BadgeElement (Fresh, review.NameOfCritic+", "+review.MediaSourceOfCritc+Environment.NewLine+Environment.NewLine+review.BriefCriticReview); elem.LineBreakMode = UILineBreakMode.WordWrap; elem.Lines = 0; elem.Font = UIFont.FromName ("AmericanTypeWriter", 8f); }else if(review.FreshOrRotten==false){ elem = new BadgeElement (Rotten, review.NameOfCritic+", "+review.MediaSourceOfCritc+Environment.NewLine+Environment.NewLine+review.BriefCriticReview); elem.LineBreakMode = UILineBreakMode.WordWrap; elem.Lines = 0; elem.Font = UIFont.FromName ("AmericanTypeWriter", 8f); }else{ elem = new BadgeElement (DontKnow, review.NameOfCritic+", "+review.MediaSourceOfCritc+Environment.NewLine+Environment.NewLine+review.BriefCriticReview); elem.LineBreakMode = UILineBreakMode.WordWrap; elem.Lines = 0; elem.Font = UIFont.FromName ("AmericanTypeWriter", 8f); } Reviews_Section.Add (elem); } var Movie_Title = new Section (entry.MovieTitle); var Movie_Title_Element = new BadgeElement(MovieThumb,entry.OverallCriticScore +"% Of Critics liked it." + Environment.NewLine + entry.AbridgedCast [0].Name + ", " + entry.AbridgedCast [1].Name + Environment.NewLine + entry.MPAA_Rating + ", " + entry.Runtime + Environment.NewLine + entry.TheatreReleaseDate); Movie_Title_Element.Font = UIFont.FromName ("AmericanTypeWriter", 10f); Movie_Title_Element.LineBreakMode = UILineBreakMode.WordWrap; Movie_Title_Element.Lines = 0; Movie_Title.Add (Movie_Title_Element); var Movie_Info_Section = new Section ("Movie Details"); var DirectorElem = new StyledStringElement("Director Names: ",Director_String,UITableViewCellStyle.Subtitle); var RatingElem = new StyledStringElement ("Rated: ", entry.MPAA_Rating, UITableViewCellStyle.Subtitle); var RunningElem = new StyledStringElement ("Running Time: ", entry.Runtime, UITableViewCellStyle.Subtitle); var GenreElem = new StyledStringElement ("Genre: ", Genre_String, UITableViewCellStyle.Subtitle); var TheatreReleaseElem = new StyledStringElement ("Theatre Release Date: ", entry.TheatreReleaseDate, UITableViewCellStyle.Subtitle); Movie_Info_Section.Add (DirectorElem); Movie_Info_Section.Add (RatingElem); Movie_Info_Section.Add (RunningElem); Movie_Info_Section.Add (GenreElem); Movie_Info_Section.Add (TheatreReleaseElem); var Synopsis_Sec = new Section ("Synopsis"); var SysnopsisElem = new MultilineElement ("Synopsis", entry.Synopsis); Synopsis_Sec.Add (SysnopsisElem); var Links_Section = new Section ("Links"); var Root_Element = new RootElement ("MOVIE DETAILS"); Root_Element.Add (Movie_Title); Root_Element.Add (Movie_Info_Section); Root_Element.Add (Actor_Section); Root_Element.Add (Reviews_Section); return Root_Element; }