Esempio n. 1
0
 public MvxActionBasedTableViewSource(IntPtr handle)
     : base(handle)
 {
     MvxLogHost.GetLog <MvxActionBasedTableViewSource>().Log(LogLevel.Warning,
                                                             "MvxActionBasedTableViewSource IntPtr constructor used - we expect this only to be called during memory leak debugging - see https://github.com/MvvmCross/MvvmCross/pull/467");
     Initialize();
 }
Esempio n. 2
0
        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:
                MvxLogHost.GetLog <MvxWindowsBindingCreator>()?.Log(LogLevel.Warning,
                                                                    "WinPhone doesn't support OneWayToSource");
                return(BindingMode.TwoWay);

            default:
                throw new ArgumentOutOfRangeException(nameof(mode));
            }
        }
Esempio n. 3
0
        public MvxWindowsViewPresenter(IMvxWindowsFrame rootFrame)
        {
            _rootFrame = rootFrame;
            _logger    = MvxLogHost.GetLog <MvxWindowsViewPresenter>();

            SystemNavigationManager.GetForCurrentView().BackRequested += BackButtonOnBackRequested;
        }
Esempio n. 4
0
 private void OnMvxIntentResultReceived(object sender, MvxIntentResultEventArgs e)
 {
     MvxLogHost.GetLog <MvxAndroidTask>()?.Log(LogLevel.Trace, "OnMvxIntentResultReceived in MvxAndroidTask");
     // TODO - is this correct - should we always remove the result registration even if this isn't necessarily our result?
     Mvx.IoCProvider.Resolve <IMvxIntentResultSource>().Result -= OnMvxIntentResultReceived;
     ProcessMvxIntentResult(e);
 }
Esempio n. 5
0
        public MvxTvosViewPresenter(IUIApplicationDelegate applicationDelegate, UIWindow window)
        {
            _applicationDelegate = applicationDelegate;
            _window = window;

            _logger = MvxLogHost.GetLog <MvxTvosViewPresenter>();
        }
Esempio n. 6
0
        private void SetPrivateFactoryInternal()
        {
            if (_setPrivateFactory)
            {
                return;
            }

            if (!(Context is IFactory2))
            {
                _setPrivateFactory = true;
                return;
            }

            try
            {
                Class  layoutInflaterClass     = Class.FromType(typeof(LayoutInflater));
                Method setPrivateFactoryMethod = layoutInflaterClass.GetMethod("setPrivateFactory", Class.FromType(typeof(IFactory2)));
                setPrivateFactoryMethod.Accessible = true;
                setPrivateFactoryMethod.Invoke(this,
                                               new PrivateFactoryWrapper2((IFactory2)Context, this, _bindingVisitor));
            }
            catch (Exception ex)
            {
                MvxLogHost.GetLog <MvxLayoutInflater>()?.Log(LogLevel.Warning, ex, "Cannot invoke LayoutInflater.setPrivateFactory :\n{0}", ex.StackTrace);
            }

            _setPrivateFactory = true;
        }
Esempio n. 7
0
        public override void DestroyItem(ViewGroup container, int position, Java.Lang.Object objectValue)
        {
            var fragment = (Fragment)objectValue;

            if (_curTransaction == null)
            {
                _curTransaction = _fragmentManager.BeginTransaction();
            }

#if DEBUG
            MvxLogHost.GetLog <MvxCachingFragmentPagerAdapter>()?.Log(LogLevel.Trace,
                                                                      $"Removing item #{position}: f={objectValue} v={((Fragment)objectValue).View} t={fragment.Tag}");
#endif

            while (_savedState.Count <= position)
            {
                _savedState.Add(null);
                _savedFragmentTags.Add(null);
            }

            _savedState[position]        = fragment.IsAdded ? _fragmentManager.SaveFragmentInstanceState(fragment) : null;
            _savedFragmentTags[position] = fragment.IsAdded ? fragment.Tag : null;
            _fragments[position]         = null;

            _curTransaction.Remove(fragment);
        }
Esempio n. 8
0
            public View?OnCreateView(View?parent, string name, Context context, IAttributeSet attrs)
            {
                if (Debug)
                {
                    MvxLogHost.GetLog <MvxLayoutInflater>()?.Log(LogLevel.Trace, "{Tag} - ... OnCreateView ... {name}", DelegateFactory1Tag, name);
                }

                return(_factoryPlaceholder.OnViewCreated(
                           _factory.OnCreateView(name, context, attrs),
                           context, attrs));
            }
 public override void HandleDisposeCalled(object sender, EventArgs e)
 {
     if (TvosView == null)
     {
         MvxLogHost.GetLog <MvxBindingViewControllerAdapter>()?.Log(
             LogLevel.Warning, "{viewName} is null for clearup of bindings", nameof(TvosView));
         return;
     }
     TvosView.ClearAllBindings();
     base.HandleDisposeCalled(sender, e);
 }
Esempio n. 10
0
        public virtual async Task <bool> ChangePresentation(MvxPresentationHint hint)
        {
            if (await HandlePresentationChange(hint))
            {
                return(true);
            }

            MvxLogHost.GetLog <MvxBaseConsoleContainer>()?.Log(LogLevel.Trace,
                                                               "Hint ignored {hintType}", hint.GetType().Name);
            return(false);
        }
Esempio n. 11
0
        public override View?OnCreateView(Context viewContext, View?parent, string name, IAttributeSet?attrs)
        {
            if (Debug)
            {
                MvxLogHost.GetLog <MvxLayoutInflater>()?.Log(LogLevel.Trace, "{Tag} - ... OnCreateView 4 ... {name}", Tag, name);
            }

            return(_bindingVisitor.OnViewCreated(
                       base.OnCreateView(viewContext, parent, name, attrs),
                       viewContext,
                       attrs));
        }
Esempio n. 12
0
            public View?OnCreateView(string name, Context context, IAttributeSet attrs)
            {
                if (Debug)
                {
                    MvxLogHost.GetLog <MvxLayoutInflater>()?.Log(LogLevel.Trace, "{Tag} - ... OnCreateView 2 ... {name}", PrivateFactoryWrapper2Tag, name);
                }

                return(_bindingVisitor.OnViewCreated(
                           // The activity's OnCreateView
                           _factory2.OnCreateView(name, context, attrs),
                           context, attrs));
            }
Esempio n. 13
0
 public virtual void ReloadTableData()
 {
     try
     {
         TableView.ReloadData();
     }
     catch (Exception exception)
     {
         MvxLogHost.GetLog <MvxBaseTableViewSource>()?.Log(LogLevel.Warning, exception,
                                                           "Exception masked during TableView ReloadData");
     }
 }
Esempio n. 14
0
        public async Task <bool> ShowViewModel(MvxViewModelRequest request)
        {
            Task action()
            {
                MvxLogHost.GetLog <MvxIosViewDispatcher>()?.LogTrace(
                    "Navigate requested to {viewModelType}", request?.ViewModelType);
                return(_presenter.Show(request));
            }

            await ExecuteOnMainThreadAsync(action);

            return(true);
        }
        /// <summary>
        /// Main constructor for the presenter, this gets the main window.
        /// </summary>
        /// <param name="mainWindow"></param>
        public MesWpfPresenter(ContentControl mainWindow) : base(mainWindow)
        {
            // New style logging can return nulls
            _log = MvxLogHost.GetLog <MesWpfPresenter>();
            _log?.LogTrace("Setup: Creating Presenter");

            // Setup main window as singleton
            if (mainWindow is IMesWindow mesWindow)
            {
                _log?.LogTrace("Setting IMesWindow to main window");
                Mvx.IoCProvider.RegisterSingleton <IMesWindow>(mesWindow);
            }
        }
Esempio n. 16
0
        protected override void EventSourceOnStartActivityForResultCalled(
            object sender, MvxValueEventArgs <MvxStartActivityForResultParameters> eventArgs)
        {
            var requestCode = eventArgs.Value.RequestCode;

            switch (requestCode)
            {
            case (int)MvxIntentRequestCode.PickFromFile:
                MvxLogHost.GetLog <MvxActivityAdapter>()?.Log(LogLevel.Warning,
                                                              "Warning - activity request code may clash with Mvx code for {requestCode}",
                                                              (MvxIntentRequestCode)requestCode);
                break;
            }
        }
Esempio n. 17
0
        protected void StartActivityForResult(int requestCode, Intent intent)
        {
            DoOnActivity(activity =>
            {
                var androidView = activity as IMvxStartActivityForResult;
                if (androidView == null)
                {
                    MvxLogHost.GetLog <MvxAndroidTask>()?.Log(LogLevel.Error, "Error - current activity is null or does not support IMvxAndroidView");
                    return;
                }

                Mvx.IoCProvider.Resolve <IMvxIntentResultSource>().Result += OnMvxIntentResultReceived;
                androidView.MvxInternalStartActivityForResult(intent, requestCode);
            });
        }
Esempio n. 18
0
        public override async Task <bool> ChangePresentation(MvxPresentationHint hint)
        {
            if (await HandlePresentationChange(hint).ConfigureAwait(true))
            {
                return(true);
            }

            if (hint is MvxClosePresentationHint closeHint)
            {
                return(await Close(closeHint.ViewModelToClose).ConfigureAwait(true));
            }

            MvxLogHost.GetLog <MvxConsoleContainer>()?.Log(LogLevel.Trace, "Hint ignored {0}", hint.GetType().Name);
            return(false);
        }
Esempio n. 19
0
        private static object MapIfSpecialValue(object toReturn)
        {
            if (toReturn == MvxBindingConstant.DoNothing)
            {
                MvxLogHost.GetLog <MvxNativeValueConverter>()?.Log(
                    LogLevel.Trace, "DoNothing does not have an equivalent in WinRT - returning UnsetValue instead");
                return(DependencyProperty.UnsetValue);
            }

            if (toReturn == MvxBindingConstant.UnsetValue)
            {
                return(DependencyProperty.UnsetValue);
            }

            return(toReturn);
        }
Esempio n. 20
0
        /// <summary>
        /// Local theme menager
        /// </summary>
        /// <param name="messenger"></param>
        public MesThemeManager(IMvxMessenger messenger)
        {
            // Resolve logger manually, Don't force user to have logger
            _log       = MvxLogHost.GetLog <MesThemeManager>();
            _messenger = messenger;

            Themes = Mvx.IoCProvider.GetAll <IMesTheme>();

            _messenger.Subscribe <MesSettingsChangedMessage>((x) =>
            {
                if (x.Name == "ThemeName")
                {
                    SetCurrentTheme(x.Name);
                }
            });
        }
Esempio n. 21
0
        protected override View?OnCreateView(string?name, IAttributeSet?attrs)
        {
            if (Debug)
            {
                MvxLogHost.GetLog <MvxLayoutInflater>()?.Log(LogLevel.Trace, "{Tag} - ... OnCreateView 2 ... {name}", Tag, name);
            }

            View?view = null;

            if (name != null && Context != null && attrs != null)
            {
                view = AndroidViewFactory?.CreateView(null, name, Context, attrs);
            }

            view ??= PhoneLayoutInflaterOnCreateView(name, attrs) ?? base.OnCreateView(name, attrs);

            return(_bindingVisitor.OnViewCreated(view, Context, attrs));
        }
Esempio n. 22
0
        public override Task <bool> Close(IMvxViewModel viewModel)
        {
            var currentView = Mvx.IoCProvider.Resolve <IMvxConsoleCurrentView>().CurrentView;

            if (currentView == null)
            {
                MvxLogHost.GetLog <MvxConsoleContainer>()?.Log(LogLevel.Warning, "Ignoring close for viewmodel - rootframe has no current page");
                return(Task.FromResult(true));
            }

            if (currentView.ViewModel != viewModel)
            {
                MvxLogHost.GetLog <MvxConsoleContainer>()?.Log(LogLevel.Warning, "Ignoring close for viewmodel - rootframe's current page is not the view for the requested viewmodel");
                return(Task.FromResult(true));
            }

            return(GoBack());
        }
Esempio n. 23
0
        protected override void SetValueImpl(object target, object value)
        {
            var imageView = (ImageView)target;

            try
            {
                Bitmap bitmap;
                if (!GetBitmap(value, out bitmap))
                {
                    return;
                }
                SetImageBitmap(imageView, bitmap);
            }
            catch (Exception ex)
            {
                MvxLogHost.GetLog <MvxBaseImageViewTargetBinding>()?
                .Log(LogLevel.Error, ex, "Failed to set bitmap on ImageView");
                throw;
            }
        }
Esempio n. 24
0
        public MvxFrameControl(int templateId, Context context, IAttributeSet attrs)
            : base(context, attrs)
        {
            _templateId = templateId;

            if (!(context is IMvxLayoutInflaterHolder))
            {
                throw new MvxException("The owning Context for a MvxFrameControl must implement LayoutInflater");
            }

            _bindingContext = new MvxAndroidBindingContext(context, (IMvxLayoutInflaterHolder)context);
            this.DelayBind(() =>
            {
                if (Content == null && _templateId != 0)
                {
                    MvxLogHost.GetLog <MvxFrameControl>()?.Log(LogLevel.Trace, "DataContext is {dataContext}", DataContext?.ToString() ?? "Null");
                    Content = _bindingContext.BindingInflate(_templateId, this);
                }
            });
        }
Esempio n. 25
0
        private View?PhoneLayoutInflaterOnCreateView(string?name, IAttributeSet?attrs)
        {
            if (Debug)
            {
                MvxLogHost.GetLog <MvxLayoutInflater>()?.Log(LogLevel.Trace, "{Tag} - ... PhoneLayoutInflaterOnCreateView ... {name}", Tag, name);
            }

            foreach (var prefix in ClassPrefixList)
            {
                try
                {
                    return(CreateView(name, prefix, attrs));
                }
                catch (ClassNotFoundException)
                {
                }
            }

            return(null);
        }
Esempio n. 26
0
        protected virtual void ApplyBinding(MvxBindingDescription bindingDescription, Type actualType,
                                            FrameworkElement attachedObject)
        {
            DependencyProperty dependencyProperty = actualType.FindDependencyProperty(bindingDescription.TargetName);

            if (dependencyProperty == null)
            {
                MvxLogHost.GetLog <MvxWindowsBindingCreator>()?.Log(LogLevel.Warning,
                                                                    "Dependency property not found for {targetName}", bindingDescription.TargetName);
                return;
            }

            var property = actualType.FindActualProperty(bindingDescription.TargetName);

            if (property == null)
            {
                MvxLogHost.GetLog <MvxWindowsBindingCreator>()?.Log(LogLevel.Warning,
                                                                    "Property not returned for target {targetName} - may cause issues", bindingDescription.TargetName);
            }

            var sourceStep = bindingDescription.Source as MvxPathSourceStepDescription;

            if (sourceStep == null)
            {
                MvxLogHost.GetLog <MvxWindowsBindingCreator>()?.Log(LogLevel.Warning,
                                                                    "Binding description for {targetName} is not a simple path - Windows Binding cannot cope with this", bindingDescription.TargetName);
                return;
            }

            var newBinding = new Windows.UI.Xaml.Data.Binding
            {
                Path               = new PropertyPath(sourceStep.SourcePropertyPath),
                Mode               = ConvertMode(bindingDescription.Mode, property?.PropertyType ?? typeof(object)),
                Converter          = GetConverter(sourceStep.Converter),
                ConverterParameter = sourceStep.ConverterParameter,
                FallbackValue      = sourceStep.FallbackValue
            };

            BindingOperations.SetBinding(attachedObject, dependencyProperty, newBinding);
        }
Esempio n. 27
0
        public override MvxBasePresentationAttribute CreatePresentationAttribute(Type viewModelType, Type viewType)
        {
            ValidateArguments(viewModelType, viewType);

            if (MasterNavigationController == null &&
                TabBarViewController?.CanShowChildView() != true)
            {
                MvxLogHost.GetLog <MvxIosViewPresenter>()?.LogTrace(
                    $"PresentationAttribute nor MasterNavigationController found for {viewType.Name}. Assuming Root presentation");
                return(new MvxRootPresentationAttribute
                {
                    WrapInNavigationController = true, ViewType = viewType, ViewModelType = viewModelType
                });
            }

            MvxLogHost.GetLog <MvxIosViewPresenter>()?.LogTrace(
                $"PresentationAttribute not found for {viewType.Name}. Assuming animated Child presentation");

            return(new MvxChildPresentationAttribute {
                ViewType = viewType, ViewModelType = viewModelType
            });
        }
Esempio n. 28
0
        protected override void EventSourceOnSaveInstanceStateCalled(object sender, MvxValueEventArgs <Bundle> eventArgs)
        {
            var mvxBundle = AndroidView.CreateSaveStateBundle();

            if (mvxBundle != null)
            {
                if (!Mvx.IoCProvider.TryResolve <IMvxSavedStateConverter>(out var converter))
                {
                    MvxLogHost.GetLog <MvxActivityAdapter>()?.Log(LogLevel.Warning,
                                                                  "Saved state converter not available - saving state will be hard");
                }
                else
                {
                    converter.Write(eventArgs.Value, mvxBundle);
                }
            }

            if (Mvx.IoCProvider.TryResolve <IMvxSingleViewModelCache>(out var cache))
            {
                cache.Cache(AndroidView.ViewModel, eventArgs.Value);
            }
        }
Esempio n. 29
0
        internal View?CreateCustomViewInternal(View?parent, View?view, string name, Context viewContext,
                                               IAttributeSet attrs)
        {
            if (Debug)
            {
                MvxLogHost.GetLog <MvxLayoutInflater>()?.Log(LogLevel.Trace, "{Tag} - ... CreateCustomViewInternal ... {name}", Tag, name);
            }

            if (view == null &&
                !string.IsNullOrWhiteSpace(name) &&
                name.IndexOf('.', StringComparison.InvariantCulture) > -1)
            {
                // Attempt to inflate with MvvmCross unless we're trying to inflate an internal views
                // since we don't resolve those.
                if (!name.StartsWith("com.android.internal.", StringComparison.InvariantCulture))
                {
                    view = AndroidViewFactory?.CreateView(parent, name, viewContext, attrs);
                }

                if (view == null)
                {
                    var(constructorArgsArr, lastContext) = GetConstructorArgs(viewContext);

                    try
                    {
                        view = CreateViewCompat(viewContext, name, attrs);
                    }
                    catch (ClassNotFoundException)
                    {
                    }
                    finally
                    {
                        RestoreConstructorArgs(constructorArgsArr, lastContext);
                    }
                }
            }

            return(view);
        }
Esempio n. 30
0
        protected override void HandleSaveInstanceStateCalled(object sender, MvxValueEventArgs <Bundle> bundleArgs)
        {
            // it is guarannted that SaveInstanceState call will be executed before OnStop (thus before Fragment detach)
            // it is safe to assume that Fragment has activity attached

            var mvxBundle = FragmentView.CreateSaveStateBundle();

            if (mvxBundle != null)
            {
                IMvxSavedStateConverter converter;
                if (!Mvx.IoCProvider.TryResolve(out converter))
                {
                    MvxLogHost.GetLog <MvxBindingFragmentAdapter>()?.Log(LogLevel.Warning,
                                                                         "Saved state converter not available - saving state will be hard");
                }
                else
                {
                    converter.Write(bundleArgs.Value, mvxBundle);
                }
            }
            var cache = Mvx.IoCProvider.Resolve <IMvxMultipleViewModelCache>();

            cache.Cache(FragmentView.ViewModel, FragmentView.UniqueImmutableCacheTag);
        }