Ejemplo n.º 1
0
        public ReferringSitesPage(DeepLinkingService deepLinkingService,
                                  ReferringSitesViewModel referringSitesViewModel,
                                  Repository repository,
                                  IAnalyticsService analyticsService,
                                  ThemeService themeService,
                                  ReviewService reviewService,
                                  IMainThread mainThread) : base(referringSitesViewModel, analyticsService, mainThread)
        {
            Title = PageTitles.ReferringSitesPage;

            _repository         = repository;
            _themeService       = themeService;
            _reviewService      = reviewService;
            _deepLinkingService = deepLinkingService;

            reviewService.ReviewCompleted += HandleReviewCompleted;
            ViewModel.PullToRefreshFailed += HandlePullToRefreshFailed;

            var titleRowHeight = _isiOS ? 50 : 0;

            var collectionView = new ReferringSitesCollectionView()
                                 .Bind(IsVisibleProperty, nameof(ReferringSitesViewModel.IsEmptyDataViewEnabled))
                                 .Bind(EmptyDataView.TitleProperty, nameof(ReferringSitesViewModel.EmptyDataViewTitle))
                                 .Bind(EmptyDataView.DescriptionProperty, nameof(ReferringSitesViewModel.EmptyDataViewDescription))
                                 .Bind(CollectionView.ItemsSourceProperty, nameof(ReferringSitesViewModel.MobileReferringSitesList))
                                 .Invoke(collectionView => collectionView.SelectionChanged += HandleCollectionViewSelectionChanged);

            var closeButton = new CloseButton(titleRowHeight).Invoke(closeButton => closeButton.Clicked += HandleCloseButtonClicked);

            Content = new RelativeLayout()
                      .Add(new ReferringSitesRefreshView(collectionView, repository, _refreshViewCancelltionTokenSource.Token).Assign(out _refreshView)
                           .DynamicResource(RefreshView.RefreshColorProperty, nameof(BaseTheme.PullToRefreshColor))
                           .Bind(RefreshView.CommandProperty, nameof(ReferringSitesViewModel.RefreshCommand))
                           .Bind(RefreshView.IsRefreshingProperty, nameof(ReferringSitesViewModel.IsRefreshing)),
                           Constant(0), Constant(titleRowHeight), RelativeToParent(parent => parent.Width), RelativeToParent(parent => parent.Height - titleRowHeight))
                      .Add(_isiOS ? new TitleShadowView(themeService) : null,
                           Constant(0), Constant(0), RelativeToParent(parent => parent.Width), Constant(titleRowHeight))
                      .Add(_isiOS ? new TitleLabel() : null,
                           Constant(10), Constant(0))
                      .Add(_isiOS ? closeButton : null,
                           RelativeToParent(parent => parent.Width - closeButton.GetWidth(parent) - 10), Constant(0), RelativeToParent(parent => closeButton.GetWidth(parent)))
                      .Add(_storeRatingRequestView,
                           Constant(0), RelativeToParent(parent => parent.Height - _storeRatingRequestView.GetHeight(parent)), RelativeToParent(parent => parent.Width));
        }
        public ReferringSitesPage(DeepLinkingService deepLinkingService,
                                  ReferringSitesViewModel referringSitesViewModel,
                                  Repository repository,
                                  IAnalyticsService analyticsService,
                                  ThemeService themeService,
                                  ReviewService reviewService,
                                  IMainThread mainThread) : base(referringSitesViewModel, analyticsService, mainThread)
        {
            Title = PageTitles.ReferringSitesPage;

            this.repository         = repository;
            this.themeService       = themeService;
            this.reviewService      = reviewService;
            this.deepLinkingService = deepLinkingService;

            ViewModel.PullToRefreshFailed += HandlePullToRefreshFailed;
            reviewService.ReviewCompleted += HandleReviewCompleted;

            Build();
        }
Ejemplo n.º 3
0
        public ReferringSitesViewModel(GitHubApiV3Service gitHubApiV3Service,
                                       DeepLinkingService deepLinkingService,
                                       AnalyticsService analyticsService,
                                       ReferringSitesDatabase referringSitesDatabase,
                                       GitHubAuthenticationService gitHubAuthenticationService,
                                       ReviewService reviewService) : base(analyticsService)
        {
            reviewService.ReviewRequested += HandleReviewRequested;
            reviewService.ReviewCompleted += HandleReviewCompleted;

            _reviewService               = reviewService;
            _gitHubApiV3Service          = gitHubApiV3Service;
            _deepLinkingService          = deepLinkingService;
            _referringSitesDatabase      = referringSitesDatabase;
            _gitHubAuthenticationService = gitHubAuthenticationService;

            RefreshState = RefreshState.Uninitialized;

            RefreshCommand   = new AsyncCommand <(string Owner, string Repository, string RepositoryUrl, CancellationToken Token)>(tuple => ExecuteRefreshCommand(tuple.Owner, tuple.Repository, tuple.RepositoryUrl, tuple.Token));
            NoButtonCommand  = new Command(() => HandleReviewRequestButtonTapped(ReviewAction.NoButtonTapped));
            YesButtonCommand = new Command(() => HandleReviewRequestButtonTapped(ReviewAction.YesButtonTapped));

            UpdateStoreRatingRequestView();
        }
Ejemplo n.º 4
0
        public ReferringSitesPage(DeepLinkingService deepLinkingService,
                                  ReferringSitesViewModel referringSitesViewModel,
                                  Repository repository,
                                  IAnalyticsService analyticsService,
                                  ThemeService themeService,
                                  ReviewService reviewService,
                                  IMainThread mainThread) : base(referringSitesViewModel, analyticsService, mainThread, PageTitles.ReferringSitesPage)
        {
            _reviewService      = reviewService;
            _deepLinkingService = deepLinkingService;

            ViewModel.PullToRefreshFailed += HandlePullToRefreshFailed;
            reviewService.ReviewCompleted += HandleReviewCompleted;

            var collectionView = new CollectionView
            {
                AutomationId    = ReferringSitesPageAutomationIds.CollectionView,
                BackgroundColor = Color.Transparent,
                ItemTemplate    = new ReferringSitesDataTemplate(),
                SelectionMode   = SelectionMode.Single,
                ItemsLayout     = new LinearItemsLayout(ItemsLayoutOrientation.Vertical),
                //Set iOS Header to `new BoxView { HeightRequest = titleRowHeight + titleTopMargin }` following this bug fix: https://github.com/xamarin/Xamarin.Forms/issues/9879
                Header = Device.RuntimePlatform is Device.Android ? new BoxView {
                    HeightRequest = ReferringSitesDataTemplate.BottomPadding
                } : null,
                Footer = Device.RuntimePlatform is Device.Android ? new BoxView {
                    HeightRequest = ReferringSitesDataTemplate.TopPadding
                } : null,
                EmptyView = new EmptyDataView("EmptyReferringSitesList", ReferringSitesPageAutomationIds.EmptyDataView)
                            .Bind(IsVisibleProperty, nameof(ReferringSitesViewModel.IsEmptyDataViewEnabled))
                            .Bind(EmptyDataView.TitleProperty, nameof(ReferringSitesViewModel.EmptyDataViewTitle))
                            .Bind(EmptyDataView.DescriptionProperty, nameof(ReferringSitesViewModel.EmptyDataViewDescription))
            };

            collectionView.SelectionChanged += HandleCollectionViewSelectionChanged;
            collectionView.SetBinding(CollectionView.ItemsSourceProperty, nameof(ReferringSitesViewModel.MobileReferringSitesList));

            _refreshView = new RefreshView
            {
                AutomationId     = ReferringSitesPageAutomationIds.RefreshView,
                CommandParameter = (repository.OwnerLogin, repository.Name, repository.Url, _refreshViewCancelltionTokenSource.Token),
                Content          = collectionView
            };
            _refreshView.SetDynamicResource(RefreshView.RefreshColorProperty, nameof(BaseTheme.PullToRefreshColor));
            _refreshView.SetBinding(RefreshView.CommandProperty, nameof(ReferringSitesViewModel.RefreshCommand));
            _refreshView.SetBinding(RefreshView.IsRefreshingProperty, nameof(ReferringSitesViewModel.IsRefreshing));

            var relativeLayout = new RelativeLayout();

            //Add Title and Close Button to UIModalPresentationStyle.FormSheet
            if (Device.RuntimePlatform is Device.iOS)
            {
                const int titleTopMargin = 10;
                const int titleRowHeight = 50;

                var closeButton = new Button
                {
                    Text              = ReferringSitesPageConstants.CloseButtonText,
                    FontFamily        = FontFamilyConstants.RobotoRegular,
                    HeightRequest     = titleRowHeight * 3 / 5,
                    HorizontalOptions = LayoutOptions.End,
                    VerticalOptions   = LayoutOptions.Center,
                    AutomationId      = ReferringSitesPageAutomationIds.CloseButton,
                    Padding           = new Thickness(5, 0)
                };
                closeButton.Clicked += HandleCloseButtonClicked;
                closeButton.SetDynamicResource(Button.TextColorProperty, nameof(BaseTheme.CloseButtonTextColor));
                closeButton.SetDynamicResource(BackgroundColorProperty, nameof(BaseTheme.CloseButtonBackgroundColor));

                var titleLabel = new Label
                {
                    FontSize   = 30,
                    Text       = PageTitles.ReferringSitesPage,
                    FontFamily = FontFamilyConstants.RobotoMedium,
                }.Center().TextCenterVertical();
                titleLabel.SetDynamicResource(Label.TextColorProperty, nameof(BaseTheme.TextColor));

                closeButton.Margin = titleLabel.Margin = new Thickness(0, titleTopMargin, 0, 0);

                var titleShadow = new BoxView();
                titleShadow.SetDynamicResource(BackgroundColorProperty, nameof(BaseTheme.CardSurfaceColor));

                if (isLightTheme(themeService.Preference))
                {
                    titleShadow.On <iOS>().SetIsShadowEnabled(true)
                    .SetShadowColor(Color.Gray)
                    .SetShadowOffset(new Size(0, 1))
                    .SetShadowOpacity(0.5)
                    .SetShadowRadius(4);
                }


                relativeLayout.Children.Add(_refreshView,
                                            Constraint.Constant(0),
                                            Constraint.Constant(titleRowHeight),                                    //Set to `0` following this bug fix: https://github.com/xamarin/Xamarin.Forms/issues/9879
                                            Constraint.RelativeToParent(parent => parent.Width),
                                            Constraint.RelativeToParent(parent => parent.Height - titleRowHeight)); //Set to `parent => parent.Height` following this bug fix: https://github.com/xamarin/Xamarin.Forms/issues/9879

                relativeLayout.Children.Add(titleShadow,
                                            Constraint.Constant(0),
                                            Constraint.Constant(0),
                                            Constraint.RelativeToParent(parent => parent.Width),
                                            Constraint.Constant(titleRowHeight));

                relativeLayout.Children.Add(titleLabel,
                                            Constraint.Constant(10),
                                            Constraint.Constant(0));

                relativeLayout.Children.Add(closeButton,
                                            Constraint.RelativeToParent(parent => parent.Width - closeButton.GetWidth(parent) - 10),
                                            Constraint.Constant(0),
                                            Constraint.RelativeToParent(parent => closeButton.GetWidth(parent)));
            }
            else
            {
                relativeLayout.Children.Add(_refreshView,
                                            Constraint.Constant(0),
                                            Constraint.Constant(0),
                                            Constraint.RelativeToParent(parent => parent.Width),
                                            Constraint.RelativeToParent(parent => parent.Height));
            }

            relativeLayout.Children.Add(_storeRatingRequestView,
                                        Constraint.Constant(0),
                                        Constraint.RelativeToParent(parent => parent.Height - _storeRatingRequestView.GetHeight(parent)),
                                        Constraint.RelativeToParent(parent => parent.Width));

            Content = relativeLayout;
Ejemplo n.º 5
0
        public ReferringSitesPage(DeepLinkingService deepLinkingService,
                                  ReferringSitesViewModel referringSitesViewModel,
                                  Repository repository,
                                  AnalyticsService analyticsService,
                                  ReviewService reviewService) : base(referringSitesViewModel, analyticsService, PageTitles.ReferringSitesPage)
        {
            const int titleRowHeight = 50;
            const int titleTopMargin = 15;

            _deepLinkingService = deepLinkingService;
            _reviewService      = reviewService;

            ViewModel.PullToRefreshFailed += HandlePullToRefreshFailed;
            reviewService.ReviewCompleted += HandleReviewCompleted;

            var collectionView = new CollectionView
            {
                AutomationId    = ReferringSitesPageAutomationIds.CollectionView,
                BackgroundColor = Color.Transparent,
                ItemTemplate    = new ReferringSitesDataTemplate(),
                SelectionMode   = SelectionMode.Single,
                ItemsLayout     = new LinearItemsLayout(ItemsLayoutOrientation.Vertical),
                //Set iOS Header to `new BoxView { HeightRequest = titleRowHeight + titleTopMargin }` following this bug fix: https://github.com/xamarin/Xamarin.Forms/issues/9879
                Header = Device.RuntimePlatform is Device.Android ? new BoxView {
                    HeightRequest = 8
                } : null,
                Footer = Device.RuntimePlatform is Device.Android ? new BoxView {
                    HeightRequest = 8
                } : null,
                EmptyView = new EmptyDataView("EmptyReferringSitesList", ReferringSitesPageAutomationIds.EmptyDataView)
                            .Bind(IsVisibleProperty, nameof(ReferringSitesViewModel.IsEmptyDataViewEnabled))
                            .Bind(EmptyDataView.TextProperty, nameof(ReferringSitesViewModel.EmptyDataViewText))
            };

            collectionView.SelectionChanged += HandleCollectionViewSelectionChanged;
            collectionView.SetBinding(CollectionView.ItemsSourceProperty, nameof(ReferringSitesViewModel.MobileReferringSitesList));

            _refreshView = new RefreshView
            {
                AutomationId     = ReferringSitesPageAutomationIds.RefreshView,
                CommandParameter = (repository.OwnerLogin, repository.Name, repository.Url, _refreshViewCancelltionTokenSource.Token),
                Content          = collectionView
            };
            _refreshView.SetDynamicResource(RefreshView.RefreshColorProperty, nameof(BaseTheme.PullToRefreshColor));
            _refreshView.SetBinding(RefreshView.CommandProperty, nameof(ReferringSitesViewModel.RefreshCommand));
            _refreshView.SetBinding(RefreshView.IsRefreshingProperty, nameof(ReferringSitesViewModel.IsRefreshing));

            var relativeLayout = new RelativeLayout();

            //Add Title and Close Button to UIModalPresentationStyle.FormSheet
            if (Device.RuntimePlatform is Device.iOS)
            {
                const int refreshViewTopPadding = titleRowHeight + 5;

                var closeButton = new Button
                {
                    Text              = "Close",
                    FontFamily        = FontFamilyConstants.RobotoRegular,
                    HeightRequest     = titleRowHeight * 3 / 5,
                    HorizontalOptions = LayoutOptions.End,
                    VerticalOptions   = LayoutOptions.Center,
                    AutomationId      = ReferringSitesPageAutomationIds.CloseButton,
                    Padding           = new Thickness(5, 0),
                };
                closeButton.Clicked += HandleCloseButtonClicked;
                closeButton.SetDynamicResource(Button.TextColorProperty, nameof(BaseTheme.NavigationBarTextColor));
                closeButton.SetDynamicResource(Button.BorderColorProperty, nameof(BaseTheme.BorderButtonBorderColor));
                closeButton.SetDynamicResource(BackgroundColorProperty, nameof(BaseTheme.NavigationBarBackgroundColor));


                var titleRowBlurView = new BoxView {
                    Opacity = 0.5
                };
                titleRowBlurView.SetDynamicResource(BackgroundColorProperty, nameof(BaseTheme.PageBackgroundColor));

                var titleLabel = new Label
                {
                    FontSize   = 30,
                    Text       = PageTitles.ReferringSitesPage,
                    FontFamily = FontFamilyConstants.RobotoMedium,
                };
                titleLabel.SetDynamicResource(Label.TextColorProperty, nameof(BaseTheme.TextColor));

                closeButton.Margin = titleLabel.Margin = new Thickness(0, titleTopMargin, 0, 0);

                relativeLayout.Children.Add(_refreshView,
                                            Constraint.Constant(0),
                                            Constraint.Constant(refreshViewTopPadding),                                    //Set to `0` following this bug fix: https://github.com/xamarin/Xamarin.Forms/issues/9879
                                            Constraint.RelativeToParent(parent => parent.Width),
                                            Constraint.RelativeToParent(parent => parent.Height - refreshViewTopPadding)); //Set to `parent => parent.Height` following this bug fix: https://github.com/xamarin/Xamarin.Forms/issues/9879

                relativeLayout.Children.Add(titleRowBlurView,
                                            Constraint.Constant(0),
                                            Constraint.Constant(0),
                                            Constraint.RelativeToParent(parent => parent.Width),
                                            Constraint.Constant(titleRowHeight));

                relativeLayout.Children.Add(titleLabel,
                                            Constraint.Constant(10),
                                            Constraint.Constant(0));

                relativeLayout.Children.Add(closeButton,
                                            Constraint.RelativeToParent(parent => parent.Width - GetWidth(parent, closeButton) - 10),
                                            Constraint.Constant(0),
                                            Constraint.RelativeToParent(parent => GetWidth(parent, closeButton)));
            }
            else
            {
                relativeLayout.Children.Add(_refreshView,
                                            Constraint.Constant(0),
                                            Constraint.Constant(0),
                                            Constraint.RelativeToParent(parent => parent.Width),
                                            Constraint.RelativeToParent(parent => parent.Height));
            }

            relativeLayout.Children.Add(_storeRatingRequestView,
                                        Constraint.Constant(0),
                                        Constraint.RelativeToParent(parent => parent.Height - GetHeight(parent, _storeRatingRequestView)),
                                        Constraint.RelativeToParent(parent => parent.Width));

            Content = relativeLayout;
        }
Ejemplo n.º 6
0
        public ReferringSitesPage(IMainThread mainThread,
                                  Repository repository,
                                  ThemeService themeService,
                                  ReviewService reviewService,
                                  IAnalyticsService analyticsService,
                                  DeepLinkingService deepLinkingService,
                                  ReferringSitesViewModel referringSitesViewModel) : base(referringSitesViewModel, analyticsService, mainThread)
        {
            Title = PageTitles.ReferringSitesPage;

            _repository         = repository;
            _themeService       = themeService;
            _reviewService      = reviewService;
            _deepLinkingService = deepLinkingService;

            ReviewService.ReviewCompleted += HandleReviewCompleted;
            ReferringSitesViewModel.PullToRefreshFailed += HandlePullToRefreshFailed;

            var isiOS          = Device.RuntimePlatform is Device.iOS;
            var titleRowHeight = isiOS ? 50 : 0;
            var shadowHeight   = isiOS ? 1 : 0;

            var collectionView = new ReferringSitesCollectionView()
                                 .Bind(IsVisibleProperty, nameof(ReferringSitesViewModel.IsEmptyDataViewEnabled))
                                 .Bind(EmptyDataView.TitleProperty, nameof(ReferringSitesViewModel.EmptyDataViewTitle))
                                 .Bind(EmptyDataView.DescriptionProperty, nameof(ReferringSitesViewModel.EmptyDataViewDescription))
                                 .Bind(CollectionView.ItemsSourceProperty, nameof(ReferringSitesViewModel.MobileReferringSitesList))
                                 .Invoke(collectionView => collectionView.SelectionChanged += HandleCollectionViewSelectionChanged);

            Content = new Grid
            {
                RowSpacing = 0,

                RowDefinitions = Rows.Define(
                    (Row.Title, Auto),
                    (Row.TitleShadow, AbsoluteGridLength(shadowHeight)),
                    (Row.List, Star),
                    (Row.RatingRequest, Auto)),

                ColumnDefinitions = Columns.Define(
                    (Column.Title, StarGridLength(3)),
                    (Column.Button, StarGridLength(1))),

                Children =
                {
                    new ReferringSitesRefreshView(collectionView,       repository, _refreshViewCancelltionTokenSource.Token).Assign(out _refreshView)
                    .Row(Row.TitleShadow).RowSpan(3).ColumnSpan(All <Column>())
                    .Bind(RefreshView.CommandProperty,                  nameof(ReferringSitesViewModel.RefreshCommand))
                    .Bind(RefreshView.IsRefreshingProperty,             nameof(ReferringSitesViewModel.IsRefreshing))
                    .DynamicResource(RefreshView.RefreshColorProperty,  nameof(BaseTheme.PullToRefreshColor)),

                    _storeRatingRequestView
                    .Row(Row.RatingRequest).ColumnSpan(All <Column>()),
                }
            };

            if (isiOS)
            {
                var grid = (Grid)Content;

                grid.Children.Add(new TitleShadowView(themeService, titleRowHeight, shadowHeight).Row(Row.Title).ColumnSpan(All <Column>()));
                grid.Children.Add(new TitleLabel().Row(Row.Title).Column(Column.Title));
                grid.Children.Add(new CloseButton(titleRowHeight).Invoke(closeButton => closeButton.Clicked += HandleCloseButtonClicked).Row(Row.Title).Column(Column.Button));
            }
        }