Inheritance: Cirrious.MvvmCross.Droid.Fragging.Fragments.EventSource.MvxEventSourceFragment, IMvxFragmentView
Exemplo n.º 1
0
        /// <summary>
        /// Create new instance of a Fragment
        /// </summary>
        /// <param name="bundle">Usually this would be MvxViewModelRequest serialized</param>
        /// <returns>Returns an instance of a MvxFragment</returns>
        public static MvxFragment NewInstance(Bundle bundle)
        {
            // Setting Arguments needs to happen before Fragment is attached
            // to Activity. Arguments are persisted when Fragment is recreated!
            var fragment = new MvxFragment { Arguments = bundle };

            return fragment;
        }
Exemplo 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 ();
		}
Exemplo n.º 3
0
        /// <summary>
        /// Create new instance of a Fragment
        /// </summary>
        /// <param name="bundle">Usually this would be MvxViewModelRequest serialized</param>
        /// <returns>Returns an instance of a MvxFragment</returns>
        public static MvxFragment NewInstance(Bundle bundle)
        {
            // Setting Arguments needs to happen before Fragment is attached
            // to Activity. Arguments are persisted when Fragment is recreated!
            var fragment = new MvxFragment {
                Arguments = bundle
            };

            return(fragment);
        }
Exemplo n.º 4
0
 private void ShowFormHeaderFragment(MvxFragment myFragment)
 {
     var t = SupportFragmentManager.BeginTransaction();
     t.Replace(Resource.Id.titles_fragment_holder, myFragment);
     t.Commit();
 }
Exemplo n.º 5
0
		protected void ReplaceFragment (MvxFragment fragment, MvxViewModelRequest request)
		{
			PrepareFragment (fragment, request);
			((HomeView)Activity).ShowMenuItem (fragment);
		}
Exemplo n.º 6
0
        /// <summary>
        /// Read all about this, but this is a nice way if there were multiple
        /// fragments on the screen for us to decide what and where to show stuff
        /// See: http://enginecore.blogspot.ro/2013/06/more-dynamic-android-fragments-with.html
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public bool Show(MvxViewModelRequest request)
        {
            try
            {
                MvxFragment frag = null;
                var title = string.Empty;
                var section = ViewModel.GetSectionForViewModelType(request.ViewModelType);

                var shouldClearBackStack = true;
                var shouldAddToBackStack = false;

                switch (section)
                {
                    case HomeViewModel.Section.MyPage:
                    {
                        if (!ViewModel.IsAuthenticated())
                        {
                            if (SupportFragmentManager.FindFragmentById(Resource.Id.content_frame) as LoginView != null)
                                return true;

                            frag = new LoginView(ViewModel);
                            title = "Logg inn";
                        }
                        else
                        {
                            if (SupportFragmentManager.FindFragmentById(Resource.Id.content_frame) as MyPageView != null)
                                return true;

                            frag = new MyPageView();
                            title = "Min Side";
                            }
                        break;
                    }
                    case HomeViewModel.Section.Search:
                    {
                        if (SupportFragmentManager.FindFragmentById(Resource.Id.content_frame) as SearchView != null)
                            return true;

                        frag = new SearchView();
                        title = "Søk";
                        break;
                    }
                    case HomeViewModel.Section.News:
                    {
                        if (SupportFragmentManager.FindFragmentById(Resource.Id.content_frame) as NewsListingView != null)
                            return true;

                        frag = new NewsListingView();
                        title = "Nyheter";
                        break;
                    }
                    case HomeViewModel.Section.OpeningHours:
                    {
                        if (SupportFragmentManager.FindFragmentById(Resource.Id.content_frame) as OpeningHoursView != null)
                            return true;

                        frag = new OpeningHoursView();
                        title = "Åpningstider";
                        break;
                    }
                    case HomeViewModel.Section.Events:
                    {
                        if (SupportFragmentManager.FindFragmentById(Resource.Id.content_frame) as EventListView != null)
                            return true;

                        frag = new EventListView();
                        title = "Arrangement";
                        break;
                    }
                    case HomeViewModel.Section.Lists:
                    {
                        if (SupportFragmentManager.FindFragmentById(Resource.Id.content_frame) as SuggestionsListListView != null)
                            return true;

                        frag = new SuggestionsListListView();
                        title = "Anbefalinger";
                        break;
                    }
                    case HomeViewModel.Section.Contact:
                    {
                        if (SupportFragmentManager.FindFragmentById(Resource.Id.content_frame) as ContactInfoView != null)
                            return true;
                        
                        frag = new ContactInfoView();
                        title = "Kontaktinformasjon";
                        break;
                    }
                    case HomeViewModel.Section.Blogs:
                    {
                        if (SupportFragmentManager.FindFragmentById(Resource.Id.content_frame) as BlogOverviewView != null) 
                            return true;
                        
                        frag = new BlogOverviewView();
                        title = "Blogger";
                        break;
                    }
                    case HomeViewModel.Section.Home:
                    {
                        if (SupportFragmentManager.FindFragmentById(Resource.Id.content_frame) as HomeScreenView != null)
                            return true;


                        frag = new HomeScreenView();
                        title = START_PAGE_TITLE;
                        break;
                    }
                    case HomeViewModel.Section.Logout:
                    {
                        //((HomeViewModel)ViewModel).LogOut();
                        Toast.MakeText(Application.Context, "Du er nå logget ut", ToastLength.Long).Show();
                        break;
                    }
                    case HomeViewModel.Section.Unknown:
                    {
                        shouldAddToBackStack = true;
                        shouldClearBackStack = false;
                        if (request.ViewModelType == typeof (SuggestionsListViewModel))
                            frag = new SuggestionsListView();
                        if (request.ViewModelType == typeof(BlogViewModel))
                            frag = new BlogView();
                        if (request.ViewModelType == typeof (LoginViewModel))
                            frag = new LoginView(ViewModel);
                        if (request.ViewModelType == typeof (MediaDetailViewModel))
                            frag = new MediaDetailView();

                        break;
                    }
                }

                var loaderService = Mvx.Resolve<IMvxViewModelLoader>();
                var viewModel = loaderService.LoadViewModel(request, null /* saved state */);

                if (frag != null)
                {
                    frag.ViewModel = viewModel;

                    var trans = SupportFragmentManager.BeginTransaction();
                    if (shouldClearBackStack)
                    {
                        SupportFragmentManager.PopBackStackImmediate(0, (int) PopBackStackFlags.None);
                    }

                    trans.Replace(Resource.Id.content_frame, frag);
                    _currentFragment = frag;

                    if (shouldAddToBackStack)
                    {
                        trans.AddToBackStack(((BaseViewModel)frag.ViewModel).Title);
                    }
                    trans.Commit();
                }
                

                SupportActionBar.Title = _title = title;
                

                ClearAndHighlightActiveMenuItem(section);

                if (_drawer != null)
                {
                    _drawer.CloseDrawer(_drawerList);
                }
                

                return true;
            }
            finally
            {
                if (_drawer != null)
                {
                    _drawer.CloseDrawer(_drawerList);
                }
            }
        }