public async void SetupUI(string date) { //photoURIs = await GooglePhotoService.GetPhotos(); try { foreach (List <string> list in App.User.photoURIs) { string photoURI = list[0]; string photoDate = list[1]; string description = list[2]; string creationTime = list[3]; if (date.Equals(photoDate)) { Items.Add(new { Source = photoURI, Description = description, CreationTime = creationTime }); } } } catch (NullReferenceException e) { var googleService = new GoogleService(); await googleService.RefreshToken(); } }
protected override async void OnAppearing() { if (Application.Current.Properties.ContainsKey("accessToken") && Application.Current.Properties.ContainsKey("refreshToken") && Application.Current.Properties.ContainsKey("user_id")) { App.LoadApplicationProperties(); firestoreService = new FirestoreService(); firebaseFunctionsService = new FirebaseFunctionsService(); googleService = new GoogleService(); if (await googleService.RefreshToken()) { await firestoreService.LoadUser(); await GoogleService.LoadTodaysEvents(); await Navigation.PushAsync(new GoalsRoutinesTemplate()); } } }
private async void SetupUI() { Grid controlGrid = new Grid(); int rowLength = 3; double gridItemSize = (Application.Current.MainPage.Width / rowLength) - (1.2 * rowLength); controlGrid.RowDefinitions.Add(new RowDefinition { Height = gridItemSize }); for (int i = 0; i < rowLength; i++) { controlGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = gridItemSize }); } var photoCount = 0; try { foreach (List <string> list in App.User.photoURIs) { string photoURI = list[0]; string date = list[1]; string description = list[2]; string creationTime = list[3]; string id = list[4]; string note = list[5]; CachedImage webImage = new CachedImage { Source = Xamarin.Forms.ImageSource.FromUri(new Uri(photoURI)), Transformations = new List <ITransformation>() { new CropTransformation(), }, }; var tapGestureRecognizer = new TapGestureRecognizer(); tapGestureRecognizer.Tapped += async(s, e) => { await Navigation.PushAsync(new PhotoDisplayPage(webImage, date, description, id, creationTime, note)); }; webImage.GestureRecognizers.Add(tapGestureRecognizer); var indicator = new ActivityIndicator { Color = Color.Gray, WidthRequest = gridItemSize, HeightRequest = gridItemSize, }; indicator.SetBinding(ActivityIndicator.IsRunningProperty, "IsLoading"); indicator.BindingContext = webImage; controlGrid.Children.Add(indicator, photoCount % rowLength, photoCount / rowLength); controlGrid.Children.Add(webImage, photoCount % rowLength, photoCount / rowLength); photoCount++; } } catch (NullReferenceException e) { var googleService = new GoogleService(); if (await googleService.RefreshToken()) { Console.WriteLine("RefreshToken Done!"); App.User.photoURIs = await GooglePhotoService.GetPhotos(); } } //update calendar DateTime localDate = DateTime.Now; Calendar myCal = CultureInfo.InvariantCulture.Calendar; var currentYear = myCal.GetYear(localDate); var currentMonth = myCal.GetMonth(localDate); var currentDay = myCal.GetDayOfWeek(localDate); Year = currentYear; Month = currentMonth; yearLabel.Text = Year + ""; setMonthLabel(Month); SetCalendar(currentYear, currentMonth); //add navigation bar photoScrollView.HeightRequest = Application.Current.MainPage.Height - CalendarContent.Height - NavBar.Height; if (App.User.photoURIs != null) { photoScrollView.Content = controlGrid; } else { Label noPhotosLabel = new Label() { Text = "No photos to Show", VerticalOptions = LayoutOptions.CenterAndExpand, HorizontalOptions = LayoutOptions.CenterAndExpand, TextColor = Color.DimGray }; photoScrollView.Content = noPhotosLabel; } AddTapGestures(); }
async void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e) { var authenticator = sender as OAuth2Authenticator; if (authenticator != null) { authenticator.Completed -= OnAuthCompleted; authenticator.Error -= OnAuthError; } if (e.IsAuthenticated) { loginButton.Opacity = 0; loginButton.Clicked -= LoginClicked; // If the user is authenticated, request their basic user data from Google // UserInfoUrl = https://www.googleapis.com/oauth2/v2/userinfo var request = new OAuth2Request("GET", new Uri(Constants.UserInfoUrl), null, e.Account); var response = await request.GetResponseAsync(); JObject userJson = null; if (response != null) { // Deserialize the data and store it in the account store // The users email address will be used to identify data in SimpleDB string userJsonString = await response.GetResponseTextAsync(); userJson = JObject.Parse(userJsonString); } else { loginButton.Opacity = 1; loginButton.Clicked += LoginClicked; } if (userJson != null) { Console.WriteLine("HERE is the TOKEN------------------------------------------------"); Console.WriteLine(e.Account.Properties["access_token"]); Console.WriteLine("HERE is the REFRESH TOKEN----------------------------------------"); Console.WriteLine(e.Account.Properties["refresh_token"]); Console.WriteLine("----------------------------------------------------------------"); //Reset accessToken accessToken = e.Account.Properties["access_token"]; refreshToken = e.Account.Properties["refresh_token"]; App.User = new user(); firebaseFunctionsService = new FirebaseFunctionsService(); //Query for email in Users collection App.User.email = userJson["email"].ToString(); App.User.id = firebaseFunctionsService.FindUserDoc(App.User.email).Result; if (App.User.id == "") { await DisplayAlert("Oops!", "Looks like your trusted advisor hasn't registered your account yet. Please ask for their assistance!", "OK"); loginButton.Opacity = 1; loginButton.Clicked += LoginClicked; return; } firestoreService = new FirestoreService(); //Save to App.User AND Update Firebase with pertitnent info var googleService = new GoogleService(); await googleService.SaveAccessTokenToFireBase(accessToken); Console.WriteLine(refreshToken); await googleService.SaveRefreshTokenToFireBase(refreshToken); //Save Properies inside phone for auto login Application.Current.Properties["accessToken"] = accessToken; Application.Current.Properties["refreshToken"] = refreshToken; Application.Current.Properties["user_id"] = App.User.id; App.LoadApplicationProperties(); await googleService.RefreshToken(); //Navigate to the Daily Page after Login await Navigation.PushAsync(new LoadingPage()); } } }