Exemplo n.º 1
0
        /// <summary>
        /// Performs forward navigation from the <paramref name="sourceView"/> to the target one with provided <paramref name="parameters"/> and receiving a result when it finished.
        /// </summary>
        /// <typeparam name="TTargetView">The type of the target view.</typeparam>
        /// <typeparam name="TParameters">The type of the target view model parameters.</typeparam>
        /// <typeparam name="TResult">The type of the target view model result.</typeparam>
        /// <param name="sourceView">The source view from which navigation is performed from.</param>
        /// <param name="parameters">The target view model parameters.</param>
        /// <param name="navigationStrategy">The strategy used for performing navigation. Default is <see cref="ForwardNavigationStrategy.StartActivityForResult(Android.OS.Bundle)"/>.</param>
        /// <exception cref="ArgumentNullException">
        ///     <para><paramref name="sourceView"/> is <c>null</c>.</para>
        ///     <para>-or-</para>
        ///     <para><see cref="Android.Support.V4.App.FragmentActivity"/> returned by <paramref name="sourceView"/> is <c>null</c>.</para>
        /// </exception>
        public void NavigateForResult <TTargetView, TParameters, TResult>(
            INavigationView <IViewModelWithResultHandler> sourceView,
            TParameters?parameters,
            ForwardNavigationDelegate?navigationStrategy = null)
            where TTargetView : Android.Support.V4.App.FragmentActivity, IView <IViewModelWithParameters <TParameters> >, INavigationView <IViewModelWithResult <TResult> >
            where TParameters : Parameters
            where TResult : Result
        {
            if (sourceView == null)
            {
                throw new ArgumentNullException(nameof(sourceView));
            }

            var context = sourceView.GetActivity();

            if (context == null)
            {
                throw new ArgumentNullException("View's activity is 'null'.", nameof(sourceView));
            }

            var intent = new Intent(context, typeof(TTargetView));

            intent.PutParameters(parameters);
            var requestCode = sourceView.RequestCode.GetFor <DefaultResultMapper <TResult> >();

            (navigationStrategy ?? NavigationStrategy.Forward.StartActivityForResult()).Invoke(sourceView, intent, requestCode);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Performs forward navigation from the <paramref name="sourceView"/> to the target one with the provided lifecycle-aware view model <paramref name="parameters"/>
        /// and handling a lifecycle-aware view model result when it finished.
        /// </summary>
        /// <typeparam name="TTargetView">The type of the target view.</typeparam>
        /// <typeparam name="TParameters">The type of the target view model parameters.</typeparam>
        /// <typeparam name="TResult">The type of the target view model result.</typeparam>
        /// <param name="sourceView">The source navigation view from which navigation is performed from.</param>
        /// <param name="parameters">The target view model parameters. Can be <see langword="null"/>.</param>
        /// <param name="navigationStrategy">
        /// The strategy used for performing navigation. Can be <see langword="null"/>.
        /// <para>The default is <see cref="ForwardNavigationStrategy.StartActivityForResult(Bundle?)"/>.</para>
        /// </param>
        /// <exception cref="ArgumentNullException"><paramref name="sourceView"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentException">
        /// The <paramref name="sourceView" /> is derived from a class other than the <see cref="FragmentActivity"/> or <see cref="Fragment"/>.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// <see cref="NavigationViewExtensions.GetActivity(INavigationView{ILifecycleViewModel})"/> returned <see langword="null"/> value for the provided <paramref name="sourceView"/>.
        /// </exception>
        public void NavigateForResult <TTargetView, TParameters, TResult>(
            INavigationView <ILifecycleViewModelWithResultHandler> sourceView,
            TParameters?parameters,
            ForwardNavigationDelegate?navigationStrategy = null)
            where TTargetView : FragmentActivity, INavigationView <ILifecycleViewModelWithParameters <TParameters> >, INavigationView <ILifecycleViewModelWithResult <TResult> >
            where TParameters : Parameters
            where TResult : Result
        {
            if (sourceView == null)
            {
                throw new ArgumentNullException(nameof(sourceView));
            }

            var context = sourceView.GetActivity();

            if (context == null)
            {
                throw new InvalidOperationException(
                          $"'{TypeFormatter.FormatName(sourceView.GetType())}.{nameof(NavigationViewExtensions.GetActivity)}' returned 'null' value.");
            }

            var targetViewIntent = new Intent(context, typeof(TTargetView));

            targetViewIntent.PutParameters(parameters);
            var requestCode = sourceView.RequestCode.GetFor <DefaultResultMapper <TResult> >();

            (navigationStrategy ?? NavigationStrategy.Forward.StartActivityForResult()).Invoke(sourceView, targetViewIntent, requestCode);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Performs forward navigation from the <paramref name="sourceView"/> to the target one.
        /// </summary>
        /// <typeparam name="TTargetView">The type of the target view.</typeparam>
        /// <param name="sourceView">The source view from which navigation is performed from.</param>
        /// <param name="navigationStrategy">The strategy used for performing navigation. Default is <see cref="ForwardNavigationStrategy.StartActivity(Android.OS.Bundle)"/>.</param>
        /// <exception cref="ArgumentNullException">
        ///     <para><paramref name="sourceView"/> is <c>null</c>.</para>
        ///     <para>-or-</para>
        ///     <para><see cref="Android.Support.V4.App.FragmentActivity"/> returned by <paramref name="sourceView"/> is <c>null</c>.</para>
        /// </exception>
        public void Navigate <TTargetView>(
            [NotNull] INavigationView <IViewModel> sourceView,
            [CanBeNull] ForwardNavigationDelegate navigationStrategy = null)
            where TTargetView : Android.Support.V4.App.FragmentActivity, IView <IViewModel>
        {
            if (sourceView == null)
            {
                throw new ArgumentNullException(nameof(sourceView));
            }

            var context = sourceView.GetActivity();

            if (context == null)
            {
                throw new ArgumentNullException("View's activity is 'null'.", nameof(sourceView));
            }

            var intent = new Intent(context, typeof(TTargetView));

            (navigationStrategy ?? NavigationStrategy.Forward.StartActivity()).Invoke(sourceView, intent);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Performs forward navigation from the <paramref name="sourceView"/> to the target one.
        /// </summary>
        /// <typeparam name="TTargetView">The type of the target view.</typeparam>
        /// <param name="sourceView">The source navigation view from which navigation is performed from.</param>
        /// <param name="navigationStrategy">
        /// The strategy used for performing navigation. Can be <see langword="null"/>.
        /// <para>The default is <see cref="ForwardNavigationStrategy.StartActivity(Bundle?)"/>.</para>
        /// </param>
        /// <exception cref="ArgumentNullException"><paramref name="sourceView"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentException">
        /// The <paramref name="sourceView" /> is derived from a class other than the <see cref="FragmentActivity"/> or <see cref="Fragment"/>.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// <see cref="NavigationViewExtensions.GetActivity(INavigationView{ILifecycleViewModel})"/> returned <see langword="null"/> value for the provided <paramref name="sourceView"/>.
        /// </exception>
        public void Navigate <TTargetView>(
            INavigationView <ILifecycleViewModel> sourceView,
            ForwardNavigationDelegate?navigationStrategy = null)
            where TTargetView : FragmentActivity
        {
            if (sourceView == null)
            {
                throw new ArgumentNullException(nameof(sourceView));
            }

            var context = sourceView.GetActivity();

            if (context == null)
            {
                throw new InvalidOperationException(
                          $"'{TypeFormatter.FormatName(sourceView.GetType())}.{nameof(NavigationViewExtensions.GetActivity)}' returned 'null' value.");
            }

            var targetViewIntent = new Intent(context, typeof(TTargetView));

            (navigationStrategy ?? NavigationStrategy.Forward.StartActivity()).Invoke(sourceView, targetViewIntent, RequestCode.InvalidRequestCode);
        }