Skip to content

Commit

Permalink
Lot of changes in loading boards
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusz-kierepka-hl committed Oct 7, 2024
1 parent 1207864 commit a26ef63
Show file tree
Hide file tree
Showing 12 changed files with 828 additions and 559 deletions.
3 changes: 3 additions & 0 deletions ChatAAC/Converters/ColorConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ public class ColorConverter : IValueConverter
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is not string colorString) return Colors.Transparent;

if (string.IsNullOrEmpty(colorString)) return Colors.Transparent;

var rgb = colorString.Split(['(', ',', ')'], StringSplitOptions.RemoveEmptyEntries)
.Skip(1) // Skip "rgb"
.Select(int.Parse).ToList();
Expand Down
44 changes: 44 additions & 0 deletions ChatAAC/Converters/IntFromStringConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace ChatAAC.Converters;

public class IntFromStringConverter : JsonConverter<int>
{
public override int Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
try
{
switch (reader.TokenType)
{
case JsonTokenType.Number:
return reader.GetInt32();
case JsonTokenType.String:
{
var stringValue = reader.GetString();
if (int.TryParse(stringValue, out int result))
{
return result;
}

break;
}
default:
return 0;
}
}
catch
{
// Ignorujemy wyjątki i przechodzimy do zwrócenia wartości domyślnej
}

// Jeśli nie udało się sparsować, zwracamy domyślną wartość (np. 0) lub rzucamy wyjątek
return 0;
}

public override void Write(Utf8JsonWriter writer, int value, JsonSerializerOptions options)
{
writer.WriteNumberValue(value);
}
}
9 changes: 6 additions & 3 deletions ChatAAC/Models/Obf/Button.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
using System.Text.Json.Serialization;
using ChatAAC.Converters;

namespace ChatAAC.Models.Obf;

// Class for Button
public class Button
{
[JsonPropertyName("id")] public int Id { get; set; }
[JsonPropertyName("id")]
[JsonConverter(typeof(IntFromStringConverter))]
public int Id { get; set; }

[JsonPropertyName("label")] public string Label { get; set; } = string.Empty;

Expand All @@ -32,7 +35,7 @@ public int Width
get
{
var width = Image?.Width + 10;
if (width <= 10) width = 90;
if (width <= 10) width = ImageWidth;
if (width > ImageWidth) width = ImageWidth;
return width ?? ImageWidth;
}
Expand All @@ -44,7 +47,7 @@ public int Height
get
{
var height = Image?.Height + 30;
if (height <= 30) height = 110;
if (height <= 30) height = ImageHeight;
if (height > ImageHeight) height = ImageHeight;
return height ?? ImageHeight;
}
Expand Down
Loading

0 comments on commit a26ef63

Please sign in to comment.