Example #1
0
        private void NavigateToFragment(MvxFragment fragment, bool addToBackStack)
        {
            try
            {
                var transaction = FragmentManager.BeginTransaction();

                // Note: this *replaces* the actual fragment host specified in Page_StartUp.axml
                // but keeps the same id
                transaction.Replace(this.FragmentHostID, fragment);

                if (addToBackStack)
                {
                    transaction.AddToBackStack(null);
                }

                transaction.Commit();

                this.FragmentChanged(fragment);
            }
            catch (Java.Lang.IllegalStateException ex)
            {
                MvxTrace.Warning("IllegalStateException occurred on fragment change: {0}", ex.Message);
                // If the app is in the background, for example if the user has pressed the device Home button or put the device into sleep mode before the fragment change occurs,
                // then an error will be thrown: "java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState".
                // If this happens then swallow the exception rather than crash the app, in which case the user will need to re-trigger the fragment change when they resume the app.
            }
        }
Example #2
0
        protected void Show(MvxFragment fragment, bool backStack)
        {
            if (!fragment.HasRegionAttribute())
            {
                throw new InvalidOperationException("Fragment has no region attribute.");
            }

            int regionResourceId = fragment.GetRegionId();

            if (!_validRegionIds.Contains(regionResourceId))
            {
                throw new InvalidOperationException("Id specified in resource attribute is invalid.");
            }

            if (regionResourceId == Resource.Id.PopupRegion)
            {
                // show popup transparency
                var transparency = FindViewById(Resource.Id.PopupTransparency);
                transparency.Visibility = ViewStates.Visible;
            }

            // load fragment into view
            var ft = SupportFragmentManager.BeginTransaction();

            ft.Replace(regionResourceId, fragment);
            if (backStack)
            {
                // TODO:
                // The back button will return to this.  However,
                //   setting this may mess up the custom
                //   OnBackPressed() behavior
                ft.AddToBackStack(null);
            }
            ft.Commit();
        }
        private void selectOption(int position)
        {
            var mainAct = (this.Activity as Whistle.Droid.Views.MainView);
            // var viewModel =.ViewModel; // we can do better...
            string      title      = string.Empty;
            MvxFragment newContent = null;

            switch (position)
            {
            case 0:
                mainAct.OnSelectContext();
                return;

            case 1:
                newContent = new GenericFragment(Resource.Layout.Registration, Resource.Menu.menu_switch)
                {
                    ViewModel = mainAct.ViewModel
                };
                title = "EDIT PROFILE";
                break;

            case 2:
                newContent = new GenericFragment(Resource.Layout.Favorite, Resource.Menu.menu_switch);
                title      = "MY FAVORITES";
                break;

            case 3:
                newContent = new GenericFragment(Resource.Layout.Setting, Resource.Menu.menu_switch);
                title      = "SETTINGS";
                break;

            case 4:
                newContent = new GenericFragment(Resource.Layout.About, Resource.Menu.menu_switch);
                title      = "ABOUT WHISTLE";
                break;

            case 5:
                newContent = new GenericFragment(Resource.Layout.WhistleWork, Resource.Menu.menu_switch);
                title      = "HOW WHISTLE WORKS";
                break;

            case 6:
                (new GenericAlertFragment(Resource.Color.app_gray_modal_color))
                .WithIcon(Resource.Drawable.signout_green_big_icon)
                .WithTitle(Resource.String.d_sign_out)
                .WithDescription(Resource.String.d_sign_out_msg)
                .AddButton(Resource.String.d_btn_sign_out, () => { mainAct.SupportFragmentManager.ExecutePendingTransactions(); mainAct.ViewModel.SignOut(); })
                .AddButton(Resource.String.d_btn_cancel, () => { })
                .Show(Activity.SupportFragmentManager, "sign_out");
                return;
            }
            var viewmodel = (BaseViewModel)mainAct.ViewModel;

            viewmodel.Title      = title;
            newContent.ViewModel = viewmodel;
            if (mainAct != null)
            {
                mainAct.SwitchContent(newContent);
            }
        }
Example #4
0
        private void ShowFormHeaderFragment(MvxFragment myFragment)
        {
            var t = SupportFragmentManager.BeginTransaction();

            t.Replace(Resource.Id.titles_fragment_holder, myFragment);
            t.Commit();
        }
Example #5
0
 public PhotoGalleryService(MvxFragment fragment, ImageButton imageButton, bool useFrontCamera = false)
 {
     imageLat       = imageLong = 0;
     Fragment       = fragment;
     ImageButton    = imageButton;
     UseFrontCamera = useFrontCamera;
     NeedCrop       = true;
     PermissionHelper.AddPermission(Fragment.Activity, new List <string> {
         Manifest.Permission.WriteExternalStorage, Manifest.Permission.Camera
     });
     if (ImageButton == null)
     {
         return;
     }
     ImageButton.Click += (s, e) =>
     {
         if (!AppInstalled(fragment.Context, "com.instagram.android"))
         {
             AlertDialog.Builder alertDialog = new AlertDialog.Builder(fragment.Context);
             alertDialog.SetMessage("Unable to find the Instagram App on your device. This challenge requires Instagram.");
             alertDialog.SetPositiveButton("OK", (sender, args) =>
             {
             });
             Dialog dialod = alertDialog.Create();
             dialod.Show();
         }
         else if ((Fragment.ViewModel as IChallengeShareViewModel).CheckNetworkConnected())
         {
             BtnUpdatePhoto();
         }
     };
 }
Example #6
0
        public void CreateViewFor(MvxFragment fragment, IMvxViewModel viewModel, int container)
        {
            fragment.ViewModel = viewModel;

            FragmentManager.BeginTransaction()
            .Replace(container, fragment)
            .Commit();
        }
Example #7
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);
        }
Example #8
0
 public void ShowFragment(MvxFragment fragment, ViewModelBase viewModel, int frameContentId, string tag = null)
 {
     fragment.ViewModel = viewModel;
     RunOnUiThread(() =>
     {
         FragmentManager.BeginTransaction().Replace(frameContentId, fragment, tag).Commit();
     });
 }
Example #9
0
 protected void SwitchScreen(MvxFragment fragment, string stackInfo)
 {
     _content = fragment as Android.Support.V4.App.Fragment;
     SupportFragmentManager.BeginTransaction()
     .Replace(Resource.Id.contentFrame, fragment)
     .AddToBackStack(stackInfo)
     .Commit();
 }
        public void Show(MvxFragment fragment)
        {
            var ft = FragmentManager.BeginTransaction();

            ft.Replace(Resource.Id.phone_main_region, fragment);

            ft.Commit();
        }
Example #11
0
        protected void Show(MvxFragment fragment, bool backStack)
        {
            var ft = SupportFragmentManager.BeginTransaction();

            ft.Replace(Resource.Id.content_frame, fragment);
            ft.AddToBackStack(null);
            ft.Commit();
        }
Example #12
0
        public virtual void FragmentChanged(MvxFragment fragment = null)
        {
            this.SetActivityTitleFromFragment(fragment ?? this.CurrentFragment);

            if (this.OnFragmentChanged != null)
            {
                this.OnFragmentChanged(this, EventArgs.Empty);
            }
        }
        public static void ProvideViewModelRequest(this MvxFragment fragment, MvxViewModelRequest request)
        {
            var bundle = fragment.Arguments ?? (fragment.Arguments = new Bundle());

            var serializer    = Mvx.Resolve <IMvxNavigationSerializer> ();
            var requestString = serializer.Serializer.SerializeObject(request);

            bundle.PutString(ViewModelRequestKey, requestString);
        }
Example #14
0
 public override void SwitchContent(MvxFragment fragment)
 {
     _content = fragment;
     SupportFragmentManager
     .BeginTransaction()
     .Replace(Resource.Id.contentArea, fragment)
     .Commit();
     SlidingMenu.ShowContent();
 }
 protected virtual void DestroyMvxFragment(MvxFragment fragment)
 {
     fragment.StartCalled  -= MvxFragment_StartCalled;
     fragment.ResumeCalled -= MvxFragment_ResumeCalled;
     if (fragment.View != null && fragment.View.HasOnClickListeners)
     {
         fragment.View.SetOnClickListener(null);
     }
 }
Example #16
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 = this.ViewModel.GetSectionForViewModelType(request.ViewModelType);

                switch (section)
                {
                case HomeViewModel.Section.EnterTime:
                {
                    if (this.SupportFragmentManager.FindFragmentById(Resource.Id.content_frame) as EnterTimeView != null)
                    {
                        return(true);
                    }

                    frag  = new EnterTimeView();
                    title = "Enter Time";
                }
                break;

                case HomeViewModel.Section.CreateNewJob:
                {
                    if (this.SupportFragmentManager.FindFragmentById(Resource.Id.content_frame) as CreateNewJobView != null)
                    {
                        return(true);
                    }

                    frag  = new CreateNewJobView();
                    title = "Create New Job";
                }
                break;
                }

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

                frag.ViewModel = viewModelLocal;

                // TODO - replace this with extension method when available

                //Normally we would do this, but we already have it
                this.SupportFragmentManager.BeginTransaction().Replace(Resource.Id.content_frame, frag, title).Commit();
                this._drawerList.SetItemChecked(this.ViewModel.MenuItems.FindIndex(m => m.Id == (int)section), true);
                this.ActionBar.Title = this._title = title;

                this._drawer.CloseDrawer(this._drawerList);

                return(true);
            }
            finally
            {
                this._drawer.CloseDrawer(this._drawerList);
            }
        }
Example #17
0
 public InviteService(MvxFragment fragment, bool needMultiselect = true)
 {
     _context        = Application.Context;
     Fragment        = fragment;
     NeedMultiselect = needMultiselect;
     PermissionHelper.AddPermission(Fragment.Activity, new List <string> {
         Manifest.Permission.ReadExternalStorage, Manifest.Permission.ReadContacts, Manifest.Permission.WriteContacts
     });
     //PermissionHelper.AddPermission(Fragment.Activity, new List<string> { Manifest.Permission.ReadExternalStorage, Manifest.Permission.ReadContacts, Manifest.Permission.WriteContacts, Manifest.Permission.SendSms });
 }
Example #18
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();
        }
Example #19
0
        private void CloseFragment(MvxFragment fragment)
        {
            if (fragment.GetRegionId() == Resource.Id.PopupRegion)
            {
                _transparentPopupView.Visibility = ViewStates.Gone;
            }

            var ft = SupportFragmentManager.BeginTransaction();

            ft.Remove(fragment);
            ft.Commit();
        }
Example #20
0
        private MvxFragment GetActiveFragmentForViewModel(IMvxViewModel viewModel)
        {
            foreach (int regionId in _validRegionIds)
            {
                MvxFragment fragment = SupportFragmentManager.FindFragmentById(regionId) as MvxFragment;
                if (fragment != null && fragment.ViewModel == viewModel)
                {
                    return(fragment);
                }
            }

            return(null);
        }
        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();
        }
        protected override void SetOnClickListenerToFragment(MvxFragment fragment)
        {
            if (ItemClick != null)
            {
                var listener = new ARViewPagerPageClickListener(
                    fragment.DataContext,
                    (obj) =>
                {
                    ExecuteCommandOnItem(ItemClick, obj);
                });

                fragment.View.SetOnClickListener(listener);
            }
        }
        protected virtual void SetOnClickListenerToFragment(MvxFragment fragment)
        {
            if (ItemClick != null)
            {
                var listener = new ARViewPagerPageClickListener(
                    fragment,
                    (obj) =>
                {
                    ExecuteCommandOnItem(ItemClick, GetItemPosition((Java.Lang.Object)obj));
                });

                fragment.View.SetOnClickListener(listener);
            }
        }
        protected override void OnFragmentResume(MvxFragment mvxFragment)
        {
            base.OnFragmentResume(mvxFragment);

            var vm = mvxFragment?.ViewModel;

            if (vm != null)
            {
                if (!IsVmStarted?.Invoke(vm) ?? true)
                {
                    vm.Start();
                }
            }
        }
Example #25
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);
            }
        }
Example #26
0
        /// <summary>
        /// 指定したレイアウトIDにFragmentを表示.
        /// </summary>
        /// <param name="containerId">レイアウトID.</param>
        /// <param name="newFlg">表示するFragment.</param>
        private void Show(int containerId, MvxFragment newFlg)
        {
            FragmentTransaction transaction = this.SupportFragmentManager.BeginTransaction();

            var currentFlg = SupportFragmentManager.FindFragmentById(containerId);

            if (newFlg == currentFlg)
            {
                return;
            }

            transaction.Replace(containerId, newFlg);
            transaction.AddToBackStack(null);

            transaction.Commit();
        }
Example #27
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)
            {
            }
        }
Example #28
0
        public bool Show(MvxViewModelRequest request)
        {
            // At this point simply display any supported fragment in the FrameLayout.
            // In future we may change this for different device form factors, for example to display tiled fragments.
            MvxFragment fragment = null;

            if (SupportedFragmentViewModels.ContainsKey(request.ViewModelType))
            {
                var fragmentType = SupportedFragmentViewModels[request.ViewModelType];
                fragment = (MvxFragment)Activator.CreateInstance(fragmentType);
                fragment.LoadViewModelFrom(request, null);
            }

            if (fragment == null)
            {
                return(false);
            }

            this.NavigateToFragment(fragment, addToBackStack: true);

            return(true);
        }
        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);
        }
Example #30
0
        protected virtual void ShowMvxFragment(MvxFragment fragment, MvxViewModelRequest request, Type fragmentType, bool isCachedInActivity)
        {
            if (fragment.ViewModel == null)
            {
                fragment.ViewModel = GetViewModel(fragment, request);
            }

            if (isCachedInActivity && fragment is INoCacheViewModel)
            {
                fragment.ViewModel = _viewModelLoader.LoadViewModel(request, null);
            }
            else
            {
                if (fragment is IHolderFragment)
                {
                    fragmentHolderActivity.Show(fragment, fragmentType);

                    if (fragment.ViewModel == null)
                    {
                        fragment.ViewModel = _viewModelLoader.LoadViewModel(request, null);
                    }

                    return;
                }

                if (fragment is IChildFragment)
                {
                    var fragmentHolder = fragmentHolderActivity.GetHolderFragment();
                    if (fragmentHolder != null)
                    {
                        fragmentHolder?.Show(fragment, fragmentType);
                        return;
                    }
                }
            }

            fragmentHolderActivity.Show(fragment, fragmentType);
        }