diff --git a/DdfGuide.Android/AudioDramaListAdapter.cs b/DdfGuide.Android/AudioDramaListAdapter.cs index afb9d26..e73c7b8 100644 --- a/DdfGuide.Android/AudioDramaListAdapter.cs +++ b/DdfGuide.Android/AudioDramaListAdapter.cs @@ -55,14 +55,9 @@ public override View GetView(int position, View convertView, ViewGroup parent) var favoriteView = view.FindViewById(Resource.Id.listcheckboxfavorite); favoriteView.Checked = audioDrama.AudioDramaUserData.IsFavorite; - if (_releaseDateService.IsReleased(audioDrama.AudioDramaDto)) - { - view.SetBackgroundColor(Color.White); - } - else - { - view.SetBackgroundColor(Color.LightGray); - } + view.SetBackgroundColor(_releaseDateService.IsReleased(audioDrama.AudioDramaDto) + ? Color.White + : Color.LightGray); return view; } diff --git a/DdfGuide.Android/AudioDramaListView.cs b/DdfGuide.Android/AudioDramaListView.cs index d56e62d..c56ee08 100644 --- a/DdfGuide.Android/AudioDramaListView.cs +++ b/DdfGuide.Android/AudioDramaListView.cs @@ -53,6 +53,8 @@ public override View OnCreateView(LayoutInflater inflater, ViewGroup container, private void SetupFloatingRandomButton() { var fab = _view.FindViewById(Resource.Id.floatingActionButtonRandom); + + // todo: #26 fab.SetBackgroundColor(Resources.GetColor(Resource.Color.ddfBlue)); fab.Click += (sender, args) => { RandomClicked?.Invoke(this, EventArgs.Empty); }; @@ -77,6 +79,8 @@ private void SetupToolbar() { _toolbar = _view.FindViewById(Resource.Id.toolbar); _toolbar.SetTitle(Resource.String.app_name); + + // todo: #26 _toolbar.SetTitleTextColor(Resources.GetColor(Resource.Color.ddfWhite)); SetupMenuItems(); diff --git a/DdfGuide.Android/DdfGuide.Android.csproj b/DdfGuide.Android/DdfGuide.Android.csproj index 1f84602..2e63f19 100644 --- a/DdfGuide.Android/DdfGuide.Android.csproj +++ b/DdfGuide.Android/DdfGuide.Android.csproj @@ -105,6 +105,9 @@ 12.0.1 + + 3.0.1 + 3.1.1 diff --git a/DdfGuide.Android/MainActivity.cs b/DdfGuide.Android/MainActivity.cs index 7ee9c3e..142ec0a 100644 --- a/DdfGuide.Android/MainActivity.cs +++ b/DdfGuide.Android/MainActivity.cs @@ -8,7 +8,8 @@ namespace DdfGuide.Android { - [Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true,ScreenOrientation = ScreenOrientation.Portrait, ConfigurationChanges = ConfigChanges.Orientation)] + [Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true, + ScreenOrientation = ScreenOrientation.Portrait, ConfigurationChanges = ConfigChanges.Orientation)] public class MainActivity : Activity, IRootView { private Core.DdfGuide _ddfGuide; @@ -49,7 +50,7 @@ private void ScheduleReleaseNotificationJob() { var jobBuilder = this.CreateJobBuilderUsingJobId(1); var jobInfo = jobBuilder - .SetPeriodic(TimeSpan.FromHours(12).Milliseconds, TimeSpan.FromHours(6).Milliseconds) + .SetPeriodic(TimeSpan.FromHours(6).Milliseconds, TimeSpan.FromHours(1).Milliseconds) .SetPersisted(true) .Build(); @@ -61,7 +62,7 @@ public void Show(IView view) { if (!(view is Fragment fragment)) { - throw new Exception("View needs to be of type Android.App.Fragment"); + throw new Exception("View needs to be of type Android.App.Fragment"); } var transaction = FragmentManager.BeginTransaction(); diff --git a/DdfGuide.Android/ReleaseNotificationJob.cs b/DdfGuide.Android/ReleaseNotificationJob.cs index 69a3ef0..59e1b1b 100644 --- a/DdfGuide.Android/ReleaseNotificationJob.cs +++ b/DdfGuide.Android/ReleaseNotificationJob.cs @@ -8,6 +8,7 @@ using Android.Support.V4.App; using DdfGuide.Core; using FFImageLoading; +using Nito.AsyncEx; namespace DdfGuide.Android { @@ -17,73 +18,79 @@ public class ReleaseNotificationJob : JobService { public override bool OnStartJob(JobParameters @params) { - Task.Run(async () => - { - var source = new DtoCache(); - var dtos = source.Load()?.ToList(); + Task.Run(() => ShowNotificationsIfApplicable(@params)); - if (dtos == null) - { - JobFinished(@params, false); - return; - } + return true; + } - var lastNoficationCache = new LastNotificationCache(); - var lastNofication = lastNoficationCache.Load(); + private void ShowNotificationsIfApplicable(JobParameters @params) + { + var source = new DtoCache(); + var dtos = source.Load()?.ToList(); - if (lastNofication.Date == DateTime.Today) - { - JobFinished(@params, false); - return; - } + 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(); + var releaseDateService = new ReleaseDateService(); + var releases = releaseDateService.GetTodaysReleasesFrom(dtos).ToList(); - CreateNotificationChannel(); - var notificationManager = NotificationManagerCompat.From(this); + if (!releases.Any()) + { + JobFinished(@params, false); + return; + } - for (var i = 0; i < releases.Count; i++) - { - var dto = releases[i]; + CreateNotificationChannel(); + var notificationManager = NotificationManagerCompat.From(this); - var cover = await DownloadCover(dto); + for (var i = 0; i < releases.Count; i++) + { + var dto = releases[i]; - var builder = new NotificationCompat.Builder(this, "channelid") - .SetOnlyAlertOnce(true) - .SetAutoCancel(true) - .SetContentTitle($"Neue {dto.Interpreter}-Folge!") - .SetSmallIcon(Resource.Mipmap.ic_stat_notification) - .SetLargeIcon(cover) - .SetContentText(dto.Title); + var cover = AsyncContext.Run(() => DownloadCover(dto)); - notificationManager.Notify(i, builder.Build()); + 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); - lastNoficationCache.Save(DateTime.Now); - } + notificationManager.Notify(i, builder.Build()); - JobFinished(@params, false); - }); + lastNotificationCache.Save(DateTime.Now); + } - return true; + JobFinished(@params, false); } private async Task DownloadCover(AudioDramaDto dto) { - Bitmap cover = null; + if (string.IsNullOrWhiteSpace(dto.CoverUrl)) + { + return BitmapFactory.DecodeResource(Resources, Resource.Drawable.ic_launcher); + } + try { - cover = (await ImageService.Instance.LoadUrl(dto.CoverUrl).AsBitmapDrawableAsync()).Bitmap; + return (await ImageService.Instance.LoadUrl(dto.CoverUrl).AsBitmapDrawableAsync()).Bitmap; } - finally + catch (Exception) { - if (cover == null) - { - cover = BitmapFactory.DecodeResource(Resources, Resource.Drawable.ic_launcher); - } + return BitmapFactory.DecodeResource(Resources, Resource.Drawable.ic_launcher); } - - return cover; } public override bool OnStopJob(JobParameters @params) diff --git a/DdfGuide.Parser/HoerspielDeParser.cs b/DdfGuide.Parser/HoerspielDeParser.cs index 835ddc8..cd04199 100644 --- a/DdfGuide.Parser/HoerspielDeParser.cs +++ b/DdfGuide.Parser/HoerspielDeParser.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; -using System.Net; using DdfGuide.Core; using HtmlAgilityPack; diff --git a/DdfGuide.Test/AudioDramaExplorerTests.cs b/DdfGuide.Test/AudioDramaExplorerTests.cs index 3406317..40da91b 100644 --- a/DdfGuide.Test/AudioDramaExplorerTests.cs +++ b/DdfGuide.Test/AudioDramaExplorerTests.cs @@ -6,7 +6,6 @@ using DdfGuide.Core.Sorting; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; -using Moq.AutoMock; namespace DdfGuide.Test { diff --git a/DdfGuide.Test/DtoFileTests.cs b/DdfGuide.Test/DtoFileTests.cs index 76be5ea..646e3f7 100644 --- a/DdfGuide.Test/DtoFileTests.cs +++ b/DdfGuide.Test/DtoFileTests.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; using System.Linq; using DdfGuide.Core; diff --git a/DdfGuide.Test/HoerspielDeParserTests.cs b/DdfGuide.Test/HoerspielDeParserTests.cs index 12702b4..bedc80d 100644 --- a/DdfGuide.Test/HoerspielDeParserTests.cs +++ b/DdfGuide.Test/HoerspielDeParserTests.cs @@ -1,5 +1,4 @@ using System; -using System.IO; using System.Linq; using System.Net; using System.Text; diff --git a/DdfGuide.Test/ReleaseDateServiceTests.cs b/DdfGuide.Test/ReleaseDateServiceTests.cs index b57261f..c26cdbd 100644 --- a/DdfGuide.Test/ReleaseDateServiceTests.cs +++ b/DdfGuide.Test/ReleaseDateServiceTests.cs @@ -1,10 +1,8 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Runtime.InteropServices; using DdfGuide.Core; using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; namespace DdfGuide.Test {