Esempio n. 1
0
        /// <summary>
        /// Returns true iff the view has a region attribute.
        /// </summary>
        /// <param name="view"></param>
        /// <returns></returns>
        public static bool HasRegionAttribute(this MvxFragment view)
        {
            var attributes = view
                             .GetType()
                             .GetCustomAttributes(typeof(RegionAttribute), true);

            return(attributes.Count() > 0);
        }
Esempio n. 2
0
        public void ShowMenuItem(MvxFragment fragment)
        {
            var topFragment = SupportFragmentManager.FindFragmentById(Resource.Id.content_frame);

            if (topFragment != null && topFragment.GetType().Equals(fragment.GetType()))
            {
                return;
            }

            SupportFragmentManager.BeginTransaction().Replace(Resource.Id.content_frame, fragment).Commit();
        }
        private void ShowFragment(MvxFragment fragment, bool addToBackStack)
        {
            var transaction = _fragmentManager.BeginTransaction();

            if (addToBackStack)
            {
                transaction.AddToBackStack(fragment.GetType().Name);
            }

            transaction
            .Replace(Resource.Id.contentFrame, fragment)
            .Commit();
        }
Esempio n. 4
0
        /// <summary>
        /// Gets the Android resource ID from the RecionAttribute associated with the view.
        /// </summary>
        /// <param name="view"></param>
        /// <returns></returns>
        public static int GetRegionId(this MvxFragment view)
        {
            var attributes = view
                             .GetType()
                             .GetCustomAttributes(typeof(RegionAttribute), true);

            if (attributes.Count() == 0)
            {
                throw new InvalidOperationException("The IMvxView has no region attribute.");
            }
            else
            {
                return(((RegionAttribute)attributes.First()).Id);
            }
        }
Esempio n. 5
0
        private void showFragment(MvxFragment fragment, bool addToBackStack)
        {
            var transaction = this.fragmentManager.BeginTransaction();

            if (addToBackStack && !fragment.ToString().StartsWith("LoginView"))
            {
                transaction.AddToBackStack(fragment.GetType().Name);
            }
            try
            {
                transaction
                .Replace(Resource.Id.contentFrame, fragment)
                .Commit();
            }
            catch (Exception)
            {
            }
        }
        private void CloseCurrentFragment(Type fragmentType)
        {
            IList <Android.Support.V4.App.Fragment> fragments = SupportFragmentManager.Fragments;

            if (fragments.Count == 0)
            {
                return;
            }

            MvxFragment currentFragment     = (MvxFragment)fragments[fragments.Count - 1];
            Type        currentFragmentType = currentFragment.GetType();

            if (currentFragmentType == fragmentType)
            {
                Finish();
                return;
            }

            BaseViewModel viewModel = (BaseViewModel)currentFragment.ViewModel;

            viewModel.GoBackCommand?.Execute(null);
        }
Esempio n. 7
0
        public bool Show(MvxViewModelRequest request)
        {
            try
            {
                if (_enableDrawerOnNextNavigation)
                {
                    this.EnableDrawer();
                    _enableDrawerOnNextNavigation = false;
                }

                var         loaderService = Mvx.Resolve <IMvxViewModelLoader>();
                var         homeViewModel = this.ViewModel as HomeViewModel;
                MvxFragment fragment      = null;

                var section = homeViewModel.GetSectionForViewModelType(request.ViewModelType);
                if (section == MenuSection.Unknown)
                {
                    this.Navigate(request, loaderService);
                    return(true);
                }

                this.CloseSlidingPanel();

                switch (section)
                {
                case MenuSection.Map:
                    _currentSection = MenuSection.Map;

                    this.SupportActionBar.Title = homeViewModel.Title;

                    _navigationView.SetCheckedItem(0);

                    var map = this.FragmentManager.FindFragmentById(Resource.Id.mapView) as MapView;
                    if (map.ViewModel == null)
                    {
                        map.MapClicked += (s, a) => this.CloseSlidingPanel();
                        map.ViewModel   = loaderService.LoadViewModel(request, null /* saved state */);
                    }

                    var transaction = this.FragmentManager.BeginTransaction();
                    foreach (var viewType in _frag2tag.Keys)
                    {
                        if (viewType != typeof(MapView))
                        {
                            var fragmentToRemove = this.FragmentManager.FindFragmentByTag(_frag2tag[viewType]);
                            if (fragmentToRemove != null)
                            {
                                transaction.Remove(fragmentToRemove);
                            }
                        }
                    }

                    this.CloseSlidingPanel();

                    this.FragmentManager.PopBackStackImmediate(null, PopBackStackFlags.None | PopBackStackFlags.Inclusive);
                    transaction.Commit();
                    return(true);

                case MenuSection.Routes:
                    fragment        = this.FindFragment <RoutesView>() ?? new RoutesView();
                    _currentSection = section;
                    break;

                case MenuSection.RouteStops:
                    fragment        = this.FindFragment <RouteStopsView>() ?? new RouteStopsView();
                    _currentSection = section;
                    break;

                case MenuSection.Preferences:
                    fragment        = this.FindFragment <PreferencesView>() ?? new PreferencesView();
                    _currentSection = section;
                    break;

                case MenuSection.About:
                    fragment        = this.FindFragment <AboutView>() ?? new AboutView();
                    _currentSection = section;
                    break;
                }

                IMvxFragmentView mvxFragmentView = fragment;
                if (mvxFragmentView != null && mvxFragmentView.ViewModel == null)
                {
                    mvxFragmentView.ViewModel = loaderService.LoadViewModel(request, null /* saved state */);
                }

                if (!_frag2tag.ContainsKey(fragment.GetType()))
                {
                    _frag2tag[fragment.GetType()] = Guid.NewGuid().ToString();
                }

                this.FragmentManager.BeginTransaction()
                .Replace(Resource.Id.content_frame, fragment, _frag2tag[fragment.GetType()])
                .AddToBackStack(null)
                .Commit();

                var menuItem = homeViewModel.MenuItems.First(x => x.Id == (int)section);
                _navigationView.SetCheckedItem(homeViewModel.MenuItems.IndexOf(menuItem));

                _drawer.CloseDrawer(_navigationView);

                return(true);
            }
            finally
            {
                _drawer.CloseDrawer(_navigationView);
            }
        }