Esempio n. 1
0
        private void AdapterOnDeviceDiscovered(object sender, DeviceEventArgs e)
        {
            _spotTimes[e.Device.Id] = DateTime.UtcNow;

            var device = ScannedDeviceViewModels.FirstOrDefault(model => model.ScannedDevice.Device.Id == e.Device.Id);

            if (device != null)
            {
                device.SignalStrength = e.Device.Rssi;
            }
            else
            {
                using (var scope = ResourceLocator.ObtainScope())
                {
                    ScannedDeviceViewModels.Add(scope.TypedResolve <ScannedDeviceViewModel>(new ScannedDevice
                    {
                        Device         = e.Device,
                        Guid           = e.Device.Id,
                        MacAddress     = _bluetoothDeviceDataExtractor.GetMacAddressFromDevice(e.Device),
                        AdvertisedName = e.Device.Name,
                        SignalStrength = e.Device.Rssi
                    }));
                }
            }
        }
Esempio n. 2
0
 TViewModel ICustomDialogDependencyResolver.Resolve <TViewModel>()
 {
     using (var scope = ResourceLocator.ObtainScope())
     {
         return(scope.Resolve <TViewModel>());
     }
 }
Esempio n. 3
0
 TViewModel IViewModelResolver.Resolve <TViewModel>()
 {
     using (var scope = ResourceLocator.ObtainScope())
     {
         return(scope.Resolve <TViewModel>());
     }
 }
 public TViewModel Resolve <TViewModel>()
     where TViewModel : CustomDialogViewModelBase
 {
     using (var scope = ResourceLocator.ObtainScope())
     {
         return(scope.Resolve <TViewModel>());
     }
 }
Esempio n. 5
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            this.ApplyTheme();

            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            AppCenter.Start("c0a878f9-4b3b-4c60-b56d-41e237fbf515", typeof(Analytics), typeof(Crashes));
            SetContentView(Resource.Layout.activity_main);

            if (!_initialized)
            {
                App.NavigationManager = new NavigationManager <PageIndex>(
                    SupportFragmentManager,
                    RootView,
                    new DependencyResolver());
                App.DialogManager = new CustomDialogsManager <DialogIndex>(
                    SupportFragmentManager,
                    new Dictionary <DialogIndex, ICustomDialogProvider>
                {
                    { DialogIndex.ChangelogDialog, new OneshotCustomDialogProvider <ChangelogDialog>() }
                },
                    new DependencyResolver());

                AppInitializationRoutines.InitializeDependencies();


                using (var scope = ResourceLocator.ObtainScope())
                {
                    ViewModel = scope.Resolve <MainViewModel>();
                    _logger   = scope.Resolve <ILogger <MainActivity> >();
                }
                SetSupportActionBar(Toolbar);
                InitDrawer();
                ViewModel.Initialize();

                _initialized = true;
            }
            else
            {
                App.NavigationManager.RestoreState(SupportFragmentManager, RootView);
                App.DialogManager.ChangeFragmentManager(SupportFragmentManager);
                if (App.NavigationManager.CurrentPage == PageIndex.Feed)
                {
                    App.NavigationManager.PageDefinitions[PageIndex.Feed].Page.NavigatedTo();
                }
                SetSupportActionBar(Toolbar);
                InitDrawer();
            }
        }
Esempio n. 6
0
 public TViewModel Resolve <TViewModel>()
 {
     Log.Debug(nameof(App), $"Resolving ViewModel: {typeof(TViewModel).Name}");
     try
     {
         using (var scope = ResourceLocator.ObtainScope())
         {
             return(scope.Resolve <TViewModel>());
         }
     }
     catch (Exception e)
     {
         Debugger.Break();
         throw;
     }
 }
Esempio n. 7
0
        public MainPage()
        {
            this.InitializeComponent();

            App.NavigationManager = new NavigationManager <PageIndex>(RootFrame, new DependencyResolver());
            App.DialogManager     =
                new CustomDialogsManager <DialogIndex>(
                    new Dictionary <DialogIndex, ICustomDialogProvider>
            {
                { DialogIndex.TestDialogA, new OneshotCustomDialogProvider <TestDialogA>() },
                { DialogIndex.TestDialogB, new OneshotCustomDialogProvider <TestDialogB>() }
            },
                    new DependencyResolver());

            ResourceLocator.ObtainScope().Resolve <MainViewModel>().Initialize();
        }
Esempio n. 8
0
        public MainPage()
        {
            this.InitializeComponent();
            NavigationView.PaneDisplayMode = NavigationViewPaneDisplayMode.Auto;
            App.NavigationManager          = new UwpNavigationManager(new Dictionary <NavigationStack, Frame>
            {
                { NavigationStack.MainStack, MainFrame },
                { NavigationStack.OffStack, OffFrame },
            }, new UwpStackResolver());

            App.DialogManager =
                new CustomDialogsManager <DialogIndex>(
                    new Dictionary <DialogIndex, ICustomDialogProvider>
            {
                { DialogIndex.ChangelogDialog, new OneshotCustomDialogProvider <ChangelogDialog>() },
            },
                    new DependencyResolver());

            Messenger.Default.Register <NavigationStackUpdateMessage>(this, OnNavigationStackUpdateMessage);
            ViewModel   = ResourceLocator.ObtainScope().Resolve <MainViewModel>();
            DataContext = ViewModel;
            ViewModel.Initialize();
        }
Esempio n. 9
0
        public static void ApplyTheme(this AppCompatActivity activity)
        {
            var settings = ResourceLocator.ObtainScope().Resolve <ISettings>();
            var theme    = settings.AppTheme;

            CurrentTheme = theme;
            // Base
            if ((theme & AppTheme.Dark) == AppTheme.Dark)
            {
                activity.SetTheme(Resource.Style.AoTracker_Dark);
                activity.Window.SetStatusBarColor(DarkBackgroundColour);
            }
            else if ((theme & AppTheme.Black) == AppTheme.Black)
            {
                activity.SetTheme(Resource.Style.AoTracker_Black);
                activity.Window.SetStatusBarColor(Color.Black);
            }
            else
            {
                activity.SetTheme(Resource.Style.AoTracker_Light);
            }

            // Colour scheme
            if ((theme & AppTheme.Orange) == AppTheme.Orange)
            {
                activity.Theme.ApplyStyle(Resource.Style.ColourSchemeOrange, true);
            }
            else if ((theme & AppTheme.Lime) == AppTheme.Lime)
            {
                activity.Theme.ApplyStyle(Resource.Style.ColourSchemeLime, true);
            }
            else if ((theme & AppTheme.Cyan) == AppTheme.Cyan)
            {
                activity.Theme.ApplyStyle(Resource.Style.ColourSchemeCyan, true);
            }
            else if ((theme & AppTheme.Purple) == AppTheme.Purple)
            {
                activity.Theme.ApplyStyle(Resource.Style.ColourSchemePurple, true);
            }
            else if ((theme & AppTheme.SkyBlue) == AppTheme.SkyBlue)
            {
                activity.Theme.ApplyStyle(Resource.Style.ColourSchemeSkyBlue, true);
            }
            else if ((theme & AppTheme.Red) == AppTheme.Red)
            {
                activity.Theme.ApplyStyle(Resource.Style.ColourSchemeRed, true);
            }
            else if ((theme & AppTheme.Pink) == AppTheme.Pink)
            {
                activity.Theme.ApplyStyle(Resource.Style.ColourSchemePink, true);
            }

            // Toolbar overrides
            if ((theme & AppTheme.Dark) == AppTheme.Dark)
            {
                activity.Theme.ApplyStyle(Resource.Style.ColourSchemeToolbarDark, true);
            }
            else if ((theme & AppTheme.Black) == AppTheme.Black)
            {
                activity.Theme.ApplyStyle(Resource.Style.ColourSchemeToolbarBlack, true);
            }

            if (Build.VERSION.SdkInt >= BuildVersionCodes.M)
            {
                RedColour  = activity.Resources.GetColor(Resource.Color.RedColour, activity.Theme);
                LimeColour = activity.Resources.GetColor(Resource.Color.LimeColour, activity.Theme);
            }
            else
            {
#pragma warning disable 618
                RedColour  = activity.Resources.GetColor(Resource.Color.RedColour);
                LimeColour = activity.Resources.GetColor(Resource.Color.LimeColour);
#pragma warning restore 618
            }

            // Colour settings

            AccentColour       = ResolveColour(activity, Resource.Attribute.AccentColour);
            TextColour         = ResolveColour(activity, Resource.Attribute.TextColour);
            TextInvertedColour = ResolveColour(activity, Resource.Attribute.TextInvertedColour);
            ToolbarTextColour  = ResolveColour(activity, Resource.Attribute.ToolbarTextColour);
        }
Esempio n. 10
0
 public TDependency Resolve <TDependency>()
 {
     return(ResourceLocator.ObtainScope().Resolve <TDependency>());
 }
Esempio n. 11
0
        public override bool OnStartJob(JobParameters jobParameters)
        {
            Log.Info(nameof(FeedUpdateService), "Starting feed update job service.");
            Task.Run(async() =>
            {
                try
                {
                    AppInitializationRoutines.InitializeDependenciesForBackground(DependenciesRegistration);
                    using (var scope = ResourceLocator.ObtainScope())
                    {
                        var userDataProvider = scope.Resolve <IUserDataProvider>();
                        await userDataProvider.Initialize();

                        if (!userDataProvider.CrawlingSets.Any())
                        {
                            return;
                        }

                        var feedProvider        = scope.Resolve <IFeedProvider>();
                        var feedHistoryProvider = scope.Resolve <IFeedHistoryProvider>();
                        var cts             = new CancellationTokenSource();
                        var tcs             = new TaskCompletionSource <bool>();
                        var finishSemaphore = new SemaphoreSlim(1);

                        feedProvider.NewCrawlerBatch += async(sender, batch) =>
                        {
                            try
                            {
                                await finishSemaphore.WaitAsync(cts.Token);

                                if (batch.CrawlerResult.Success)
                                {
                                    if (await feedHistoryProvider.HasAnyChanged(
                                            batch.SetOfOrigin,
                                            batch.CrawlerResult.Results))
                                    {
                                        cts.Cancel();
                                        Log.Info(nameof(FeedUpdateService), "Found new feed content.");
                                        tcs.SetResult(true);
                                    }
                                }
                            }
                            catch (TaskCanceledException)
                            {
                            }
                            finally
                            {
                                finishSemaphore.Release();
                            }
                        };

                        feedProvider.Finished += async(sender, args) =>
                        {
                            if (tcs.Task.IsCompleted)
                            {
                                return;
                            }
                            try
                            {
                                await finishSemaphore.WaitAsync(cts.Token);
                                if (tcs.Task.IsCompleted)
                                {
                                    return;
                                }
                                tcs.SetResult(false);
                            }
                            catch
                            {
                                //not important at this point
                            }
                        };

                        feedProvider.StartAggregating(
                            userDataProvider.CrawlingSets.ToList(),
                            cts.Token,
                            true);

                        var result = await tcs.Task;

                        if (result)
                        {
                            var builder = new NotificationCompat.Builder(this, FeedUpdateChannel)
                                          .SetSmallIcon(Resource.Drawable.icon_logo_small)
                                          .SetContentTitle(AppResources.Notification_FeedUpdate)
                                          .SetContentText(AppResources.Notification_FeedUpdate_Description)
                                          .SetPriority(NotificationCompat.PriorityDefault);
                            CreateNotificationChannel();

                            var manager = NotificationManager.FromContext(this);
                            manager.Notify(NotificationId, builder.Build());
                        }

                        Log.Info(nameof(FeedUpdateService), "Finishing feed update job service.");
                        JobFinished(jobParameters, true);
                    }
                }
                catch (Exception e)
                {
                    Log.Error(nameof(FeedUpdateService), $"Failed to process feed update notification. {e}");
                }
            });

            return(true);
        }