public override Android.Views.View GetView(int position, Android.Views.View convertView, Android.Views.ViewGroup parent) { View view = convertView; if (view == null) { view = context.LayoutInflater.Inflate(Resource.Layout.RestaurantRow, parent, false); } RestaurantModel restaurantObject = data[position]; ImageView restaurantImage = view.FindViewById <Refractored.Controls.CircleImageView>(Resource.Id.imageViewRestaurantPicture); ImageView distanceImageView = view.FindViewById <ImageView>(Resource.Id.imageViewDistance); TextView distanceValueTextView = view.FindViewById <TextView>(Resource.Id.textViewDistance); TextView distanceUnitsTextView = view.FindViewById <TextView>(Resource.Id.textViewDistanceUnits); TextView restaurantNameTextView = view.FindViewById <TextView>(Resource.Id.textViewRestaurantName); TextView restaurantAddressTextView = view.FindViewById <TextView>(Resource.Id.textViewRestaurantAddress); TextView restaurantNumberTextView = view.FindViewById <TextView>(Resource.Id.textViewRestaurantPhoneNumber); TextView noRatingTextView = view.FindViewById <TextView>(Resource.Id.textViewNoRatingAvailable); Button callButton = view.FindViewById <Button>(Resource.Id.ButtonCall); var callBtnContent = view.FindViewById <RelativeLayout>(Resource.Id.callBtnContent); Button urlButton = view.FindViewById <Button>(Resource.Id.ButtonURL); var urlBtnContent = view.FindViewById <RelativeLayout>(Resource.Id.urlBtnContent); Button mapButton = view.FindViewById <Button>(Resource.Id.ButtonMap); RatingBar restauarantRatingBar = view.FindViewById <RatingBar>(Resource.Id.ratingRestaurant); if (restaurantObject.imageString != null) { /*var imageBitmap = GetImageBitmapFromUrl(restaurantObject.imageString); * restaurantImage.SetImageBitmap(imageBitmap);*/ Koush.UrlImageViewHelper.SetUrlDrawable(restaurantImage, restaurantObject.imageString, Resource.Drawable.ic_restaurantPlaceholder); } else { restaurantImage.SetImageResource(Resource.Drawable.ic_restaurantPlaceholder); } if (restaurantObject.url == null) { urlButton.Visibility = ViewStates.Invisible; urlBtnContent.Visibility = ViewStates.Invisible; } else { urlButton.Visibility = ViewStates.Visible; urlBtnContent.Visibility = ViewStates.Visible; } restaurantNameTextView.Text = restaurantObject.restaurantName; if (isNear == true) { if (restaurantObject.streetAddress != null) { restaurantAddressTextView.Text = restaurantObject.streetAddress + ", " + restaurantObject.cityAdress + ", " + restaurantObject.stateAdress; } else { restaurantAddressTextView.Text = restaurantObject.cityAdress + ", " + restaurantObject.stateAdress + ", " + restaurantObject.ccAdress; } } else { if (restaurantObject.streetAddress != null) { restaurantAddressTextView.Text = restaurantObject.streetAddress + ", " + restaurantObject.cityAdress + ", " + restaurantObject.stateAdress; } else { restaurantAddressTextView.Text = restaurantObject.cityAdress + ", " + restaurantObject.stateAdress + ", " + restaurantObject.ccAdress; } } if (isNear == true) { if (MainActivity.preferences.GetBoolean("isKilometers", false) == false) { string meterDistanceString = restaurantObject.distance.ToString(); double meterDistance = Convert.ToDouble(meterDistanceString); double mileDistance = meterDistance / 1609.34; double roundedMileDistance = Math.Round(mileDistance, 2); distanceValueTextView.Text = roundedMileDistance.ToString(); distanceUnitsTextView.Text = "miles"; } else { string meterDistanceString = restaurantObject.distance.ToString(); double meterDistance = Convert.ToDouble(meterDistanceString); double kmsDistance = meterDistance / 1000; double roundedkmsDistance = Math.Round(kmsDistance, 2); distanceValueTextView.Text = roundedkmsDistance.ToString(); distanceUnitsTextView.Text = "kms"; } } else { distanceImageView.Visibility = ViewStates.Gone; distanceValueTextView.Visibility = ViewStates.Gone; distanceUnitsTextView.Visibility = ViewStates.Gone; } if (restaurantObject.phoneNumber != null) { restaurantNumberTextView.Text = "Ph : " + restaurantObject.phoneNumber; } else if (restaurantObject.nonFormattedPhoneNumber != null) { restaurantNumberTextView.Text = "Ph : " + restaurantObject.nonFormattedPhoneNumber; } else { callButton.Visibility = ViewStates.Invisible; callBtnContent.Visibility = ViewStates.Invisible; restaurantNumberTextView.Text = ""; } if (restaurantObject.ratingColor != null) { float rating = Convert.ToSingle(restaurantObject.rating); float halfRating = rating / 2; Console.WriteLine("The rating of the restaurant is:D {0}", halfRating); restauarantRatingBar.Rating = 3.5f; /*Drawable drawable = restauarantRatingBar.ProgressDrawable; * drawable.SetColorFilter(Color.ParseColor("#" + ""), PorterDuff.Mode.SrcAtop);*/ restauarantRatingBar.Visibility = ViewStates.Visible; noRatingTextView.Visibility = ViewStates.Invisible; } else { restauarantRatingBar.Visibility = ViewStates.Invisible; noRatingTextView.Visibility = ViewStates.Visible; } callButton.Click += (sender, e) => { var uri = Android.Net.Uri.Parse("tel:" + restaurantObject.nonFormattedPhoneNumber); var intent = new Intent(Intent.ActionDial, uri); context.StartActivity(intent); }; urlButton.Click += (sender, e) => { var intent = new Intent(context, typeof(RestaurantMainPageActivity)); intent.PutExtra("url", restaurantObject.url); intent.PutExtra("resName", restaurantObject.restaurantName); context.StartActivity(intent); }; mapButton.Click += (sender, e) => { var intent = new Intent(context, typeof(MapActivity)); intent.PutExtra("lat", restaurantObject.lat); intent.PutExtra("lng", restaurantObject.lng); intent.PutExtra("name", restaurantObject.restaurantName); context.StartActivity(intent); }; return(view); }
void InitializeRestaurantData(JsonValue responseJson, string resName) { try { JsonValue response = responseJson["response"]["groups"][0]["items"]; int counter = 0; for (int i = 0; i < response.Count; i++) { RestaurantModel restaurantObject = new RestaurantModel(); if (response[i]["venue"].ContainsKey("rating")) { restaurantObject.rating = response[i]["venue"]["rating"]; restaurantObject.ratingColor = response[i]["venue"]["ratingColor"]; } else { restaurantObject.ratingColor = null; } restaurantObject.restaurantName = response[i]["venue"]["name"]; if (response[i]["venue"]["location"].ContainsKey("address")) { restaurantObject.streetAddress = response[i]["venue"]["location"]["address"]; } else { restaurantObject.streetAddress = null; } if (isNear == true) { int lastIndex = (response[i]["venue"]["location"]["formattedAddress"]).Count - 1; restaurantObject.countryAdress = response[i]["venue"]["location"]["formattedAddress"][lastIndex]; } if (isNear == true) { restaurantObject.distance = response[i]["venue"]["location"]["distance"]; } if (response[i]["venue"].ContainsKey("url")) { restaurantObject.url = response[i]["venue"]["url"]; } else { restaurantObject.url = null; } if (response[i]["venue"]["location"].ContainsKey("city")) { restaurantObject.cityAdress = response[i]["venue"]["location"]["city"]; } else { restaurantObject.cityAdress = null; } if (response[i]["venue"]["location"].ContainsKey("state")) { restaurantObject.stateAdress = response[i]["venue"]["location"]["state"]; } else { restaurantObject.stateAdress = null; } if (response[i]["venue"]["location"].ContainsKey("country")) { restaurantObject.ccAdress = response[i]["venue"]["location"]["country"]; } else { restaurantObject.ccAdress = null; } if ((response[i]["venue"]["photos"]["count"]).ToString() == "0") { restaurantObject.imageString = null; } else { JsonValue image = response[i]["venue"]["photos"]["groups"][0]["items"][0]; restaurantObject.imageString = image["prefix"] + "100x100" + image["suffix"]; } if (isNear == true) { if (response[i]["venue"]["contact"].ContainsKey("formattedPhone")) { restaurantObject.phoneNumber = response[i]["venue"]["contact"]["formattedPhone"]; } else { restaurantObject.phoneNumber = null; } if (response[i]["venue"]["contact"].ContainsKey("phone")) { restaurantObject.nonFormattedPhoneNumber = response[i]["venue"]["contact"]["phone"]; } else { restaurantObject.nonFormattedPhoneNumber = null; } } restaurantObject.lat = response[i]["venue"]["location"]["lat"]; restaurantObject.lng = response[i]["venue"]["location"]["lng"]; searchResultsList.Add(restaurantObject); restaurantObject = null; Console.WriteLine("The value of the counter is: {0}", counter); counter++; } if (response.Count == 0 || response[0] == null) { Android.Support.V7.App.AlertDialog.Builder errorNotification = new Android.Support.V7.App.AlertDialog.Builder(this); errorNotification.SetTitle("No Search Results"); errorNotification.SetMessage("There are no " + resName + " within the specified radius"); errorNotification.SetPositiveButton("OK", (sender, e) => { //Alert Dialog closes. }); var alert = errorNotification.Create(); alert.Show(); } else { var adapter = new SearchResultsListViewAdapter(this, searchResultsList, isNear); searchResultsListView.Adapter = adapter; } } catch (Exception e) { } }