Skip to content

Commit

Permalink
Update more dependency injection
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmontemagno committed Feb 25, 2022
1 parent a006599 commit cabf95d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
10 changes: 8 additions & 2 deletions src/Mobile/Controls/Player.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@

public partial class Player : ContentView
{
private readonly PlayerService playerService;
private PlayerService playerService;

public Player()
{
InitializeComponent();
this.playerService = this.Handler.MauiContext.Services.GetService<PlayerService>();
this.IsVisible = false;
}

protected override void OnHandlerChanged()
{
base.OnHandlerChanged();

this.playerService ??= this.Handler.MauiContext.Services.GetService<PlayerService>();
}

private async void PlayGesture_Tapped(object sender, EventArgs e)
{
await playerService.PlayAsync(playerService.CurrentEpisode, playerService.CurrentShow);
Expand Down
4 changes: 2 additions & 2 deletions src/Mobile/Models/Episode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ public Episode(RoomPlayerState playerState)
Url = new Uri(playerState.Episode.Url);
}

public Episode(EpisodeResponse response)
public Episode(EpisodeResponse response, ListenLaterService listenLater)
{
Id = response.Id;
Title = response.Title;
Description = response.Description;
Published = response.Published;
Duration = response.Duration;
Url = response.Url;
listenLaterService = ServicesProvider.GetService<ListenLaterService>();
listenLaterService = listenLater;
IsInListenLater = listenLaterService.IsInListenLater(this);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Mobile/Models/Show.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ public Show(RoomPlayerState playerState)
Image = new Uri(playerState.Episode.Show.Image);
}

public Show(ShowResponse response)
public Show(ShowResponse response, ListenLaterService listenLaterService)
{
Id = response.Id;
Title = response.Title;
Author = response.Author;
Description = response.Description;
Image = response.Image;
Updated = response.Updated;
Episodes = response.Episodes?.Select(resp => new Episode(resp));
Episodes = response.Episodes?.Select(resp => new Episode(resp, listenLaterService));
Categories = response.Categories?.Select(resp => new Category(resp));
}

Expand Down
6 changes: 4 additions & 2 deletions src/Mobile/Services/ShowsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ namespace Microsoft.NetConf2021.Maui.Services;
public class ShowsService
{
private readonly HttpClient httpClient;
private readonly ListenLaterService listenLaterService;

public ShowsService(HttpClient httpClient)
public ShowsService(HttpClient httpClient, ListenLaterService listenLaterService)
{
this.httpClient = httpClient;
this.listenLaterService = listenLaterService;
}

public async Task<IEnumerable<Category>> GetAllCategories()
Expand Down Expand Up @@ -68,7 +70,7 @@ public async Task<IEnumerable<Show>> SearchShowsAsync(string term)

private Show GetShow(ShowResponse response)
{
return new Show(response);
return new Show(response, listenLaterService);
}

private async Task<T> TryGetAsync<T>(string path)
Expand Down

0 comments on commit cabf95d

Please sign in to comment.