public static void NavigateForResult <TActivity, TParameters, TResult>(
            [NotNull] this NavigationServiceBase navigationService,
            [NotNull] IAndroidView <IViewModelWithResultHandler> fromView,
            [CanBeNull] TParameters parameters,
            [CanBeNull] ForwardNavigationDelegate navigationStrategy = null)
            where TActivity : Activity, IActivityView <IViewModelWithParameters <TParameters> >, IActivityView <IViewModelWithResult <TResult> >
            where TParameters : ViewModelParametersBase
            where TResult : ViewModelResultBase
        {
            if (navigationService == null)
            {
                throw new ArgumentNullException(nameof(navigationService));
            }
            if (fromView == null)
            {
                throw new ArgumentNullException(nameof(fromView));
            }

            var activity           = fromView.GetActivity();
            var targetActivityType = typeof(TActivity);
            var intent             = new Intent(activity, targetActivityType);

            intent.PutViewModelParameters(parameters);
            var requestCode = RequestCode.Get <TResult>(activity, targetActivityType);

            (navigationStrategy ?? NavigationStrategy.Forward.Default()).Invoke(fromView, requestCode, intent);
        }
Exemplo n.º 2
0
        internal static IAndroidView <IViewModel> FindParentViewWithModel([NotNull] this IAndroidView view)
        {
            IAndroidView <IViewModel> parentView = null;

            if (view is Android.Support.V4.App.Fragment appCompatFragment)
            {
                parentView = FindParentViewWithModel(appCompatFragment);
            }
            else if (view is Fragment fragment)
            {
                parentView = FindParentViewWithModel(fragment);
            }

            return(parentView);
        }
Exemplo n.º 3
0
        private static IAndroidView <IViewModel> FindParentViewWithModel([NotNull] Fragment fragment)
        {
            IAndroidView <IViewModel> parentView = null;
            var parentFragment = fragment.ParentFragment;

            while (parentView == null && parentFragment != null)
            {
                parentView     = parentFragment as IAndroidView <IViewModel>;
                parentFragment = parentFragment.ParentFragment;
            }

            if (parentView == null)
            {
                parentView = fragment.Activity as IAndroidView <IViewModel>;
            }

            return(parentView);
        }
        public static void Navigate <TActivity>(
            [NotNull] this NavigationServiceBase navigationService,
            [NotNull] IAndroidView fromView,
            [CanBeNull] ForwardNavigationDelegate navigationStrategy = null)
            where TActivity : Activity, IActivityView <IViewModelWithoutParameters>
        {
            if (navigationService == null)
            {
                throw new ArgumentNullException(nameof(navigationService));
            }
            if (fromView == null)
            {
                throw new ArgumentNullException(nameof(fromView));
            }

            var activity           = fromView.GetActivity();
            var targetActivityType = typeof(TActivity);
            var intent             = new Intent(activity, targetActivityType);

            (navigationStrategy ?? NavigationStrategy.Forward.Default()).Invoke(fromView, null, intent);
        }
        public static void Navigate(
            [NotNull] this NavigationServiceBase navigationService,
            [NotNull] IAndroidView fromView,
            [NotNull] Type toViewType,
            [CanBeNull] ForwardNavigationDelegate navigationStrategy = null)
        {
            if (navigationService == null)
            {
                throw new ArgumentNullException(nameof(navigationService));
            }
            if (fromView == null)
            {
                throw new ArgumentNullException(nameof(fromView));
            }
            if (toViewType == null)
            {
                throw new ArgumentNullException(nameof(toViewType));
            }

            var activity = fromView.GetActivity();
            var intent   = new Intent(activity, toViewType);

            (navigationStrategy ?? NavigationStrategy.Forward.Default()).Invoke(fromView, null, intent);
        }
Exemplo n.º 6
0
        public static Activity GetActivity([NotNull] this IAndroidView view)
        {
            if (view == null)
            {
                throw new System.ArgumentNullException(nameof(view));
            }

            Activity parentActivityOrSelf = null;

            if (view is Activity activity)
            {
                parentActivityOrSelf = activity;
            }
            else if (view is Android.Support.V4.App.Fragment appCompatFragment)
            {
                parentActivityOrSelf = appCompatFragment.Activity;
            }
            else if (view is Fragment fragment)
            {
                parentActivityOrSelf = fragment.Activity;
            }

            return(parentActivityOrSelf);
        }