Exemple #1
0
        private static void OnLifetimeEvent(this IMvxAndroidView androidView,
                                            Action <IMvxAndroidActivityLifetimeListener, Activity> report)
        {
            var activityTracker = Mvx.IoCProvider.Resolve <IMvxAndroidActivityLifetimeListener>();

            report(activityTracker, androidView.ToActivity());
        }
        private static ValueTask EnsureSetupInitialized(this IMvxAndroidView androidView)
        {
            var activity = androidView.ToActivity();
            var setup    = MvxAndroidSetupSingleton.EnsureSingletonAvailable(activity.ApplicationContext);

            return(setup.EnsureInitialized());
        }
        public static void OnViewDestroy(this IMvxAndroidView androidView)
        {
            androidView.OnLifetimeEvent((listener, activity) => listener.OnDestroy(activity));
            var view = androidView as IMvxView;

            view.OnViewDestroy();
        }
Exemple #4
0
        private static void OnLifetimeEvent <TViewModel>(this IMvxAndroidView <TViewModel> androidView, Action <IMvxAndroidActivityLifetimeListener, Activity> report)
            where TViewModel : class, IMvxViewModel
        {
            var activityTracker = androidView.GetService <IMvxAndroidActivityLifetimeListener>();

            report(activityTracker, androidView.ToActivity());
        }
Exemple #5
0
        public static void OnViewDestroy <TViewModel>(this IMvxAndroidView <TViewModel> androidView)
            where TViewModel : class, IMvxViewModel
        {
            androidView.OnLifetimeEvent((listener, activity) => listener.OnDestroy(activity));
            var view = androidView as IMvxView <TViewModel>;

            view.OnViewDestroy();
        }
Exemple #6
0
 public static Intent CreateIntentFor<TTargetViewModel>(this IMvxAndroidView view,
                                                        IDictionary<string, string> parameterValues = null)
     where TTargetViewModel : class, IMvxViewModel
 {
     var parameterBundle = new MvxBundle(parameterValues);
     var request = new MvxViewModelRequest<TTargetViewModel>(parameterBundle, null);
     return view.CreateIntentFor(request);
 }
Exemple #7
0
        public static void OnViewCreate <TViewModel>(this IMvxAndroidView <TViewModel> androidView)
            where TViewModel : class, IMvxViewModel
        {
            androidView.EnsureSetupInitialized();
            androidView.OnLifetimeEvent((listener, activity) => listener.OnCreate(activity));
            var view = androidView as IMvxView <TViewModel>;

            view.OnViewCreate(() => { return(androidView.LoadViewModel()); });
        }
Exemple #8
0
        public static Activity ToActivity(this IMvxAndroidView androidView)
        {
            var activity = androidView as Activity;

            if (activity == null)
            {
                throw new MvxException("OnViewCreate called from an IMvxView which is not an Android Activity");
            }
            return(activity);
        }
        public static async ValueTask OnViewCreate(this IMvxAndroidView androidView, Bundle bundle)
        {
            androidView.OnLifetimeEvent((listener, activity) => listener.OnCreate(activity, bundle));

            var cache  = Mvx.IoCProvider.Resolve <IMvxSingleViewModelCache>();
            var cached = cache.GetAndClear(bundle);

            var view       = (IMvxView)androidView;
            var savedState = GetSavedStateFromBundle(bundle);
            await view.OnViewCreate(async() => cached ?? await androidView.LoadViewModel(savedState).ConfigureAwait(false)).ConfigureAwait(false);
        }
Exemple #10
0
        private static void EnsureSetupInitialized(this IMvxAndroidView androidView)
        {
            if (androidView is IMvxAndroidSplashScreenActivity)
            {
                // splash screen views manage their own setup initialization
                return;
            }

            var activity = androidView.ToActivity();
            var setup    = MvxAndroidSetupSingleton.GetOrCreateSetup(activity.ApplicationContext);

            setup.EnsureInitialized(androidView.GetType());
        }
Exemple #11
0
        private static void EnsureSetupInitialized(this IMvxAndroidView androidView)
        {
            if (androidView is IMvxSetupMonitor)
            {
                // setup monitor views manage their own setup initialization
                return;
            }

            var activity = androidView.ToActivity();
            var setup    = MvxAndroidSetupSingleton.EnsureSingletonAvailable(activity.ApplicationContext);

            setup.EnsureInitialized();
        }
Exemple #12
0
        public static void OnViewCreate(this IMvxAndroidView androidView, Bundle bundle)
        {
            androidView.EnsureSetupInitialized();
            androidView.OnLifetimeEvent((listener, activity) => listener.OnCreate(activity, bundle));

            var cache  = Mvx.IoCProvider.Resolve <IMvxSingleViewModelCache>();
            var cached = cache.GetAndClear(bundle);

            var view       = (IMvxView)androidView;
            var savedState = GetSavedStateFromBundle(bundle);

            view.OnViewCreate(() => cached ?? androidView.LoadViewModel(savedState));
        }
Exemple #13
0
        public static void OnViewNewIntent(this IMvxAndroidView androidView)
        {
            throw new MvxException("Sorry - we don't currently support OnNewIntent in MvvmCross-Android");

            /*
             * androidView.EnsureSetupInitialized();
             * androidView.OnLifetimeEvent((listener, activity) => listener.OnViewNewIntent(activity));
             *
             * var view = androidView as IMvxView;
             * MvxTrace.Warning(
             *             "OnViewNewIntent isn't well understood or tested inside MvvmCross - it's not really a cross-platform concept.");
             * view.OnViewNewIntent(() => { return androidView.LoadViewModel(null); });
             */
        }
Exemple #14
0
        public static void OnViewDestroy(this IMvxAndroidView androidView)
        {
            androidView.OnLifetimeEvent((listener, activity) => listener.OnDestroy(activity));
            var view = androidView as IMvxView;

            view.OnViewDestroy();

            var currentActivity = Mvx.IoCProvider.Resolve <IMvxAndroidCurrentTopActivity>()?.Activity;

            if (currentActivity == null && view is Activity destroyedActivity && destroyedActivity.IsFinishing && Mvx.IoCProvider.TryResolve <IMvxAppStart>(out var appStart))
            {
                appStart?.ResetStart();
            }
        }
Exemple #15
0
        private static TViewModel LoadViewModel <TViewModel>(this IMvxAndroidView <TViewModel> androidView)
            where TViewModel : class, IMvxViewModel
        {
            var activity = androidView.ToActivity();

            if (typeof(TViewModel) == typeof(MvxNullViewModel))
            {
                return(new MvxNullViewModel() as TViewModel);
            }

            var translatorService = androidView.GetService <IMvxAndroidViewModelLoader>();
            var viewModel         = translatorService.Load(activity.Intent);

            return((TViewModel)viewModel);
        }
        private static async ValueTask <IMvxViewModel?> LoadViewModel(this IMvxAndroidView androidView, IMvxBundle?savedState)
        {
            var activity = androidView.ToActivity();

            var viewModelType = androidView.FindAssociatedViewModelTypeOrNull();

            if (viewModelType == typeof(MvxNullViewModel))
            {
                return(new MvxNullViewModel());
            }

            if (viewModelType == null ||
                viewModelType == typeof(IMvxViewModel))
            {
                MvxLog.Instance.Trace("No ViewModel class specified for {0} in LoadViewModel",
                                      androidView.GetType().Name);
            }

            var translatorService = Mvx.IoCProvider.Resolve <IMvxAndroidViewModelLoader>();

            return(await translatorService.Load(activity.Intent, savedState, viewModelType).ConfigureAwait(false));
        }
        private static IMvxViewModel LoadViewModel(this IMvxAndroidView androidView, IMvxBundle savedState)
        {
            var activity = androidView.ToActivity();

            var viewModelType = androidView.FindAssociatedViewModelTypeOrNull();

            if (viewModelType == typeof(MvxNullViewModel))
            {
                return(new MvxNullViewModel());
            }

            if (viewModelType == null ||
                viewModelType == typeof(IMvxViewModel))
            {
                MvxLog.Instance.Trace("No ViewModel class specified for {0} in LoadViewModel",
                                      androidView.GetType().Name);
            }

            var translatorService = Mvx.Resolve <IMvxAndroidViewModelLoader>();
            var viewModel         = translatorService.Load(activity.Intent, savedState, viewModelType);

            return(viewModel);
        }
Exemple #18
0
 public static void OnViewNewIntent(this IMvxAndroidView androidView)
 {
     MvxLog.Instance.Trace("OnViewNewIntent called - MvvmCross lifecycle won't run automatically in this case.");
 }
        public static void OnViewNewIntent(this IMvxAndroidView androidView)
        {
#warning Should this be an exception here as we do not respond to the new intent message
            Mvx.Warning("OnViewNewIntent called - but this is not fully handled within MvvmCross currently. Check https://github.com/slodge/MvvmCross/pull/294 for more info");
            //throw new MvxException("Sorry - we don't currently support OnNewIntent in MvvmCross-Android");
        }
Exemple #20
0
 public static void OnViewPause <TViewModel>(this IMvxAndroidView <TViewModel> androidView)
     where TViewModel : class, IMvxViewModel
 {
     androidView.OnLifetimeEvent((listener, activity) => listener.OnPause(activity));
 }
 public static Intent CreateIntentFor(this IMvxAndroidView view, MvxViewModelRequest request)
 {
     return(Mvx.Resolve <IMvxAndroidViewModelRequestTranslator>().GetIntentFor(request));
 }
 public static Intent CreateIntentFor <TTargetViewModel>(this IMvxAndroidView view, object parameterObject)
     where TTargetViewModel : class, IMvxViewModel
 {
     return(view.CreateIntentFor <TTargetViewModel>(parameterObject.ToSimplePropertyDictionary()));
 }
Exemple #23
0
 public static void OnViewStop(this IMvxAndroidView androidView)
 {
     androidView.OnLifetimeEvent((listener, activity) => listener.OnStop(activity));
 }
Exemple #24
0
 public static void OnViewNewIntent(this IMvxAndroidView androidView)
 {
     MvxLogHost.Default?.Log(LogLevel.Trace, "OnViewNewIntent called - MvvmCross lifecycle won't run automatically in this case.");
 }