Beispiel #1
0
 public async Task <List <CryptoCurrencyReminderDto> > GetReminder(ReminderSearchDto search)
 {
     return(await Task.Run(() => {
         var response = RealmService.GetReminder(search);
         return response;
     }));
 }
Beispiel #2
0
        public async void DoLoadMyCryptoCurrency()
        {
            DialogService.ShowDialog(true);

            try
            {
                var searchDto = new ReminderSearchDto
                {
                    Type = SearchType.GroupedReminders
                };

                MyCryptoCurrencyList = await CryptoDelegate.GetReminder(searchDto);

                SortedMyCryptoCurrencyList = MyCryptoCurrencyList;
            }
            catch (Exception ex)
            {
            }

            DialogService.ShowDialog(false);
        }
Beispiel #3
0
        public async void DoLoadReminders()
        {
            DialogService.ShowDialog(true);

            try
            {
                var searchDto = new ReminderSearchDto
                {
                    Type           = SearchType.AllRemindersFor1Coin,
                    cryptoCurrency = Current
                };

                Reminders = await CryptoDelegate.GetReminder(searchDto);

                SortedReminders = Reminders;
            }
            catch (Exception ex)
            {
            }

            DialogService.ShowDialog(false);
        }
        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)
            {
            }
        }
        public List <CryptoCurrencyReminderDto> GetReminder(ReminderSearchDto search)
        {
            var reminders = new List <CryptoCurrencyReminderDto>();

            if (search == null)
            {
                return(null);
            }

            try
            {
                _realm = Realm.GetInstance(_realmConfiguration);

                switch (search.Type)
                {
                case SearchType.AllReminders:

                    var allRemindersRealm = _realm.All <CryptoCurrencyReminderRealm>().ToList();
                    foreach (var reminderRealm in allRemindersRealm)
                    {
                        reminders.Add(new CryptoCurrencyReminderDto
                        {
                            Id         = reminderRealm.Id,
                            MarketName = reminderRealm.MarketName,
                            LowerLimit = reminderRealm.LowerLimit,
                            UpperLimit = reminderRealm.UpperLimit,
                            ExactValue = reminderRealm.ExactValue,
                        });
                    }
                    break;

                case SearchType.GroupedReminders:

                    var groupedRemindersRealm = _realm.All <CryptoCurrencyReminderRealm>().ToList();
                    var groupedReminders      = groupedRemindersRealm.GroupBy(x => x.MarketName).Select(x => x.FirstOrDefault());
                    foreach (var reminderRealm in groupedReminders)
                    {
                        reminders.Add(new CryptoCurrencyReminderDto
                        {
                            Id         = reminderRealm.Id,
                            MarketName = reminderRealm.MarketName,
                            LowerLimit = reminderRealm.LowerLimit,
                            UpperLimit = reminderRealm.UpperLimit,
                            ExactValue = reminderRealm.ExactValue,
                        });
                    }
                    break;

                case SearchType.AllRemindersFor1Coin:

                    var cryptoCurrency = search.cryptoCurrency;
                    if (cryptoCurrency != null)
                    {
                        var realmReminders     = _realm.All <CryptoCurrencyReminderRealm>().ToList();
                        var realmRemindersList = realmReminders.Where(x => x.MarketName == cryptoCurrency.MarketName);
                        foreach (var reminderRealm in realmRemindersList)
                        {
                            reminders.Add(new CryptoCurrencyReminderDto
                            {
                                Id         = reminderRealm.Id,
                                MarketName = reminderRealm.MarketName,
                                LowerLimit = reminderRealm.LowerLimit,
                                UpperLimit = reminderRealm.UpperLimit,
                                ExactValue = reminderRealm.ExactValue,
                            });
                        }
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
            }

            return(reminders);
        }