-
-
Notifications
You must be signed in to change notification settings - Fork 54
feat: customize delay before the controls automatically hide #670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
109536e
172eec7
a76b789
5fce0f8
d2f13f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,76 @@ | ||||||||||
#nullable enable | ||||||||||
|
||||||||||
using System; | ||||||||||
using Windows.UI.Xaml.Data; | ||||||||||
|
||||||||||
namespace Screenbox.Converters; | ||||||||||
|
||||||||||
/// <summary> | ||||||||||
/// Defines the unit types for formatting numeric values with localized and pluralized resource strings. | ||||||||||
/// </summary> | ||||||||||
/// <remarks>This enumeration is used by the <see cref="IntToUnitStringConverter.Unit"/> property.</remarks> | ||||||||||
public enum UnitType | ||||||||||
{ | ||||||||||
None = 0, | ||||||||||
Albums = 1, | ||||||||||
Songs = 2, | ||||||||||
Seconds = 4, | ||||||||||
Items = 11, | ||||||||||
Comment on lines
+17
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The enum values use non-sequential numbers (1, 2, 4, 11) which creates magic numbers without clear purpose. Consider using sequential values starting from 0 or add comments explaining the significance of these specific numbers.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, the gaps are there for time related units, like Millisecond, Minutes, Hours, etc. |
||||||||||
} | ||||||||||
|
||||||||||
/// <summary> | ||||||||||
/// Converts an integer representing a quantity into a localized string representation for a specified unit, | ||||||||||
/// automatically adjusting for singular or plural forms based on the value. | ||||||||||
/// </summary> | ||||||||||
public sealed class IntToUnitStringConverter : IValueConverter | ||||||||||
{ | ||||||||||
/// <summary> | ||||||||||
/// Gets or sets the unit type used to represent the count. | ||||||||||
/// </summary> | ||||||||||
public UnitType Unit { get; set; } = UnitType.None; | ||||||||||
|
||||||||||
/// <summary> | ||||||||||
/// Converts an <see cref="int"/> value to a localized <see cref="string"/>, | ||||||||||
/// using the appropriate singular or plural resource for the specified unit type. | ||||||||||
/// </summary> | ||||||||||
/// <param name="value">The <see cref="int"/> being passed to the target.</param> | ||||||||||
/// <param name="targetType">The type of the target property. Not used.</param> | ||||||||||
/// <param name="parameter">An optional parameter to be used in the converter logic. Not used.</param> | ||||||||||
/// <param name="language">The language of the conversion. Not used.</param> | ||||||||||
/// <returns>The <see cref="string"/> representing the amount and its unit; otherwise, the value as a <see cref="string"/>.</returns> | ||||||||||
public object Convert(object value, Type targetType, object parameter, string language) | ||||||||||
{ | ||||||||||
if (value is int quantity && Unit is not UnitType.None) | ||||||||||
{ | ||||||||||
return GetLocalizedCountAndUnit(quantity, Unit); | ||||||||||
} | ||||||||||
|
||||||||||
return value?.ToString() ?? string.Empty; | ||||||||||
} | ||||||||||
|
||||||||||
/// <summary> | ||||||||||
/// Not implemented. | ||||||||||
/// </summary> | ||||||||||
/// <param name="value">The target data being passed to the source.</param> | ||||||||||
/// <param name="targetType">The type of the target property.</param> | ||||||||||
/// <param name="parameter">An optional parameter to be used in the converter logic.</param> | ||||||||||
/// <param name="language">The language of the conversion.</param> | ||||||||||
/// <returns>The value to be passed to the source object.</returns> | ||||||||||
/// <exception cref="NotImplementedException"></exception> | ||||||||||
public object ConvertBack(object value, Type targetType, object parameter, string language) | ||||||||||
{ | ||||||||||
throw new NotImplementedException(); | ||||||||||
} | ||||||||||
|
||||||||||
private string GetLocalizedCountAndUnit(int value, UnitType unit) | ||||||||||
{ | ||||||||||
return unit switch | ||||||||||
{ | ||||||||||
UnitType.Albums => Strings.Resources.AlbumsCount(value), | ||||||||||
UnitType.Songs => Strings.Resources.SongsCount(value), | ||||||||||
UnitType.Seconds => Strings.Resources.SecondsCount(value), | ||||||||||
UnitType.Items => Strings.Resources.ItemsCount(value), | ||||||||||
_ => $"{value} {unit.ToString().ToLowerInvariant()}" | ||||||||||
}; | ||||||||||
} | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm confused. How would we use this code? I only see the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was made for the seconds unit, but I chose to expand it to make it future-proof. If you think it's unnecessary or detrimental, I can scale it back to its original focus. |
||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hardcoded array of options should be moved to a configuration file or made configurable. This makes it difficult to modify the available delay options without code changes.
Copilot uses AI. Check for mistakes.