Exemple #1
0
        //Creates the main attributes of the page when it is loaded
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View v = inflater.Inflate(Resource.Layout.landlordDashboard, container, false);

            mainLayout = v.FindViewById <LinearLayout>(Resource.Id.mainLayout);
            Button navHome           = v.FindViewById <Button>(Resource.Id.bProperties);
            Button displayUser       = v.FindViewById <Button>(Resource.Id.displayUser);
            Button displayProperties = v.FindViewById <Button>(Resource.Id.showProperty);

            id = int.Parse(ap.getAccessKey()); //gets the current user's ID
            //This is an invisible button that is used so the list of properties is displayed when it loads
            displayProperties.Click += async delegate
            {
                //Getting the php page with the data on for the properties
                string    url  = "http://housechecker.co.uk/api/export_property.php";
                JsonValue json = await FetchUserAsync(url);                                 //storing the data in a Json object using the asynchronous function written below

                string jsonString = json.ToString();                                        //converting the json to a string
                //Adding the properties to the list
                propertyList = JsonConvert.DeserializeObject <List <Address> >(jsonString); //Storing all the the individual property objects in the property list
                //Laying out the data
                LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, LinearLayout.LayoutParams.WrapContent);
                lp.SetMargins(130, 20, 0, 0);
                //Creating a title and setting the layout for it
                TextView propertyTitle = new TextView(this.Context);
                propertyTitle.Text             = "Your Properties:";
                propertyTitle.TextSize         = 20;
                propertyTitle.LayoutParameters = lp;
                mainLayout.AddView(propertyTitle);
                //Getting the php page with the data on for the reviews
                string ratingUrl = "http://housechecker.co.uk/api/export_review.php";
                json = await FetchUserAsync(ratingUrl);

                jsonString = json.ToString();
                var reviewList = JsonConvert.DeserializeObject <List <Review> >(jsonString);        //storing all reviews in a list of reviews
                //Creating a new list with the properties in that the current landlord owns
                List <Address> propertiesOwned = propertyList.Where(a => a.user_id == id).ToList(); //Creating a seperate list of properties of the properties that the current user owns

                foreach (var address in propertiesOwned)                                            //loops through each property in the User's property list
                {
                    double        average_score;
                    List <Review> review = reviewList.Where(a => a.property_id == address.id).ToList(); //Gets all the reviews for each property in propertiesOwned
                    if (review.Count > 0)
                    {
                        average_score = review.Average(a => a.rating);  //If there is a review for the property, find the average of all the ratings in reviews
                    }
                    else
                    {
                        average_score = 0; //If there are no reviews, set the average to 0
                    }

                    if (review != null)
                    {
                        address.rating = average_score; //If review list isn't empty, set the property's rating to the average, worked out above
                    }
                }

                List <Review> propertyReviews = new List <Review>();

                if (propertiesOwned.Count > 0)                                                                  //If the landlord owns a property
                {
                    foreach (var property in propertiesOwned)                                                   //Loop through all the properties they own
                    {
                        propertyReviews.AddRange(reviewList.Where(a => a.property_id == property.id).ToList()); //Add all the revews for the property to a list
                        property.reviewCount = reviewList.Where(a => a.property_id == property.id).Count();     //Sets how many reviews there are for a property
                    }

                    Address topRatedAccom    = propertiesOwned.Where(o => o.user_id == id).OrderByDescending(o => o.rating).Take(1).FirstOrDefault(); //Gets the best accomodation by taking the top property from a list ordered by rating
                    Address lowestRatedAccom = propertiesOwned.Where(o => o.user_id == id).OrderBy(o => o.rating).Take(1).FirstOrDefault();           //Gets the worst property by taking the bottom property from a list ordered by rating
                    Address mostPopularAccom = propertiesOwned.OrderByDescending(a => a.reviewCount).Take(1).FirstOrDefault();                        //Takes the most popular accomodation based upomn how many reviews it has received
                    Review  mostRecentReview = propertyReviews.OrderByDescending(a => a.date_of_review).Take(1).FirstOrDefault();                     //Gets the most recent review of a property


                    //Sets parameters for each property that has been defined above
                    TextView topRatedAccomDescp   = new TextView(this.Context);
                    TextView lowestRatedAccomDesc = new TextView(this.Context);
                    TextView mostPopularAccomDesc = new TextView(this.Context);
                    TextView mostRecentReviewDesc = new TextView(this.Context);

                    TextView topRatedAccomTitle    = new TextView(this.Context);
                    TextView lowestRatedAccomTitle = new TextView(this.Context);
                    TextView mostPopularAccomTitle = new TextView(this.Context);
                    TextView mostRecentReviewTitle = new TextView(this.Context);

                    topRatedAccomDescp.Text   = "\nAccom Title: " + topRatedAccom.address1 + "\nPostcode: " + topRatedAccom.postcode;
                    lowestRatedAccomDesc.Text = "\nAccom Title: " + lowestRatedAccom.address1 + "\nPostcode: " + lowestRatedAccom.postcode;
                    mostPopularAccomDesc.Text = "\nAccom Title: " + mostPopularAccom.address1 + "\nPostcode: " + mostPopularAccom.postcode;
                    mostRecentReviewDesc.Text = "\nReview Title: " + mostRecentReview.title + "\nComment: " + mostRecentReview.comment;

                    topRatedAccomTitle.Text    = "Top Rated Accomodation: ";
                    lowestRatedAccomTitle.Text = "Worst Rated Accomodation: ";
                    mostPopularAccomTitle.Text = "Most Popular Accomodation: ";
                    mostRecentReviewTitle.Text = "Most Recent Review: ";

                    topRatedAccomDescp.LayoutParameters   = lp;
                    lowestRatedAccomDesc.LayoutParameters = lp;
                    mostPopularAccomDesc.LayoutParameters = lp;
                    mostRecentReviewDesc.LayoutParameters = lp;

                    topRatedAccomTitle.LayoutParameters    = lp;
                    lowestRatedAccomTitle.LayoutParameters = lp;
                    mostPopularAccomTitle.LayoutParameters = lp;
                    mostRecentReviewTitle.LayoutParameters = lp;

                    topRatedAccomTitle.TextSize    = 20;
                    lowestRatedAccomTitle.TextSize = 20;
                    mostPopularAccomTitle.TextSize = 20;
                    mostRecentReviewTitle.TextSize = 20;

                    //If the text has been clicked, Text to Speech will happen
                    topRatedAccomTitle.Click += async(senderSpeak, eSpeak) =>
                    {
                        string txt = "Your top rated accomodation is " + topRatedAccom.address1 + ", in, " + topRatedAccom.city;
                        await CrossTextToSpeech.Current.Speak(txt);
                    };

                    lowestRatedAccomTitle.Click += async(senderSpeak, eSpeak) =>
                    {
                        string txt = "Your lowest rated accomodation is " + lowestRatedAccom.address1 + ", in, " + lowestRatedAccom.city;
                        await CrossTextToSpeech.Current.Speak(txt);
                    };

                    mostPopularAccomTitle.Click += async(senderSpeak, eSpeak) =>
                    {
                        string txt = "Your most popular accomodation is " + mostPopularAccom.address1 + ", in, " + mostPopularAccom.city;
                        await CrossTextToSpeech.Current.Speak(txt);
                    };

                    mostRecentReviewTitle.Click += async(senderSpeak, eSpeak) =>
                    {
                        string txt = "Your most recent review was rated " + mostRecentReview.rating + ", in, " + mostRecentReview.comment;
                        await CrossTextToSpeech.Current.Speak(txt);
                    };
                    //Adds the properties to the page to display them on the screen
                    LinearLayout topRatedLayout = new LinearLayout(this.Context);
                    topRatedLayout.Orientation = Orientation.Vertical;
                    topRatedLayout.AddView(topRatedAccomTitle);
                    topRatedLayout.AddView(topRatedAccomDescp);
                    topRatedLayout.AddView(GetImage(topRatedAccom));

                    LinearLayout worstRatedLayout = new LinearLayout(this.Context);
                    worstRatedLayout.Orientation = Orientation.Vertical;
                    worstRatedLayout.AddView(lowestRatedAccomTitle);
                    worstRatedLayout.AddView(lowestRatedAccomDesc);
                    worstRatedLayout.AddView(GetImage(lowestRatedAccom));

                    LinearLayout mostPopularLayout = new LinearLayout(this.Context);
                    mostPopularLayout.Orientation = Orientation.Vertical;
                    mostPopularLayout.AddView(mostPopularAccomTitle);
                    mostPopularLayout.AddView(mostPopularAccomDesc);
                    mostPopularLayout.AddView(GetImage(mostPopularAccom));

                    LinearLayout reviewLayout = new LinearLayout(this.Context);
                    mainLayout.AddView(mostRecentReviewTitle);
                    mainLayout.AddView(mostRecentReviewDesc);

                    mainLayout.AddView(topRatedLayout);
                    mainLayout.AddView(worstRatedLayout);
                    mainLayout.AddView(mostPopularLayout);
                    mainLayout.AddView(reviewLayout);
                }
            };

            displayUser.Click += async delegate //Gets the current landlord's information when the page is loaded
            {
                string    url  = "http://housechecker.co.uk/api/landlord_export.php";
                JsonValue json = await FetchUserAsync(url);

                string          jsonString      = json.ToString();
                List <Landlord> listOfLandlords = JsonConvert.DeserializeObject <List <Landlord> >(jsonString);
                var             user            = listOfLandlords.Where(a => a.Id == id).FirstOrDefault();
            };

            displayUser.CallOnClick(); //Automatically calls click methods on the invisible buttons to begin functionality
            displayProperties.CallOnClick();
            return(v);
        }
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            //Set new names to fields
            v        = inflater.Inflate(Resource.Layout.AppPropertyView, container, false);
            submit   = v.FindViewById <Button>(Resource.Id.submitProperty);
            address1 = v.FindViewById <EditText>(Resource.Id.getAddress1);
            address2 = v.FindViewById <EditText>(Resource.Id.getAddress2);
            city     = v.FindViewById <EditText>(Resource.Id.getCity);
            price    = v.FindViewById <EditText>(Resource.Id.getPrice);
            postcode = v.FindViewById <EditText>(Resource.Id.getPostcode);
            bedrooms = v.FindViewById <Spinner>(Resource.Id.bedroomSpinner);
            addImage = v.FindViewById <Button>(Resource.Id.addImage);
            //Get user ID from the previous page
            id = int.Parse(ap.getAccessKey());

            //Set for drop down boxs
            bedrooms.ItemSelected += new EventHandler <AdapterView.ItemSelectedEventArgs>(bedrooms_ItemSelected);
            var bedroomAdapter = ArrayAdapter.CreateFromResource(
                Android.App.Application.Context, Resource.Array.bedroom_array, Android.Resource.Layout.SimpleSpinnerItem);

            bedroomAdapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
            bedrooms.Adapter = bedroomAdapter;

            bathrooms = v.FindViewById <Spinner>(Resource.Id.bathroomSpinner);

            bathrooms.ItemSelected += new EventHandler <AdapterView.ItemSelectedEventArgs>(bathrooms_ItemSelected);
            var bathroomsAdapter = ArrayAdapter.CreateFromResource(
                Android.App.Application.Context, Resource.Array.bathroom_array, Android.Resource.Layout.SimpleSpinnerItem);

            bathroomsAdapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
            bathrooms.Adapter = bathroomsAdapter;

            //set drop downs for accomodation type
            accomType = v.FindViewById <Spinner>(Resource.Id.typeSpinner);

            accomType.ItemSelected += new EventHandler <AdapterView.ItemSelectedEventArgs>(type_ItemSelected);
            var accomTypeAdapter = ArrayAdapter.CreateFromResource(
                Android.App.Application.Context, Resource.Array.type_array, Android.Resource.Layout.SimpleSpinnerItem);

            accomTypeAdapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
            accomType.Adapter = accomTypeAdapter;

            //Set wifi and bills to new name
            wifi  = v.FindViewById <RadioGroup>(Resource.Id.getWifi);
            bills = v.FindViewById <RadioGroup>(Resource.Id.getBills);

            submit.Click += async delegate
            {
                //URL which will use php to add a new property
                string url = "http://housechecker.co.uk/api/new_property.php?";
                //Set data to fetched url
                string data = await FetchUserAsync(url);

                //Exporting user data
                url = "http://housechecker.co.uk/api/export.php";
                JsonValue json = await GetData(url);

                string jsonString = json.ToString();
                //Get list of users
                List <Student> userList = JsonConvert.DeserializeObject <List <Student> >(jsonString);

                var companySelected = userList.Where(a => a.Id == id).FirstOrDefault();

                //Set message which says that it has been added
                string message = "Hello, " + companySelected.CompanyName
                                 + ", you have successfully added the accomodation: " + address1.Text;
                string subject = "New property added";
                string to      = companySelected.Email;
                //Send email to URL
                url  = "http://housechecker.co.uk/api/email.php";
                data = await SendEmail(url, to, message, subject);

                //New fragment for when emailed
                FragmentTransaction fragmentTx        = FragmentManager.BeginTransaction();
                LandlordDashboard   landlordDashboard = new LandlordDashboard();

                fragmentTx.Replace(Resource.Id.content_frame, landlordDashboard);
                fragmentTx.Commit();
            };
            return(v);
        }
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            //Set buttons and main layout
            View v = inflater.Inflate(Resource.Layout.myReviews, container, false);

            mainLayout = v.FindViewById <LinearLayout>(Resource.Id.mainLayout);
            Button showReviews = v.FindViewById <Button>(Resource.Id.showReviews);

            //Get ID from previous page
            id = int.Parse(ap.getAccessKey());

            showReviews.Click += async delegate
            {
                //Grab url json data for the review tables
                string url = "http://housechecker.co.uk/api/export_review.php";
                //Get the json data
                JsonValue json = await FetchUserAsync(url);

                //convert to string
                string jsonString = json.ToString();
                //Set the review list
                reviewList = JsonConvert.DeserializeObject <List <Review> >(jsonString);

                //For every review with user id that equals the current user id
                foreach (var reviews in reviewList.Where(a => a.user_id.Equals(id)))
                {
                    //Get url of the property table which shows every property
                    url  = "http://housechecker.co.uk/api/export_property.php";
                    json = await FetchUserAsync(url);

                    Address accom = JsonConvert.DeserializeObject <List <Address> >(json.ToString())
                                    .Where(a => a.id == reviews.property_id).FirstOrDefault();

                    //start dynamically creating layout of the reviews
                    LinearLayout reviewDisplay = new LinearLayout(this.Context);
                    reviewDisplay.Orientation = Orientation.Vertical;

                    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, LinearLayout.LayoutParams.WrapContent);
                    lp.SetMargins(100, 20, 0, 0);

                    //Set accomodation title and display the review
                    TextView accomTitle    = new TextView(this.Context);
                    TextView displayReview = new TextView(this.Context);

                    reviewDisplay.LayoutParameters = lp;

                    accomTitle.TextSize    = 20;
                    displayReview.TextSize = 16;

                    //Display the reviews which belong to the user
                    displayReview.Text = "Review title: " + reviews.title + "\nReview Comment: "
                                         + reviews.comment + "\nReview Rating: " + reviews.rating;
                    accomTitle.Text = accom.address1;

                    reviewDisplay.AddView(accomTitle);
                    reviewDisplay.AddView(displayReview);


                    mainLayout.AddView(reviewDisplay);
                }
            };
            showReviews.CallOnClick();
            return(v);
        }
Exemple #4
0
        //Creates the main attributes of the page when it is loaded
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View v = inflater.Inflate(Resource.Layout.myProperties, container, false);

            mainLayout = v.FindViewById <LinearLayout>(Resource.Id.mainLayout);
            Button displayProperties = v.FindViewById <Button>(Resource.Id.showProperty);

            id = int.Parse(ap.getAccessKey());

            displayProperties.Click += async delegate
            {
                string    url  = "http://housechecker.co.uk/api/export_property.php";
                JsonValue json = await FetchUserAsync(url);

                string jsonString = json.ToString();
                //Getting the properties from the database and putting it into the list
                propertyList = JsonConvert.DeserializeObject <List <Address> >(jsonString);
                //Getting each property for the current landlord
                foreach (var accomodation in propertyList.Where(a => a.user_id.Equals(id)))
                {
                    //Creating the layout for the properties
                    LinearLayout newLayout = new LinearLayout(this.Context);
                    newLayout.Orientation = Orientation.Vertical;
                    TextView displayAddress = new TextView(this.Context);
                    displayAddress.Text = "Address: " + accomodation.address1 + ", " + accomodation.address2 + "\nCity: " +
                                          accomodation.city + "\nPostcode " + accomodation.postcode;
                    displayAddress.Typeface = Typeface.DefaultBold;
                    displayAddress.TextSize = 16;
                    displayAddress.Gravity  = GravityFlags.Center;

                    //Button to allow for more informaiton

                    ImageView imageView = new ImageView(this.Context);

                    try
                    {
                        string imageURL = accomodation.image.Remove(0, 2);
                        imageURL = "http://housechecker.co.uk" + imageURL;
                        WebRequest request = WebRequest.Create(imageURL);
                        // Creates the image URL based from what is stored in the database
                        WebResponse resp       = request.GetResponse();
                        Stream      respStream = resp.GetResponseStream();
                        Bitmap      bmp        = BitmapFactory.DecodeStream(respStream);
                        Bitmap      image      = Bitmap.CreateScaledBitmap(bmp, 500, 500, false);
                        // Resizes the image to fit
                        respStream.Dispose();
                        imageView.SetImageBitmap(image);
                        imageView.RefreshDrawableState();
                        // Creates it and sets it to the view
                    }
                    catch (Exception e)
                    {
                        imageView.SetImageDrawable(Resources.GetDrawable(Resource.Drawable.propertyStock));
                    }

                    imageView.Click += (senderNew, eNew) =>
                    {
                        FragmentTransaction fragmentTx     = FragmentManager.BeginTransaction();
                        PropertyDetail      propertyDetail = new PropertyDetail();
                        Bundle bundle = new Bundle();
                        bundle.PutString("accomID", accomodation.id.ToString());
                        propertyDetail.Arguments = bundle;
                        fragmentTx.Replace(Resource.Id.content_frame, propertyDetail);
                        fragmentTx.Commit();
                        // Creates a click event function for the image so it will go to the selected property
                    };

                    newLayout.AddView(imageView);
                    newLayout.AddView(displayAddress);
                    mainLayout.AddView(newLayout);
                }
            };
            displayProperties.CallOnClick();
            return(v);
        }
Exemple #5
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View v = inflater.Inflate(Resource.Layout.Profile, container, false);

            Button navHome     = v.FindViewById <Button>(Resource.Id.bProperties);
            Button displayUser = v.FindViewById <Button>(Resource.Id.displayUser);
            Button submitEdit  = v.FindViewById <Button>(Resource.Id.submitEdit);

            TextView displayFirstName   = v.FindViewById <TextView>(Resource.Id.displayFirstName);
            TextView displayLastName    = v.FindViewById <TextView>(Resource.Id.displayLastName);
            TextView displayEmail       = v.FindViewById <TextView>(Resource.Id.displayEmail);
            TextView displayUni         = v.FindViewById <TextView>(Resource.Id.displayUni);
            TextView displayNumber      = v.FindViewById <TextView>(Resource.Id.displayNumber);
            TextView displayCompanyName = v.FindViewById <TextView>(Resource.Id.displayCompanyName);

            ImageView    editFirstName   = v.FindViewById <ImageView>(Resource.Id.editName);
            ImageView    editLastName    = v.FindViewById <ImageView>(Resource.Id.editLastName);
            ImageView    editUni         = v.FindViewById <ImageView>(Resource.Id.editUni);
            ImageView    editEmail       = v.FindViewById <ImageView>(Resource.Id.editEmail);
            ImageView    editNumber      = v.FindViewById <ImageView>(Resource.Id.editNumber);
            ImageView    editCompanyName = v.FindViewById <ImageView>(Resource.Id.editCompanyName);
            LinearLayout editLayout      = v.FindViewById <LinearLayout>(Resource.Id.editLayout);

            EditText submitEditValue = v.FindViewById <EditText>(Resource.Id.editValue);

            LinearLayout firstNameLayout   = v.FindViewById <LinearLayout>(Resource.Id.firstNameLayout);
            LinearLayout lastNameLayout    = v.FindViewById <LinearLayout>(Resource.Id.lastNameLayout);
            LinearLayout uniLayout         = v.FindViewById <LinearLayout>(Resource.Id.uniLayout);
            LinearLayout phoneLayout       = v.FindViewById <LinearLayout>(Resource.Id.numberLayout);
            LinearLayout emailLayout       = v.FindViewById <LinearLayout>(Resource.Id.emailLayout);
            LinearLayout companyNameLayout = v.FindViewById <LinearLayout>(Resource.Id.companyNameLayout);

            // Retrieves all objects from the XAML page

            id = int.Parse(ap.getAccessKey());

            displayUser.Click += async(sender, e) =>
            {
                string    url  = "http://housechecker.co.uk/api/export.php";
                JsonValue json = await FetchUserAsync(url);

                string         jsonString     = json.ToString();
                List <Student> listOfStudents = JsonConvert.DeserializeObject <List <Student> >(jsonString);
                var            user           = listOfStudents.Where(a => a.Id == id).FirstOrDefault();
                if (user.Type == "Student")
                {
                    firstNameLayout.Visibility = ViewStates.Visible;
                    lastNameLayout.Visibility  = ViewStates.Visible;
                    uniLayout.Visibility       = ViewStates.Visible;
                    phoneLayout.Visibility     = ViewStates.Visible;
                    emailLayout.Visibility     = ViewStates.Visible;

                    displayFirstName.Text += user.Firstname;
                    displayLastName.Text  += user.Lastname;
                    displayEmail.Text     += user.Email;
                    displayUni.Text       += user.Uni;
                    displayNumber.Text    += user.Phone;

                    // If the user is a student select the correct fields to show
                }
                else
                {
                    phoneLayout.Visibility       = ViewStates.Visible;
                    emailLayout.Visibility       = ViewStates.Visible;
                    companyNameLayout.Visibility = ViewStates.Visible;

                    displayEmail.Text       += user.Email;
                    displayNumber.Text      += user.Phone;
                    displayCompanyName.Text += user.CompanyName;

                    // Same if the user is a landlord
                }
            };

            editFirstName.Click += delegate
            {
                editChoice            = "first_name";
                editLayout.Visibility = ViewStates.Visible;
            };

            editLastName.Click += delegate
            {
                editChoice            = "last_name";
                editLayout.Visibility = ViewStates.Visible;
            };

            editUni.Click += delegate
            {
                editChoice            = "university";
                editLayout.Visibility = ViewStates.Visible;
            };

            editEmail.Click += delegate
            {
                editChoice            = "email";
                editLayout.Visibility = ViewStates.Visible;
            };

            editNumber.Click += delegate
            {
                editChoice            = "phone";
                editLayout.Visibility = ViewStates.Visible;
            };

            editCompanyName.Click += delegate
            {
                editChoice            = "company_name";
                editLayout.Visibility = ViewStates.Visible;
            };

            // Adds a click event to each edit icon to allow the user to select what field they want to edit

            submitEdit.Click += async delegate
            {
                string url      = "http://housechecker.co.uk/api/edit_user.php";
                string newValue = submitEditValue.Text;
                string data     = await editValue(url, newValue);
            };

            // This submits the data to be edited

            displayUser.CallOnClick();
            return(v);
        }
Exemple #6
0
        //Creates the main attributes of the page when it is loaded
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View v = inflater.Inflate(Resource.Layout.studentDashboard, container, false);

            mainLayout = v.FindViewById <LinearLayout>(Resource.Id.mainLayout);
            Button showReviews = v.FindViewById <Button>(Resource.Id.showReviews);
            Button showMap     = v.FindViewById <Button>(Resource.Id.showMap);

            id = int.Parse(ap.getAccessKey());

            showMap.Click += async(sender, e) =>
            {
                await GetUserAddress();

                string    url  = "http://housechecker.co.uk/api/export_property.php";
                JsonValue json = await FetchUserAsync(url);

                string jsonString = json.ToString();
                addressList = JsonConvert.DeserializeObject <List <Address> >(jsonString).Where(o => o.city.Equals(userAddress.Locality)).ToList();
                await getCoordinates();

                string ratingUrl = "http://housechecker.co.uk/api/export_review.php";
                json = await FetchUserAsync(ratingUrl);

                jsonString = json.ToString();
                var reviewList = JsonConvert.DeserializeObject <List <Review> >(jsonString);

                // Getting information for properties and ratings and parsing them into a list

                foreach (var address in addressList)
                {
                    List <Review> review = reviewList.Where(a => a.property_id == address.id).ToList();
                    if (review.Count > 0)
                    {
                        address.rating = review.Average(a => a.rating);
                    }
                    else
                    {
                        address.rating = 0;
                    }
                }

                // Adding a rating to each accomodation

                List <Address> RatingSortedAddress = addressList.OrderByDescending(o => o.rating).Take(5).ToList();
                foreach (var coordinate in coordinates)
                {
                    var distance = CalculateDistance(userAddress.Latitude, userAddress.Longitude, coordinate.latitude, coordinate.longitude);
                    foreach (var address in RatingSortedAddress.Where(r => r.address1.Equals(coordinate.name)))
                    {
                        address.distance = distance;
                    }
                }

                // Sorts the list by rating and takes the highest 5
                // Works out a distance for each one using the calculate distance

                LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, LinearLayout.LayoutParams.WrapContent);
                lp.SetMargins(130, 20, 0, 0);

                // Sets up the margins for padding

                foreach (var address in RatingSortedAddress)
                {
                    if (address.distance < 0.75)
                    {
                        // If the distance is less than 0.75
                        ImageView    propertyImage  = new ImageView(this.Context);
                        LinearLayout accomDisplay   = new LinearLayout(this.Context);
                        TextView     displayAddress = new TextView(this.Context);

                        accomDisplay.LayoutParameters = lp;

                        displayAddress.TextSize = 16;

                        displayAddress.Text = "Address line 1: " + address.address1 + "\nAddress line 2: "
                                              + address.address2 + "\nCity: " + address.city + "\nPostcode: " + address.postcode + "\nRating: "
                                              + address.rating + "\nDistance: " + address.distance.ToString("F") + " km.";

                        // Creates the text that will contain the address

                        try
                        {
                            string imageURL = address.image.Remove(0, 2);
                            imageURL = "http://housechecker.co.uk" + imageURL;
                            WebRequest  request    = WebRequest.Create(imageURL);
                            WebResponse resp       = request.GetResponse();
                            Stream      respStream = resp.GetResponseStream();
                            Bitmap      bmp        = BitmapFactory.DecodeStream(respStream);
                            Bitmap      image      = Bitmap.CreateScaledBitmap(bmp, 500, 500, false);
                            respStream.Dispose();
                            propertyImage.SetImageBitmap(image);
                            propertyImage.RefreshDrawableState();
                        }
                        catch (Exception imageError)
                        {
                            propertyImage.SetImageDrawable(Resources.GetDrawable(Resource.Drawable.propertyStock));
                        }

                        //  Typeface tf = Typeface.CreateFromAsset(Activity.Assets, "fonts/roboto.ttf");
                        LinearLayout.LayoutParams textParam = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, LinearLayout.LayoutParams.WrapContent);
                        lp.SetMargins(0, 5, 0, 0);
                        TextView getFont = v.FindViewById <TextView>(Resource.Id.getFont);
                        displayAddress.Typeface         = getFont.Typeface;
                        displayAddress.LayoutParameters = textParam;

                        // Formats all the display properties

                        accomDisplay.AddView(propertyImage);
                        accomDisplay.AddView(displayAddress);

                        propertyImage.Click += delegate
                        {
                            FragmentTransaction fragmentTx     = FragmentManager.BeginTransaction();
                            PropertyDetail      propertyDetail = new PropertyDetail();
                            Bundle bundle = new Bundle();
                            bundle.PutString("accomID", address.id.ToString());
                            propertyDetail.Arguments = bundle;
                            fragmentTx.Replace(Resource.Id.content_frame, propertyDetail);
                            fragmentTx.Commit();
                        };

                        // Adds an on click event to the image that takes you to the accomodation

                        displayAddress.Click += async delegate
                        {
                            await CrossTextToSpeech.Current.Speak(displayAddress.Text);
                        };

                        mainLayout.AddView(accomDisplay);
                    }
                }
            };

            showMap.CallOnClick();
            return(v);
        }
        //Creates the main attributes of the page when it is loaded
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            v       = inflater.Inflate(Resource.Layout.addReview, container, false);
            accomId = int.Parse(Arguments.GetString("accomID"));
            userId  = int.Parse(ap.getAccessKey());
            Button navHome = v.FindViewById <Button>(Resource.Id.bProperties);

            // setting the editText variables to the fields from axml
            input_review_title   = (EditText)v.FindViewById(Resource.Id.reviewTitle);
            input_review_Comment = (EditText)v.FindViewById(Resource.Id.reviewComment);
            clean_Rating         = (RatingBar)v.FindViewById(Resource.Id.cleanRating);
            landlord_Rating      = (RatingBar)v.FindViewById(Resource.Id.landlordRating);
            value_Rating         = (RatingBar)v.FindViewById(Resource.Id.valueRating);
            location_Rating      = (RatingBar)v.FindViewById(Resource.Id.locationRating);
            b_add_review1        = (Button)v.FindViewById(Resource.Id.b_add_review);
            //Adding a review when the button is clicked
            b_add_review1.Click += async delegate
            {
                //Creating new variables for each field
                float clean     = clean_Rating.Rating;
                float value     = value_Rating.Rating;
                float location  = location_Rating.Rating;
                float landlord  = landlord_Rating.Rating;
                float avg_score = (clean + value + location + landlord) / 4;
                //Getting the url to create a new review
                string url  = "http://housechecker.co.uk/api/new_review.php?";
                string data = await FetchUserAsync(url);

                //Getting the property details from the php page
                url = "http://housechecker.co.uk/api/export_property.php";
                JsonValue json = await GetData(url);

                string jsonString = json.ToString();
                //Creating a new list for the properties
                List <Address> propertyList = JsonConvert.DeserializeObject <List <Address> >(jsonString);

                Address selectedProperty = propertyList.Where(a => a.id == accomId).FirstOrDefault();
                //Getting the list of users to to then send an email welcoming then to the app
                url  = "http://housechecker.co.uk/api/export.php";
                json = await GetData(url);

                jsonString = json.ToString();
                List <Student> userList = JsonConvert.DeserializeObject <List <Student> >(jsonString);

                var companySelected = userList.Where(a => a.Id == selectedProperty.user_id).FirstOrDefault();
                //Sending the email
                string message = "Hello, " + companySelected.CompanyName + ", someone has added a new review for your property: " +
                                 selectedProperty.address1 + "\n They scored you an average of: " + avg_score;
                string subject = "New review";
                string to      = companySelected.Email;
                url  = "http://housechecker.co.uk/api/email.php";
                data = await SendEmail(url, to, message, subject);

                var user = userList.Where(a => a.Id == userId).FirstOrDefault();
                //Sending an email to the landlord to tell them that they have a new review
                message = "Hello, " + user.Firstname + ", thank you for adding a review for the property " + selectedProperty.address1;
                subject = "New review";
                to      = user.Email;
                url     = "http://housechecker.co.uk/api/email.php";
                data    = await SendEmail(url, to, message, subject);
            };
            return(v);
        }