async void HandleInitializationComplete(object sender, InitializationCompleteEventArgs e) { _animationCancellationToken?.Cancel(); if (e.IsInitializationSuccessful) { #if DEBUG await ChangeLabelText(SplashScreenPageConstants.PreviewMode, SplashScreenPageConstants.WarningsMayAppear); //Display Text await Task.Delay(TimeSpan.FromMilliseconds(500)); #else await ChangeLabelText("Let's go!"); #endif await NavigateToNextPage(); } else { await ChangeLabelText(SplashScreenPageConstants.InitializationFailed, $"\n{SplashScreenPageConstants.EnsureInternetConnectionAndLatestVersion}"); AnalyticsService.Track("Initialization Failed"); } Task NavigateToNextPage() { return(MainThread.InvokeOnMainThreadAsync(async() => { //Explode & Fade Everything var explodeImageTask = Task.WhenAll(Content.ScaleTo(100, 250, Easing.CubicOut), Content.FadeTo(0, 250, Easing.CubicIn)); BackgroundColor = (Color)Application.Current.Resources[nameof(BaseTheme.PageBackgroundColor)]; var scope = ContainerService.Container.BeginLifetimeScope(); var repositoryPage = scope.Resolve <RepositoryPage>(); if (_firstRunService.IsFirstRun) { repositoryPage.Appearing += HandleRepositoryPageAppearing; } await explodeImageTask; Application.Current.MainPage = new BaseNavigationPage(repositoryPage); async void HandleRepositoryPageAppearing(object sender, EventArgs e) { repositoryPage.Appearing -= HandleRepositoryPageAppearing; //Yield the UI thread to allow MainPage to be set await Task.Delay(TimeSpan.FromMilliseconds(500)); var onboardingCarouselPage = scope.Resolve <OnboardingCarouselPage>(); await repositoryPage.Navigation.PushModalAsync(onboardingCarouselPage); } })); } }
async void HandleContributorSelectionChanged(object sender, SelectionChangedEventArgs e) { var collectionView = (CollectionView)sender; collectionView.SelectedItem = null; if (e.CurrentSelection.FirstOrDefault() is Contributor contributor) { AnalyticsService.Track("Contributor Tapped", nameof(Contributor.Login), contributor.Login); await _deepLinkingService.OpenBrowser(contributor.GitHubUrl); } }
async void HandleLibrarySelectionChanged(object sender, SelectionChangedEventArgs e) { var collectionView = (CollectionView)sender; collectionView.SelectedItem = null; if (e.CurrentSelection.FirstOrDefault() is NuGetPackageModel nuGetPackageModel) { AnalyticsService.Track("Library Tapped", nameof(NuGetPackageModel.PackageName), nuGetPackageModel.PackageName); await _deepLinkingService.OpenBrowser(nuGetPackageModel.WebsiteUri); } }
async void HandleReferringSitesToolbarItemClicked(object sender, EventArgs e) { AnalyticsService.Track("Referring Sites Button Tapped"); var referringSitesPage = ContainerService.Container.Resolve <ReferringSitesPage>(new TypedParameter(typeof(Repository), _repository)); if (Device.RuntimePlatform is Device.iOS) { await Navigation.PushModalAsync(referringSitesPage); } else { await Navigation.PushAsync(referringSitesPage); } }
async void HandleInitializationComplete(object sender, InitializationCompleteEventArgs e) { _animationCancellationToken?.Cancel(); if (e.IsInitializationSuccessful) { #if DEBUG await ChangeLabelText("Preview Mode", "Certain license warnings may appear"); //Display Text await Task.Delay(500); #else await ChangeLabelText("Let's go!"); #endif await NavigateToNextPage(); } else { await ChangeLabelText("Initialization Failed", "\nEnsure Internet Connection Is Available and Update GitTrends to the Latest Version"); AnalyticsService.Track("Initialization Failed"); } Task NavigateToNextPage() { return(MainThread.InvokeOnMainThreadAsync(async() => { //Explode & Fade Everything var explodeImageTask = Task.WhenAll(Content.ScaleTo(100, 250, Easing.CubicOut), Content.FadeTo(0, 250, Easing.CubicIn)); BackgroundColor = (Color)Application.Current.Resources[nameof(BaseTheme.PageBackgroundColor)]; using var scope = ContainerService.Container.BeginLifetimeScope(); var repositoryPage = scope.Resolve <RepositoryPage>(); await explodeImageTask; Application.Current.MainPage = new BaseNavigationPage(repositoryPage); if (FirstRunService.IsFirstRun) { //Yield the UI thread to allow MainPage to be set await Task.Delay(250); var onboardingCarouselPage = scope.Resolve <OnboardingCarouselPage>(); await repositoryPage.Navigation.PushModalAsync(onboardingCarouselPage); } })); } }
public AboutViewModel(IMainThread mainThread, LibrariesService librariesService, IAnalyticsService analyticsService, DeepLinkingService deepLinkingService, GitTrendsStatisticsService gitTrendsStatisticsService) : base(analyticsService, mainThread) { if (gitTrendsStatisticsService.Stars.HasValue) { Stars = gitTrendsStatisticsService.Stars.Value; } if (gitTrendsStatisticsService.Watchers.HasValue) { Watchers = gitTrendsStatisticsService.Watchers.Value; } if (gitTrendsStatisticsService.Forks.HasValue) { Forks = gitTrendsStatisticsService.Forks.Value; } InstalledLibraries = librariesService.InstalledLibraries; GitTrendsContributors = gitTrendsStatisticsService.Contributors.OrderByDescending(x => x.ContributionCount).ToList(); ViewOnGitHubCommand = new AsyncCommand(() => { if (gitTrendsStatisticsService?.GitHubUri is null) { return(Task.CompletedTask); } AnalyticsService.Track("View On GitHub Tapped"); return(deepLinkingService.OpenBrowser(gitTrendsStatisticsService.GitHubUri)); }); RequestFeatureCommand = new AsyncCommand(() => { if (gitTrendsStatisticsService?.GitHubUri is null) { return(Task.CompletedTask); } AnalyticsService.Track("Request Feature Tapped"); return(deepLinkingService.OpenBrowser(gitTrendsStatisticsService.GitHubUri + "/issues/new?template=feature_request.md")); }); }
async void HandleCollectionViewSelectionChanged(object sender, SelectionChangedEventArgs e) { var collectionView = (CollectionView)sender; collectionView.SelectedItem = null; if (e?.CurrentSelection.FirstOrDefault() is ReferringSiteModel referingSite && referingSite.IsReferrerUriValid && referingSite.ReferrerUri != null) { AnalyticsService.Track("Referring Site Tapped", new Dictionary <string, string> { { nameof(ReferringSiteModel) + nameof(ReferringSiteModel.Referrer), referingSite.Referrer }, { nameof(ReferringSiteModel) + nameof(ReferringSiteModel.ReferrerUri), referingSite.ReferrerUri.ToString() } }); await _deepLinkingService.OpenBrowser(referingSite.ReferrerUri); } }
async void HandleInitializationComplete(object sender, InitializationCompleteEventArgs e) { _animationCancellationToken?.Cancel(); #if DEBUG await ChangeLabelText(new FormattedString { Spans = { new Span { FontAttributes = FontAttributes.Bold, Text = "Preview Mode" }, new Span { Text = "\nCertain license warnings may appear" } } }); //Display Text await Task.Delay(500); await NavigateToRepositoryPage(); #else if (e.IsInitializationSuccessful) { await ChangeLabelText("Let's go!"); await NavigateToRepositoryPage(); } else { await ChangeLabelText(new FormattedString { Spans = { new Span { FontAttributes = FontAttributes.Bold, Text = "Initialization Failed\n" }, new Span { Text = "Ensure Internet Connection Is Available\n + \nUpdate App to the Latest Version" } } }); AnalyticsService.Track("Initialization Failed"); } #endif Task NavigateToRepositoryPage() { return(MainThread.InvokeOnMainThreadAsync(async() => { //Explode & Fade Everything var explodeImageTask = Task.WhenAll(Content.ScaleTo(100, 250, Easing.CubicOut), Content.FadeTo(0, 250, Easing.CubicIn)); BackgroundColor = (Color)Application.Current.Resources[nameof(BaseTheme.PageBackgroundColor)]; await explodeImageTask; using var scope = ContainerService.Container.BeginLifetimeScope(); Application.Current.MainPage = new BaseNavigationPage(scope.Resolve <RepositoryPage>()); })); } }
RelativeLayout CreateLayout(bool isPortraitOrientation) { var gitHubSettingsView = new GitHubSettingsView(); var trendsSettingsView = new TrendsChartSettingsView(_trendsChartSettingsService); var versionNumberLabel = new Label { #if AppStore Text = $"Version: {VersionTracking.CurrentVersion}", #elif RELEASE Text = $"Version: {VersionTracking.CurrentVersion} (Release)", #elif DEBUG Text = $"Version: {VersionTracking.CurrentVersion} (Debug)", #else throw new NotSupportedException() #endif HorizontalTextAlignment = TextAlignment.Start, Opacity = 0.75, Margin = new Thickness(2, 5, 0, 0), FontSize = 14 }; versionNumberLabel.SetDynamicResource(Label.TextColorProperty, nameof(BaseTheme.TextColor)); var createdByLabel = new Label { Margin = new Thickness(0, 5), VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand, HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.End, Text = "Mobile App Created by Code Traveler LLC", FontSize = 12, }; createdByLabel.SetDynamicResource(Label.TextColorProperty, nameof(BaseTheme.TextColor)); createdByLabel.GestureRecognizers.Add(new TapGestureRecognizer { Command = new AsyncCommand(CreatedByLabelTapped) }); var relativeLayout = new RelativeLayout { Margin = isPortraitOrientation ? new Thickness(20, 20, 20, 30) : new Thickness(20, 20, 20, 0) }; relativeLayout.Children.Add(createdByLabel, xConstraint: Constraint.RelativeToParent(parent => parent.Width / 2 - GetWidth(parent, createdByLabel) / 2), yConstraint: Constraint.RelativeToParent(parent => parent.Height - GetHeight(parent, createdByLabel) - 10)); relativeLayout.Children.Add(gitHubSettingsView, //Keep at left of the screen xConstraint: Constraint.Constant(0), //Keep at top of the screen yConstraint: Constraint.Constant(0), //Portrait: Full width; Landscape: Half of the screen widthConstraint: isPortraitOrientation ? Constraint.RelativeToParent(parent => parent.Width) : Constraint.RelativeToParent(parent => parent.Width / 2), //Portrait: Half height; Landscape: Full height heightConstraint: isPortraitOrientation ? Constraint.RelativeToParent(parent => parent.Height / 2) : Constraint.RelativeToParent(parent => parent.Height)); relativeLayout.Children.Add(trendsSettingsView, //Portrait: Place under GitHubSettingsView; Landscape: Place to the right of GitHubSettingsView xConstraint: isPortraitOrientation ? Constraint.Constant(0) : Constraint.RelativeToParent(parent => parent.Width / 2), //Portrait: Place under GitHubSettingsView; Landscape: Place on the top yConstraint: isPortraitOrientation ? Constraint.RelativeToView(gitHubSettingsView, (parent, view) => view.Y + view.Height + 10) : Constraint.Constant(0), //Portrait: Full width; Landscape: Half of the screen widthConstraint: isPortraitOrientation ? Constraint.RelativeToParent(parent => parent.Width) : Constraint.RelativeToParent(parent => parent.Width / 2)); relativeLayout.Children.Add(versionNumberLabel, xConstraint: Constraint.RelativeToView(trendsSettingsView, (parent, view) => view.X), yConstraint: Constraint.RelativeToView(trendsSettingsView, (parent, view) => view.Y + view.Height + 10)); return(relativeLayout); } async void HandleGitHubLoginUrlRetrieved(object sender, string?loginUrl) { if (!string.IsNullOrWhiteSpace(loginUrl)) { await OpenBrowser(loginUrl); } else { await DisplayAlert("Error", "Couldn't connect to GitHub Login. Check your internet connection and try again", "OK"); } } Task CreatedByLabelTapped() { AnalyticsService.Track("CreatedBy Label Tapped"); return(_deepLinkingService.OpenApp("twitter://user?id=3418408341", "https://twitter.com/intent/user?user_id=3418408341")); } }
void HandleSkipButtonTapped(object sender, EventArgs e) { AnalyticsService.Track("Skip Button Tapped"); MainThread.BeginInvokeOnMainThread(() => CurrentPage = Children.Last()); }
protected override void OnAppearing() { base.OnAppearing(); _analyticsService.Track($"{GetType().Name} Appeared"); }
Task CreatedByLabelTapped() { AnalyticsService.Track("CreatedBy Label Tapped"); return(_deepLinkingService.OpenApp("twitter://user?id=3418408341", "https://twitter.com/intent/user?user_id=3418408341")); }