Exemple #1
0
        private void ShowNotificationsIfApplicable(JobParameters @params)
        {
            var source = new DtoCache();
            var dtos   = source.Load()?.ToList();

            if (dtos == null)
            {
                JobFinished(@params, false);
                return;
            }

            var lastNotificationCache = new LastNotificationCache();
            var lastNotification      = lastNotificationCache.Load();

            if (lastNotification.Date == DateTime.Today)
            {
                JobFinished(@params, false);
                return;
            }

            var releaseDateService = new ReleaseDateService();
            var releases           = releaseDateService.GetTodaysReleasesFrom(dtos).ToList();

            if (!releases.Any())
            {
                JobFinished(@params, false);
                return;
            }

            CreateNotificationChannel();
            var notificationManager = NotificationManagerCompat.From(this);

            for (var i = 0; i < releases.Count; i++)
            {
                var dto = releases[i];

                var cover = AsyncContext.Run(() => DownloadCover(dto));

                var builder = new NotificationCompat.Builder(this, "channelid")
                              .SetAutoCancel(true)
                              .SetContentTitle($"Neue {dto.Interpreter}-Folge!")
                              .SetSmallIcon(Resource.Mipmap.ic_stat_notification)
                              .SetLargeIcon(cover)
                              .SetContentText(dto.Title);

                notificationManager.Notify(i, builder.Build());

                lastNotificationCache.Save(DateTime.Now);
            }

            JobFinished(@params, false);
        }
Exemple #2
0
        protected override async void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.activity_main);

            var releaseDateService = new ReleaseDateService();
            var filler             = new ImageViewFiller();
            var userNotifier       = new ToastNotifier(this);
            var audioDramaListView = new AudioDramaListView(filler, releaseDateService, userNotifier);
            var audioDramaView     = new AudioDramaView(filler);
            var rootView           = this;
            var dtoCache           = new DtoCache();
            var userDataCache      = new UserDataCache();
            var shutdown           = new AndroidShutdown(this);
            var uriInvoker         = new UriInvoker(this);
            var clipboardService   = new ClipboardService(this);
            var yesNoDialog        = new YesNoDialog(this);
            var okDialog           = new OkDialog(this);
            var updatingView       = new UpdatingView();

            _ddfGuide = new Core.DdfGuide(
                audioDramaListView,
                audioDramaView,
                rootView,
                dtoCache,
                userDataCache,
                shutdown,
                userNotifier,
                uriInvoker,
                clipboardService,
                yesNoDialog,
                okDialog,
                updatingView
                );

            await _ddfGuide.Start();

            ScheduleReleaseNotificationJob();
        }