forked from not-nullptr/Aerochat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Change time from 12 hr to 24 and back, also began working on th…
…e Attributes loader (not-nullptr#58)
- Loading branch information
Showing
12 changed files
with
309 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
// (iL - 21.12.2024) This is basically another abstraction layer for developers. | ||
// Let's say you have a beautiful DropDown for the Settings, but your Enum Variable Names are pretty cryptic | ||
// for the average End-User. With Aerochat.Attributes, you can show the user a beautiful string in the UI, | ||
// while here in the Code you can keep your cryptic and scary sounding Names. | ||
|
||
namespace Aerochat.Attributes | ||
{ | ||
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false)] | ||
public class DisplayAttribute : Attribute | ||
{ | ||
public string Name { get; set; } | ||
|
||
public DisplayAttribute(string name) | ||
{ | ||
Name = name; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using Aerochat.Enums; | ||
using Aerochat.Settings; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows.Data; | ||
|
||
namespace Aerochat.Windows | ||
{ | ||
public class TimeFormatConverter : IValueConverter | ||
{ | ||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
if (value is DateTime dateTime) | ||
{ | ||
// Retrieve SelectedTimeFormat from the SettingsManager | ||
var format = SettingsManager.Instance.SelectedTimeFormat; | ||
string formatString = format == TimeFormat.TwentyFourHour ? "HH:mm:ss" : "h:mm tt"; | ||
|
||
return dateTime.ToString(formatString); | ||
} | ||
return value; | ||
} | ||
|
||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Aerochat.Attributes; | ||
|
||
namespace Aerochat.Enums | ||
{ | ||
public enum TimeFormat | ||
{ | ||
[Display("24-Hour Clock")] | ||
TwentyFourHour, | ||
|
||
[Display("12-Hour Clock (AM/PM)")] | ||
TwelveHour | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Aerochat.Attributes; | ||
|
||
namespace Aerochat.Helpers | ||
{ | ||
public static class EnumHelper | ||
{ | ||
public static string GetDisplayName(Enum enumValue) | ||
{ | ||
var fieldInfo = enumValue.GetType() | ||
.GetField(enumValue.ToString(), BindingFlags.Public | BindingFlags.Static); | ||
|
||
if (fieldInfo != null) | ||
{ | ||
var displayAttribute = fieldInfo.GetCustomAttribute<DisplayAttribute>(); | ||
|
||
if (displayAttribute != null) | ||
{ | ||
return displayAttribute.Name; | ||
} | ||
} | ||
|
||
return enumValue.ToString(); | ||
} | ||
|
||
public static List<(string DisplayName, T EnumValue)> GetEnumDisplayList<T>() where T : Enum | ||
{ | ||
return Enum.GetValues(typeof(T)) | ||
.Cast<T>() | ||
.Select(e => (GetDisplayName(e), e)) // Create tuple of DisplayName and EnumValue | ||
.ToList(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.