Esempio n. 1
0
        private async void BtnRecal_Clicked(object sender, EventArgs e)
        {
            bool decision = await DisplayAlert("Recommendation recalibration", "Are you sure you want to recalibrate your movie recommendations?", "Yes", "No");

            if (decision == true)
            {
                await PopupNavigation.Instance.PushAsync(new BusyPopUp());

                try
                {
                    user.movies.Clear();
                    await ReaderWriter.UpdatePerson(Username.Text, Email.Text, user.friends, user.movies);

                    await Navigation.PushAsync(new GenreAssignmentPage(user.email));
                }
                finally
                {
                    await PopupNavigation.Instance.PopAsync();
                }
            }
            else
            {
                //nič
            };
        }
        async void LikeBtn(object sender, EventArgs args)
        {
            var user = await ReaderWriter.GetPerson(email);

            //Implement like
            //DisplayAlert("JE VŠEČ", "NAJS", "OK");

            try
            {
                movieList.Add(CurrentMovie.idMovie.ToString());
                ++counter;
                likecounter++;
                if (MoviesQueue.Count == 0)
                {
                    await PopupNavigation.Instance.PushAsync(new BusyPopUp());

                    try
                    {
                        if (likecounter > 10)
                        {
                            bool decision = await DisplayAlert("Thats awkward", "You only liked less than 10 movies would you like to start over?", "Yes", "No");

                            if (decision == true)
                            {
                                if (restart == null)
                                {
                                    restart = new GenreAssignmentPage(user.email);
                                }
                                App.Current.MainPage = new NavigationPage(restart);
                            }
                            else
                            {
                                await ReaderWriter.UpdatePerson(user.username, user.email, user.friends, movieList);

                                await Navigation.PushAsync(new GridPage(user.email));

                                return;
                            }
                        }
                    }
                    finally
                    {
                        await PopupNavigation.Instance.PopAsync();
                    }
                }
                ChangeElements();
            }
            catch (Exception e)
            {
                await DisplayAlert("Error", "There has been an unexpected error. Please try again!", "OK");
            }
        }
Esempio n. 3
0
        //void MoviesCommand(object sender, EventArgs args)
        //{
        //    DisplayAlert("Rabim event handler", "Implementiraj me", "OK");
        //}
        //void TVSeriesCommand(object sender, EventArgs args)
        //{
        //    DisplayAlert("Dela", "Implementiraj me", "OK");
        //}
        //void DocumentariesCommand(object sender, EventArgs args)
        //{
        //    DisplayAlert("Dela", "Implementiraj me", "OK");
        //}
        //void AnimeCommand(object sender, EventArgs args)
        //{
        //    DisplayAlert("Dela", "Implementiraj me", "OK");
        //}

        //public async void OnShowMenu()
        //{
        //    if (_isAnimationRun)
        //        return;

        //    _isAnimationRun = true;
        //    var animationDuration = AnimationDuration;
        //    if (Page.Scale < 1)
        //    {
        //        animationDuration = (int)(AnimationDuration * SlideAnimationDuration);
        //        GetCollapseAnimation().Commit(this, CollapseAnimationName, 16,
        //            (uint)(AnimationDuration * SlideAnimationDuration),
        //            Easing.Linear,
        //            null, () => false);
        //    }
        //    else
        //    {
        //        GetExpandAnimation().Commit(this, ExpandAnimationName, 16,
        //            AnimationDuration,
        //            Easing.Linear,
        //            null, () => false);
        //    }

        //    await Task.Delay(animationDuration);
        //    _isAnimationRun = false;
        //}

        //private Animation GetExpandAnimation()
        //{
        //    var iconAnimationTime = (1 - SlideAnimationDuration) / _menuItemsView.Count();
        //    var animation = new Animation
        //    {
        //        {0, SlideAnimationDuration, new Animation(v => ToolbarSafeAreaRow.Height = v, _safeInsetsTop, 0)},
        //        {
        //            0, SlideAnimationDuration,
        //            new Animation(v => Page.TranslationX = v, 0, Device.Info.ScaledScreenSize.Width * PageTranslation)
        //        },
        //        {0, SlideAnimationDuration, new Animation(v => Page.Scale = v, 1, PageScale)},
        //        {
        //            0, SlideAnimationDuration,
        //            new Animation(v => Page.Margin = new Thickness(0, v, 0, 0), 0, _safeInsetsTop)
        //        },
        //        {0, SlideAnimationDuration, new Animation(v => Page.CornerRadius = (float) v, 0, 5)}
        //    };

        //    foreach (var view in _menuItemsView)
        //    {
        //        var index = _menuItemsView.IndexOf(view);
        //        animation.Add(SlideAnimationDuration + iconAnimationTime * index - 0.05,
        //            SlideAnimationDuration + iconAnimationTime * (index + 1) - 0.05, new Animation(
        //                v => view.Opacity = (float)v, 0, 1));
        //        animation.Add(SlideAnimationDuration + iconAnimationTime * index,
        //            SlideAnimationDuration + iconAnimationTime * (index + 1), new Animation(
        //                v => view.TranslationY = (float)v, -10, 0));
        //    }

        //    return animation;
        //}

        //private Animation GetCollapseAnimation()
        //{
        //    var animation = new Animation
        //    {
        //        {0, 1, new Animation(v => ToolbarSafeAreaRow.Height = v, 0, _safeInsetsTop)},
        //        {0, 1, new Animation(v => Page.TranslationX = v, Device.Info.ScaledScreenSize.Width * PageTranslation, 0)},
        //        {0, 1, new Animation(v => Page.Scale = v, PageScale, 1)},
        //        {0, 1, new Animation(v => Page.Margin = new Thickness(0, v, 0, 0), _safeInsetsTop, 0)},
        //        {0, 1, new Animation(v => Page.CornerRadius = (float) v, 5, 0)}
        //    };

        //    foreach (var view in _menuItemsView)
        //    {
        //        animation.Add(0, 1, new Animation(
        //            v => view.Opacity = (float)v, 1, 0));
        //        animation.Add(0, 1, new Animation(
        //            v => view.TranslationY = (float)v, 0, -10));
        //    }

        //    return animation;
        //}
        private async void BtnSave_Clicked(object sender, EventArgs e)
        {
            bool decision = await DisplayAlert("Update user credentials", "Are you sure you want to update your user credentials?", "Yes", "No");

            if (decision == true)
            {
                await PopupNavigation.Instance.PushAsync(new BusyPopUp());

                try
                {
                    await ReaderWriter.UpdatePerson(Username.Text, Email.Text, user.friends, user.movies);
                }
                finally
                {
                    await PopupNavigation.Instance.PopAsync();
                }
            }
            else
            {
                //nič
            };
        }
Esempio n. 4
0
        private async void FillFriendsList(Grid grid)
        {
            try
            {
                var user = await ReaderWriter.GetPerson(email);

                var counter = 3;
                if (user == null)
                {
                    return;
                }
                foreach (var friend in user.friends)
                {
                    Image img = new Image
                    {
                        Source            = "profile.jpg", //profilna uporabnika
                        HeightRequest     = 25,
                        VerticalOptions   = LayoutOptions.End,
                        HorizontalOptions = LayoutOptions.Center
                    };
                    Label lbl = new Label
                    {
                        Text              = friend, //spremeni pol v username
                        FontSize          = 18,
                        TextColor         = Color.Black,
                        HorizontalOptions = LayoutOptions.Start,
                        VerticalOptions   = LayoutOptions.Start,
                        Padding           = new Thickness(0, -3, 0, 0)
                    };
                    var eventOnTap = new TapGestureRecognizer();
                    eventOnTap.Tapped += async(s, e) =>
                    {
                        string action = await DisplayActionSheet("What would you like to do with your friend " + friend + "?", "Cancel", null, "Display movies you both like", "Remove friend");

                        //bool decision = await DisplayAlert(friend, "What would you like to do?", "Display movies you both like", "Remove friend");
                        if (action == "Display movies you both like")
                        {
                            await PopupNavigation.Instance.PushAsync(new BusyPopUp());

                            try
                            {
                                var friendMovies = FillTheQueueWithMovies(await ReaderWriter.GetUserMoviesByUsername(friend)).ToList();

                                // Two lists of movie rec. (friendMovies, UserMovies) what now?

                                var commonList = friendMovies.Concat(UserMovies).ToList();
                                var avgOfList  = commonList.Select(x => x.Vote_Average).DefaultIfEmpty(0).Average();
                                var finalList  = commonList.Where(x => x.Vote_Average > avgOfList).ToList();
                                MovieGrid.Children.Clear();

                                RefreshGrid(MovieGrid, finalList);
                            }
                            finally
                            {
                                await PopupNavigation.Instance.PopAsync();
                            }
                        }
                        else if (action == "Remove friend")
                        {
                            await PopupNavigation.Instance.PushAsync(new BusyPopUp());

                            try
                            {
                                user.friends.Remove(friend);
                                await ReaderWriter.UpdatePerson(user.username, user.email, user.friends, user.movies);

                                // To remove from the list once its removed from the databse
                                var button  = (BindableObject)s;
                                var row     = Grid.GetRow(button);
                                var column  = Grid.GetColumn(button);
                                var getgrid = button as Grid;
                                //assuming the image is in column 1
                                var result    = grid.Children.Where(x => Grid.GetRow(x) == row && Grid.GetColumn(x) == column);
                                var resultImg = grid.Children.Where(x => Grid.GetRow(x) == row && Grid.GetColumn(x) == column - 1);
                                foreach (var label in result)
                                {
                                    grid.Children.Remove(label);
                                    break;
                                }
                                foreach (var image in resultImg)
                                {
                                    grid.Children.Remove(image);
                                    break;
                                }
                                await DisplayAlert("Success", "User successfully removed from your friends list", "Close");
                            }
                            finally
                            {
                                await PopupNavigation.Instance.PopAsync();
                            }
                        }
                        else
                        {
                            return;
                        }
                    };
                    lbl.GestureRecognizers.Add(eventOnTap);

                    grid.Children.Add(img, 0, counter); //column, row
                    grid.Children.Add(lbl, 1, counter);
                    Grid.SetColumnSpan(lbl, 2);
                    counter++;
                }
            }
            catch (Exception e)
            {
                await DisplayAlert("Exception", e.Message, "Ok");
            }
        }