예제 #1
0
        //Creating a new instance of the addReview
        public static addReview NewInstance()
        {
            var frag1 = new addReview {
                Arguments = new Bundle()
            };

            return(frag1);
        }
예제 #2
0
        //Sending the information to the database
        private async Task <string> FetchUserAsync(string url)
        {
            string success = "";

            string title    = input_review_title.Text;
            string comment  = input_review_Comment.Text;
            float  clean    = clean_Rating.Rating;
            float  value    = value_Rating.Rating;
            float  location = location_Rating.Rating;
            float  landlord = landlord_Rating.Rating;
            string str6     = userId.ToString();
            string str5     = accomId.ToString();
            string str1     = clean.ToString();
            string str2     = value.ToString();
            string str3     = location.ToString();
            string str4     = landlord.ToString();

            using (var webClient = new WebClient())
            {
                var data = new NameValueCollection();
                data["property_id"] = str5;
                data["user_id"]     = str6;
                data["title"]       = title;
                data["comment"]     = comment;
                data["clean"]       = str1;
                data["value"]       = str2;
                data["landlord"]    = str3;
                data["location"]    = str4;

                var response = webClient.UploadValues(url, "POST", data);

                FragmentTransaction fragmentTx = FragmentManager.BeginTransaction();
                addReview           addReview  = new addReview();
                Bundle bundle = new Bundle();
                bundle.PutString("accomID", str5);
                addReview.Arguments = bundle;
                fragmentTx.Replace(Resource.Id.content_frame, addReview);
                fragmentTx.Commit();
            }
            return(success);
        }
예제 #3
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View v = inflater.Inflate(Resource.Layout.PropertyDetailView, container, false);

            accomId          = int.Parse(Arguments.GetString("accomID"));
            addReview        = v.FindViewById <Button>(Resource.Id.addReview);
            displayAccom     = v.FindViewById <Button>(Resource.Id.displayAccom);
            displayAddress   = v.FindViewById <TextView>(Resource.Id.displayAddress);
            displayBills     = v.FindViewById <TextView>(Resource.Id.displayBills);
            displayWifi      = v.FindViewById <TextView>(Resource.Id.displayWifi);
            displayPrice     = v.FindViewById <TextView>(Resource.Id.displayPrice);
            displayBedrooms  = v.FindViewById <TextView>(Resource.Id.displayBedrooms);
            displayBathrooms = v.FindViewById <TextView>(Resource.Id.displayBathrooms);
            displayRating    = v.FindViewById <TextView>(Resource.Id.displayRating);
            LinearLayout reviewLayout    = v.FindViewById <LinearLayout>(Resource.Id.reviewLayout);
            Button       addToFavourites = v.FindViewById <Button>(Resource.Id.addFavourite);

            addressList = new List <Address>();

            // Gets all the views

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

            // Takes you to the add a review page

            displayAccom.Click += async(sender, e) =>
            {
                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);

                Address accomodation = addressList.Where(a => a.id == accomId).FirstOrDefault();

                ImageView imageView = v.FindViewById <ImageView>(Resource.Id.propertyImage);

                // Finds the accomodation that matches the ID that you have passed in

                try
                {
                    string imageURL = accomodation.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();
                    imageView.SetImageBitmap(image);
                    imageView.RefreshDrawableState();
                }
                catch (Exception error)
                {
                    imageView.SetImageDrawable(Resources.GetDrawable(Resource.Drawable.propertyStock));
                }

                // Finds and displays the image

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

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

                // Gets all the reviewws and puts it into a review list

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

                // Gets the rating from each review that is linked to the property and averages it

                displayRating.Text   = "Average Rating: " + accomodation.rating;
                displayRating.Click += async delegate
                {
                    await CrossTextToSpeech.Current.Speak(displayRating.Text);
                };

                displayBills.Text   = "Bills included: " + accomodation.bills;
                displayBills.Click += async delegate
                {
                    await CrossTextToSpeech.Current.Speak(displayBills.Text);
                };

                displayWifi.Text   = "Wifi included: " + accomodation.wifi;
                displayWifi.Click += async delegate
                {
                    await CrossTextToSpeech.Current.Speak(displayWifi.Text);
                };

                displayPrice.Text   = "Price per week: " + accomodation.price;
                displayPrice.Click += async delegate
                {
                    await CrossTextToSpeech.Current.Speak(displayPrice.Text);
                };

                displayBathrooms.Text   = "Number of bathrooms: " + accomodation.bathrooms;
                displayBathrooms.Click += async delegate
                {
                    await CrossTextToSpeech.Current.Speak(displayBathrooms.Text);
                };

                displayBedrooms.Text   = "Number of bedrooms: " + accomodation.bedrooms;
                displayBedrooms.Click += async delegate
                {
                    await CrossTextToSpeech.Current.Speak(displayBedrooms.Text);
                };

                displayAddress.Text = "Address: " + accomodation.address1 + ", " + accomodation.address2 + ", " +
                                      accomodation.city + ", " + accomodation.postcode;
                displayAddress.Click += async delegate
                {
                    await CrossTextToSpeech.Current.Speak(displayAddress.Text);
                };

                // Creates an on click event that reads out whatever the text says

                TextView reviewTitle = new TextView(this.Context);
                reviewTitle.Text     = "Most recent reviews: ";
                reviewTitle.TextSize = 32;
                reviewTitle.Typeface = Typeface.DefaultBold;
                reviewTitle.Gravity  = GravityFlags.Center;
                reviewLayout.AddView(reviewTitle);

                // Creates a title for the reviews section

                foreach (var accomReview in review.OrderBy(a => a.date_of_review).Take(20))
                {
                    TextView newReviewText = new TextView(this.Context);

                    newReviewText.Text = "Title: " + accomReview.title + "\nComment: "
                                         + accomReview.comment + "\nRating: " + accomReview.rating;

                    newReviewText.TextSize = 24;
                    newReviewText.Gravity  = GravityFlags.Center;

                    reviewLayout.AddView(newReviewText);

                    // Gets the top 20 reviews for this accomodation, ordered by date, and creates a text view for them
                }

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

                jsonString = json.ToString();
                var favouriteList = JsonConvert.DeserializeObject <List <Favourite> >(jsonString);
                int userID        = Int32.Parse(ap.getAccessKey());

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

                jsonString = json.ToString();
                Student user = JsonConvert.DeserializeObject <List <Student> >(jsonString).Where(a => a.Id == userID).FirstOrDefault();

                // Gets the favourite list and decides if the user is a student or not

                if (user.Type == "Student")
                {
                    addToFavourites.Visibility = ViewStates.Visible;
                }

                if (user.Type == "Landlord")
                {
                    addReview.Visibility = ViewStates.Invisible;
                }

                // Landlords cant add a favourite

                var accomFavourite = favouriteList.Where(a => a.user_id == userID &&
                                                         a.accom_id == accomodation.id).FirstOrDefault();

                // Gets the value for a saved favourite for that accomodation and user

                if (accomFavourite != null)
                {
                    // If a favourite exists it means the user has added it to their favourites
                    addToFavourites.Text   = "Remove from favourites";
                    addToFavourites.Click += async delegate
                    {
                        url  = "http://housechecker.co.uk/api/delete_favourite.php";
                        json = await DeleteFavourite(url, accomFavourite.favourite_id);

                        // This will remove the favourited accomodation from their list
                        Activity.RunOnUiThread(() =>
                        {
                            Android.App.AlertDialog.Builder dialog = new Android.App.AlertDialog.Builder(Activity);
                            Android.App.AlertDialog alert          = dialog.Create();
                            dialog.SetCancelable(false);
                            alert.SetTitle("Complete");
                            alert.SetMessage("Successfully removed from favourites");
                            alert.SetButton("OK", (c, ev) =>
                            {
                                // Ok button click task
                            });
                            alert.Show();
                        });
                        // Shows a pop up window informing the user it has worked
                    };
                }
                else
                {
                    addToFavourites.Text   = "Add to Favourites";
                    addToFavourites.Click += async delegate
                    {
                        url  = "http://housechecker.co.uk/api/import_favourite.php";
                        json = await AddFavourite(url, accomodation.id);

                        // This will add the property to the list
                        Activity.RunOnUiThread(() =>
                        {
                            Android.App.AlertDialog.Builder dialog = new Android.App.AlertDialog.Builder(Activity);
                            Android.App.AlertDialog alert          = dialog.Create();
                            dialog.SetCancelable(false);
                            alert.SetTitle("Complete");
                            alert.SetMessage("Successfully added to favourites");
                            alert.SetButton("OK", (c, ev) =>
                            {
                                // Ok button click task
                            });
                            alert.Show();
                        });
                    };
                }
            };
            displayAccom.CallOnClick();
            return(v);
        }