示例#1
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);
        }
示例#2
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);
        }