Beispiel #1
0
        //
        // This method is invoked when the application has loaded and is ready to run. In this
        // method you should instantiate the window, load the UI into it and then make the window
        // visible.
        //
        // You have 17 seconds to return from this method, or iOS will terminate your application.
        //
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            global::Xamarin.Forms.Forms.Init();
            SfListViewRenderer.Init();
            CachedImageRenderer.Init();
            Syncfusion.XForms.iOS.ProgressBar.SfCircularProgressBarRenderer.Init();
            Syncfusion.SfChart.XForms.iOS.Renderers.SfChartRenderer.Init();

            DeviceSize.FullScreenWidth  = (int)UIScreen.MainScreen.Bounds.Size.Width;
            DeviceSize.FullScreenHeight = (int)UIScreen.MainScreen.Bounds.Size.Height;

            LoadApplication(new App());
            Xamarin.FormsMaps.Init();
            ImageCircleRenderer.Init();

            AppCenter.Start("f091513f-6c14-4845-8737-dbdc8dbeff2f", typeof(Analytics), typeof(Crashes));

            MessagingCenter.Subscribe <SyncMessage>(this, string.Empty, async(sender) =>
            {
                if (await _syncPossibility.CheckAsync(true))
                {
                    SyncService sync = new SyncService();
                    sync.Start(sender?.RouteId, sender.NeedCheckVersionRoute);
                }
            });

            return(base.FinishedLaunching(app, options));
        }
Beispiel #2
0
        public async Task <(string PositionAddress, string PointName)> GetPositionAddress(Position position)
        {
            string          address          = string.Empty;
            string          pointName        = string.Empty;
            SyncPossibility possibility      = new SyncPossibility();
            bool            networkAvailable = await possibility.CheckAsync(false);

            if (networkAvailable)
            {
                var locator = CrossGeolocator.Current;
                try
                {
                    IEnumerable <Address> addresses = await locator.GetAddressesForPositionAsync(position);

                    var addressItem = addresses.FirstOrDefault();
                    if (addressItem != null)
                    {
                        address = $"{addressItem.SubThoroughfare}, {addressItem.Thoroughfare}, {addressItem.Locality}, {addressItem.CountryName}";
                        if (!string.IsNullOrEmpty(addressItem.SubLocality))
                        {
                            pointName = $"{addressItem.SubLocality}";
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(addressItem.Locality))
                            {
                                pointName = $"{addressItem.CountryName},{addressItem.Locality}";
                            }
                            else
                            {
                                pointName = $"{addressItem.CountryName},{addressItem.SubAdminArea}";
                            }
                        }
                    }
                }
                catch (Exception exception)
                {
                    var properties = new Dictionary <string, string> {
                        { "GeolocatorManager", "GetPositionAddress" }
                    };
                    Crashes.TrackError(exception, properties);
                }
            }
            return(address, pointName);
        }
        protected override void OnCreate(Bundle bundle)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            base.OnCreate(bundle);

            this.Window.DecorView.Background = null;
            this.Window.DecorView.SetBackgroundColor(Android.Graphics.Color.White);

            CrossCurrentActivity.Current.Init(this, bundle);

            global::Xamarin.Forms.Forms.Init(this, bundle);
            FFImageLoading.Forms.Platform.CachedImageRenderer.Init(enableFastRenderer: true);
            //https://github.com/roubachof/Xamarin.Forms.Nuke
#if DEBUG
            Android.Glide.Forms.Init(this, debug: true);
#else
            Android.Glide.Forms.Init(this);
#endif

            Xamarin.FormsMaps.Init(this, bundle);
            ImageCircleRenderer.Init();
            Xamarin.Essentials.Platform.Init(this, bundle);
            UserDialogs.Init(this);
            CustomTabsConfiguration.CustomTabsClosingMessage = null;

            PushReceiverSetup pushReceiverSetup = new PushReceiverSetup(this);
            pushReceiverSetup.Setup();

            string shareSubject     = Intent.GetStringExtra("shareSubject") ?? string.Empty;
            string shareDescription = Intent.GetStringExtra("shareDescription") ?? string.Empty;

            DeviceSize.FullScreenHeight = (int)(Resources.DisplayMetrics.HeightPixels / Resources.DisplayMetrics.Density);
            DeviceSize.FullScreenWidth  = (int)(Resources.DisplayMetrics.WidthPixels / Resources.DisplayMetrics.Density);

            LoadApplication(new App());

            if (Intent?.Extras != null)
            {
                if (Intent.Extras?.KeySet()?.Count > 0)
                {
                    //ToDo: несмотря на передачу extra в FirebaseNotificationService они почему-то не передаются
                    //Актуально когда гош открываешь из сообщения в шторке
                    string messageBody = Intent.Extras.GetString("messageBodyText");
                    Xamarin.Forms.MessagingCenter.Send <ReceivePushMessage>(new ReceivePushMessage()
                    {
                        MessageBody = messageBody, MessageTitle = string.Empty
                    }, string.Empty);
                }
            }

            /*if (Intent != null)
             * {
             *  processShareIntent(Intent);
             * }*/

            /*if (!string.IsNullOrEmpty(shareDescription))
             * {
             *  var pageCollections = new PagesCollection();
             *  MainPageMenuItem destinationPage = pageCollections.GetProcessSharePage();
             *  Xamarin.Forms.MessagingCenter.Send<ShareFromGoogleMapsMessage>(new ShareFromGoogleMapsMessage() { Subject = shareSubject, Description = shareDescription }, string.Empty);
             * }*/

            MessagingCenter.Subscribe <SyncMessage>(this, string.Empty, async(sender) =>
            {
                if (await _syncPossibility.CheckAsync(true))
                {
                    Intent syncIntent = new Intent(this, typeof(SyncIntentService));
                    if ((sender != null) && !string.IsNullOrEmpty(sender.RouteId))
                    {
                        syncIntent.PutExtra("RouteId", sender.RouteId);
                        syncIntent.PutExtra("NeedCheckVersionRoute", sender.NeedCheckVersionRoute);
                    }
                    var result = StartService(syncIntent);
                }
            });

            MessagingCenter.Subscribe <AddRouteViewedMessage>(this, string.Empty, async(sender) =>
            {
                if (await _syncPossibility.CheckAsync(true))
                {
                    Intent intent = new Intent(this, typeof(SendRouteViewedIntentService));
                    intent.PutExtra("RouteId", sender.RouteId);
                    StartService(intent);
                }
            });

            MessagingCenter.Subscribe <SetEmotionRouteMessage>(this, string.Empty, async(sender) =>
            {
                if (await _syncPossibility.CheckAsync(true))
                {
                    Intent intent = new Intent(this, typeof(SetEmotionRouteIntentService));
                    intent.PutExtra("RouteId", sender.RouteId);
                    intent.PutExtra("Emotion", sender.Emotion);
                    StartService(intent);
                }
            });

            //Используется для вывода нативного окна выбора oauth учетки
            MessagingCenter.Subscribe <OAuthDialogShowRequest>(this, string.Empty, (sender) =>
            {
                var intent = AuthenticationState.Authenticator.GetUI(Android.App.Application.Context);
                intent.SetFlags(ActivityFlags.NewTask);
                try
                {
                    Android.App.Application.Context.StartActivity(intent);
                }
                catch (Exception e)
                {
                    Xamarin.Forms.MessagingCenter.Send <UIAlertMessage>(new UIAlertMessage()
                    {
                        Title = CommonResource.Login_GoogleAuthCaption, Message = CommonResource.Login_GoogleAuthError
                    }, string.Empty);
                    Analytics.TrackEvent("Login OAuth error", new Dictionary <string, string> {
                        { "ExceptionMessage", e.Message }, { "Google Chrome auth", "error" }
                    });
                    Xamarin.Forms.MessagingCenter.Send <UIAlertMessage>(new UIAlertMessage()
                    {
                        Title = "Error", Message = "Error syncing server. Try to open feed."
                    }, string.Empty);
                }
            });
        }