Esempio n. 1
0
        public virtual void EnsureInitialized()
        {
            lock (LockObject)
            {
                if (_initialized)
                {
                    return;
                }

                if (IsInitialisedTaskCompletionSource != null)
                {
                    Mvx.Trace("EnsureInitialized has already been called so now waiting for completion");
                    IsInitialisedTaskCompletionSource.Task.Wait();
                }
                else
                {
                    IsInitialisedTaskCompletionSource = new TaskCompletionSource <bool>();
                    _setup.Initialize();
                    _initialized = true;

                    if (_currentSplashScreen != null)
                    {
                        Mvx.Warning("Current splash screen not null during direct initialization - not sure this should ever happen!");
                        var dispatcher = Mvx.GetSingleton <IMvxMainThreadDispatcher>();
                        dispatcher.RequestMainThreadAction(() =>
                        {
                            _currentSplashScreen?.InitializationComplete();
                        }, false);
                    }

                    IsInitialisedTaskCompletionSource.SetResult(true);
                }
            }
        }
Esempio n. 2
0
        public void CreateBindings(object sender, DependencyPropertyChangedEventArgs args,
                                   Func <string, IEnumerable <MvxBindingDescription> > parseBindingDescriptions)
        {
            var attachedObject = sender as FrameworkElement;

            if (attachedObject == null)
            {
                Mvx.Warning("Null attached FrameworkElement seen in Bi.nd binding");
                return;
            }

            var text = args.NewValue as string;

            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            var bindingDescriptions = parseBindingDescriptions(text);

            if (bindingDescriptions == null)
            {
                return;
            }

            ApplyBindings(attachedObject, bindingDescriptions);
        }
        public override void Close(IMvxViewModel viewModel)
        {
            var currentView = _rootFrame.Content as IMvxView;

            if (currentView == null)
            {
                Mvx.Warning("Ignoring close for viewmodel - rootframe has no current page");
                return;
            }

            if (currentView.ViewModel != viewModel)
            {
                Mvx.Warning("Ignoring close for viewmodel - rootframe's current page is not the view for the requested viewmodel");
                return;
            }

            if (!_rootFrame.CanGoBack)
            {
                Mvx.Warning("Ignoring close for viewmodel - rootframe refuses to go back");
                return;
            }

            _rootFrame.GoBack();

            HandleBackButtonVisibility();
        }
        protected virtual void InjectProperty(object toReturn, PropertyInfo injectableProperty, IMvxPropertyInjectorOptions options)
        {
            object propertyValue;

            if (Mvx.TryResolve(injectableProperty.PropertyType, out propertyValue))
            {
                try
                {
                    injectableProperty.SetValue(toReturn, propertyValue, null);
                }
                catch (TargetInvocationException invocation)
                {
                    throw new MvxIoCResolveException(invocation, "Failed to inject into {0} on {1}", injectableProperty.Name, toReturn.GetType().Name);
                }
            }
            else
            {
                if (options.ThrowIfPropertyInjectionFails)
                {
                    throw new MvxIoCResolveException("IoC property injection failed for {0} on {1}", injectableProperty.Name, toReturn.GetType().Name);
                }
                else
                {
                    Mvx.Warning("IoC property injection skipped for {0} on {1}", injectableProperty.Name, toReturn.GetType().Name);
                }
            }
        }
        protected static BindingMode ConvertMode(MvxBindingMode mode, Type propertyType)
        {
            switch (mode)
            {
            case MvxBindingMode.Default:
                // if we return TwoWay for ImageSource then we end up in
                // problems with WP7 not doing the auto-conversion
                // see some of my angst in http://stackoverflow.com/questions/16752242/how-does-xaml-create-the-string-to-bitmapimage-value-conversion-when-binding-to/16753488#16753488
                // Note: if we discover other issues here, then we should make a more flexible solution
                if (propertyType == typeof(ImageSource))
                {
                    return(BindingMode.OneWay);
                }

                return(BindingMode.TwoWay);

            case MvxBindingMode.TwoWay:
                return(BindingMode.TwoWay);

            case MvxBindingMode.OneWay:
                return(BindingMode.OneWay);

            case MvxBindingMode.OneTime:
                return(BindingMode.OneTime);

            case MvxBindingMode.OneWayToSource:
                Mvx.Warning("WinPhone doesn't support OneWayToSource");
                return(BindingMode.TwoWay);

            default:
                throw new ArgumentOutOfRangeException(nameof(mode));
            }
        }
Esempio n. 6
0
        public void CreateBindings(object sender,
                                   object oldValue,
                                   object newValue,
                                   Func <string, IEnumerable <MvxBindingDescription> > parseBindingDescriptions)
        {
            var attachedObject = sender as Element;

            if (attachedObject == null)
            {
                Mvx.Warning("Null attached Element seen in Bi.nd binding");
                return;
            }

            var text = newValue as string;

            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            var bindingDescriptions = parseBindingDescriptions(text);

            if (bindingDescriptions == null)
            {
                return;
            }

            ApplyBindings(attachedObject, bindingDescriptions);
        }
Esempio n. 7
0
 private void SetCurrentlyActive()
 {
     if (_currentlyActive)
     {
         Mvx.Warning("MvxImagePickerTask called when task already active");
     }
     _currentlyActive = true;
 }
Esempio n. 8
0
 private void ClearCurrentlyActive()
 {
     if (!_currentlyActive)
     {
         Mvx.Warning("Tried to clear currently active - but already cleared");
     }
     _currentlyActive = false;
 }
Esempio n. 9
0
 public virtual void ReloadTableData()
 {
     try
     {
         this._tableView.ReloadData();
     }
     catch (Exception exception)
     {
         Mvx.Warning("Exception masked during TableView ReloadData {0}", exception.ToLongString());
     }
 }
Esempio n. 10
0
 public virtual void ReloadData()
 {
     try
     {
         _collectionView.ReloadData();
     }
     catch (Exception exception)
     {
         Mvx.Warning("Exception masked during CollectionView ReloadData {0}", exception.ToString());
     }
 }
Esempio n. 11
0
 protected virtual void RealNotifyDataSetChanged()
 {
     try
     {
         base.NotifyDataSetChanged();
     }
     catch (Exception exception)
     {
         Mvx.Warning("Exception masked during Adapter RealNotifyDataSetChanged {0}", exception.ToLongString());
     }
 }
        protected override void PlatformSpecificStart(MvxLocationOptions options)
        {
            lock (this)
            {
                if (_locationManager != null)
                {
                    throw new MvxException("You cannot start the MvxLocation service more than once");
                }

                _locationManager          = new CLLocationManager();
                _locationManager.Delegate = new LocationDelegate(this);

                if (options.MovementThresholdInM > 0)
                {
                    _locationManager.DistanceFilter = options.MovementThresholdInM;
                }
                else
                {
                    _locationManager.DistanceFilter = CLLocationDistance.FilterNone;
                }
                _locationManager.DesiredAccuracy = options.Accuracy == MvxLocationAccuracy.Fine ? CLLocation.AccuracyBest : CLLocation.AccuracyKilometer;
                if (options.TimeBetweenUpdates > TimeSpan.Zero)
                {
                    Mvx.Warning("TimeBetweenUpdates specified for MvxLocationOptions - but this is not supported in iOS");
                }


                if (options.TrackingMode == MvxLocationTrackingMode.Background)
                {
                    if (IsIOS8orHigher)
                    {
                        _locationManager.RequestAlwaysAuthorization();
                    }
                    else
                    {
                        Mvx.Warning("MvxLocationTrackingMode.Background is not supported for iOS before 8");
                    }
                }
                else
                {
                    if (IsIOS8orHigher)
                    {
                        _locationManager.RequestWhenInUseAuthorization();
                    }
                }

                if (CLLocationManager.HeadingAvailable)
                {
                    _locationManager.StartUpdatingHeading();
                }

                _locationManager.StartUpdatingLocation();
            }
        }
Esempio n. 13
0
        private static TFragment SafeCast <TFragment>(Fragment fragment) where TFragment : Fragment
        {
            if (!(fragment is TFragment))
            {
                Mvx.Warning("Fragment type mismatch got {0} but expected {1}", fragment.GetType().FullName,
                            typeof(TFragment).FullName);
                return(default(TFragment));
            }

            return((TFragment)fragment);
        }
Esempio n. 14
0
        /// <summary>
        /// Register your ViewModel to be presented at a IMvxFragmentHost. Backingstore for this is a
        /// Dictionary, hence you can only have a ViewModel registered at one IMvxFragmentHost at a time.
        /// Just call this method whenever you need to change the host.
        /// </summary>
        /// <typeparam name="TViewModel">Type of the ViewModel to present</typeparam>
        /// <param name="host">Which IMvxFragmentHost (Activity) to present it at</param>
        public void RegisterViewModelAtHost <TViewModel>(IMvxFragmentHost host)
            where TViewModel : IMvxViewModel
        {
            if (host == null)
            {
                Mvx.Warning("You passed a null IMvxFragmentHost, removing the registration instead");
                UnRegisterViewModelAtHost <TViewModel>();
            }

            _dictionary[typeof(TViewModel)] = host;
        }
Esempio n. 15
0
        public static void LoadViewModelFrom(this IMvxFragmentView view, MvxViewModelRequest request, IMvxBundle savedState = null)
        {
            var loader    = Mvx.Resolve <IMvxViewModelLoader>();
            var viewModel = loader.LoadViewModel(request, savedState);

            if (viewModel == null)
            {
                Mvx.Warning("ViewModel not loaded for {0}", request.ViewModelType.FullName);
                return;
            }

            view.ViewModel = viewModel;
        }
Esempio n. 16
0
        public static TFragment FindFragmentByTag <TFragment>(this Views.MvxActivity activity, string tag)
            where TFragment : Fragment
        {
            var fragment = activity.FragmentManager.FindFragmentByTag(tag);

            if (fragment == null)
            {
                Mvx.Warning("Failed to find fragment tag {0} in {1}", tag, activity.GetType().Name);
                return(default(TFragment));
            }

            return(SafeCast <TFragment>(fragment));
        }
Esempio n. 17
0
        public static TFragment FindFragmentById <TFragment>(this Views.MvxActivity activity, int resourceId)
            where TFragment : Fragment
        {
            var fragment = activity.FragmentManager.FindFragmentById(resourceId);

            if (fragment == null)
            {
                Mvx.Warning("Failed to find fragment id {0} in {1}", resourceId, activity.GetType().Name);
                return(default(TFragment));
            }

            return(SafeCast <TFragment>(fragment));
        }
Esempio n. 18
0
 protected virtual void RealNotifyDataSetChanged()
 {
     try
     {
         base.NotifyDataSetChanged();
     }
     catch (Exception exception)
     {
         Mvx.Warning(
             "Exception masked during Adapter RealNotifyDataSetChanged {0}. Are you trying to update your collection from a background task? See http://goo.gl/0nW0L6",
             exception.ToLongString());
     }
 }
Esempio n. 19
0
        public void Execute(object parameter = null)
        {
            if (_wrapped == null)
            {
                return;
            }

            if (parameter != null)
            {
                Mvx.Warning("Non-null parameter overridden in MvxWrappingCommand");
            }
            _wrapped.Execute(_commandParameterOverride);
        }
        private static bool ReadIsTvosVersionOrHigher(int target, bool defaultValue)
        {
            IMvxTvosSystem touchSystem;

            Mvx.TryResolve <IMvxTvosSystem>(out touchSystem);
            if (touchSystem == null)
            {
                Mvx.Warning("IMvxTvosSystem not found - so assuming we {1} on tvOS {0} or later", target, defaultValue ? "are" : "are not");
                return(defaultValue);
            }

            return(touchSystem.Version.Major >= target);
        }
Esempio n. 21
0
 public static IEnumerable <Type> ExceptionSafeGetTypes(this Assembly assembly)
 {
     try
     {
         return(assembly.GetTypes());
     }
     catch (ReflectionTypeLoadException e)
     {
         Mvx.Warning("ReflectionTypeLoadException masked during loading of {0} - error {1}",
                     assembly.FullName, e.ToLongString());
         return(new Type[0]);
     }
 }
Esempio n. 22
0
        protected virtual void BackButtonOnBackRequested(object sender, BackRequestedEventArgs backRequestedEventArgs)
        {
            var currentView = _rootFrame.Content as IMvxView;

            if (currentView == null)
            {
                Mvx.Warning("Ignoring close for viewmodel - rootframe has no current page");
                return;
            }

            var navigationService = Mvx.Resolve <IMvxNavigationService>();

            navigationService.Close(currentView.ViewModel);
        }
Esempio n. 23
0
 public override void OnLayoutChildren(Android.Support.V7.Widget.RecyclerView.Recycler recycler,
                                       Android.Support.V7.Widget.RecyclerView.State state)
 {
     try
     {
         base.OnLayoutChildren(recycler, state);
     }
     catch (IndexOutOfBoundsException e)
     {
         Mvx.Warning(
             "Workaround of issue - https://code.google.com/p/android/issues/detail?id=77846#c1 - IndexOutOfBoundsException " +
             e.Message);
     }
 }
Esempio n. 24
0
        public bool CanExecute(object parameter = null)
        {
            if (_wrapped == null)
            {
                return(false);
            }

            if (parameter != null)
            {
                Mvx.Warning("Non-null parameter will be ignored in MvxWrappingCommand.CanExecute");
            }

            return(_wrapped.CanExecute(_commandParameterOverride));
        }
Esempio n. 25
0
 private static void SetTextInputLayoutControlColor(TextInputLayout textInputLayoutControl, ColorStateList textHintColor)
 {
     try
     {
         var defaultTextColor = Java.Lang.Class.FromType(typeof(TextInputLayout)).GetDeclaredField("mDefaultTextColor");
         defaultTextColor.Accessible = true;
         defaultTextColor.Set(textInputLayoutControl, textHintColor);
         var focusedTextColor = Java.Lang.Class.FromType(typeof(TextInputLayout)).GetDeclaredField("mFocusedTextColor");
         focusedTextColor.Accessible = true;
         focusedTextColor.Set(textInputLayoutControl, textHintColor);
     }
     catch (Exception e)
     {
         Mvx.Warning($"Failed to use reflection to set the hint color :{e.Message}");
     }
 }
 protected virtual void SetCookieContainer(MvxRestRequest restRequest, HttpWebRequest httpRequest)
 {
     // note that we don't call
     //   httpRequest.SupportsCookieContainer
     // here - this is because Android complained about this...
     try
     {
         if (restRequest.CookieContainer != null)
         {
             httpRequest.CookieContainer = restRequest.CookieContainer;
         }
     }
     catch (Exception exception)
     {
         Mvx.Warning("Error masked during Rest call - cookie creation - {0}", exception.ToLongString());
     }
 }
Esempio n. 27
0
 protected static void ReplaceFont(string staticTypefaceFieldName, Typeface newTypeface)
 {
     try
     {
         var staticField = Class.FromType(typeof(Typeface)).GetDeclaredField(staticTypefaceFieldName);
         staticField.Accessible = true;
         staticField.Set(null, newTypeface);
     }
     catch (NoSuchFieldException e)
     {
         Mvx.Warning(e.Message);
     }
     catch (IllegalAccessException e)
     {
         Mvx.Warning(e.Message);
     }
 }
        private void TryChangeViewPresentation(ChangePresentationHint hint)
        {
            var view = CurrentTopViewController as IChangePresentation;

            if (view != null)
            {
                view.ChangePresentation(hint);
                foreach (var subview in CurrentTopViewController.View.FindSubviewsOfType <IChangePresentation>())
                {
                    subview.ChangePresentation(hint);
                }
            }
            else
            {
                Mvx.Warning("Can't change presentation, view controller doesn't support IChangePresentation");
            }
        }
        private void RemovePreviousViewFromHistory()
        {
            var navController = Mvx.Resolve <UINavigationController>();

            var controllers = navController.ViewControllers;

            if (controllers.Length > 1)
            {
                var listOfControllers = new List <UIViewController>(controllers);
                listOfControllers.RemoveAt(listOfControllers.Count - 2);
                navController.ViewControllers = listOfControllers.ToArray();
            }
            else
            {
                Mvx.Warning("Can't remove previous view, not enough UIViewControllers in the stack");
            }
        }
        public override void Show(IMvxIosView view)
        {
            if (view is IMvxModalIosView)
            {
                PresentModalViewController(view as UIViewController, true);
                return;
            }

            var viewController = view as UIViewController;

            if (viewController == null)
            {
                throw new MvxException("Passed in IMvxIosView is not a UIViewController");
            }

            if (this.RootViewController == null)
            {
                this.InitRootViewController();
            }

            var viewPresentationAttribute = GetViewPresentationAttribute(view);

            //Create fall back viewPresentationAttribute, when nothing is set
            if (viewPresentationAttribute == null)
            {
                Mvx.Warning("No " + nameof(MvxPanelPresentationAttribute) + " has been set, each viewcontroller should provide one.");
                viewPresentationAttribute = new MvxPanelPresentationAttribute(MvxPanelEnum.Center, MvxPanelHintType.ActivePanel, true);
            }

            switch (viewPresentationAttribute.HintType)
            {
            case MvxPanelHintType.PopToRoot:
                ChangePresentation(new MvxSidebarPopToRootPresentationHint(viewPresentationAttribute.Panel, RootViewController, viewController));
                break;

            case MvxPanelHintType.ResetRoot:
                ChangePresentation(new MvxSidebarResetRootPresentationHint(viewPresentationAttribute.Panel, RootViewController, viewController));
                break;

            case MvxPanelHintType.ActivePanel:
            default:
                ChangePresentation(new MvxSidebarActivePanelPresentationHint(viewPresentationAttribute.Panel, RootViewController, viewController));
                break;
            }
        }