Exemplo n.º 1
0
		protected virtual FragmentReplaceMode ShouldReplaceCurrentFragment(IMvxCachedFragmentInfo newFragment, IMvxCachedFragmentInfo currentFragment, Bundle replacementBundle)
		{
			var oldBundle = ((Android.Support.V4.App.Fragment)newFragment.CachedFragment)?.Arguments;
			if (oldBundle == null) return FragmentReplaceMode.ReplaceFragment;

			var serializer = Mvx.Resolve<IMvxNavigationSerializer>();

			var json = oldBundle.GetString(MvxFragmentsPresenter.ViewModelRequestBundleKey);
			var oldRequest = serializer.Serializer.DeserializeObject<MvxViewModelRequest>(json);
			if (oldRequest == null) return FragmentReplaceMode.ReplaceFragment;

			json = replacementBundle.GetString(MvxFragmentsPresenter.ViewModelRequestBundleKey);
			var replacementRequest = serializer.Serializer.DeserializeObject<MvxViewModelRequest>(json);
			if (replacementRequest == null) return FragmentReplaceMode.ReplaceFragment;

			var areParametersEqual = ((oldRequest.ParameterValues == replacementRequest.ParameterValues) ||
				(oldRequest.ParameterValues.Count == replacementRequest.ParameterValues.Count &&
					!oldRequest.ParameterValues.Except(replacementRequest.ParameterValues).Any()));

			if (currentFragment?.Tag != newFragment.Tag)
			{
				return !areParametersEqual
					? FragmentReplaceMode.ReplaceFragmentAndViewModel
						: FragmentReplaceMode.ReplaceFragment;
			}
			else
				return !areParametersEqual
					? FragmentReplaceMode.ReplaceFragmentAndViewModel
						: FragmentReplaceMode.NoReplace;
		}
 public override void OnBeforeFragmentChanging(IMvxCachedFragmentInfo fragmentInfo,
                                               FragmentTransaction transaction)
 {
     transaction.SetCustomAnimations(Resource.Animation.abc_fade_in,
                                     Resource.Animation.abc_fade_out);
     base.OnBeforeFragmentChanging(fragmentInfo, transaction);
 }
        public override void OnFragmentCreated(IMvxCachedFragmentInfo fragmentInfo, FragmentTransaction transaction)
        {
            var myCustomInfo = (CustomFragmentInfo)fragmentInfo;

            // You can do fragment + transaction based configurations here.
            // Note that, the cached fragment might be reused in another transaction afterwards.
        }
Exemplo n.º 4
0
        public override void OnBeforeFragmentChanging(IMvxCachedFragmentInfo fragmentInfo, FragmentTransaction transaction)
        {
            transaction.SetCustomAnimations(
                // Your entrance animation xml reference
                Android.Resource.Animation.SlideInLeft,
                // Your exit animation xml reference
                Android.Resource.Animation.SlideOutRight);

            base.OnBeforeFragmentChanging(fragmentInfo, transaction);
        }
        public override SerializableMvxCachedFragmentInfo GetSerializableFragmentInfo(
            IMvxCachedFragmentInfo objectToSerialize)
        {
            var baseSerializableCachedFragmentInfo = base.GetSerializableFragmentInfo(objectToSerialize);
            var customFragmentInfo = objectToSerialize as MainActivity.CustomFragmentInfo;

            return(new SerializableCustomFragmentInfo(baseSerializableCachedFragmentInfo)
            {
                IsRoot = customFragmentInfo?.IsRoot ?? false
            });
        }
        public override SerializableMvxCachedFragmentInfo GetSerializableFragmentInfo(
            IMvxCachedFragmentInfo objectToSerialize)
        {
            var baseSerializableCachedFragmentInfo = base.GetSerializableFragmentInfo(objectToSerialize);
            var customFragmentInfo = objectToSerialize as CustomFragmentInfo;

            return new SerializableCustomFragmentInfo(baseSerializableCachedFragmentInfo)
            {
                IsRoot = customFragmentInfo?.IsRoot ?? false
            };
        }
 public virtual SerializableMvxCachedFragmentInfo GetSerializableFragmentInfo(IMvxCachedFragmentInfo objectToSerialize)
 {
     return new SerializableMvxCachedFragmentInfo()
     {
         Tag = objectToSerialize.Tag,
         FragmentType = objectToSerialize.FragmentType,
         ViewModelType = objectToSerialize.ViewModelType,
         ContentId = objectToSerialize.ContentId,
         AddToBackStack = objectToSerialize.AddToBackStack
     };
 }
Exemplo n.º 8
0
        public override void OnBeforeFragmentChanging(IMvxCachedFragmentInfo fragmentInfo, Android.Support.V4.App.FragmentTransaction transaction)
        {
            var currentFrag = SupportFragmentManager.FindFragmentById(Resource.Id.content_frame) as MvxFragment;

            if (currentFrag != null && fragmentInfo.ViewModelType != typeof(MenuViewModel) &&
                currentFrag.FindAssociatedViewModelType() != fragmentInfo.ViewModelType)
            {
                fragmentInfo.AddToBackStack = true;
            }
            base.OnBeforeFragmentChanging(fragmentInfo, transaction);
        }
 public SerializableMvxCachedFragmentInfo GetSerializableFragmentInfo(IMvxCachedFragmentInfo objectToSerialize)
 {
     return(new SerializableMvxCachedFragmentInfo()
     {
         Tag = objectToSerialize.Tag,
         FragmentType = objectToSerialize.FragmentType,
         ViewModelType = objectToSerialize.ViewModelType,
         ContentId = objectToSerialize.ContentId,
         AddToBackStack = objectToSerialize.AddToBackStack
     });
 }
Exemplo n.º 10
0
        public override void OnBeforeFragmentChanging(IMvxCachedFragmentInfo fragmentInfo, Android.Support.V4.App.FragmentTransaction transaction)
        {
            if (fragmentInfo.ViewModelType == typeof(AllOffersViewModel) ||
                fragmentInfo.ViewModelType == typeof(MyOffersViewModel))
            {
                transaction.SetCustomAnimations(
                    Resource.Animation.abc_fade_in,
                    Resource.Animation.slide_from_center_to_right,
                    Resource.Animation.abc_fade_in,
                    Resource.Animation.slide_from_center_to_right);
            }

            base.OnBeforeFragmentChanging(fragmentInfo, transaction);
        }
Exemplo n.º 11
0
        public override void OnBeforeFragmentChanging(IMvxCachedFragmentInfo fragmentInfo, Android.Support.V4.App.FragmentTransaction transaction)
        {
            if (fragmentInfo.ViewModelType == typeof(OffererProfileViewModel))
            {
                var avatar = FindViewById <CircleImageView>(Resource.Id.profileAvatar);
                transaction.AddSharedElement(avatar, "profileAvatar");
            }

            transaction.SetCustomAnimations(
                Resource.Animation.abc_grow_fade_in_from_bottom,
                Resource.Animation.abc_shrink_fade_out_from_bottom);

            base.OnBeforeFragmentChanging(fragmentInfo, transaction);
        }
Exemplo n.º 12
0
        public override void OnBeforeFragmentChanging(IMvxCachedFragmentInfo fragmentInfo,
                                                      FragmentTransaction transaction)
        {
            var currentFrag = SupportFragmentManager.FindFragmentById(Resource.Id.content_frame) as MvxFragment;

            if (currentFrag != null &&
                currentFrag.FindAssociatedViewModelType(typeof(MainActivity)) != fragmentInfo.ViewModelType)
            {
                fragmentInfo.AddToBackStack = true;
            }

            transaction.SetCustomAnimations(Resource.Animation.abc_fade_in,
                                            Resource.Animation.abc_fade_out);

            base.OnBeforeFragmentChanging(fragmentInfo, transaction);
        }
Exemplo n.º 13
0
        protected override FragmentReplaceMode ShouldReplaceCurrentFragment(IMvxCachedFragmentInfo newFragment, IMvxCachedFragmentInfo currentFragment, Bundle replacementBundle)
        {
            var fragInfo = newFragment as CustomFragmentInfo;

            newFragment.ContentId = Resource.Id.content_frame;

            var current     = SupportFragmentManager.FindFragmentById(Resource.Id.adminid);
            var transaction = SupportFragmentManager.BeginTransaction();


            newFragment.CachedFragment = Android.Support.V4.App.Fragment.Instantiate(this, FragmentJavaName(newFragment.FragmentType), replacementBundle) as IMvxFragmentView;

            var cache = Mvx.GetSingleton <IMvxMultipleViewModelCache> ();

            cache.GetAndClear(newFragment.ViewModelType, GetTagFromFragment(newFragment.CachedFragment as Android.Support.V4.App.Fragment));

            try {
                if (fragInfo.IsRoot)
                {
                    SupportFragmentManager.PopBackStack(null, (int)PopBackStackFlags.Inclusive);
                    transaction.Replace(newFragment.ContentId, (Android.Support.V4.App.Fragment)newFragment.CachedFragment, newFragment.Tag);
                }
                else
                {
                    transaction.Replace(newFragment.ContentId, (Android.Support.V4.App.Fragment)newFragment.CachedFragment, newFragment.Tag)
                    .AddToBackStack(null);
                }

                //transaction.Add (newFragment.ContentId, (Android.Support.V4.App.Fragment)newFragment.CachedFragment, newFragment.Tag)
                // .AddToBackStack (null);
                //if (current != null)
                //	transaction.Hide (current);


                transaction.Commit();
                Show(fragInfo);
            } catch (Exception ex) {
            }



            return(FragmentReplaceMode.NoReplace);
        }
Exemplo n.º 14
0
        public override void OnBeforeFragmentChanging(IMvxCachedFragmentInfo fragmentInfo, Android.Support.V4.App.FragmentTransaction transaction)
        {
            if (fragmentInfo.ViewModelType == typeof(SignupViewModel))
            {
                SupportActionBar.Show();

                transaction.SetCustomAnimations(
                    Resource.Animation.abc_grow_fade_in_from_bottom,
                    Resource.Animation.abc_shrink_fade_out_from_bottom,
                    Resource.Animation.abc_grow_fade_in_from_bottom,
                    Resource.Animation.abc_shrink_fade_out_from_bottom)
                .AddToBackStack(null);
            }
            else
            {
                SupportActionBar.Hide();
            }

            base.OnBeforeFragmentChanging(fragmentInfo, transaction);
        }
Exemplo n.º 15
0
 protected virtual void ReplaceFragment(FragmentTransaction ft, IMvxCachedFragmentInfo fragInfo)
 {
     ft.Replace(fragInfo.ContentId, fragInfo.CachedFragment as Fragment, fragInfo.Tag);
 }
Exemplo n.º 16
0
 protected virtual void ReplaceFragment(FragmentTransaction ft, IMvxCachedFragmentInfo fragInfo)
 {
     ft.Replace(fragInfo.ContentId, fragInfo.CachedFragment as Android.Support.V4.App.Fragment, fragInfo.Tag);
 }
        protected virtual FragmentReplaceMode ShouldReplaceCurrentFragment(IMvxCachedFragmentInfo newFragment, IMvxCachedFragmentInfo currentFragment, Bundle replacementBundle)
        {
            var oldBundle = newFragment.CachedFragment?.Arguments;
            if (oldBundle == null) return FragmentReplaceMode.ReplaceFragment;

            var serializer = Mvx.Resolve<IMvxNavigationSerializer>();

            var json = oldBundle.GetString(MvxFragmentsPresenter.ViewModelRequestBundleKey);
            var oldRequest = serializer.Serializer.DeserializeObject<MvxViewModelRequest>(json);
            if (oldRequest == null) return FragmentReplaceMode.ReplaceFragment;

            json = replacementBundle.GetString(MvxFragmentsPresenter.ViewModelRequestBundleKey);
            var replacementRequest = serializer.Serializer.DeserializeObject<MvxViewModelRequest>(json);
            if (replacementRequest == null) return FragmentReplaceMode.ReplaceFragment;

            var areParametersEqual = ((oldRequest.ParameterValues == replacementRequest.ParameterValues) ||
                (oldRequest.ParameterValues.Count == replacementRequest.ParameterValues.Count &&
                    !oldRequest.ParameterValues.Except(replacementRequest.ParameterValues).Any()));

            if (currentFragment?.Tag != newFragment.Tag)
            {
                return !areParametersEqual
                    ? FragmentReplaceMode.ReplaceFragmentAndViewModel
                        : FragmentReplaceMode.ReplaceFragment;
            }
            else
                return !areParametersEqual
                    ? FragmentReplaceMode.ReplaceFragmentAndViewModel
                        : FragmentReplaceMode.NoReplace;
        }
 protected virtual void ReplaceFragment(FragmentTransaction ft, IMvxCachedFragmentInfo fragInfo)
 {
     ft.Replace(fragInfo.ContentId, fragInfo.CachedFragment, fragInfo.Tag);
 }
 public virtual void OnFragmentCreated(IMvxCachedFragmentInfo fragmentInfo, FragmentTransaction transaction)
 {
 }
 // Called before the transaction is commited
 public virtual void OnFragmentChanging(IMvxCachedFragmentInfo fragmentInfo, FragmentTransaction transaction)
 {
 }
 public virtual void OnFragmentChanged(IMvxCachedFragmentInfo fragmentInfo)
 {
 }
 public override void OnFragmentChanged(IMvxCachedFragmentInfo fragmentInfo)
 {
     currentFragmentInfo = fragmentInfo as CustomFragmentInfo;
 }
Exemplo n.º 23
0
        /// <summary>
        ///     Show Fragment with a specific tag at a specific placeholder
        /// </summary>
        /// <param name="tag">The tag for the fragment to lookup</param>
        /// <param name="contentId">Where you want to show the Fragment</param>
        /// <param name="bundle">Bundle which usually contains a Serialized MvxViewModelRequest</param>
        /// <param name="forceAddToBackStack">If you want to force add the fragment to the backstack so on backbutton it will go back to it. Note: This will override IMvxCachedFragmentInfo.AddToBackStack configuration.</param>
        /// <param name="forceReplaceFragment">If you want the fragment to be re-created</param>
        protected virtual void ShowFragment(string tag, int contentId, Bundle bundle, bool forceAddToBackStack = false, bool forceReplaceFragment = false)
        {
            IMvxCachedFragmentInfo fragInfo;

            FragmentCacheConfiguration.TryGetValue(tag, out fragInfo);

            IMvxCachedFragmentInfo currentFragInfo = null;
            var currentFragment = FragmentManager.FindFragmentById(contentId);

            if (currentFragment != null)
            {
                FragmentCacheConfiguration.TryGetValue(currentFragment.Tag, out currentFragInfo);
            }

            if (fragInfo == null)
            {
                throw new MvxException("Could not find tag: {0} in cache, you need to register it first.", tag);
            }

            // We shouldn't replace the current fragment unless we really need to.
            FragmentReplaceMode fragmentReplaceMode = FragmentReplaceMode.ReplaceFragmentAndViewModel;

            if (!forceReplaceFragment)
            {
                fragmentReplaceMode = ShouldReplaceCurrentFragment(fragInfo, currentFragInfo, bundle);
            }

            if (fragmentReplaceMode == FragmentReplaceMode.NoReplace)
            {
                return;
            }

            var ft = FragmentManager.BeginTransaction();

            OnBeforeFragmentChanging(fragInfo, ft);

            fragInfo.ContentId = contentId;

            //If we already have a previously created fragment, we only need to send the new parameters
            if (fragInfo.CachedFragment != null && fragmentReplaceMode == FragmentReplaceMode.ReplaceFragment)
            {
                (fragInfo.CachedFragment as Fragment).Arguments.Clear();
                (fragInfo.CachedFragment as Fragment).Arguments.PutAll(bundle);
            }
            else
            {
                //Otherwise, create one and cache it
                fragInfo.CachedFragment = Fragment.Instantiate(this, FragmentJavaName(fragInfo.FragmentType),
                                                               bundle) as IMvxFragmentView;
                OnFragmentCreated(fragInfo, ft);
            }

            currentFragment = fragInfo.CachedFragment as Fragment;
            ft.Replace(fragInfo.ContentId, fragInfo.CachedFragment as Fragment, fragInfo.Tag);

            //if replacing ViewModel then clear the cache after the fragment
            //has been added to the transaction so that the Tag property is not null
            //and the UniqueImmutableCacheTag property (if not overridden) has the correct value
            if (fragmentReplaceMode == FragmentReplaceMode.ReplaceFragmentAndViewModel)
            {
                var cache = Mvx.GetSingleton <IMvxMultipleViewModelCache>();
                cache.GetAndClear(fragInfo.ViewModelType, GetTagFromFragment(fragInfo.CachedFragment as Fragment));
            }

            if ((currentFragment != null && fragInfo.AddToBackStack) || forceAddToBackStack)
            {
                ft.AddToBackStack(fragInfo.Tag);
            }

            OnFragmentChanging(fragInfo, ft);
            ft.Commit();
            FragmentManager.ExecutePendingTransactions();
            OnFragmentChanged(fragInfo);
        }
Exemplo n.º 24
0
 public virtual void OnFragmentChanged(IMvxCachedFragmentInfo fragmentInfo)
 {
 }
Exemplo n.º 25
0
 // Called before the transaction is commited
 public virtual void OnFragmentChanging(IMvxCachedFragmentInfo fragmentInfo, FragmentTransaction transaction)
 {
 }
Exemplo n.º 26
0
 public bool TryGetValue(string registeredFragmentTag, out IMvxCachedFragmentInfo cachedFragmentInfo)
 {
     return(_lookup.TryGetValue(registeredFragmentTag, out cachedFragmentInfo));
 }
Exemplo n.º 27
0
 public virtual void OnFragmentCreated(IMvxCachedFragmentInfo fragmentInfo, FragmentTransaction transaction)
 {
 }
        public override void OnFragmentChanged(IMvxCachedFragmentInfo fragmentInfo)
        {
            var myCustomInfo = fragmentInfo as CustomFragmentInfo;

            CheckIfMenuIsNeeded(myCustomInfo);
        }