async void refineDishResults(ListView listview) { string uri = "https://zeno.computing.dundee.ac.uk/2018-projects/foodfinder/api/mainmenu/"; string otherhalf = "DishRefinements?lat=" + lat + "&lon=" + lon + "&dish=" + searchedString + "&sort=" + sort + "&dietary=" + dietary + "&openNow=" + openNow; Uri result = null; if (Uri.TryCreate(new Uri(uri), otherhalf, out result)) { var httpClient = new HttpClient(); var refineResult = (await httpClient.GetStringAsync(result)); List <Post> RestaurantList = JsonConvert.DeserializeObject <List <Post> >(refineResult); if (RestaurantList.Count == 0) { test.Text = "Sorry, no restaurants nearby with those refinements"; } else { test.Text = "Restaurants nearby with the dish refine '" + searchedString + "'"; myRestaurantListViewAdapter adapter = new myRestaurantListViewAdapter(this.Context as Activity, RestaurantList); listview.Adapter = adapter; listview.ItemClick += (object sender, AdapterView.ItemClickEventArgs e) => { string restName = RestaurantList[e.Position].RestaurantName; //Toast.MakeText(Context as Activity, restName, ToastLength.Short).Show(); Intent intent = new Intent(Context as Activity, typeof(RestaurantProfileActivity)); intent.PutExtra("RestaurantInfo", JsonConvert.SerializeObject(RestaurantList[e.Position])); StartActivity(intent); }; } } }
//Getting all restaurants near the users device and displaying it in order of distance async void GetRestaurants(ListView listview) { string uri = "https://zeno.computing.dundee.ac.uk/2018-projects/foodfinder/api/mainmenu/"; string otherhalf = "HomeResults?lat=" + lat + "&lon=" + lon; Uri result = null; if (Uri.TryCreate(new Uri(uri), otherhalf, out result)) { var httpClient = new HttpClient(); var refineResult = (await httpClient.GetStringAsync(result)); //Deserialize json object List <Post> RestaurantList = JsonConvert.DeserializeObject <List <Post> >(refineResult); if (RestaurantList.Count == 0) { //display message to the user test.Text = "Sorry, no restaurants nearby"; } else { myRestaurantListViewAdapter adapter = new myRestaurantListViewAdapter(this.Context as Activity, RestaurantList); listview.Adapter = adapter; //when restaurant item is clicked show the restaurant's profile listview.ItemClick += (object sender, AdapterView.ItemClickEventArgs e) => { Intent intent = new Intent(Context as Activity, typeof(RestaurantProfileActivity)); //sending all the POST information for the chosen restaurant to it's restaurant profile page. intent.PutExtra("RestaurantInfo", JsonConvert.SerializeObject(RestaurantList[e.Position])); StartActivity(intent); }; } } }
async void ShowCategoryResults(string searchedString, ListView listview) { string uri = "https://zeno.computing.dundee.ac.uk/2018-projects/foodfinder/api/mainmenu/"; string otherhalf = "GetRestaurantsAccordingToCategories?lon=" + lon + "&lat=" + lat + "&category=" + searchedString; Uri result = null; if (Uri.TryCreate(new Uri(uri), otherhalf, out result)) { var httpClient = new HttpClient(); var refineResult = (await httpClient.GetStringAsync(result)); List <Post> RestaurantList = JsonConvert.DeserializeObject <List <Post> >(refineResult); if (RestaurantList.Count == 0) { test.Text = "Sorry, no restaurants nearby with category '" + searchedString + "'"; } else { test.Text = "Restaurants nearby with the category '" + searchedString + " " + sort + "'"; myRestaurantListViewAdapter adapter = new myRestaurantListViewAdapter(this.Context as Activity, RestaurantList); listview.Adapter = adapter; listview.ItemClick += (object sender, AdapterView.ItemClickEventArgs e) => { string restName = RestaurantList[e.Position].RestaurantName; Intent intent = new Intent(Context as Activity, typeof(RestaurantProfileActivity)); intent.PutExtra("RestaurantInfo", JsonConvert.SerializeObject(RestaurantList[e.Position])); StartActivity(intent); }; } } }
//sending the refinements to the API and displaying the results async void refineList(ListView listview, string value, string value2, string value3) { string uri = "https://zeno.computing.dundee.ac.uk/2018-projects/foodfinder/api/mainmenu/"; string otherhalf = "refinements2?lat=" + lat + "&lon=" + lon + "&sort=" + value + "&dietary=" + value2 + "&openNow=" + value3; Uri result = null; if (Uri.TryCreate(new Uri(uri), otherhalf, out result)) { var httpClient = new HttpClient(); var refineResult = (await httpClient.GetStringAsync(result)); List <Post> RestaurantList = JsonConvert.DeserializeObject <List <Post> >(refineResult); if (RestaurantList.Count == 0) { test.Text = "Sorry, no results"; } else { myRestaurantListViewAdapter adapter = new myRestaurantListViewAdapter(this.Context as Activity, RestaurantList); listview.Adapter = adapter; listview.ItemClick += (object sender, AdapterView.ItemClickEventArgs e) => { Intent intent = new Intent(Context as Activity, typeof(RestaurantProfileActivity)); intent.PutExtra("RestaurantInfo", JsonConvert.SerializeObject(RestaurantList[e.Position])); StartActivity(intent); }; } } }