Esempio n. 1
0
        /// <summary>
        /// This method is in charge of retrieving the result of the Picture dialog fragment.
        /// </summary>
        /// <param name="sender"> Reference to the object that raised the event </param>
        /// <param name="e"> Contains the event data </param>
        private void PictureAction(object sender, PicEvent e)
        {
            using var webClient = new WebClient { BaseAddress = "http://" + MainActivity.Ipv4 + ":8080/CookTime_war/cookAPI/" };
            var response = e.Message;

            if (response == 0)
            {
                // do this code when the user chose to see the logo
                if (!string.IsNullOrEmpty(bsns.photo))
                {
                    var transaction = SupportFragmentManager.BeginTransaction();
                    var dialogPShow = new DialogPShow();

                    dialogPShow.Url      = logoUrl;
                    dialogPShow.TypeText = "Business logo";
                    dialogPShow.Show(transaction, "bsns");
                }
                else
                {
                    // happens when the user has no image so we must display default.
                    string toastText = "you have not set a logo yet. To view one, you must first set it up.";
                    _toast = Toast.MakeText(this, toastText, ToastLength.Short);
                    _toast.Show();
                }
            }
            else
            {
                // do this code when the user chose to change their image.
                Intent gallery = new Intent();
                gallery.SetType("image/*");
                gallery.SetAction(Intent.ActionGetContent);
                StartActivityForResult(Intent.CreateChooser(gallery, "select a logo"), 0);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// This method is called when the activity is starting.
        /// It contains the logic for the buttons shown in this activity.
        /// </summary>
        /// <param name="savedInstanceState"> a Bundle that contains the data the activity most recently
        /// supplied if the activity is being re-initialized after previously being shut down. </param>
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.PrivBusiness);

            loggedId = Intent.GetStringExtra("LoggedId");
            bsnsJson = Intent.GetStringExtra("Bsns");
            bsns     = JsonConvert.DeserializeObject <Business>(bsnsJson);

            bsnsNameTV     = FindViewById <TextView>(Resource.Id.bsnsName);
            _bsnsHoursTV   = FindViewById <TextView>(Resource.Id.businessHoursPView);
            _bsnsContactTV = FindViewById <TextView>(Resource.Id.contactPView);
            scoreView      = FindViewById <TextView>(Resource.Id.scorePView);
            _locationText  = FindViewById <TextView>(Resource.Id.locationView);
            _btnFollowers  = FindViewById <Button>(Resource.Id.btnPBFollowers);
            _btnFollow     = FindViewById <Button>(Resource.Id.btnPBFollow);

            _logo = FindViewById <ImageView>(Resource.Id.businessLogo);

            _btnRate      = FindViewById <Button>(Resource.Id.btnPBRate);
            _btnDate      = FindViewById <Button>(Resource.Id.btnBDate);
            _btnScore     = FindViewById <Button>(Resource.Id.btnBScore);
            _btnDiff      = FindViewById <Button>(Resource.Id.btnBDiff);
            _menuListView = FindViewById <ListView>(Resource.Id.menuListView);

            bsnsNameTV.Text     = bsns.name;
            _bsnsHoursTV.Text   = "Business hours: " + bsns.businessHours;
            _bsnsContactTV.Text = "Contact: " + bsns.contact;
            _btnFollowers.Text  = "Followers: " + bsns.followers.Count;
            scoreView.Text      = "Score: " + bsns.rating;
            _locationText.Text  = "Location: " + bsns.location;

            // sets the business logo to the imageView
            if (!string.IsNullOrEmpty(bsns.photo))
            {
                logoUrl = $"http://{MainActivity.Ipv4}:8080/CookTime_war/cookAPI/resources/getPicture?id={bsns.photo}";
                Bitmap bitmap = GetImageBitmapFromUrl(logoUrl);
                _logo.SetImageBitmap(bitmap);
            }

            using var webClient = new WebClient { BaseAddress = "http://" + MainActivity.Ipv4 + ":8080/CookTime_war/cookAPI/" };

            var url = "resources/isFollowingBusiness?email=" + loggedId + "&id=" + bsns.id;

            webClient.Headers[HttpRequestHeader.ContentType] = "application/json";
            var response = webClient.DownloadString(url);

            _btnFollow.Text = response == "0" ? "FOLLOW" : "UNFOLLOW";

            url = "resources/businessPublic?id=" + bsns.id + "&filter=date";
            webClient.Headers[HttpRequestHeader.ContentType] = "application/json";
            var send = webClient.DownloadString(url);

            _menuList = JsonConvert.DeserializeObject <IList <string> >(send);

            _adapter = new RecipeAdapter(this, _menuList);
            _menuListView.Adapter    = _adapter;
            _menuListView.ItemClick += ListClick;

            _btnFollowers.Click += (sender, args) =>
            {
                var intent = new Intent(this, typeof(FollowActivity));
                intent.PutExtra("Title", "Followers");
                intent.PutExtra("LoggedId", loggedId);
                intent.PutStringArrayListExtra("FollowList", bsns.followers);
                StartActivity(intent);
                OverridePendingTransition(Android.Resource.Animation.SlideInLeft, Android.Resource.Animation.SlideOutRight);
            };

            _btnFollow.Click += (sender, args) =>
            {
                using var webClient2 = new WebClient { BaseAddress = "http://" + MainActivity.Ipv4 + ":8080/CookTime_war/cookAPI/" };
                var followUrl = "resources/followBusiness?email=" + loggedId + "&id=" + bsns.id;
                webClient2.Headers[HttpRequestHeader.ContentType] = "application/json";
                var answer = webClient2.DownloadString(followUrl);

                followUrl = "resources/getUser?id=" + loggedId;
                webClient2.Headers[HttpRequestHeader.ContentType] = "application/json";
                var userJson = webClient2.DownloadString(followUrl);

                _btnFollow.Text = answer == "0" ? "FOLLOW" : "UNFOLLOW";

                var toastText = answer == "0" ? "unfollowed" : "followed";

                var toast = Toast.MakeText(this, "User " + toastText + ". Redirecting to MyProfile...", ToastLength.Short);
                toast.Show();

                var intent = new Intent(this, typeof(MyProfileActivity));
                intent.PutExtra("User", userJson);
                intent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask);
                StartActivity(intent);
                OverridePendingTransition(Android.Resource.Animation.SlideInLeft, Android.Resource.Animation.SlideOutRight);
            };

            _btnDate.Click += (sender, args) =>
            {
                sortStr = "date";
                SortMenu();
            };

            _btnScore.Click += (sender, args) =>
            {
                sortStr = "score";
                SortMenu();
            };

            _btnDiff.Click += (sender, args) =>
            {
                sortStr = "difficulty";
                SortMenu();
            };

            _btnRate.Click += (sender, args) =>
            {
                //Brings dialog fragment forward
                var transaction = SupportFragmentManager.BeginTransaction();
                var dialogRate  = new DialogRate();

                dialogRate.Show(transaction, "rate");
                dialogRate.LoggedId = loggedId;
                dialogRate.BsnsId   = bsns.id;
                dialogRate.Type     = 2;

                dialogRate.EventHandlerRate += RateResult;
            };

            _logo.Click += (sender, args) =>
            {
                if (!string.IsNullOrEmpty(bsns.photo))
                {
                    var transaction = SupportFragmentManager.BeginTransaction();
                    var dialogPShow = new DialogPShow();

                    dialogPShow.Url      = logoUrl;
                    dialogPShow.TypeText = "Business logo";
                    dialogPShow.Show(transaction, "privBsns");
                }
                else
                {
                    string toastText = "Business has set no logo you can view.";
                    Toast  _toast    = Toast.MakeText(this, toastText, ToastLength.Short);
                    _toast.Show();
                }
            };
        }
Esempio n. 3
0
        /// <summary>
        /// This method is called when the activity is starting.
        /// All of the recipe info is shown here.
        /// </summary>
        /// <param name="savedInstanceState"> a Bundle that contains the data the activity most recently
        /// supplied if the activity is being re-initialized after previously being shut down. </param>
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Recipe);


            var recipe = Intent.GetStringExtra("Recipe");

            _recipe   = JsonConvert.DeserializeObject <Recipe>(recipe);
            _loggedId = Intent.GetStringExtra("LoggedId");

            // setting all the fields to axml file identities
            authorButton  = FindViewById <Button>(Resource.Id.authorButton);
            rateButton    = FindViewById <Button>(Resource.Id.rateButton);
            commentButton = FindViewById <Button>(Resource.Id.commentButton);
            shareButton   = FindViewById <Button>(Resource.Id.shareButton);

            _recipePic           = FindViewById <ImageView>(Resource.Id.recipePicture);
            recipeNameText       = FindViewById <TextView>(Resource.Id.recipeNameText);
            authorText           = FindViewById <TextView>(Resource.Id.authorText);
            dateText             = FindViewById <TextView>(Resource.Id.dateText);
            dishTypeText         = FindViewById <TextView>(Resource.Id.dishTypeText);
            dishTimeText         = FindViewById <TextView>(Resource.Id.dishTimeText);
            portionsText         = FindViewById <TextView>(Resource.Id.portionsText);
            durationText         = FindViewById <TextView>(Resource.Id.durationText);
            difficultyText       = FindViewById <TextView>(Resource.Id.difficultyText);
            dishTagsText         = FindViewById <TextView>(Resource.Id.dishTagsText);
            priceText            = FindViewById <TextView>(Resource.Id.priceText);
            scoreText            = FindViewById <TextView>(Resource.Id.scoreText);
            scoreTimes           = FindViewById <TextView>(Resource.Id.sTimesText);
            commentsText         = FindViewById <TextView>(Resource.Id.commentsText);
            ingredientListView   = FindViewById <ListView>(Resource.Id.ingredientListView);
            instructionsListView = FindViewById <ListView>(Resource.Id.instructionsListView);
            dishTagsListView     = FindViewById <ListView>(Resource.Id.dishTagsListView);
            commentsListView     = FindViewById <ListView>(Resource.Id.commentsListView);

            // Setting all the text values to the recipe attribute
            recipeNameText.Text = _recipe.name;
            authorText.Text     = "Author: " + _recipe.authorName;
            dateText.Text       = "Date posted: " + _recipe.postTimeString;
            dishTypeText.Text   = "Dish type: " + _recipe.dishType;
            dishTimeText.Text   = "Dish Time: " + _recipe.dishTime;
            portionsText.Text   = "Portions: " + _recipe.portions;
            durationText.Text   = "Duration: " + _recipe.duration + " minutes";
            difficultyText.Text = "Difficulty: " + _recipe.difficulty;
            dishTagsText.Text   = _recipe.dishTags.Count == 0 ? "Dish tags: none" : "Dish tags:";
            priceText.Text      = "Price: $" + _recipe.price;
            scoreText.Text      = "Score: " + _recipe.score;
            scoreTimes.Text     = "Number of Ratings: " + _recipe.scoreTimes;
            commentsText.Text   = _recipe.comments.Count == 0 ? "Comments: none" : "Comments:";

            if (!string.IsNullOrEmpty(_recipe.photo))
            {
                picUrl = $"http://{MainActivity.Ipv4}:8080/CookTime_war/cookAPI/resources/getPicture?id={_recipe.photo}";
                Bitmap bitmap = GetImageBitmapFromUrl(picUrl);
                _recipePic.SetImageBitmap(bitmap);
            }

            var adapter1 = new IngredientAdapter(this, _recipe.ingredientsList);

            ingredientListView.Adapter = adapter1;

            var adapter2 = new CompAdapter(this, _recipe.instructions);

            instructionsListView.Adapter = adapter2;

            var adapter3 = new CompAdapter(this, _recipe.dishTags);

            dishTagsListView.Adapter = adapter3;

            var adapter4 = new CommentAdapter(this, _recipe.comments);

            commentsListView.Adapter = adapter4;

            _recipePic.Click += (sender, args) =>
            {
                if (!string.IsNullOrEmpty(_recipe.photo))
                {
                    var transaction = SupportFragmentManager.BeginTransaction();
                    var dialogPShow = new DialogPShow();
                    dialogPShow.Url      = picUrl;
                    dialogPShow.TypeText = "Recipe photo";
                    dialogPShow.Show(transaction, "recipe");
                }
            };

            shareButton.Click += (sender, args) =>
            {
                using var webClient = new WebClient { BaseAddress = "http://" + MainActivity.Ipv4 + ":8080/CookTime_war/cookAPI/" };

                var url = "resources/shareRecipe?id=" + _recipe.id + "&email=" + _loggedId;
                webClient.Headers[HttpRequestHeader.ContentType] = "application/json";
                var send = webClient.DownloadString(url);

                string toastText;
                if (send == "0")
                {
                    toastText = "You've already shared this recipe.";
                }

                else
                {
                    toastText = "Recipe shared! Redirecting to MyProfile...";
                    url       = "resources/getUser?id=" + _loggedId;
                    webClient.Headers[HttpRequestHeader.ContentType] = "application/json";
                    var userJson = webClient.DownloadString(url);

                    var intent = new Intent(this, typeof(MyProfileActivity));
                    intent.PutExtra("User", userJson);
                    intent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask);
                    StartActivity(intent);
                    OverridePendingTransition(Android.Resource.Animation.SlideInLeft, Android.Resource.Animation.SlideOutRight);
                }
                var toast = Toast.MakeText(this, toastText, ToastLength.Short);
                toast.Show();
            };

            commentButton.Click += (sender, args) =>
            {
                //Brings dialog fragment forward
                var transaction = SupportFragmentManager.BeginTransaction();
                var dialogComm  = new DialogComment();

                dialogComm.Show(transaction, "rate");
                dialogComm.LoggedId = _loggedId;
                dialogComm.RecipeId = _recipe.id;

                dialogComm.EventHandlerComm += CommResult;
            };

            rateButton.Click += (sender, args) =>
            {
                //Brings dialog fragment forward
                var transaction = SupportFragmentManager.BeginTransaction();
                var dialogRate  = new DialogRate();

                dialogRate.Show(transaction, "rate");
                dialogRate.LoggedId = _loggedId;
                dialogRate.RecipeId = _recipe.id;
                dialogRate.Type     = 0;

                dialogRate.EventHandlerRate += RateResult;
            };

            authorButton.Click += (sender, args) =>
            {
                Intent intent;
                using var webClient = new WebClient { BaseAddress = "http://" + MainActivity.Ipv4 + ":8080/CookTime_war/cookAPI/" };
                string url;
                string send;

                if (_recipe.businessId == 0)
                {
                    url = "resources/getUser?id=" + _recipe.authorEmail;
                    webClient.Headers[HttpRequestHeader.ContentType] = "application/json";
                    send = webClient.DownloadString(url);

                    if (_recipe.authorEmail == _loggedId)
                    {
                        intent = new Intent(this, typeof(MyProfileActivity));
                        intent.PutExtra("User", send);
                        StartActivity(intent);
                        OverridePendingTransition(Android.Resource.Animation.SlideInLeft, Android.Resource.Animation.SlideOutRight);
                    }
                    else
                    {
                        intent = new Intent(this, typeof(PrivProfileActivity));
                        intent.PutExtra("User", send);
                        intent.PutExtra("LoggedId", _loggedId);
                        StartActivity(intent);
                        OverridePendingTransition(Android.Resource.Animation.SlideInLeft, Android.Resource.Animation.SlideOutRight);
                    }
                }
                else
                {
                    url = "resources/getBusiness?id=" + _recipe.businessId;
                    webClient.Headers[HttpRequestHeader.ContentType] = "application/json";
                    send = webClient.DownloadString(url);

                    url = "resources/isEmployee?email=" + _loggedId + "&id=" + _recipe.businessId;
                    webClient.Headers[HttpRequestHeader.ContentType] = "application/json";
                    var result = webClient.DownloadString(url);

                    if (result == "1")
                    {
                        intent = new Intent(this, typeof(MyBusiness));
                        intent.PutExtra("Bsns", send);
                        intent.PutExtra("LoggedId", _loggedId);
                        StartActivity(intent);
                        OverridePendingTransition(Android.Resource.Animation.SlideInLeft, Android.Resource.Animation.SlideOutRight);
                    }
                    else
                    {
                        intent = new Intent(this, typeof(PrivateBusiness));
                        intent.PutExtra("Bsns", send);
                        intent.PutExtra("LoggedId", _loggedId);
                        StartActivity(intent);
                        OverridePendingTransition(Android.Resource.Animation.SlideInLeft, Android.Resource.Animation.SlideOutRight);
                    }
                }
            };
        }
Esempio n. 4
0
        /// <summary>
        /// This method is called when the activity is starting.
        /// It contains the logic for the buttons shown in this activity.
        /// </summary>
        /// <param name="savedInstanceState"> a Bundle that contains the data the activity most recently
        /// supplied if the activity is being re-initialized after previously being shut down. </param>
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.PrivateProfile);

            _loggedId = Intent.GetStringExtra("LoggedId");

            var json = Intent.GetStringExtra("User");

            _user = JsonConvert.DeserializeObject <User>(json);

            _nameView  = FindViewById <TextView>(Resource.Id.nameView);
            _ageView   = FindViewById <TextView>(Resource.Id.ageView);
            _chefView  = FindViewById <TextView>(Resource.Id.chefPText);
            _scoreView = FindViewById <TextView>(Resource.Id.scorePText);

            _pfp          = FindViewById <ImageView>(Resource.Id.profilePic);
            _btnFollowers = FindViewById <Button>(Resource.Id.btnFollowers);
            _btnFollowing = FindViewById <Button>(Resource.Id.btnFollowing);
            _btnFollow    = FindViewById <Button>(Resource.Id.btnCFollow);
            _btnDate      = FindViewById <Button>(Resource.Id.btnPDate);
            _btnScore     = FindViewById <Button>(Resource.Id.btnPScore);
            _btnDiff      = FindViewById <Button>(Resource.Id.btnPDiff);
            _btnRateChef  = FindViewById <Button>(Resource.Id.btnRateChef);

            _menuListView = FindViewById <ListView>(Resource.Id.menuListView);

            _nameView.Text = "Name: " + _user.firstName + " " + _user.lastName;
            _ageView.Text  = "Age: " + _user.age;


            if (!string.IsNullOrEmpty(_user.photo))
            {
                pictureUrl = $"http://{MainActivity.Ipv4}:8080/CookTime_war/cookAPI/resources/getPicture?id={_user.photo}";
                Bitmap bitmap = GetImageBitmapFromUrl(pictureUrl);
                _pfp.SetImageBitmap(bitmap);
            }
            if (_user.chef)
            {
                _chefView.Text          = "Chef: yes";
                _scoreView.Text         = "Score: " + _user.chefScore;
                _btnRateChef.Visibility = ViewStates.Visible;
            }
            else
            {
                _chefView.Text          = "Chef: no";
                _scoreView.Text         = "";
                _btnRateChef.Visibility = ViewStates.Gone;
            }

            _btnFollowers.Text = "FOLLOWERS: " + _user.followerEmails.Count;
            _btnFollowing.Text = "FOLLOWING: " + _user.followingEmails.Count;

            using var webClient = new WebClient { BaseAddress = "http://" + MainActivity.Ipv4 + ":8080/CookTime_war/cookAPI/" };

            var url = "resources/isFollowing?ownEmail=" + _loggedId + "&followingEmail=" + _user.email;

            webClient.Headers[HttpRequestHeader.ContentType] = "application/json";
            var response = webClient.DownloadString(url);

            _btnFollow.Text = response == "0" ? "FOLLOW" : "UNFOLLOW";

            url = "resources/myMenu?email=" + _user.email + "&filter=date";
            var send = webClient.DownloadString(url);

            _menuList                = JsonConvert.DeserializeObject <IList <string> >(send);
            _adapter                 = new RecipeAdapter(this, _menuList);
            _menuListView.Adapter    = _adapter;
            _menuListView.ItemClick += ListClick;

            _btnFollow.Click += (sender, args) =>
            {
                using var webClient2 = new WebClient { BaseAddress = "http://" + MainActivity.Ipv4 + ":8080/CookTime_war/cookAPI/" };
                var followUrl = "resources/followUser?ownEmail=" + _loggedId + "&followingEmail=" + _user.email;
                webClient2.Headers[HttpRequestHeader.ContentType] = "application/json";
                var answer = webClient2.DownloadString(followUrl);

                followUrl = "resources/getUser?id=" + _loggedId;
                webClient2.Headers[HttpRequestHeader.ContentType] = "application/json";
                var userJson = webClient2.DownloadString(followUrl);

                _btnFollow.Text = answer == "0" ? "FOLLOW" : "UNFOLLOW";

                var toastText = answer == "0" ? "unfollowed" : "followed";

                var toast = Toast.MakeText(this, "User " + toastText + ". Redirecting to MyProfile...", ToastLength.Short);
                toast.Show();

                var intent = new Intent(this, typeof(MyProfileActivity));
                intent.PutExtra("User", userJson);
                intent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearTask);
                StartActivity(intent);
                OverridePendingTransition(Android.Resource.Animation.SlideInLeft, Android.Resource.Animation.SlideOutRight);
            };

            _btnFollowers.Click += (sender, args) =>
            {
                var intent = new Intent(this, typeof(FollowActivity));
                intent.PutExtra("Title", "Followers");
                intent.PutExtra("LoggedId", _loggedId);
                intent.PutStringArrayListExtra("FollowList", _user.followerEmails);

                StartActivity(intent);
                OverridePendingTransition(Android.Resource.Animation.SlideInLeft, Android.Resource.Animation.SlideOutRight);
            };

            _btnFollowing.Click += (sender, args) =>
            {
                var intent = new Intent(this, typeof(FollowActivity));
                intent.PutExtra("Title", "Following");
                intent.PutExtra("LoggedId", _loggedId);
                intent.PutStringArrayListExtra("FollowList", _user.followingEmails);

                StartActivity(intent);
                OverridePendingTransition(Android.Resource.Animation.SlideInLeft, Android.Resource.Animation.SlideOutRight);
            };

            _btnDate.Click += (sender, args) =>
            {
                sortStr = "date";
                SortMenu();
            };

            _btnScore.Click += (sender, args) =>
            {
                sortStr = "score";
                SortMenu();
            };

            _btnDiff.Click += (sender, args) =>
            {
                sortStr = "difficulty";
                SortMenu();
            };

            _btnRateChef.Click += (sender, args) =>
            {
                //Brings dialog fragment forward
                var transaction = SupportFragmentManager.BeginTransaction();
                var dialogRate  = new DialogRate();

                dialogRate.Show(transaction, "rate");
                dialogRate.LoggedId = _loggedId;
                dialogRate.ChefId   = _user.email;
                dialogRate.Type     = 1;

                dialogRate.EventHandlerRate += RateResult;
            };

            _pfp.Click += (sender, args) =>
            {
                if (!string.IsNullOrEmpty(_user.photo))
                {
                    var transaction = SupportFragmentManager.BeginTransaction();
                    var dialogPShow = new DialogPShow();

                    dialogPShow.Url      = pictureUrl;
                    dialogPShow.TypeText = "Profile Picture";
                    dialogPShow.Show(transaction, "privPfp");
                }
                else
                {
                    string toastText = "user has not set a profile picture you can view.";
                    Toast  _toast    = Toast.MakeText(this, toastText, ToastLength.Short);
                    _toast.Show();
                }
            };
        }