Skip to content

Commit ccd7985

Browse files
committed
Refactore view models
1 parent 2fe6717 commit ccd7985

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+543
-589
lines changed

.tools/Bible.Alarm.Audio.Links.Harvestor/Utility/MediaReader.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,8 @@
99

1010
namespace Bible.Alarm.Audio.Links.Harvestor.Utility
1111
{
12-
public class MediaReader
12+
public class MediaReader(string indexRoot)
1313
{
14-
private readonly string indexRoot;
15-
public MediaReader(string indexRoot)
16-
{
17-
this.indexRoot = indexRoot;
18-
}
19-
2014
public async Task<Dictionary<string, Language>> GetBibleLanguages()
2115
{
2216
var root = indexRoot;

src/Bible.Alarm.Shared/Models/Media/Bible/BibleBook.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ public class BibleBook : IComparable
1111
public int Number { get; set; }
1212

1313
public int BibleTranslationId { get; set; }
14-
public BibleTranslation? BibleTranslation { get; set; }
14+
public BibleTranslation BibleTranslation { get; set; }
1515

1616
public List<BibleChapter> Chapters { get; set; } = new List<BibleChapter>();
1717

18-
public int CompareTo(object? obj)
18+
public int CompareTo(object obj)
1919
{
2020
if (obj is not BibleBook other) return 1;
2121
return Number.CompareTo(other.Number);

src/Bible.Alarm.Shared/Models/Media/Bible/BibleChapter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ public class BibleChapter : IComparable
1010

1111
public string Title => $"Chapter {Number}";
1212

13-
public AudioSource? Source { get; set; }
13+
public AudioSource Source { get; set; }
1414

1515
public int BibleBookId { get; set; }
16-
public BibleBook? Book { get; set; }
16+
public BibleBook Book { get; set; }
1717

18-
public int CompareTo(object? obj)
18+
public int CompareTo(object obj)
1919
{
2020
if (obj is not BibleChapter other) return 1;
2121
return Number.CompareTo(other.Number);

src/Bible.Alarm.Shared/Models/Media/Music/MusicTrack.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ public class MusicTrack : IComparable
99
public int Number { get; set; }
1010
public string Title { get; set; } = string.Empty;
1111

12-
public AudioSource? Source { get; set; }
12+
public AudioSource Source { get; set; }
1313

14-
public int CompareTo(object? obj)
14+
public int CompareTo(object obj)
1515
{
1616
if (obj is not MusicTrack other) return 1;
1717
return Number.CompareTo(other.Number);

src/Bible.Alarm.Shared/Models/Media/PlayItem.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
namespace Bible.Alarm.Shared.Models.Media
22
{
3-
public class PlayItem
3+
public class PlayItem(NotificationDetail detail, string url)
44
{
5-
public NotificationDetail PlayDetail { get; set; }
5+
public NotificationDetail PlayDetail { get; set; } = detail;
66

7-
public string Url { get; set; }
8-
9-
public PlayItem(NotificationDetail detail, string url)
10-
{
11-
PlayDetail = detail;
12-
Url = url;
13-
}
7+
public string Url { get; set; } = url;
148

159
public override string ToString()
1610
{

src/Bible.Alarm/App.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public App(ILogger logger, IServiceProvider serviceProvider)
4444
WeakReferenceMessenger.Default.Register<ClearToastsMessage>(this);
4545
}
4646

47-
protected override Window CreateWindow(IActivationState? activationState)
47+
protected override Window CreateWindow(IActivationState activationState)
4848
{
4949
var loadingPage = _serviceProvider.GetRequiredService<LoadingPage>();
5050
var navigationPage = new NavigationPage(loadingPage)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System.Threading.Tasks;
2+
3+
namespace Bible.Alarm.Common.Interfaces.Media;
4+
5+
public interface IScheduleDisplayService
6+
{
7+
Task<string> GetChapterDisplayNameAsync(long scheduleId, bool force = false);
8+
}
9+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Threading.Tasks;
2+
3+
namespace Bible.Alarm.Common.Interfaces.Media;
4+
5+
public interface ISchedulePlaybackService
6+
{
7+
Task PlayScheduleAsync(long scheduleId);
8+
Task<bool> CanMoveChapterAsync();
9+
}
10+
Lines changed: 18 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,48 @@
11
namespace Bible.Alarm.Common.Messenger;
22

33
// Message classes for WeakReferenceMessenger
4-
public class InitializedMessage
4+
public class InitializedMessage(bool value)
55
{
6-
public bool Value { get; }
7-
8-
public InitializedMessage(bool value)
9-
{
10-
Value = value;
11-
}
6+
public bool Value { get; } = value;
127
}
138

14-
public class ShowAlarmModalMessage
9+
public class ShowAlarmModalMessage(object value)
1510
{
16-
public object Value { get; }
17-
18-
public ShowAlarmModalMessage(object value)
19-
{
20-
Value = value;
21-
}
11+
public object Value { get; } = value;
2212
}
2313

24-
public class HideAlarmModalMessage
14+
public class HideAlarmModalMessage(object value)
2515
{
26-
public object Value { get; }
27-
28-
public HideAlarmModalMessage(object value)
29-
{
30-
Value = value;
31-
}
16+
public object Value { get; } = value;
3217
}
3318

34-
public class ShowMediaProgressModalMessage
19+
public class ShowMediaProgressModalMessage(object value)
3520
{
36-
public object Value { get; }
37-
38-
public ShowMediaProgressModalMessage(object value)
39-
{
40-
Value = value;
41-
}
21+
public object Value { get; } = value;
4222
}
4323

44-
public class HideMediaProgressModalMessage
24+
public class HideMediaProgressModalMessage(object value)
4525
{
46-
public object Value { get; }
47-
48-
public HideMediaProgressModalMessage(object value)
49-
{
50-
Value = value;
51-
}
26+
public object Value { get; } = value;
5227
}
5328

54-
public class MediaProgressMessage
29+
public class MediaProgressMessage(object value)
5530
{
56-
public object Value { get; }
57-
58-
public MediaProgressMessage(object value)
59-
{
60-
Value = value;
61-
}
31+
public object Value { get; } = value;
6232
}
6333

64-
public class TrackChangedMessage
34+
public class TrackChangedMessage(int value)
6535
{
66-
public int Value { get; }
67-
68-
public TrackChangedMessage(int value)
69-
{
70-
Value = value;
71-
}
36+
public int Value { get; } = value;
7237
}
7338

74-
public class ShowToastMessage
39+
public class ShowToastMessage(object value)
7540
{
76-
public object Value { get; }
77-
78-
public ShowToastMessage(object value)
79-
{
80-
Value = value;
81-
}
41+
public object Value { get; } = value;
8242
}
8343

84-
public class ClearToastsMessage
44+
public class ClearToastsMessage(object value)
8545
{
86-
public object Value { get; }
87-
88-
public ClearToastsMessage(object value)
89-
{
90-
Value = value;
91-
}
46+
public object Value { get; } = value;
9247
}
9348

src/Bible.Alarm/MauiProgram.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Bible.Alarm.Common.Interfaces.UI;
1111
using Bible.Alarm.Database;
1212
using Bible.Alarm.Models.Schedule;
13+
using Bible.Alarm.Services.Database;
1314
using Bible.Alarm.Services.Media;
1415
using Bible.Alarm.Services.Media.Interfaces;
1516
using Bible.Alarm.Services.Network;
@@ -88,6 +89,8 @@ public static MauiApp CreateMauiApp()
8889

8990
// Initialize Fluxor store
9091
var store = app.Services.GetRequiredService<IStore>();
92+
// Store initialization happens automatically, but we ensure it's ready
93+
store.InitializeAsync().GetAwaiter().GetResult();
9194
ReduxContainer.Store = store;
9295

9396
return app;
@@ -129,12 +132,16 @@ private static void RegisterCommonServices(IServiceCollection services)
129132
services.AddSingleton<IMediaCacheService, MediaCacheService>();
130133
services.AddSingleton<IPlaylistService, PlaylistService>();
131134
services.AddSingleton<IAlarmService, AlarmService>();
135+
services.AddSingleton<IScheduleStateService, ScheduleStateService>();
136+
services.AddSingleton<ISchedulePlaybackService, SchedulePlaybackService>();
137+
services.AddSingleton<IScheduleDisplayService, ScheduleDisplayService>();
132138
services.AddSingleton<INetworkStatusService, NetworkStatusService>();
133139
services.AddSingleton<IMediaElementAudioService, MediaElementAudioService>();
134140
services.AddSingleton<IPlaybackService, PlaybackService>();
135141
services.AddSingleton<SchedulerService>();
136142
services.AddSingleton<ISchedulerService>(sp => sp.GetRequiredService<SchedulerService>());
137143
services.AddSingleton<IMediaIndexService>(sp => sp.GetRequiredService<MediaIndexService>());
144+
services.AddSingleton<IDatabaseSeedService, DatabaseSeedService>();
138145

139146
// Register platform-specific version finder
140147
#if ANDROID

0 commit comments

Comments
 (0)