Skip to content

Commit

Permalink
Update to Release of Net 8.0 (#1064)
Browse files Browse the repository at this point in the history
* Update to Release of Net 8.0

Fix code recommendations where relevant

* use non latest for the moment

The latest version seams to be missing Android SDK platform for API level 31
  • Loading branch information
ChrisPulman authored Nov 15, 2023
1 parent 42980da commit f63a155
Show file tree
Hide file tree
Showing 42 changed files with 112 additions and 189 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ jobs:
with:
configuration: Release
productNamespacePrefix: "Splat"
useVisualStudioPreview: true
useVisualStudioPreview: false
useMauiCheckDotNetTool: false
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
with:
configuration: Release
productNamespacePrefix: "Splat"
useVisualStudioPreview: true
useVisualStudioPreview: false
useMauiCheckDotNetTool: false
secrets:
SIGN_CLIENT_USER_ID: ${{ secrets.SIGN_CLIENT_USER_ID }}
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.build.props
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.Reactive.Testing" Version="6.0.0" />
<PackageReference Include="PublicApiGenerator" Version="11.0.0" />
<PackageReference Include="Verify.Xunit" Version="22.2.0" />
<PackageReference Include="Verify.Xunit" Version="22.3.0" />
</ItemGroup>

<ItemGroup Condition="$(IsTestProject)">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public sealed class ApplicationInsightsViewTracking(TelemetryClient telemetryCli
/// <param name="telemetry">Telemetry data.</param>
public void OnViewNavigation(PageViewTelemetry telemetry)
{
var pageViewTelemetry = GetPageViewTelemetry();
_ = GetPageViewTelemetry();
_telemetryClient.TrackPageView(telemetry);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Splat.Avalonia.DryIoc/Splat.Avalonia.DryIoc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<ItemGroup>
<PackageReference Include="Avalonia.ReactiveUI" Version="11.0.5" />
<PackageReference Include="DryIoc.Dll" Version="5.4.2" />
<PackageReference Include="DryIoc.Dll" Version="5.4.3" />
<ProjectReference Include="..\Splat\Splat.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<ItemGroup>
<PackageReference Include="Avalonia.ReactiveUI" Version="11.0.5" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0-rc.2.23479.6" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<ProjectReference Include="..\Splat\Splat.csproj" />
</ItemGroup>

Expand Down
9 changes: 4 additions & 5 deletions src/Splat.Drawing/Bitmaps/BitmapLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@ public static IBitmapLoader Current
get
{
var ret = _current;
if (ret is null)
return ret switch
{
throw new BitmapLoaderException("Could not find a default bitmap loader. This should never happen, your dependency resolver is broken");
}

return ret;
null => throw new BitmapLoaderException("Could not find a default bitmap loader. This should never happen, your dependency resolver is broken"),
_ => ret
};
}
set => _current = value;
}
Expand Down
10 changes: 5 additions & 5 deletions src/Splat.Drawing/Colors/SplatColor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ internal enum ColorType : short
/// <summary>
/// Gets a value indicating whether the current color is transparent black. Eg where R,G,B,A == 0.
/// </summary>
public bool IsEmpty => _state == (short)ColorType.Empty;
public readonly bool IsEmpty => _state == (short)ColorType.Empty;

/// <summary>
/// Gets the alpha component of the color.
Expand Down Expand Up @@ -101,17 +101,17 @@ public string Name
/// <summary>
/// Gets a value indicating whether the color is part of the <see cref="ColorType.Known"/> group.
/// </summary>
public bool IsKnownColor => (_state & ((short)ColorType.Known)) != 0;
public readonly bool IsKnownColor => (_state & ((short)ColorType.Known)) != 0;

/// <summary>
/// Gets a value indicating whether the color is part of the <see cref="ColorType.System"/> group.
/// </summary>
public bool IsSystemColor => (_state & ((short)ColorType.System)) != 0;
public readonly bool IsSystemColor => (_state & ((short)ColorType.System)) != 0;

/// <summary>
/// Gets a value indicating whether the color is par tof the <see cref="ColorType.Known"/> or <see cref="ColorType.Named"/> groups.
/// </summary>
public bool IsNamedColor => (_state & (short)(ColorType.Known | ColorType.Named)) != 0;
public readonly bool IsNamedColor => (_state & (short)(ColorType.Known | ColorType.Named)) != 0;

#if TARGET_JVM
/// <summary>
Expand Down Expand Up @@ -352,7 +352,7 @@ public float GetHue()

/// <summary>Gets the <see cref="KnownColor"/> of the current value (if one is available).</summary>
/// <returns>Returns the KnownColor enum value for this color, 0 if is not known.</returns>
public KnownColor ToKnownColor() => (KnownColor)_knownColor;
public readonly KnownColor ToKnownColor() => (KnownColor)_knownColor;

/// <inheritdoc />
public override bool Equals(object? obj) => obj switch
Expand Down
4 changes: 2 additions & 2 deletions src/Splat.Drawing/Platforms/Android/Bitmaps/BitmapMixins.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static class BitmapMixins
/// <returns>A <see cref="Drawable"/> bitmap.</returns>
public static Drawable ToNative(this IBitmap value) => value switch
{
null => throw new System.ArgumentNullException(nameof(value)),
null => throw new ArgumentNullException(nameof(value)),
AndroidBitmap androidBitmap => new BitmapDrawable(Application.Context.Resources, androidBitmap.Inner),
_ => ((DrawableBitmap)value).Inner,
};
Expand All @@ -39,7 +39,7 @@ public static IBitmap FromNative(this Bitmap value, bool copy = false)
#else
if (value is null)
{
throw new System.ArgumentNullException(nameof(value));
throw new ArgumentNullException(nameof(value));
}
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ internal sealed class DrawableBitmap(Drawable inner) : IBitmap
public void Dispose()
{
var disp = Interlocked.Exchange(ref _inner, null);
if (disp is not null)
{
disp.Dispose();
}
disp?.Dispose();
}
}
4 changes: 2 additions & 2 deletions src/Splat.Drawing/Platforms/Android/Maths/PointExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static System.Drawing.Point FromNative(this Point value)
#else
if (value == null)
{
throw new System.ArgumentNullException(nameof(value));
throw new ArgumentNullException(nameof(value));
}
#endif

Expand All @@ -57,7 +57,7 @@ public static System.Drawing.PointF FromNative(this PointF value)
#else
if (value == null)
{
throw new System.ArgumentNullException(nameof(value));
throw new ArgumentNullException(nameof(value));
}
#endif

Expand Down
4 changes: 2 additions & 2 deletions src/Splat.Drawing/Platforms/Android/Maths/RectExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static System.Drawing.Rectangle FromNative(this Rect value)
#else
if (value == null)
{
throw new System.ArgumentNullException(nameof(value));
throw new ArgumentNullException(nameof(value));
}
#endif

Expand All @@ -57,7 +57,7 @@ public static System.Drawing.RectangleF FromNative(this RectF value)
#else
if (value == null)
{
throw new System.ArgumentNullException(nameof(value));
throw new ArgumentNullException(nameof(value));
}
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static void RegisterPlatformBitmapLoader(this IMutableDependencyResolver
#else
if (resolver == null)
{
throw new System.ArgumentNullException(nameof(resolver));
throw new ArgumentNullException(nameof(resolver));
}
#endif

Expand Down
12 changes: 4 additions & 8 deletions src/Splat.Drawing/Platforms/Tizen/Bitmaps/BitmapMixins.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,9 @@ public static class BitmapMixins
/// </summary>
/// <param name="value">The bitmap to convert.</param>
/// <returns>A <see cref="BitmapFrame"/> bitmap.</returns>
public static BitmapFrame ToNative(this IBitmap value)
public static BitmapFrame ToNative(this IBitmap value) => value switch
{
if (value is null)
{
throw new System.ArgumentNullException(nameof(value));
}

return (value as TizenBitmap)?.Inner ?? throw new InvalidOperationException("Bitmap has been disposed");
}
null => throw new ArgumentNullException(nameof(value)),
_ => (value as TizenBitmap)?.Inner ?? throw new InvalidOperationException("Bitmap has been disposed")
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ public class PlatformBitmapLoader : IBitmapLoader
/// This is used due to the fact Tizen does not have a empty image object.
/// </summary>
private static readonly byte[] _emptyImage =
{
[
137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 100, 0, 0, 0, 100, 8, 2, 0, 0, 0, 255, 128, 2, 3, 0, 0, 0, 1, 115, 82, 71, 66, 0, 174, 206, 28, 233, 0, 0, 0, 4,
103, 65, 77, 65, 0, 0, 177, 143, 11, 252, 97, 5, 0, 0, 0, 9, 112, 72, 89, 115, 0, 0, 14, 195, 0, 0, 14, 195, 1, 199, 111, 168, 100, 0, 0, 0, 52, 73, 68, 65, 84, 120, 94, 237, 193, 1, 13, 0, 0, 0,
194, 160, 247, 79, 109, 14, 55, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 27, 53, 117, 148, 0, 1, 4, 253, 190, 98, 0, 0, 0,
0, 73, 69, 78, 68, 174, 66, 96, 130,
};
];

/// <inheritdoc />
public IBitmap Create(float width, float height) => new TizenBitmap(_emptyImage);
Expand Down
21 changes: 7 additions & 14 deletions src/Splat.Drawing/Platforms/Tizen/Bitmaps/TizenBitmap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ namespace Splat;
internal sealed class TizenBitmap : IBitmap
{
private static readonly ImageDecoder[] _decoderList =
{
[
new JpegDecoder(),
new PngDecoder(),
new BmpDecoder(),
new GifDecoder(),
};
];

/// <summary>
/// Initializes a new instance of the <see cref="TizenBitmap"/> class.
Expand Down Expand Up @@ -65,19 +65,12 @@ public Task Save(CompressedBitmapFormat format, float quality, Stream target)
break;
case CompressedBitmapFormat.Png:
encoder = new PngEncoder();
switch (qualityPercent)
((PngEncoder)encoder).Compression = qualityPercent switch
{
case 100:
((PngEncoder)encoder).Compression = PngCompression.None;
break;
case < 10:
((PngEncoder)encoder).Compression = PngCompression.Level1;
break;
default:
((PngEncoder)encoder).Compression = (PngCompression)(qualityPercent / 10);
break;
}

100 => PngCompression.None,
< 10 => PngCompression.Level1,
_ => (PngCompression)(qualityPercent / 10),
};
break;
}

Expand Down
12 changes: 4 additions & 8 deletions src/Splat.Drawing/Platforms/net4/Bitmaps/BitmapMixins.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,9 @@ public static class BitmapMixins
/// </summary>
/// <param name="value">The native bitmap to convert from.</param>
/// <returns>A <see cref="IBitmap"/> bitmap.</returns>
public static BitmapSource ToNative(this IBitmap value)
public static BitmapSource ToNative(this IBitmap value) => value switch
{
if (value is null)
{
throw new System.ArgumentNullException(nameof(value));
}

return ((BitmapSourceBitmap)value).Inner ?? throw new InvalidOperationException("There is not a valid bitmap");
}
null => throw new ArgumentNullException(nameof(value)),
_ => ((BitmapSourceBitmap)value).Inner ?? throw new InvalidOperationException("There is not a valid bitmap")
};
}
14 changes: 5 additions & 9 deletions src/Splat.Drawing/Platforms/net4/Bitmaps/BitmapSourceBitmap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,19 @@ internal sealed class BitmapSourceBitmap(BitmapSource bitmap) : IBitmap
public BitmapSource? Inner { get; private set; } = bitmap;

/// <inheritdoc />
public Task Save(CompressedBitmapFormat format, float quality, Stream target)
public Task Save(CompressedBitmapFormat format, float quality, Stream target) => Inner switch
{
if (Inner is null)
{
return Task.CompletedTask;
}

return Task.Run(() =>
null => Task.CompletedTask,
_ => Task.Run(() =>
{
var encoder = format == CompressedBitmapFormat.Jpeg ?
new JpegBitmapEncoder() { QualityLevel = (int)(quality * 100.0f) } :
(BitmapEncoder)new PngBitmapEncoder();

encoder.Frames.Add(BitmapFrame.Create(Inner));
encoder.Save(target);
});
}
})
};

/// <inheritdoc />
public void Dispose() => Inner = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ public static class BitmapMixins
/// </summary>
/// <param name="value">The bitmap to convert.</param>
/// <returns>A <see cref="BitmapSource"/> bitmap.</returns>
public static IBitmap FromNative(this BitmapSource value)
{
return new BitmapSourceBitmap(value);
}
public static IBitmap FromNative(this BitmapSource value) => new BitmapSourceBitmap(value);

/// <summary>
/// Converts a <see cref="BitmapSource"/> to a splat <see cref="IBitmap"/>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ internal sealed class BitmapSourceBitmap : IBitmap
/// Initializes a new instance of the <see cref="BitmapSourceBitmap"/> class.
/// </summary>
/// <param name="bitmap">The platform native bitmap we are wrapping.</param>
public BitmapSourceBitmap(BitmapSource bitmap)
{
Inner = bitmap;
}
public BitmapSourceBitmap(BitmapSource bitmap) => Inner = bitmap;

/// <inheritdoc />
public float Width => (float)(Inner?.Width ?? 0);
Expand Down Expand Up @@ -54,9 +51,6 @@ public Task Save(CompressedBitmapFormat format, float quality, Stream target)
}

/// <inheritdoc />
public void Dispose()
{
Inner = null;
}
public void Dispose() => Inner = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ public static class ColorExtensions
/// </summary>
/// <param name="value">The System.Drawing.Color to convert.</param>
/// <returns>A native XAML color.</returns>
public static Color ToNative(this System.Drawing.Color value)
{
return Color.FromArgb(value.A, value.R, value.G, value.B);
}
public static Color ToNative(this System.Drawing.Color value) =>
Color.FromArgb(value.A, value.R, value.G, value.B);

/// <summary>
/// Converts a <see cref="System.Drawing.Color"/> into the cocoa native <see cref="SolidColorBrush"/>.
Expand All @@ -39,9 +37,7 @@ public static SolidColorBrush ToNativeBrush(this System.Drawing.Color value)
/// </summary>
/// <param name="value">The color to convert.</param>
/// <returns>The <see cref="System.Drawing.Color"/> generated.</returns>
public static System.Drawing.Color FromNative(this Color value)
{
return System.Drawing.Color.FromArgb(value.A, value.R, value.G, value.B);
}
public static System.Drawing.Color FromNative(this Color value) =>
System.Drawing.Color.FromArgb(value.A, value.R, value.G, value.B);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ public static class SplatColorExtensions
/// </summary>
/// <param name="value">The color to convert.</param>
/// <returns>The <see cref="Color"/> generated.</returns>
public static Color ToNative(this SplatColor value)
{
return Color.FromArgb(value.A, value.R, value.G, value.B);
}
public static Color ToNative(this SplatColor value) =>
Color.FromArgb(value.A, value.R, value.G, value.B);

/// <summary>
/// Converts a <see cref="SplatColor"/> into the XAML <see cref="SolidColorBrush"/>.
Expand All @@ -39,9 +37,7 @@ public static SolidColorBrush ToNativeBrush(this SplatColor value)
/// </summary>
/// <param name="value">The color to convert.</param>
/// <returns>The <see cref="SplatColor"/> generated.</returns>
public static SplatColor FromNative(this Color value)
{
return SplatColor.FromArgb(value.A, value.R, value.G, value.B);
}
public static SplatColor FromNative(this Color value) =>
SplatColor.FromArgb(value.A, value.R, value.G, value.B);
}
}
Loading

0 comments on commit f63a155

Please sign in to comment.