Пример #1
0
        protected override void OnCreate(Bundle bundle)
        {
            // The following two lines can be removed if this activity is navigated to immediately after the splash screen
            var setupSingleton = MvxAndroidSetupSingleton.EnsureSingletonAvailable(ApplicationContext);

            setupSingleton.EnsureInitialized();

            base.OnCreate(bundle);

            SetContentView(Resource.Layout.my_resource_name);
        }
Пример #2
0
        protected override void OnCreate(Bundle bundle)
        {
            // Required for proper Push notifications handling
            var setupSingleton = MvxAndroidSetupSingleton.EnsureSingletonAvailable(ApplicationContext);

            setupSingleton.EnsureInitialized();

            base.OnCreate(bundle);
            ViewModel?.ViewCreated();
            InitializeForms(bundle);
        }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Required for proper Push notifications handling
            var setupSingleton = MvxAndroidSetupSingleton.EnsureSingletonAvailable(ApplicationContext);

            setupSingleton.EnsureInitialized();

            LifetimeListener.OnCreate(this);
        }
        public override bool OnStartJob(JobParameters @params)
        {
            // mvvmcross might not be initialized here
            var setupSingleton = MvxAndroidSetupSingleton.EnsureSingletonAvailable(this.ApplicationContext);

            setupSingleton.EnsureInitialized();

            Task.Run(async() =>
            {
                var bitcoinPriceService = Mvx.Resolve <BitcoinPriceService>();

                try
                {
                    var bitcoinDataResponse = await bitcoinPriceService.QueryForBitcoinData();

                    // show toast on main thread
                    using (Handler handler = new Handler(Looper.MainLooper))
                    {
                        handler.Post(() =>
                        {
                            if (bitcoinDataResponse.IsSuccess)
                            {
                                Toast.MakeText(ApplicationContext, "Bitcoin price for date: " + bitcoinDataResponse.Results.Time.Updated + " is " + bitcoinDataResponse.Results.Price.Usd.RateFloat + " USD.", ToastLength.Long)
                                .Show();
                            }
                            else
                            {
                                Toast.MakeText(ApplicationContext, bitcoinDataResponse.FormattedErrorMessages, ToastLength.Long)
                                .Show();
                            }
                        });
                    }
                }
                catch (ApiException e)
                {
                    using (Handler handler = new Handler(Looper.MainLooper))
                    {
                        handler.Post(() =>
                        {
                            Toast.MakeText(ApplicationContext, "HTTP call ended without success - response code: " + e.StatusCode, ToastLength.Long)
                            .Show();
                        });
                    }
                }
                finally
                {
                    JobFinished(@params, true);
                }
            });


            return(true); // return true if job deferred to other thread (task longer than 16ms)
        }
        protected override void OnCreate(Bundle bundle)
        {
            // ensuring mvvmcross is running here is required
            // otherwise app will crash when inflating the view because of the Forms base class
            var setup = MvxAndroidSetupSingleton.EnsureSingletonAvailable(ApplicationContext);

            setup.EnsureInitialized();

            base.OnCreate(bundle);
            ViewModel?.ViewCreated();
            RunAppStart(bundle);
        }
        private void DoBackgroundWork(JobParameters args)
        {
            new Thread(async() =>
            {
                MvxAndroidSetupSingleton setupSingleton = MvxAndroidSetupSingleton.EnsureSingletonAvailable(Application.Context);
                setupSingleton.EnsureInitialized();

                await Mvx.IoCProvider.Resolve <INewPostsService>().CheckNewPosts();

                JobFinished(args, true);
            }).Start();
        }
Пример #7
0
        public static void EnsureSetupInitialized(this IMvxFragmentView fragmentView)
        {
            var fragment = fragmentView.ToFragment();

            if (fragment == null)
            {
                throw new MvxException("EnsureSetupInitialized called on an IMvxFragmentView which is not an Android Fragment: {0}", fragmentView);
            }

            var setupSingleton = MvxAndroidSetupSingleton.EnsureSingletonAvailable(fragment.Activity.ApplicationContext);

            setupSingleton.EnsureInitialized();
        }
Пример #8
0
        public static void EnsureSetupInitialized(this IMvxFragmentView fragmentView)
        {
            var fragment = fragmentView.ToFragment();

            if (fragment == null)
            {
                throw new MvxException($"{nameof(EnsureSetupInitialized)} called on an {nameof(IMvxFragmentView)} which is not an Android Fragment: {fragmentView}");
            }

            var setup = MvxAndroidSetupSingleton.EnsureSingletonAvailable(fragment.Activity.ApplicationContext);

            setup.EnsureInitialized();
        }
Пример #9
0
        private static void EnsureSetupInitialized(this IMvxAndroidView androidView)
        {
            if (androidView is IMvxAndroidSplashScreenActivity)
            {
                // splash screen views manage their own setup initialization
                return;
            }

            var activity = androidView.ToActivity();
            var setup    = MvxAndroidSetupSingleton.GetOrCreateSetup(activity.ApplicationContext);

            setup.EnsureInitialized(androidView.GetType());
        }
Пример #10
0
        private static void EnsureSetupInitialized(this IMvxAndroidView androidView)
        {
            if (androidView is IMvxSetupMonitor)
            {
                // setup monitor views manage their own setup initialization
                return;
            }

            var activity = androidView.ToActivity();
            var setup    = MvxAndroidSetupSingleton.EnsureSingletonAvailable(activity.ApplicationContext);

            setup.EnsureInitialized();
        }
Пример #11
0
        public override void OnMessageReceived(RemoteMessage remoteMessage)
        {
            var setup = MvxAndroidSetupSingleton.EnsureSingletonAvailable(Application.Context);

            setup.EnsureInitialized();

            if (remoteMessage?.Data != null &&
                PushNotificationHelper.TryParse(remoteMessage.Data, out NotificationType type, out string payload) &&
                Mvx.IoCProvider.Resolve <IAppService>() is IAppService appService)
            {
                new Thread(() => appService.RaiseNotificationReceived(type, payload)).Start();
                ShowForegroundNotification(type, payload, remoteMessage.Data);
            }
        }
Пример #12
0
        // this will be called when device
        public override void OnReceive(Context context, Intent intent)
        {
            // mvvmcross won't be initialized at this point
            var setupSingleton = MvxAndroidSetupSingleton.EnsureSingletonAvailable(context);

            setupSingleton.EnsureInitialized();

            var bitcoinPriceBackgroundServiceScheduler = Mvx.Resolve <BitcoinPriceBackgroundServiceScheduler>();

            // there should be check
            // if ( User Has Clicked Start Background Service Button in PAST
            // using some kind of storage
            bitcoinPriceBackgroundServiceScheduler.StartPeriodicBackgroundWorkUsingAlarmManager();
        }
Пример #13
0
        private void Init(Context context)
        {
            try
            {
                var setupSingleton = MvxAndroidSetupSingleton.EnsureSingletonAvailable(context);
                setupSingleton.EnsureInitialized();

                this.storage             = Mvx.Resolve <IPermanentStorageService>();
                this.notificationService = Mvx.Resolve <INotificationService>();
            }
            catch (Exception ex)
            {
                Console.WriteLine($"[PILLER] Error during NotificationPublisher Init: {ex}");
            }
        }
Пример #14
0
        protected override void OnCreate(Bundle bundle)
        {
            RequestWindowFeatures();

            var setup = MvxAndroidSetupSingleton.EnsureSingletonAvailable(ApplicationContext);

            setup.InitializeFromSplashScreen(this);

            base.OnCreate(bundle);

            if (_resourceId != NoContent)
            {
                // Set our view from the "splash" layout resource
                // Be careful to use non-binding inflation
                var content = LayoutInflater.Inflate(_resourceId, null);
                SetContentView(content);
            }
        }
Пример #15
0
        public override void OnNewToken(string token)
        {
            Debug.WriteLine($"*** {GetType().Name}.{nameof(OnNewToken)} - Token: {token}");

            var deviceInfo = new DeviceInfo {
                Handle   = token,
                Platform = DeviceType.Fcm
            };

            // We aren't guaranteed that Mvx is set up yet.
            var setup = MvxAndroidSetupSingleton.EnsureSingletonAvailable(Application.Context);

            setup.EnsureInitialized();

            var auth = Mvx.IoCProvider.Resolve <IAuthenticationService>();

            auth.DeviceInfo = deviceInfo;
        }
Пример #16
0
        public override bool OnStartJob(JobParameters @params)
        {
            MvxAndroidSetupSingleton
            .EnsureSingletonAvailable(ApplicationContext)
            .EnsureInitialized();

            if (!Mvx.TryResolve <IInteractorFactory>(out var interactorFactory))
            {
                return(false);
            }

            disposable = interactorFactory
                         .RunBackgroundSync()
                         .Execute()
                         .Subscribe(_ => JobFinished(@params, false));

            return(true);
        }
        protected override void OnHandleWork(Intent intent)
        {
            var setup = MvxAndroidSetupSingleton.EnsureSingletonAvailable(ApplicationContext);

            setup.EnsureInitialized();

            if (!Mvx.TryResolve <IInteractorFactory>(out var interactorFactory))
            {
                return;
            }

            disposable?.Dispose();
            disposable = null;

            disposable = interactorFactory
                         .ScheduleEventNotificationsForNextWeek()
                         .Execute()
                         .Subscribe();
        }
Пример #18
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            var setup = MvxAndroidSetupSingleton.EnsureSingletonAvailable(ApplicationContext);

            setup.EnsureInitialized();

            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.MainTabBarActivity);
            OverridePendingTransition(Resource.Animation.abc_fade_in, Resource.Animation.abc_fade_out);

            InitializeViews();
            showInitialFragment();

            navigationView
            .Rx()
            .ItemSelected()
            .Subscribe(onTabSelected)
            .DisposedBy(DisposeBag);
        }
        protected override void OnCreate(Bundle bundle)
        {
            // Prevents crash when activity in background with history enable is reopened after
            // Android does some auto memory management.
            var setup = MvxAndroidSetupSingleton.EnsureSingletonAvailable(this);

            setup.EnsureInitialized();

            base.OnCreate(bundle);

            var rootView = Window.DecorView.RootView;

            EventHandler onGlobalLayout = null;

            onGlobalLayout = (sender, args) =>
            {
                rootView.ViewTreeObserver.GlobalLayout -= onGlobalLayout;
                ViewModel?.Appeared();
            };

            rootView.ViewTreeObserver.GlobalLayout += onGlobalLayout;

            if (bundle == null)
            {
                HandleIntent(Intent);
            }
            else
            {
                IMvxJsonConverter serializer;
                if (!Mvx.TryResolve(out serializer))
                {
                    Mvx.Trace(
                        "Could not resolve IMvxJsonConverter, it is going to be hard to create ViewModel cache");
                    return;
                }

                FragmentCacheConfiguration.RestoreCacheConfiguration(bundle, serializer);
                // Gabriel has blown his trumpet. Ressurect Fragments from the dead
                RestoreFragmentsCache();

                RestoreViewModelsFromBundle(serializer, bundle);
            }
        }
        protected override void OnCreate(Bundle bundle)
        {
            TabLayoutResource = Resource.Layout.tabbar;
            ToolbarResource   = Resource.Layout.toolbar;

            base.OnCreate(bundle);
            Forms.Init(this, bundle);
            MvxAndroidSetupSingleton.EnsureSingletonAvailable(ApplicationContext).EnsureInitialized();

            // register interactive alerts
            InteractiveAlerts.Init(() => this);
            Mvx.RegisterSingleton(InteractiveAlerts.Instance);

            var mvxFormsApp = new MvxFormsApplication();

            LoadApplication(mvxFormsApp);
            if (Mvx.Resolve <IMvxViewPresenter>() is CustomPresenter presenter)
            {
                presenter.FormsApplication = mvxFormsApp;
            }

            Mvx.Resolve <IMvxAppStart>().Start();

            //var cancellationToken = CancellationToken.None;
            //var autheService = Mvx.Resolve<IAuthenticationService>();
            //var needsToAuthenticate = autheService.NeedsToAuthenticate(cancellationToken).WaitAsync().Result;
            //if (needsToAuthenticate)
            //{
            //    try
            //    {
            //        var token = autheService.GetAccessToken("adam", "asdf3235", cancellationToken).WaitAsync().Result;
            //        var accessToken = token.Token;
            //    }
            //    catch (Exception ex)
            //    {

            //    }
            //}

            _lifetimeListener = Mvx.Resolve <IMvxAndroidActivityLifetimeListener>();
            _lifetimeListener.OnCreate(this);
        }
Пример #21
0
        protected override void OnCreate(Bundle bundle)
        {
            RequestWindowFeature(WindowFeatures.NoTitle);

            _setup = MvxAndroidSetupSingleton.GetOrCreateSetup(ApplicationContext);

            // initialize app if necessary
            if (_setup.State == MvxSetup.MvxSetupState.Uninitialized)
            {
                _setup.InitializePrimary();
            }

            base.OnCreate(bundle);

            if (_resourceId != NoContent)
            {
                // Set our view from the "splash" layout resource
                // Be careful to use non-binding inflation
                var content = LayoutInflater.Inflate(_resourceId, null);
                SetContentView(content);
            }
        }
Пример #22
0
        protected override void OnCreate(Bundle bundle)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            try
            {
                //MK Possilbe fix for an issue where Mvx.Resolve<> throws object null reference
                //   https://github.com/MvvmCross/MvvmCross/issues/1192
                //   https://github.com/MvvmCross/MvvmCross/issues/1245
                var setup = MvxAndroidSetupSingleton.EnsureSingletonAvailable(ApplicationContext);
                setup.EnsureInitialized();
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e);
            }

            base.OnCreate(bundle);

            Forms.Init(this, bundle);

            // Set up mvvmcross
            var mvxFormsApp = new App();

            LoadApplication(mvxFormsApp);

            var presenter = Mvx.Resolve <IMvxViewPresenter>() as MvxFormsDroidPagePresenter;

            if (presenter != null)
            {
                presenter.MvxFormsApp = mvxFormsApp;
            }

            Mvx.Resolve <IMvxAppStart>().Start();

            ApplicationContext = this;
            InitDownloadManager();
        }
Пример #23
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            Logger.Initialize(this.GetType().FullName);
            this._errorHandlingHelper = new ErrorHandlingHelper(this);

            // ensure the initialization is done
            var setup = MvxAndroidSetupSingleton.EnsureSingletonAvailable(this.ApplicationContext);

            setup.EnsureInitialized();

            base.OnCreate(savedInstanceState);

            try
            {
                this.SetViewPermissions();
            }
            catch (NotImplementedException)
            {
                Logger.Debug("View permissions not set for this activity. We'll pretend this never happened.");
            }

            ResolveStartPoint(savedInstanceState);
        }
        protected override void OnHandleWork(Intent intent)
        {
            var setup = MvxAndroidSetupSingleton.EnsureSingletonAvailable(ApplicationContext);

            setup.EnsureInitialized();

            var dependencyContainer = AndroidDependencyContainer.Instance;

            if (!dependencyContainer.UserAccessManager.CheckIfLoggedIn())
            {
                return;
            }

            var interactorFactory = dependencyContainer.InteractorFactory;

            disposable?.Dispose();
            disposable = null;

            disposable = interactorFactory
                         .ScheduleEventNotificationsForNextWeek()
                         .Execute()
                         .Subscribe();
        }
        public override bool OnStartJob(JobParameters @params)
        {
            // Background sync is temporary disabled due to a crash that is hard to reproduce
            // Calling JobFinished and eturning early here stops the background job from running
            JobFinished(@params, false);
            return(true);

            MvxAndroidSetupSingleton
            .EnsureSingletonAvailable(ApplicationContext)
            .EnsureInitialized();

            if (!Mvx.TryResolve <IInteractorFactory>(out var interactorFactory))
            {
                return(false);
            }

            disposable = interactorFactory
                         .RunBackgroundSync()
                         .Execute()
                         .Subscribe(_ => JobFinished(@params, false));

            return(true);
        }
Пример #26
0
        protected override void OnHandleIntent(Intent intent)
        {
            var setup = MvxAndroidSetupSingleton.EnsureSingletonAvailable(ApplicationContext);

            setup.EnsureInitialized();
        }
Пример #27
0
        protected override void OnCreate(Bundle bundle)
        {
            var setup = MvxAndroidSetupSingleton.EnsureSingletonAvailable(ApplicationContext);

            setup.EnsureInitialized();

            base.OnCreate(bundle);
            var onCreateStopwatch = localStopwatchProvider.Create(MeasuredOperation.MainActivityOnCreate);

            onCreateStopwatch.Start();
            SetContentView(Resource.Layout.MainActivity);
            OverridePendingTransition(Resource.Animation.abc_fade_in, Resource.Animation.abc_fade_out);

            InitializeViews();

            SetSupportActionBar(FindViewById <Toolbar>(Resource.Id.Toolbar));
            SupportActionBar.SetDisplayShowHomeEnabled(false);
            SupportActionBar.SetDisplayShowTitleEnabled(false);

            runningEntryCardFrame.Visibility = ViewStates.Invisible;

            reportsView.Rx().BindAction(ViewModel.OpenReports).DisposedBy(DisposeBag);
            settingsView.Rx().BindAction(ViewModel.OpenSettings).DisposedBy(DisposeBag);
            stopButton.Rx().BindAction(ViewModel.StopTimeEntry, _ => TimeEntryStopOrigin.Manual).DisposedBy(DisposeBag);

            playButton.Rx().BindAction(ViewModel.StartTimeEntry, _ => true).DisposedBy(DisposeBag);
            playButton.Rx().BindAction(ViewModel.StartTimeEntry, _ => false, ButtonEventType.LongPress).DisposedBy(DisposeBag);

            timeEntryCard.Rx().Tap()
            .WithLatestFrom(ViewModel.CurrentRunningTimeEntry, (_, te) => te.Id)
            .Subscribe(ViewModel.SelectTimeEntry.Inputs)
            .DisposedBy(DisposeBag);

            ViewModel.ElapsedTime
            .Subscribe(timeEntryCardTimerLabel.Rx().TextObserver())
            .DisposedBy(DisposeBag);

            ViewModel.CurrentRunningTimeEntry
            .Select(te => te?.Description ?? "")
            .Subscribe(timeEntryCardDescriptionLabel.Rx().TextObserver())
            .DisposedBy(DisposeBag);

            ViewModel.CurrentRunningTimeEntry
            .Select(te => string.IsNullOrWhiteSpace(te?.Description))
            .Subscribe(timeEntryCardAddDescriptionLabel.Rx().IsVisible())
            .DisposedBy(DisposeBag);

            ViewModel.CurrentRunningTimeEntry
            .Select(te => string.IsNullOrWhiteSpace(te?.Description))
            .Invert()
            .Subscribe(timeEntryCardDescriptionLabel.Rx().IsVisible())
            .DisposedBy(DisposeBag);

            ViewModel.CurrentRunningTimeEntry
            .Select(createProjectClientTaskLabel)
            .Subscribe(timeEntryCardProjectClientTaskLabel.Rx().TextFormattedObserver())
            .DisposedBy(DisposeBag);

            var projectVisibilityObservable = ViewModel.CurrentRunningTimeEntry
                                              .Select(te => te?.Project != null);

            projectVisibilityObservable
            .Subscribe(timeEntryCardProjectClientTaskLabel.Rx().IsVisible())
            .DisposedBy(DisposeBag);

            projectVisibilityObservable
            .Subscribe(timeEntryCardDotContainer.Rx().IsVisible())
            .DisposedBy(DisposeBag);

            var projectColorObservable = ViewModel.CurrentRunningTimeEntry
                                         .Select(te => te?.Project?.Color ?? "#000000")
                                         .Select(Color.ParseColor);

            projectColorObservable
            .Subscribe(timeEntryCardDotView.Rx().DrawableColor())
            .DisposedBy(DisposeBag);

            var addDrawable  = ContextCompat.GetDrawable(this, Resource.Drawable.add_white);
            var playDrawable = ContextCompat.GetDrawable(this, Resource.Drawable.play_white);

            ViewModel.IsInManualMode
            .Select(isInManualMode => isInManualMode ? addDrawable : playDrawable)
            .Subscribe(playButton.SetImageDrawable)
            .DisposedBy(DisposeBag);

            ViewModel.IsTimeEntryRunning
            .Subscribe(onTimeEntryCardVisibilityChanged)
            .DisposedBy(DisposeBag);

            ViewModel.SyncProgressState
            .Subscribe(onSyncChanged)
            .DisposedBy(DisposeBag);

            mainRecyclerAdapter = new MainRecyclerAdapter(ViewModel.TimeEntries, ViewModel.TimeService)
            {
                SuggestionsViewModel = ViewModel.SuggestionsViewModel,
                RatingViewModel      = ViewModel.RatingViewModel,
                StopwatchProvider    = localStopwatchProvider
            };

            mainRecyclerAdapter.TimeEntryTaps
            .Select(te => te.Id)
            .Subscribe(ViewModel.SelectTimeEntry.Inputs)
            .DisposedBy(DisposeBag);

            mainRecyclerAdapter.ContinueTimeEntrySubject
            .Subscribe(ViewModel.ContinueTimeEntry.Inputs)
            .DisposedBy(DisposeBag);

            mainRecyclerAdapter.DeleteTimeEntrySubject
            .Subscribe(ViewModel.TimeEntriesViewModel.DelayDeleteTimeEntry.Inputs)
            .DisposedBy(DisposeBag);

            ViewModel.TimeEntriesViewModel.ShouldShowUndo
            .Subscribe(showUndoDeletion)
            .DisposedBy(DisposeBag);

            ViewModel.SyncProgressState
            .Subscribe(updateSyncingIndicator)
            .DisposedBy(DisposeBag);

            refreshLayout.Rx().Refreshed()
            .Subscribe(ViewModel.Refresh.Inputs)
            .DisposedBy(DisposeBag);

            setupLayoutManager(mainRecyclerAdapter);

            ViewModel.TimeEntries.CollectionChange
            .ObserveOn(SynchronizationContext.Current)
            .Subscribe(mainRecyclerAdapter.UpdateCollection)
            .DisposedBy(DisposeBag);

            ViewModel.IsTimeEntryRunning
            .ObserveOn(SynchronizationContext.Current)
            .Subscribe(updateRecyclerViewPadding)
            .DisposedBy(DisposeBag);

            notificationManager = GetSystemService(NotificationService) as NotificationManager;
            this.BindRunningTimeEntry(notificationManager, ViewModel.CurrentRunningTimeEntry, ViewModel.ShouldShowRunningTimeEntryNotification)
            .DisposedBy(DisposeBag);
            this.BindIdleTimer(notificationManager, ViewModel.IsTimeEntryRunning, ViewModel.ShouldShowStoppedTimeEntryNotification)
            .DisposedBy(DisposeBag);
            setupItemTouchHelper(mainRecyclerAdapter);

            ViewModel.TimeEntriesCount
            .Subscribe(timeEntriesCountSubject)
            .DisposedBy(DisposeBag);

            ViewModel.ShouldReloadTimeEntryLog
            .Subscribe(reload)
            .DisposedBy(DisposeBag);

            ViewModel.ShouldShowWelcomeBack
            .Subscribe(onWelcomeBackViewVisibilityChanged)
            .DisposedBy(DisposeBag);

            ViewModel.ShouldShowEmptyState
            .Subscribe(onEmptyStateVisibilityChanged)
            .DisposedBy(DisposeBag);

            setupOnboardingSteps();
            onCreateStopwatch.Stop();
        }
Пример #28
0
 /// <summary>
 /// If the app is already initializing async (via the splash screen), attempting to call MvxAndroidSetupSingleton.EnsureInitialized would normally crash
 /// https://github.com/MvvmCross/MvvmCross/issues/955
 /// </summary>
 public static void SafeEnsureInitialized([CallerMemberName] string caller = null)
 {
     System.Console.WriteLine("{0} SafeEnsureInitialized: Trying EnsureInitialized() from {1}", nameof(AndroidMvxInitializer), caller);
     MvxAndroidSetupSingleton.EnsureSingletonAvailable(Application.Context).EnsureInitialized();
 }
Пример #29
0
        public override void OnReceive(Context context, Intent intent)
        {
            var setup = MvxAndroidSetupSingleton.EnsureSingletonAvailable(context);

            setup.EnsureInitialized();
        }
Пример #30
0
        public async override void OnReceive(Context context, Intent intent)
        {
            try
            {
                var setupSingleton = MvxAndroidSetupSingleton.EnsureSingletonAvailable(context);
                setupSingleton.EnsureInitialized();

                RealmService   = new CryptoRealmService();
                CryptoDelegate = new CryptoDelegate();

                var cryptoCurrencies = await CryptoDelegate.GetCryptoCurrencyList();

                if (cryptoCurrencies != null && cryptoCurrencies.Count > 0)
                {
                    var searchDto = new ReminderSearchDto
                    {
                        Type = SearchType.AllReminders
                    };

                    var    reminders = RealmService.GetReminder(searchDto);
                    string message   = "";

                    foreach (var reminder in reminders)
                    {
                        var cryptoCurrency = cryptoCurrencies.FirstOrDefault(x => x.MarketName == reminder.MarketName);

                        if (cryptoCurrency == null)
                        {
                            continue;
                        }

                        if (reminder.IsExactValueSet && cryptoCurrency.Last == reminder.ExactValue)
                        {
                            message += reminder.MarketName + " has reached " + reminder.ExactValue.ConvertExpo() + ". \n";
                        }

                        if (reminder.IsLowerLimitSet && cryptoCurrency.Last < reminder.LowerLimit)
                        {
                            message += reminder.MarketName + " has gone below " + reminder.LowerLimit.ConvertExpo() + ". It's current value is " + cryptoCurrency.Last.ConvertExpo() + ". \n";
                        }

                        if (reminder.IsUpperLimitSet && cryptoCurrency.Last > reminder.UpperLimit)
                        {
                            message += reminder.MarketName + " has gone above " + reminder.UpperLimit.ConvertExpo() + ". It's current value is " + cryptoCurrency.Last.ConvertExpo() + ". \n";
                        }
                    }

                    message.TrimEnd('\r', '\n');

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

                    Notification.BigTextStyle textStyle = new Notification.BigTextStyle();
                    textStyle.BigText(message);
                    Notification.Builder builder = new Notification.Builder(context)
                                                   .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification))
                                                   .SetContentTitle("Crypto Reminder.")
                                                   .SetSmallIcon(Resource.Drawable.notification_bg)
                                                   .SetStyle(textStyle);

                    // Build the notification:
                    Notification notification = builder.Build();

                    // Get the notification manager:
                    NotificationManager notificationManager = context.GetSystemService(Context.NotificationService) as NotificationManager;

                    // Publish the notification:
                    const int notificationId = 0;
                    notificationManager.Notify(notificationId, notification);
                }
            }
            catch (Exception ex)
            {
            }
        }