Skip to content
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

Code Quality: Icon improvements #14792

Merged
merged 11 commits into from
Feb 21, 2024
Merged

Code Quality: Icon improvements #14792

merged 11 commits into from
Feb 21, 2024

Conversation

yaira2
Copy link
Member

@yaira2 yaira2 commented Feb 20, 2024

  • added an IconOptions enum
  • separated code for retrieving icons & icon overlays

@yaira2 yaira2 force-pushed the ya/GetOverlay branch 4 times, most recently from 6b17da7 to 1779e4e Compare February 20, 2024 21:59
@yaira2 yaira2 changed the title Code Quality: Separate icons and icon overlays Code Quality: Icon improvements Feb 20, 2024
@yaira2 yaira2 marked this pull request as ready for review February 20, 2024 22:01
@yaira2 yaira2 requested a review from 0x5bfa February 20, 2024 22:01
/// </summary>
public float AppWindowDpi
private float appWindowDPI = InteropHelpers.GetDpiForWindow(MainWindow.Instance.WindowHandle) / 96f;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the coding guideline, this should be _AppWindowDPI - a field backing a property.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the other properties in AppModel as well in order to be consistent

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

/// <returns></returns>
public static (byte[]? icon, byte[]? overlay, bool isIconCached) GetFileIconAndOverlay(
public static (byte[]? icon, bool isIconCached) GetIcon(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use out variable for isIconCached.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What changes would need to be made and what's the benefit?

Copy link
Member

@0x5bfa 0x5bfa Feb 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to avoid returning tuple type. I'd like methods to return single variable(struct type, pre-defined types) to have single resposibility.

Now

public static async Task<(byte[] IconData, bool isIconCached)> GetIconAsync(
	string path,
	uint requestedSize,
	bool isFolder,
	bool getThumbnailOnly,
	IconOptions iconOptions)

After

public static async Task<byte[] IconData> GetIconAsync(
	string path,
	uint requestedSize,
	bool isFolder,
	bool getThumbnailOnly,
	IconOptions iconOptions,
	out bool isIconCached)

Besides, I see isIconCached often is not used.
So when you want to discard, you can just do:

public static async Task<byte[] IconData> GetIconAsync(
	"",
	0,
	false,
	false,
	IconOptions.None,
	out var _)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this is just my preferences for codebase quality.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do this in a future phase 👍

src/Files.App/Utils/Storage/Search/FolderSearch.cs Outdated Show resolved Hide resolved
@@ -97,7 +97,9 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
{
ViewModel.IsAblumCoverModified = true;
ViewModel.ModifiedAlbumCover = new Picture(file.Path);
ViewModel.IconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(file.Path, Constants.ShellIconSizes.ExtraLarge, false, false, false, true);

var result = await FileThumbnailHelper.GetIconAsync(file.Path, Constants.ShellIconSizes.ExtraLarge, false, false, IconOptions.UseCurrentScale);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above.

var iconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(Item.ItemPath, Constants.ShellIconSizes.Jumbo, false, false, false, false);
if (iconData is not null)
await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(async () => FileImage = await iconData.ToBitmapAsync());
var result = await FileThumbnailHelper.GetIconAsync(Item.ItemPath, Constants.ShellIconSizes.Jumbo, false, false, IconOptions.None);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above. I think this line should one more line break.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still working on the code in GetIconAsync so I'd rather wait until that's complete before putting time into the formatting.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

/// <summary>
/// Behavior used to retrieve and adjust icons
/// </summary>
public enum IconOptions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't need [Flags] attribute?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the pointer

@yaira2 yaira2 requested a review from 0x5bfa February 21, 2024 16:55
Copy link
Member

@0x5bfa 0x5bfa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A+
LGTM!

@yaira2 yaira2 added ready to merge Pull requests that are approved and ready to merge and removed needs - code review labels Feb 21, 2024
@yaira2 yaira2 merged commit b458649 into main Feb 21, 2024
@yaira2 yaira2 deleted the ya/GetOverlay branch February 21, 2024 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready to merge Pull requests that are approved and ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants