Beispiel #1
0
        private static IConnectionService SetupConnectionService()
        {
            var instance = new ConnectionService
            {
                ErrorWhenConnectionFailed = AppSettings.ErrorWhenConnectionFailed,
                ErrorWhenTaskCanceled     = AppSettings.ErrorWhenTaskCanceled,
                IsConnectionAvailable     = () => Task <bool> .Factory.StartNew(() =>
                {
                    if (Mvx.CanResolve <IMvxReachability>())
                    {
                        return(Mvx.Resolve <IMvxReachability>().IsHostReachable(AppSettings.Host));
                    }
                    return(true);
                }),
                RequestTimeoutInSeconds = AppSettings.RequestTimeoutInSeconds,
                BaseUrl           = new System.Uri(AppSettings.Host),
                CreateHandlerFunc = () => new NativeMessageHandler()
            };

            instance.Headers.Add("ApiKey", AppSettings.ApiKey);
            instance.Headers.Add("Device", Mvx.Resolve <IDeviceService>().DeviceInfo);
            instance.Headers.Add("DeviceToken", Mvx.Resolve <IDeviceService>().Token);
            instance.Headers.Add("Company", AppSettings.CompanyID);
            instance.Headers.Add("Region", AppSettings.RegionID ?? AppSettings.DefaultRegionID);
            instance.Headers.Add("Accept-Language", AppSettings.SettingsCulture.Name);
#if DEBUG
            instance.Headers.Add("Debug", "true");
#endif

            return(instance);
        }
Beispiel #2
0
        public static void Check()
        {
            if (_checked)
            {
                return;
            }

            _checked = true;

            // if Application.Current == null Forms is in design mode
            if (Application.Current != null)
            {
                return;
            }

            if (MvxSingleton <IMvxIoCProvider> .Instance == null)
            {
                var iocProvider = MvxSimpleIoCContainer.Initialize();
                Mvx.RegisterSingleton(iocProvider);
            }

            if (!Mvx.CanResolve <IMvxBindingParser>())
            {
                //We might want to look into returning the platform specific Forms binder
                var builder = new MvxBindingBuilder();
                builder.DoRegistration();
            }
        }
Beispiel #3
0
        public static void Check()
        {
            if (_checked)
            {
                return;
            }

            _checked = true;

#if WINDOWS_WPF
            if (!(bool)DesignerProperties.IsInDesignModeProperty.GetMetadata(typeof(DependencyObject)).DefaultValue)
            {
                return;
            }
#endif
#if WINDOWS_COMMON
            if (!Windows.ApplicationModel.DesignMode.DesignModeEnabled)
            {
                return;
            }
#endif

            if (MvxSingleton <IMvxIoCProvider> .Instance == null)
            {
                var iocProvider = MvxSimpleIoCContainer.Initialize();
                Mvx.RegisterSingleton(iocProvider);
            }

            if (!Mvx.CanResolve <IMvxBindingParser>())
            {
                var builder = new MvxWindowsBindingBuilder(MvxWindowsBindingBuilder.BindingType.MvvmCross);
                builder.DoRegistration();
            }
        }
        public static void Check()
        {
            if (_checked)
            {
                return;
            }

            _checked = true;

            if (!DesignMode.DesignModeEnabled)
            {
                return;
            }

            if (MvxSingleton <IMvxIoCProvider> .Instance == null)
            {
                var iocProvider = MvxIoCProvider.Initialize();
                Mvx.RegisterSingleton(iocProvider);
            }

            if (!Mvx.CanResolve <IMvxBindingParser>())
            {
                var builder = new MvxWindowsBindingBuilder(MvxWindowsBindingBuilder.BindingType.MvvmCross);
                builder.DoRegistration();
            }
        }
 public IPlateformService ResolvePlateform()
 {
     if (Mvx.CanResolve <IPlateformService>())
     {
         return(Mvx.Resolve <IPlateformService>());
     }
     return(null);
 }
 public ICalendarService ResolveCalendar()
 {
     if (Mvx.CanResolve <ICalendarService>())
     {
         return(Mvx.Resolve <ICalendarService>());
     }
     return(null);
 }
Beispiel #7
0
        protected override void Handle(CookingCanceledMessage message)
        {
            if (Mvx.CanResolve <CookingForegroundServiceConnection>())
            {
                Mvx.Resolve <CookingForegroundServiceConnection>().Binder.Service.Stop();
            }

            notificationService.ClearNotifications();
        }
        private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            var ex = e.ExceptionObject as Exception;

            if (Mvx.CanResolve <ILogger>() && ex != null)
            {
                Mvx.Resolve <ILogger>().LogError(new Exception("Unhandled exception", ex));
            }
        }
 protected virtual void RegisterLanguageBindingParser()
 {
     if (Mvx.CanResolve <IMvxLanguageBindingParser>())
     {
         MvxBindingLog.Trace("Binding Parser already registered - so skipping Language parser");
         return;
     }
     MvxBindingLog.Trace("Registering Language Binding Parser");
     Mvx.RegisterSingleton(CreateLanguageBindingParser());
 }
Beispiel #10
0
        protected override IMvxViewModelLocator CreateDefaultViewModelLocator()
        {
            var locator = base.CreateDefaultViewModelLocator();

            if (!Mvx.CanResolve <IMvxViewModelLocator>())
            {
                Mvx.RegisterSingleton <IMvxViewModelLocator>(locator);
            }
            return(locator);
        }
 protected virtual void RegisterLanguageBindingParser()
 {
     if (Mvx.CanResolve <IMvxLanguageBindingParser>())
     {
         MvxBindingTrace.Trace(MvxTraceLevel.Diagnostic,
                               "Binding Parser already registered - so skipping Language parser");
         return;
     }
     MvxBindingTrace.Trace(MvxTraceLevel.Diagnostic, "Registering Language Binding Parser");
     Mvx.RegisterSingleton(this.CreateLanguageBindingParser());
 }
Beispiel #12
0
        public MvxVisibilityDesignTimeHelper()
        {
            if (!IsInDesignTool)
                return;

            if (Mvx.CanResolve<IMvxNativeVisibility>())
                return;

            var forceVisibilityLoaded = new Plugin();
            forceVisibilityLoaded.Load();
        }
Beispiel #13
0
        protected override IMvxViewModelLocator CreateDefaultViewModelLocator()
        {
            // register the instance
            if (!Mvx.CanResolve <IMvxViewModelLocator>())
            {
                var locator = base.CreateDefaultViewModelLocator();
                Mvx.RegisterSingleton(locator);
            }

            return(Mvx.Resolve <IMvxViewModelLocator>());
        }
Beispiel #14
0
        //private bool _loaded;

        public void EnsureLoaded()
        {
            if (Mvx.CanResolve <IMvxMessenger>())
            //if (_loaded)
            {
                return;
            }

            Mvx.RegisterSingleton <IMvxMessenger>(new MvxMessengerHub());
            //_loaded = true;
        }
Beispiel #15
0
        /// <summary>
        /// Initialization of the ViewModel
        /// </summary>
        public async void Init()
        {
            NavigationModel model = null;

            if (Mvx.CanResolve <LibraryViewModel.NavigationModel>())
            {
                model = Mvx.Resolve <LibraryViewModel.NavigationModel>();
                Mvx.RegisterSingleton <NavigationModel>(new NavigationModel());
            }
            await RefreshListAsync();
            await OpenSgfFileAsync(model?.SgfFileInfo);
        }
Beispiel #16
0
        private static void OnLifetimeEvent(Activity activity,
                                            Action <IMvxAndroidActivityLifetimeListener, Activity> report)
        {
            if (!Mvx.CanResolve <IMvxAndroidActivityLifetimeListener>())
            {
                Debugger.Break();
            }

            var activityTracker = Mvx.Resolve <IMvxAndroidActivityLifetimeListener>();

            report(activityTracker, activity);
        }
Beispiel #17
0
        protected override void OnNewIntent(Intent intent)
        {
            base.OnNewIntent(intent);

            if (!Mvx.CanResolve <IMvxNavigationService>())
            {
                return;
            }

            var url = WebUtility.UrlDecode(intent.DataString);

            Mvx.Resolve <IMvxNavigationService>().Navigate(url);
        }
        private static async Task <ILocalization> LocalizationProvider()
        {
            if (Mvx.CanResolve <ILocalization>())
            {
                return(Mvx.Resolve <ILocalization>());
            }

            var tcs = new TaskCompletionSource <ILocalization>();

            Mvx.CallbackWhenRegistered <ILocalization>(service => tcs.TrySetResult(service));

            return(await tcs.Task);
        }
        public MvxTouchControl(string nibName, NSBundle bundle) : base(nibName, bundle)
        {
            //Hack: iOS crashes if you create a MvxUIViewController without DataContext
            DataContext = new object();

            if (!Mvx.CanResolve <IMvxControlsContainer>())
            {
                new Plugin().Load();
            }

            _container = Mvx.Resolve <IMvxControlsContainer>();
            _container.Add(this);
        }
Beispiel #20
0
        private bool TryGetSettings()
        {
            if (this.settings != null)
            {
                return(true);
            }
            if (!Mvx.CanResolve <Repository>())
            {
                return(false);
            }

            this.settings = Mvx.Resolve <Repository>().Settings;
            return(true);
        }
        private void Initialize()
        {
            EmptyControlBehaviour = this.GetDefaultEmptyControlBehaviour();

            BindingContext = new MvxAndroidBindingContext(Context, this);

            if (!Mvx.CanResolve <IMvxControlsContainer>())
            {
                new Plugin().Load();
            }

            _container = Mvx.Resolve <IMvxControlsContainer>();
            _container.Add(this);
        }
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            if (!string.IsNullOrEmpty(PropertyName))
            {
                StringBuilder bindingBuilder = new StringBuilder($"{PropertyName} {Source}");

                if (!string.IsNullOrEmpty(Converter))
                {
                    bindingBuilder.Append($", Converter={Converter}");
                }

                if (!string.IsNullOrEmpty(ConverterParameter))
                {
                    bindingBuilder.Append($", ConverterParameter={ConverterParameter}");
                }

                if (!string.IsNullOrEmpty(Key))
                {
                    bindingBuilder.Append($", Key={Key}");
                }

                if (!string.IsNullOrEmpty(FallbackValue))
                {
                    bindingBuilder.Append($", FallbackValue={FallbackValue}");
                }

                Bindable.SetValue(La.ngProperty, bindingBuilder.ToString());
            }
            else if (!string.IsNullOrEmpty(Source) && Mvx.CanResolve <IMvxTextProvider>())
            {
                if (Arguments == null)
                {
                    return(new MvxLanguageBinder(NameSpaceKey, TypeKey).GetText(Source));
                }
                else
                {
                    return(new MvxLanguageBinder(NameSpaceKey, TypeKey).GetText(Source, Arguments));
                }
            }
            else if (BindableObjectRaw is IMarkupExtension ext)
            {
                return(ext.ProvideValue(serviceProvider));
            }
            else
            {
                MvxFormsLog.Instance.Trace("Can only use MvxLang on a bindable property");
            }

            return(null);
        }
        protected virtual async Task LoadContent()
        {
            Loading = true;

            var reviews = await VmService.LoadReviews(ProductGroupId, ProductId, LOADING_REVIEWS_COUNT);

            InvokeOnMainThread(() => Reviews = reviews);

            Loading = false;

            CanPostReview = Mvx.CanResolve <ISessionService>() ? Mvx.Resolve <ISessionService>().Alive : false;
#if DEBUG
            CanPostReview = true;
#endif
        }
Beispiel #24
0
        public MvxColorDesignTimeHelper()
        {
            if (!IsInDesignTool)
            {
                return;
            }

            if (Mvx.CanResolve <IMvxNativeColor>())
            {
                return;
            }

            var forceLoaded = new Plugin();

            forceLoaded.Load();
        }
        protected virtual async void OnCallExecute()
        {
            if (Mvx.CanResolve <IAnalyticsNotifyingService>())
            {
                Mvx.Resolve <IAnalyticsNotifyingService>().NotifyEventIsHandled("order", "order_delivery_pickup_item_button");
            }

            if (await Mvx.Resolve <IUserDialogs>().Confirm($"{Mvx.Resolve<ILocalizationService>().GetLocalizableString(BasketConstants.RESX_NAME, "DeliveryPoint_MakeCallText")} {Phone}?", Mvx.Resolve <ILocalizationService>().GetLocalizableString(BasketConstants.RESX_NAME, "DeliveryPoint_MakeCall")) &&
                CrossMessaging.Current.PhoneDialer.CanMakePhoneCall)
            {
                CrossMessaging.Current.PhoneDialer.MakePhoneCall(Phone, Name);
            }
            else
            {
                await Mvx.Resolve <IUserDialogs>().Alert(Mvx.Resolve <ILocalizationService>().GetLocalizableString(BasketConstants.RESX_NAME, "DeliveryPoint_CallError"));
            }
        }
        protected void AddSegue <TTargetViewModel>(string name, Action <TTargetViewModel> setup) where TTargetViewModel : class, IMvxViewModel
        {
            if (!Mvx.CanResolve <TTargetViewModel>())
            {
                throw new ArgumentException("Unknown ViewModel", typeof(TTargetViewModel).FullName);
            }

            Action <UIStoryboardSegue> segueSetup = segue =>
            {
                var nextCtrl = segue.DestinationViewController as MvxViewController;
                if (nextCtrl != null)
                {
                    var viewModel = Mvx.Resolve <TTargetViewModel>();
                    setup(viewModel);
                    nextCtrl.Request = new MvxViewModelInstanceRequest(viewModel);
                }
            };

            segueSetups.Add(name, segueSetup);
        }
Beispiel #27
0
        public MvxStoreControl()
        {
            DataContext = null;

            EmptyControlBehaviour = this.GetDefaultEmptyControlBehaviour();

            if (DesignMode.DesignModeEnabled)
            {
                return;
            }

            if (!Mvx.CanResolve <IMvxControlsContainer>())
            {
                new Plugin().Load();
            }

            _container = Mvx.Resolve <IMvxControlsContainer>();

            Loaded   += MvxStoreControl_Loaded;
            Unloaded += MvxStoreControl_Unloaded;
        }
 private void OnBasketChanged(MvxMessage msg)
 {
     Task.Run(async() =>
     {
         try
         {
             var quantity = await ApiService.GetQuantity();
             if (Mvx.CanResolve <IMvxMessenger>() && Messenger.HasSubscriptionsFor <ModulesInteractionMessage <int> >())
             {
                 Messenger.Publish(new ModulesInteractionMessage <int>(this, quantity)
                 {
                     Type = typeof(IBasketViewModel)
                 });
             }
         }
         catch (Exception ex)
         {
             MvxTrace.TaggedTrace(MvxTraceLevel.Warning, this.GetType().FullName, ex.BuildAllMessagesAndStackTrace());
         }
     });
 }
        public MvxWpfControl()
        {
            DataContext = null;

            EmptyControlBehaviour = this.GetDefaultEmptyControlBehaviour();

            if (DesignerProperties.GetIsInDesignMode(this))
            {
                return;
            }

            if (!Mvx.CanResolve <IMvxControlsContainer>())
            {
                new Plugin().Load();
            }

            _container = Mvx.Resolve <IMvxControlsContainer>();

            Loaded   += OnLoaded;
            Unloaded += OnUnloaded;
        }
        protected virtual void OnNotificationTapped(NSDictionary userInfo)
        {
            UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0;

            try
            {
                var deeplinkKey = new NSString("deeplink");
                if (userInfo.ContainsKey(deeplinkKey))
                {
                    var deeplink = userInfo.ValueForKey(deeplinkKey).ToString();

                    if (Mvx.CanResolve <IViewModelLookupService>())
                    {
                        NavigateToDeeplinkFromPush(userInfo, deeplink);
                    }
                    else
                    {
                        Mvx.CallbackWhenRegistered <IViewModelLookupService>(() => NavigateToDeeplinkFromPush(userInfo, deeplink));
                    }
                }
            }
            catch { }
        }