コード例 #1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var na   = Locator.Current.GetService <INetworkActivityService>();
            var a    = Locator.Current.GetService <IApplicationService>();
            var feat = Locator.Current.GetService <IFeaturesService>();

            var profileViewModel      = new ProfileViewModel(a, na, feat);
            var profileViewController = new ProfileViewController {
                ViewModel = profileViewModel
            };

            profileViewController.ViewModel.GoToInterestsCommand.Subscribe(_ => SelectedIndex = 1);
            profileViewController.TabBarItem     = new UITabBarItem("Profile", Images.User, Images.UserFilled);
            profileViewController.ViewModel.View = profileViewController;

            var interestsViewModel      = new InterestsViewModel(a, feat);
            var interestsViewController = new InterestsViewController {
                ViewModel = interestsViewModel
            };

            interestsViewController.TabBarItem     = new UITabBarItem("Interests", Images.Heart, Images.HeartFilled);
            interestsViewController.ViewModel.View = interestsViewController;

            var trendingViewModel      = new TrendingViewModel(na, new RepositoryStumble.Core.Data.TrendingRepository());
            var trendingViewController = new TrendingViewController();

            trendingViewController.ViewModel      = trendingViewModel;
            trendingViewController.TabBarItem     = new UITabBarItem("Trending", Images.Trending, Images.TrendingFilled);
            trendingViewController.ViewModel.View = trendingViewController;

            var vm = new ShowcasesViewModel(Locator.Current.GetService <INetworkActivityService>(), new RepositoryStumble.Core.Data.ShowcaseRepository());
            var showcasesViewController = new ShowcasesViewController {
                ViewModel = vm
            };

            showcasesViewController.TabBarItem     = new UITabBarItem("Showcase", Images.Spotlight, Images.Spotlight);
            showcasesViewController.ViewModel.View = showcasesViewController;

            var stumble = new UIViewController();

            stumble.TabBarItem = new UITabBarItem("Stumble!", Images.Search, Images.Search);

            this.ViewControllers = new[]
            {
                new UINavigationController(profileViewController),
                new UINavigationController(interestsViewController),
                stumble,
                new UINavigationController(trendingViewController),
                new UINavigationController(showcasesViewController)
            };

            nfloat width = 60;

            if (TabBar.Subviews.Length == 5)
            {
                width = TabBar.Subviews[2].Bounds.Width;
            }

            var stumbleView = new StumbleView(new CGRect(TabBar.Bounds.Width / 2f - width / 2, 0, width, TabBar.Bounds.Height), UITabBar.Appearance.TintColor);

            stumbleView.AutoresizingMask       = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
            stumbleView.UserInteractionEnabled = false;
            TabBar.Add(stumbleView);

            nint previousSelectedIndex = 0;

            ViewControllerSelected += (sender, e) =>
            {
                if (e.ViewController == stumble)
                {
                    if (Locator.Current.GetService <IApplicationService>().Account.Interests.Count() == 0)
                    {
                        SelectedIndex = 1;
                        Locator.Current.GetService <IAlertDialogService>().Alert(
                            "You need some interests!",
                            "Please add at least one interest before you stumble!");
                    }
                    else
                    {
                        ViewModel.GoToStumbleCommand.ExecuteIfCan();
                        SelectedIndex = previousSelectedIndex;
                    }
                }
                else
                {
                    previousSelectedIndex = SelectedIndex;
                }
            };
        }
コード例 #2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var profileViewController = new ProfileViewController {
                ViewModel = IoC.Resolve <ProfileViewModel>()
            };

            profileViewController.ViewModel.GoToInterestsCommand.Subscribe(_ => SelectedIndex = 1);
            profileViewController.TabBarItem     = new UITabBarItem("Profile", Images.User, Images.UserFilled);
            profileViewController.ViewModel.View = profileViewController;

            var interestsViewController = new InterestsViewController {
                ViewModel = IoC.Resolve <InterestsViewModel>()
            };

            interestsViewController.TabBarItem     = new UITabBarItem("Interests", Images.Heart, Images.HeartFilled);
            interestsViewController.ViewModel.View = interestsViewController;

            var trendingViewController = IoC.Resolve <TrendingViewController>();

            trendingViewController.ViewModel      = IoC.Resolve <TrendingViewModel>();
            trendingViewController.TabBarItem     = new UITabBarItem("Trending", Images.Trending, Images.TrendingFilled);
            trendingViewController.ViewModel.View = trendingViewController;

            var showcasesViewController = new ShowcasesViewController {
                ViewModel = IoC.Resolve <ShowcasesViewModel>()
            };

            showcasesViewController.TabBarItem     = new UITabBarItem("Showcase", Images.Spotlight, Images.Spotlight);
            showcasesViewController.ViewModel.View = showcasesViewController;

            var stumble = new UIViewController();

            stumble.TabBarItem = new UITabBarItem("Stumble!", Images.Search, Images.Search);

            this.ViewControllers = new[]
            {
                new UINavigationController(profileViewController),
                new UINavigationController(interestsViewController),
                stumble,
                new UINavigationController(trendingViewController),
                new UINavigationController(showcasesViewController)
            };

            float width = 60;

            if (TabBar.Subviews.Length == 5)
            {
                width = TabBar.Subviews[2].Bounds.Width;
            }

            var stumbleView = new StumbleView(new RectangleF(TabBar.Bounds.Width / 2f - width / 2, 0, width, TabBar.Bounds.Height));

            stumbleView.AutoresizingMask       = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
            stumbleView.BackgroundColor        = UITabBar.Appearance.TintColor;
            stumbleView.UserInteractionEnabled = false;
            TabBar.Add(stumbleView);

            var previousSelectedIndex = 0;

            ViewControllerSelected += (sender, e) =>
            {
                if (e.ViewController == stumble)
                {
                    if (IoC.Resolve <IApplicationService>().Account.Interests.Count() == 0)
                    {
                        SelectedIndex = 1;
                        IoC.Resolve <IAlertDialogService>().Alert(
                            "You need some interests!",
                            "Please add at least one interest before you stumble!");
                    }
                    else
                    {
                        ViewModel.GoToStumbleCommand.ExecuteIfCan();
                        SelectedIndex = previousSelectedIndex;
                    }
                }
                else
                {
                    previousSelectedIndex = SelectedIndex;
                }
            };
        }