Exemplo n.º 1
0
        public CryptoDelegate()
        {
            RealmService = Mvx.Resolve <ICryptoRealmService>();

            _client = new HttpClient();
            _client.DefaultRequestHeaders.Accept.Clear();
            _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        }
Exemplo n.º 2
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)
            {
            }
        }