private async void BtnLogIn_Clicked(object sender, EventArgs e) { try { await PopupNavigation.Instance.PushAsync(new BusyPopUp()); try { //await Task.Delay(2000); string Token = await auth.LoginWithEmailPassword(Email.Text.Replace(" ", string.Empty), Password.Text); //Cleared the error with .Replace that replaces all white spaces in string if (Token != "") { var user = await ReaderWriter.GetPerson(Email.Text); if (user.movies.Count == 0) { //activityIndicator.IsRunning = true; await Navigation.PushAsync(new GenreAssignmentPage(user.email)); //activityIndicator.IsRunning = false; //BtnLogIn.IsEnabled = true; } else { //activityIndicator.IsRunning = true; await Navigation.PushAsync(new GridPage(user.email)); //activityIndicator.IsRunning = false; //BtnLogIn.IsEnabled = true; } Email.Text = string.Empty; //da ni že vpisano, v primeru da gre nazaj Password.Text = string.Empty; } else { Email.Text = string.Empty; Password.Text = string.Empty; //BtnLogIn.IsEnabled = true; //activityIndicator.IsRunning = false; await DisplayAlert("Authentication failed", "E-mail/password is incorrect. Try again!", "OK"); } } finally { await PopupNavigation.Instance.PopAsync(); } //BtnLogIn.IsEnabled = false; //activityIndicator.IsRunning = true; } catch { //BtnLogIn.IsEnabled = true; //activityIndicator.IsRunning = false; await DisplayAlert("Authentication failed", "E-mail/password is incorrect. Try again!", "OK"); } }
//private const string ExpandAnimationName = "ExpandAnimation"; //private const string CollapseAnimationName = "CollapseAnimation"; //private const double SlideAnimationDuration = 0.25; //private const int AnimationDuration = 600; //private const double PageScale = 0.9; //private const double PageTranslation = 0.35; //private readonly IEnumerable<View> _menuItemsView; //private bool _isAnimationRun; //private double _safeInsetsTop; protected async override void OnAppearing() { base.OnAppearing(); //MenuTopRow.Height = MenuBottomRow.Height = Device.Info.ScaledScreenSize.Height * (1 - PageScale) / 2; user = await ReaderWriter.GetPerson(email1); Username.Text = user.username; Email.Text = user.email; }
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"); } }
private async void onAddFriendClick(object sender, EventArgs args) { var user = await ReaderWriter.GetPerson(email); var response = await ReaderWriter.GetPersonByUsername(friendsEntry.Text); if (response == null || user.email == response.email) //Dodal da nemores dodat sebe. { if (string.IsNullOrWhiteSpace(friendsEntry.Text)) { await DisplayAlert("Error", "Enter a username first!", "OK"); return; } else { await DisplayAlert("User not found", "The user you searched for not found!", "OK"); friendsEntry.Text = ""; return; } } foreach (string a in user.friends) { if (a == response.username) //Da nemoreš dodat večkrat. { await DisplayAlert("Already friends", "The user is already your friend!", "OK"); friendsEntry.Text = ""; return; } } if (user.friends.Count >= 20) { await DisplayAlert("Friend limit reached", "You have reached the maximum number of friends!", "OK"); //max frendov friendsEntry.Text = ""; return; } await ReaderWriter.UpdateFriendsList(email, response); friendsEntry.Text = ""; FillFriendsList(Friends); await DisplayAlert("Success", "Friend added!", "Close"); }
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"); } }