Adding initial playback bar logic.
This commit is contained in:
32
Harmonia.UI/Converters/ArtistsToStringConverter.cs
Normal file
32
Harmonia.UI/Converters/ArtistsToStringConverter.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using Avalonia.Data.Converters;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
|
||||
namespace Harmonia.UI.Converters;
|
||||
|
||||
public class ArtistsToStringConverter : IValueConverter
|
||||
{
|
||||
public ArtistsToStringConverter()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is not List<string>)
|
||||
return string.Empty;
|
||||
|
||||
List<string> artists = (List<string>)value;
|
||||
|
||||
if (artists == null)
|
||||
return string.Empty;
|
||||
|
||||
return string.Join(" / ", artists);
|
||||
}
|
||||
|
||||
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
return new List<string>();
|
||||
}
|
||||
}
|
||||
29
Harmonia.UI/Converters/NullVisibilityConverter.cs
Normal file
29
Harmonia.UI/Converters/NullVisibilityConverter.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using Avalonia.Data.Converters;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Globalization;
|
||||
|
||||
namespace Harmonia.UI.Converters;
|
||||
|
||||
public sealed class NullVisibilityConverter : IValueConverter
|
||||
{
|
||||
public NullVisibilityConverter()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is IList list)
|
||||
{
|
||||
return list.Count > 0;
|
||||
}
|
||||
|
||||
return value is not null;
|
||||
}
|
||||
|
||||
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
37
Harmonia.UI/Converters/SecondsToStringConverter.cs
Normal file
37
Harmonia.UI/Converters/SecondsToStringConverter.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using Avalonia.Data.Converters;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
namespace Harmonia.UI.Converters;
|
||||
|
||||
public sealed class SecondsToStringConverter : IValueConverter
|
||||
{
|
||||
public SecondsToStringConverter()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is not double doubleValue)
|
||||
return null;
|
||||
|
||||
TimeSpan timeSpan = TimeSpan.FromSeconds(doubleValue);
|
||||
|
||||
if (timeSpan.Hours >= 1)
|
||||
return timeSpan.ToString(@"%h\:mm\:ss");
|
||||
|
||||
return timeSpan.ToString(@"%m\:ss");
|
||||
}
|
||||
|
||||
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
if (value == null)
|
||||
return null;
|
||||
|
||||
if (value is not string stringValue)
|
||||
return null;
|
||||
|
||||
return TimeSpan.Parse(stringValue);
|
||||
}
|
||||
}
|
||||
27
Harmonia.UI/Converters/SongTitleConverter.cs
Normal file
27
Harmonia.UI/Converters/SongTitleConverter.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using Avalonia.Data.Converters;
|
||||
using Harmonia.Core.Models;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
namespace Harmonia.UI.Converters;
|
||||
|
||||
public sealed class SongTitleConverter : IValueConverter
|
||||
{
|
||||
public SongTitleConverter()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is not Song song)
|
||||
return null;
|
||||
|
||||
return string.IsNullOrWhiteSpace(song.Title) ? song.ShortFileName : song.Title;
|
||||
}
|
||||
|
||||
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user