public override View GetView(int position, View convertView, ViewGroup parent) { //handle the headers JsonObject data = this [position]; View v = convertView; if (v == null) { v = context.LayoutInflater.Inflate(Resource.Layout.critic_review, null); } bool actor = data.ContainsKey("name"); var img = v.FindViewById <ImageView> (Resource.Id.critic_img); var head = v.FindViewById <TextView> (Resource.Id.critic_header); var quote = v.FindViewById <TextView> (Resource.Id.critic_quote); v.Click += delegate { var url = data ["links"] ["review"]; var intent = new Intent(Intent.ActionView, Android.Net.Uri.Parse(url)); try { context.StartActivity(intent); } catch (Exception e) { Toast.MakeText(context, "Couldn't load the review", ToastLength.Short).Show(); Console.Error.WriteLine(e); } }; img.SetImageResource(MovieListAdapter.FreshRottenId(data ["freshness"])); head.Text = data ["critic"] + ", " + data ["publication"]; quote.Text = data ["quote"]; return(v); }
public async Task <JsonObject> download(int id, FetchType type) { string root = type == FetchType.CRITIC ? "http://api.rottentomatoes.com/api/public/v1.0/movies/{0}/reviews.json?apikey={1}" : "http://api.rottentomatoes.com/api/public/v1.0/movies/{0}.json?apikey={1}"; string url = string.Format(root, id, GetString(Resource.String.key)); var client = new HttpClient(); string contents = await client.GetStringAsync(url); var data = JsonArray.Parse(contents); if (type == FetchType.MOVIE) { //set getting information as the api is fetched var title = FindViewById <TextView> (Resource.Id.movie_title); var actors = FindViewById <TextView> (Resource.Id.cast); var dir = FindViewById <TextView> (Resource.Id.movie_director); var rating = FindViewById <TextView> (Resource.Id.movie_rating); var runtime = FindViewById <TextView> (Resource.Id.movie_runtime); var genres = FindViewById <TextView> (Resource.Id.movie_genre); var releaseDate = FindViewById <TextView> (Resource.Id.movie_release); var synop = FindViewById <TextView> (Resource.Id.movie_sum); var critic = FindViewById <ListView> (Resource.Id.movie_critic); title.Text = data ["title"]; dir.Text = ListString((JsonArray)data ["abridged_directors"], "name"); runtime.Text = MovieListAdapter.GetRunTime(data ["runtime"]); genres.Text = ListString((JsonArray)data ["genres"]); releaseDate.Text = DateFormater(data ["release_dates"] ["theater"].ToString()); synop.Text = data ["synopsis"]; actors.Text = ListString((JsonArray)data ["abridged_cast"], "name"); rating.Text = data ["mpaa_rating"]; } else { FindViewById <ListView> (Resource.Id.movie_critic).Adapter = new DetailsAdapter(this, (JsonArray)data ["reviews"]); } return((JsonObject)JsonObject.Parse(contents)); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); ListView.Adapter = (myAdapter = new MovieListAdapter(this)); Refresh(); }