Skip to content

Commit

Permalink
Code cleanup and preparation for the next release (breaking changes) (#…
Browse files Browse the repository at this point in the history
…1324)

* Code cleanup and preparation for .net 8

* Update CompareConverter.shared.cs

* Revert global.json

* More CleanUps

* Remove redundant TrySetCanceled and rely on speech recognition result

* Update Formatting

---------

Co-authored-by: Brandon Minnick <[email protected]>
  • Loading branch information
VladislavAntonyuk and TheCodeTraveler authored Aug 11, 2023
1 parent 272bb46 commit 930b468
Show file tree
Hide file tree
Showing 32 changed files with 103 additions and 189 deletions.
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Project>
<PropertyGroup>
<NetVersion>net7.0</NetVersion>
<!-- Fixes https://github.com/dotnet/maui/pull/12114 -->
<PublishReadyToRun>false</PublishReadyToRun>
<LangVersion>latest</LangVersion>
Expand Down
8 changes: 4 additions & 4 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<Project>
<ItemGroup Condition="$(TargetFramework.StartsWith('Xamarin.iOS')) != true AND $(TargetFramework.StartsWith('net7.0-ios')) != true">
<ItemGroup Condition="$(TargetFramework.StartsWith('Xamarin.iOS')) != true AND $(TargetFramework.StartsWith('$(NetVersion)-ios')) != true">
<Compile Remove="**\**\*.ios.cs" />
<None Include="**\**\*.ios.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
<Compile Remove="**\ios\**\*.cs" />
<None Include="**\ios\**\*.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
</ItemGroup>
<ItemGroup Condition="$(TargetFramework.StartsWith('Xamarin.Mac')) != true AND $(TargetFramework.StartsWith('net7.0-maccatalyst')) != true">
<ItemGroup Condition="$(TargetFramework.StartsWith('Xamarin.Mac')) != true AND $(TargetFramework.StartsWith('$(NetVersion)-maccatalyst')) != true">
<Compile Remove="**\*.macos.cs" />
<None Include="**\*.macos.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
<Compile Remove="**\macos\**\*.cs" />
<None Include="**\macos\**\*.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
</ItemGroup>
<ItemGroup Condition="$(TargetFramework.StartsWith('Xamarin.Mac')) != true AND $(TargetFramework.StartsWith('Xamarin.iOS')) != true AND $(TargetFramework.StartsWith('net7.0-ios')) != true AND $(TargetFramework.StartsWith('net7.0-maccatalyst')) != true">
<ItemGroup Condition="$(TargetFramework.StartsWith('Xamarin.Mac')) != true AND $(TargetFramework.StartsWith('Xamarin.iOS')) != true AND $(TargetFramework.StartsWith('$(NetVersion)-ios')) != true AND $(TargetFramework.StartsWith('$(NetVersion)-maccatalyst')) != true">
<Compile Remove="**\*.macios.cs" />
<None Include="**\*.macios.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
<Compile Remove="**\macios\**\*.cs" />
<None Include="**\macios\**\*.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
</ItemGroup>
<ItemGroup Condition="$(TargetFramework.StartsWith('MonoAndroid')) != true AND $(TargetFramework.StartsWith('net7.0-android')) != true ">
<ItemGroup Condition="$(TargetFramework.StartsWith('MonoAndroid')) != true AND $(TargetFramework.StartsWith('$(NetVersion)-android')) != true ">
<Compile Remove="**\**\*.android.cs" />
<None Include="**\**\*.android.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
<Compile Remove="**\android\**\*.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net7.0-ios;net7.0-android;net7.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net7.0-windows10.0.19041.0</TargetFrameworks>
<TargetFrameworks Condition="'$(IncludeTizenTargetFrameworks)' == 'true'">$(TargetFrameworks);net7.0-tizen</TargetFrameworks>
<TargetFrameworks>$(NetVersion)-ios;$(NetVersion)-android;$(NetVersion)-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);$(NetVersion)-windows10.0.19041.0</TargetFrameworks>
<TargetFrameworks Condition="'$(IncludeTizenTargetFrameworks)' == 'true'">$(TargetFrameworks);$(NetVersion)-tizen</TargetFrameworks>
<OutputType>Exe</OutputType>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<Picker
Grid.Row="2"
ItemsSource="{Binding Locales}"
SelectedItem="{Binding Locale}"
SelectedItem="{Binding CurrentLocale}"
ItemDisplayBinding="{Binding ., Converter={StaticResource PickerLocaleDisplayConverter}}"
Margin="0,0,0,20">
</Picker>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ public ShowPopupInOnAppearingPage(

protected override async void OnAppearing()
{

// Proves that we now support showing a popup before the platform is even ready.
var result = await this.ShowPopupAsync(new ReturnResultPopup(popupSizeConstants));
await this.ShowPopupAsync(new ReturnResultPopup(popupSizeConstants));
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CommunityToolkit.Mvvm.ComponentModel;
using System.Diagnostics;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Microsoft.Maui.Dispatching;

Expand Down Expand Up @@ -58,7 +59,7 @@ async Task DownloadDotNetBotImage()
}
catch (Exception e)
{
Console.WriteLine(e);
Trace.WriteLine(e);
OnImageDownloadFailed(e.Message);
}
finally
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public partial class SpeechToTextViewModel : BaseViewModel
readonly ISpeechToText speechToText;

[ObservableProperty]
Locale? locale;
Locale? currentLocale;

[ObservableProperty]
string? recognitionText = "Welcome to .NET MAUI Community Toolkit!";
Expand All @@ -45,15 +45,15 @@ async Task SetLocales()
Locales.Add(locale);
}

Locale = Locales.FirstOrDefault(x => x.Language is defaultLanguage or defaultLanguage_android or defaultLanguage_tizen) ?? Locales.FirstOrDefault();
CurrentLocale = Locales.FirstOrDefault(x => x.Language is defaultLanguage or defaultLanguage_android or defaultLanguage_tizen) ?? Locales.FirstOrDefault();
}

[RelayCommand]
async Task Play(CancellationToken cancellationToken)
{
await textToSpeech.SpeakAsync(RecognitionText ?? "Welcome to .NET MAUI Community Toolkit!", new()
{
Locale = Locale,
Locale = CurrentLocale,
Pitch = 2,
Volume = 1
}, cancellationToken);
Expand All @@ -74,7 +74,7 @@ async Task Listen(CancellationToken cancellationToken)
RecognitionText = beginSpeakingPrompt;

var recognitionResult = await speechToText.ListenAsync(
CultureInfo.GetCultureInfo(Locale?.Language ?? defaultLanguage),
CultureInfo.GetCultureInfo(CurrentLocale?.Language ?? defaultLanguage),
new Progress<string>(partialText =>
{
if (RecognitionText is beginSpeakingPrompt)
Expand Down Expand Up @@ -102,6 +102,6 @@ async Task Listen(CancellationToken cancellationToken)

void HandleLocalesCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
OnPropertyChanged(nameof(Locale));
OnPropertyChanged(nameof(CurrentLocale));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,10 @@ public sealed partial class PopupAnchorViewModel : BaseViewModel
[RelayCommand]
static void ShowPopup(View anchor)
{

// Using the C# version of Popup until this get fixed
// https://github.com/dotnet/maui/issues/4300

// This works

var popup = new TransparentPopupCSharp()
{
Anchor = anchor
};

// This doesn't work

//var popup = new TransparentPopup
//{
// Anchor = anchor
//};

Page.ShowPopup(popup);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>$(NetVersion)</TargetFramework>
<IsPackable>false</IsPackable>
<UseMaui>true</UseMaui>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
Expand Down
10 changes: 5 additions & 5 deletions src/CommunityToolkit.Maui.Core/CommunityToolkit.Maui.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net7.0;net7.0-android;net7.0-ios;net7.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net7.0-windows10.0.19041.0</TargetFrameworks>
<TargetFrameworks Condition="'$(IncludeTizenTargetFrameworks)' == 'true'">$(TargetFrameworks);net7.0-tizen</TargetFrameworks>
<TargetFrameworks>$(NetVersion);$(NetVersion)-android;$(NetVersion)-ios;$(NetVersion)-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);$(NetVersion)-windows10.0.19041.0</TargetFrameworks>
<TargetFrameworks Condition="'$(IncludeTizenTargetFrameworks)' == 'true'">$(TargetFrameworks);$(NetVersion)-tizen</TargetFrameworks>
<UseMauiCore>true</UseMauiCore>
<UseMauiEssentials>true</UseMauiEssentials>
<SingleProject>true</SingleProject>
Expand All @@ -24,7 +24,7 @@
<Authors>Microsoft</Authors>
<Owners>Microsoft</Owners>
<NeutralLanguage>en</NeutralLanguage>
<Product>CommunityToolkit.Maui (net7.0)</Product>
<Product>CommunityToolkit.Maui ($(NetVersion))</Product>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/CommunityToolkit/Maui</PackageProjectUrl>
Expand Down Expand Up @@ -56,7 +56,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>

<PackageReference Include="System.Speech" Version="7.0.0" Condition="'$(TargetFramework)' == 'net7.0-windows10.0.19041.0'" />
<PackageReference Include="System.Speech" Version="7.0.0" Condition="'$(TargetFramework)' == '$(NetVersion)-windows10.0.19041.0'" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async Task<string> InternalSaveAsync(string initialPath, string fileName, Stream
var isDirectoryCreated = fileManager.CreateDirectory(tempDirectoryPath, true, null, out var error);
if (!isDirectoryCreated)
{
throw new Exception(error?.LocalizedDescription ?? "Unable to create temp directory.");
throw new FileSaveException(error?.LocalizedDescription ?? "Unable to create temp directory.");
}

var fileUrl = tempDirectoryPath.Append(fileName, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ async Task<string> ListenOnline(CultureInfo culture, IProgress<string>? recognit
await using (cancellationToken.Register(async () =>
{
await StopRecording();
speechRecognitionTaskCompletionSource.SetCanceled();
}))
{
return await speechRecognitionTaskCompletionSource.Task;
Expand Down Expand Up @@ -119,7 +118,10 @@ async Task StopRecording()
{
try
{
await speechRecognizer?.ContinuousRecognitionSession.StopAsync();
if (speechRecognizer is not null)
{
await speechRecognizer.ContinuousRecognitionSession.StopAsync();
}
}
catch
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace CommunityToolkit.Maui.Core.Platform;

static partial class StatusBar
{
static void PlatformSetColor(Color color) => throw new NotSupportedException($"{nameof(PlatformSetColor)} is only supported on net6.0-ios and net6.0-android and later");
static void PlatformSetColor(Color color) => throw new NotSupportedException($"{nameof(PlatformSetColor)} is only supported on iOS and Android 23 and later");

static void PlatformSetStyle(StatusBarStyle statusBarStyle) => throw new NotSupportedException($"{nameof(PlatformSetStyle)} is only supported on net6.0-ios and net6.0-android and later");
static void PlatformSetStyle(StatusBarStyle statusBarStyle) => throw new NotSupportedException($"{nameof(PlatformSetStyle)} is only supported on iOS and Android 23 and later");
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Collections.ObjectModel;
using Android.Content;
using Android.Views;
using CommunityToolkit.Maui.Core.Extensions;
using Microsoft.Maui.Platform;
using AColor = Android.Graphics.Color;
using APaint = Android.Graphics.Paint;
Expand Down Expand Up @@ -85,4 +87,17 @@ void Redraw()
{
Invalidate();
}

static ObservableCollection<PointF> CreateCollectionWithNormalizedPoints(in ObservableCollection<PointF> points, in int drawingViewWidth, in int drawingViewHeight, in float canvasScale)
{
var newPoints = new List<PointF>();
foreach (var point in points)
{
var pointX = Math.Clamp(point.X, 0, drawingViewWidth / canvasScale);
var pointY = Math.Clamp(point.Y, 0, drawingViewHeight / canvasScale);
newPoints.Add(new PointF(pointX, pointY));
}

return newPoints.ToObservableCollection();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ static void SetStroke(in ICanvas canvas, in float lineWidth, in Color lineColor)
canvas.StrokeColor = lineColor;
canvas.StrokeSize = lineWidth;
canvas.StrokeDashOffset = 0;
canvas.StrokeLineCap = LineCap.Butt;
canvas.StrokeLineJoin = LineJoin.Miter;
canvas.StrokeLineCap = LineCap.Round;
canvas.StrokeLineJoin = LineJoin.Round;
canvas.StrokeDashPattern = Array.Empty<float>();
}

Expand Down Expand Up @@ -221,20 +221,5 @@ static void DrawCurrentLines(in ICanvas canvas, in MauiDrawingView drawingView)
}
}
}

#if ANDROID
static ObservableCollection<PointF> CreateCollectionWithNormalizedPoints(in ObservableCollection<PointF> points, in int drawingViewWidth, in int drawingViewHeight, in float canvasScale)
{
var newPoints = new List<PointF>();
foreach (var point in points)
{
var pointX = Math.Clamp(point.X, 0, drawingViewWidth / canvasScale);
var pointY = Math.Clamp(point.Y, 0, drawingViewHeight / canvasScale);
newPoints.Add(new PointF(pointX, pointY));
}

return newPoints.ToObservableCollection();
}
#endif
}
}
79 changes: 0 additions & 79 deletions src/CommunityToolkit.Maui.Core/Views/RoundedStackView.macios.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net7.0;net7.0-android;net7.0-ios;net7.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net7.0-windows10.0.19041.0</TargetFrameworks>
<TargetFrameworks Condition="'$(IncludeTizenTargetFrameworks)' == 'true'">$(TargetFrameworks);net7.0-tizen</TargetFrameworks>
<TargetFrameworks>$(NetVersion);$(NetVersion)-android;$(NetVersion)-ios;$(NetVersion)-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);$(NetVersion)-windows10.0.19041.0</TargetFrameworks>
<TargetFrameworks Condition="'$(IncludeTizenTargetFrameworks)' == 'true'">$(TargetFrameworks);$(NetVersion)-tizen</TargetFrameworks>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand All @@ -23,7 +23,7 @@
<Authors>Microsoft</Authors>
<Owners>Microsoft</Owners>
<NeutralLanguage>en</NeutralLanguage>
<Product>CommunityToolkit.Maui (net7.0)</Product>
<Product>CommunityToolkit.Maui ($(NetVersion))</Product>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/CommunityToolkit/Maui</PackageProjectUrl>
Expand Down
Loading

0 comments on commit 930b468

Please sign in to comment.