Skip to content

Commit

Permalink
Upgrade to .net 7 and remove old xaml audio player library (#4)
Browse files Browse the repository at this point in the history
* Upgrade to .net 7 and remove old xaml audio player library

* update build for .net7 support

* Upgrade to latest support version of ios and android

* update yml build step for .net 7
  • Loading branch information
tinduong authored Jul 14, 2023
1 parent 41577de commit b24b94e
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 59 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: 6.0.x
dotnet-version: 7.0.x
- name: Install MAUI
run: dotnet workload install maui
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build CivicMobile/CivicMobile.csproj -c Release -f net6.0-android --no-restore
run: dotnet build CivicMobile/CivicMobile.csproj -c Release -f net7.0-android --no-restore

16 changes: 8 additions & 8 deletions CivicMobile/CivicMobile.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0-android;net6.0-ios;net6.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net6.0-windows10.0.19041.0</TargetFrameworks>
<TargetFrameworks>net7.0-android;net7.0-ios;net7.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net7.0-windows10.0.19041.0</TargetFrameworks>
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
<!-- <TargetFrameworks>$(TargetFrameworks);net6.0-tizen</TargetFrameworks> -->
<!-- <TargetFrameworks>$(TargetFrameworks);net7.0-tizen</TargetFrameworks> -->
<OutputType>Exe</OutputType>
<RootNamespace>CivicMobile</RootNamespace>
<UseMaui>true</UseMaui>
Expand All @@ -22,9 +22,9 @@
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
<ApplicationVersion>1</ApplicationVersion>

<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">14.2</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">16.1</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">14.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">31.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
Expand Down Expand Up @@ -56,17 +56,17 @@
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Audio\correct.wav" />
<EmbeddedResource Include="Audio\correct.wav" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Acr.UserDialogs" Version="8.0.1" />
<PackageReference Include="CommunityToolkit.Maui" Version="1.2.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.0.0" />
<PackageReference Include="Nancy" Version="2.0.0" />
<PackageReference Include="Plugin.Maui.Audio" Version="1.0.0" />
<PackageReference Include="Refractored.MvvmHelpers" Version="1.6.2" />
<PackageReference Include="sqlite-net-pcl" Version="1.8.116" />
<PackageReference Include="Xam.Plugin.SimpleAudioPlayer" Version="1.6.0" />
<PackageReference Include="Xam.Plugins.Settings" Version="3.1.1" />
</ItemGroup>

Expand Down Expand Up @@ -113,7 +113,7 @@
</ItemGroup>

<ItemGroup>
<Folder Include="Data\" />
<Folder Include="Data\" />
</ItemGroup>

</Project>
6 changes: 0 additions & 6 deletions CivicMobile/Interfaces/IAudioPlayer.cs

This file was deleted.

4 changes: 2 additions & 2 deletions CivicMobile/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using CivicMobile.ViewModels;
using CivicMobile.Views;
using CommunityToolkit.Maui;
using Plugin.Maui.Audio;

namespace CivicMobile;

Expand All @@ -24,7 +25,6 @@ public static MauiApp CreateMauiApp()

builder.Services.AddTransient<MainPage>();
builder.Services.AddTransient<MainPageViewModel>();

builder.Services.AddTransient<PracticePage>();
builder.Services.AddTransient<PracticePageViewModel>();

Expand All @@ -34,7 +34,7 @@ public static MauiApp CreateMauiApp()
builder.Services.AddTransient<SettingsPage>();
builder.Services.AddTransient<SettingsPageViewModel>();

builder.Services.AddTransient<IAudioPlayer, AudioPlayerService>();
builder.Services.AddSingleton(AudioManager.Current);

return builder.Build();
}
Expand Down
36 changes: 0 additions & 36 deletions CivicMobile/Services/AudioPlayerService.cs

This file was deleted.

20 changes: 15 additions & 5 deletions CivicMobile/ViewModels/PracticePageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
using CivicMobile.Services;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Microsoft.Maui.Storage;
using Plugin.Maui.Audio;
using System.Collections.ObjectModel;
using System.Reflection;

namespace CivicMobile.ViewModels;

Expand All @@ -24,19 +27,21 @@ public partial class PracticePageViewModel : BaseViewModel
private string _subTitle = "Yeah";

private QuestionService questionService;
private IAudioPlayer audioPlayer;
private readonly IAudioManager audioManager;

//private readonly IAudioService audioService;

[ObservableProperty]
private Boolean _isDone = false;

[ObservableProperty]
private SelectionMode _selectionMode = SelectionMode.Single;

public PracticePageViewModel(QuestionService questionService, IAudioPlayer audioPlayer)
public PracticePageViewModel(QuestionService questionService, IAudioManager audioManager)
{
Title = "Practice Exam";
this.questionService = questionService;
this.audioPlayer = audioPlayer;
this.audioManager = audioManager;
}

[RelayCommand]
Expand Down Expand Up @@ -89,7 +94,7 @@ private void NextQuestion()
}

[RelayCommand]
private void AnswerSelected()
private async void AnswerSelected()
{
if (CurrentQuestion == null || IsQuestionAnswered) return;
IsQuestionAnswered = true;
Expand All @@ -99,7 +104,12 @@ private void AnswerSelected()

if (isCorrect)
{
audioPlayer.Play("correct.wav");
// todo this probably need to be moved out of here
var assembly = typeof(App).GetTypeInfo().Assembly;
var stream = assembly.GetManifestResourceStream("CivicMobile.Audio." + "correct.wav");

var player = audioManager.CreatePlayer(stream);
player.Play();
}

#endregion
Expand Down

0 comments on commit b24b94e

Please sign in to comment.