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: Return icon size based on current layout settings #14650

Merged
merged 5 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Files.App/Data/Models/ItemViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1444,7 +1444,7 @@ private async Task RapidAddItemsToCollectionAsync(string? path, LibraryItem? lib
break;
}

await GetDefaultItemIconsAsync(folderSettings.GetIconSize());
await GetDefaultItemIconsAsync(folderSettings.GetRoundedIconSize());

if (IsLoadingCancelled)
{
Expand Down
38 changes: 30 additions & 8 deletions src/Files.App/Helpers/Layout/LayoutPreferencesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public bool IsAdaptiveLayoutEnabled
}
}

[Obsolete("Don't add more references, we're working on removing this property")]
public int GridViewSize
{
get => LayoutPreferencesItem.IconSizeGridView;
Expand Down Expand Up @@ -317,7 +318,25 @@ public LayoutPreferencesManager(FolderLayoutModes modeOverride) : this()

// Methods

public uint GetIconSize()
/// <summary>
/// This will round the current icon size to get the best result from the File Explorer thumbnail system.
///
/// Details View:
/// Always uses the Large icon size (32).
///
/// List View:
/// Always uses the Large icon size (32).
///
/// Columns View:
/// Always uses the Large icon size (32).
///
/// Tiles View:
/// Uses a range of icon sizes (64, 72, 96, 128, 180, 256) depending on the selected icon size.
///
/// Grid View:
/// Uses a range of icon sizes (64, 72, 96, 128, 180, 256) depending on the selected icon size.
/// </summary>
public uint GetRoundedIconSize()
{
return LayoutMode switch
{
Expand All @@ -327,17 +346,20 @@ public uint GetIconSize()
=> Constants.DefaultIconSizes.Large,
FolderLayoutModes.ColumnView
=> Constants.DefaultIconSizes.Large,
FolderLayoutModes.TilesView
=> Constants.Browser.GridViewBrowser.TilesView,
_ when GridViewSize <= 64
_ when LayoutMode == FolderLayoutModes.TilesView && LayoutPreferencesItem.IconSizeTilesView <= 64 ||
LayoutMode == FolderLayoutModes.GridView && LayoutPreferencesItem.IconSizeGridView <= 64
=> 64,
_ when GridViewSize <= 72
_ when LayoutMode == FolderLayoutModes.TilesView && LayoutPreferencesItem.IconSizeTilesView <= 72 ||
LayoutMode == FolderLayoutModes.GridView && LayoutPreferencesItem.IconSizeGridView <= 72
=> 72,
_ when GridViewSize <= 96
_ when LayoutMode == FolderLayoutModes.TilesView && LayoutPreferencesItem.IconSizeTilesView <= 96 ||
LayoutMode == FolderLayoutModes.GridView && LayoutPreferencesItem.IconSizeGridView <= 96
=> 96,
_ when GridViewSize <= 128
_ when LayoutMode == FolderLayoutModes.TilesView && LayoutPreferencesItem.IconSizeTilesView <= 128 ||
LayoutMode == FolderLayoutModes.GridView && LayoutPreferencesItem.IconSizeGridView <= 128
=> 128,
_ when GridViewSize <= 180
_ when LayoutMode == FolderLayoutModes.TilesView && LayoutPreferencesItem.IconSizeTilesView <= 180 ||
LayoutMode == FolderLayoutModes.GridView && LayoutPreferencesItem.IconSizeGridView <= 180
=> 180,
_ => 256,
};
Expand Down
8 changes: 4 additions & 4 deletions src/Files.App/ViewModels/UserControls/ToolbarViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -957,9 +957,9 @@ private void FolderSettings_PropertyChanged(object? sender, PropertyChangedEvent
FolderLayoutModes.TilesView => Commands.LayoutTiles.OpacityStyle!,
FolderLayoutModes.ColumnView => Commands.LayoutColumns.OpacityStyle!,
FolderLayoutModes.GridView =>
instanceViewModel.FolderSettings.GridViewSize <= Constants.Browser.GridViewBrowser.GridViewSizeSmall
instanceViewModel.FolderSettings.LayoutPreferencesItem.IconSizeGridView <= Constants.Browser.GridViewBrowser.GridViewSizeSmall
? Commands.LayoutGridSmall.OpacityStyle!
: instanceViewModel.FolderSettings.GridViewSize <= Constants.Browser.GridViewBrowser.GridViewSizeMedium
: instanceViewModel.FolderSettings.LayoutPreferencesItem.IconSizeGridView <= Constants.Browser.GridViewBrowser.GridViewSizeMedium
? Commands.LayoutGridMedium.OpacityStyle!
: Commands.LayoutGridLarge.OpacityStyle!,
_ => Commands.LayoutDetails.OpacityStyle!
Expand Down Expand Up @@ -1021,8 +1021,8 @@ public List<ListedItem> SelectedItems

public bool IsTilesLayout => instanceViewModel.FolderSettings.LayoutMode is FolderLayoutModes.TilesView;
public bool IsColumnLayout => instanceViewModel.FolderSettings.LayoutMode is FolderLayoutModes.ColumnView;
public bool IsGridSmallLayout => instanceViewModel.FolderSettings.LayoutMode is FolderLayoutModes.GridView && instanceViewModel.FolderSettings.GridViewSize <= Constants.Browser.GridViewBrowser.GridViewSizeSmall;
public bool IsGridMediumLayout => instanceViewModel.FolderSettings.LayoutMode is FolderLayoutModes.GridView && !IsGridSmallLayout && instanceViewModel.FolderSettings.GridViewSize <= Constants.Browser.GridViewBrowser.GridViewSizeMedium;
public bool IsGridSmallLayout => instanceViewModel.FolderSettings.LayoutMode is FolderLayoutModes.GridView && instanceViewModel.FolderSettings.LayoutPreferencesItem.IconSizeGridView <= Constants.Browser.GridViewBrowser.GridViewSizeSmall;
public bool IsGridMediumLayout => instanceViewModel.FolderSettings.LayoutMode is FolderLayoutModes.GridView && !IsGridSmallLayout && instanceViewModel.FolderSettings.LayoutPreferencesItem.IconSizeGridView <= Constants.Browser.GridViewBrowser.GridViewSizeMedium;
public bool IsGridLargeLayout => instanceViewModel.FolderSettings.LayoutMode is FolderLayoutModes.GridView && !IsGridSmallLayout && !IsGridMediumLayout;
public bool IsDetailsLayout => !IsListLayout && !IsTilesLayout && !IsColumnLayout && !IsGridSmallLayout && !IsGridMediumLayout && !IsGridLargeLayout;
public bool IsListLayout => instanceViewModel.FolderSettings.LayoutMode is FolderLayoutModes.ListView;
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Views/Layouts/BaseLayoutPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ protected override async void OnNavigatedTo(NavigationEventArgs e)
{
Query = navigationArguments.SearchQuery,
Folder = navigationArguments.SearchPathParam,
ThumbnailSize = InstanceViewModel!.FolderSettings.GetIconSize(),
ThumbnailSize = InstanceViewModel!.FolderSettings.GetRoundedIconSize(),
};

_ = ParentShellPageInstance.FilesystemViewModel.SearchAsync(searchInstance);
Expand Down
4 changes: 2 additions & 2 deletions src/Files.App/Views/Layouts/DetailsLayoutPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ protected override void OnNavigatedTo(NavigationEventArgs eventArgs)

ParentShellPageInstance.FilesystemViewModel.EnabledGitProperties = GetEnabledGitProperties(ColumnsViewModel);

currentIconSize = FolderSettings.GetIconSize();
currentIconSize = FolderSettings.GetRoundedIconSize();
FolderSettings.LayoutModeChangeRequested += FolderSettings_LayoutModeChangeRequested;
FolderSettings.GridViewSizeChangeRequested += FolderSettings_GridViewSizeChangeRequested;
FolderSettings.GroupOptionPreferenceUpdated += ZoomIn;
Expand Down Expand Up @@ -414,7 +414,7 @@ protected override bool CanGetItemFromElement(object element)

private async void FolderSettings_GridViewSizeChangeRequested(object? sender, EventArgs e)
{
var requestedIconSize = FolderSettings.GetIconSize(); // Get new icon size
var requestedIconSize = FolderSettings.GetRoundedIconSize(); // Get new icon size

// Prevents reloading icons when the icon size hasn't changed
if (requestedIconSize != currentIconSize)
Expand Down
8 changes: 4 additions & 4 deletions src/Files.App/Views/Layouts/GridLayoutPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public sealed partial class GridLayoutPage : BaseGroupableLayoutPage
FolderSettings.LayoutMode == FolderLayoutModes.ListView ||
FolderSettings.LayoutMode == FolderLayoutModes.TilesView
? 260
: FolderSettings.GridViewSize;
: FolderSettings.LayoutPreferencesItem.IconSizeGridView;

public bool IsPointerOver
{
Expand Down Expand Up @@ -104,7 +104,7 @@ protected override void OnNavigatedTo(NavigationEventArgs eventArgs)

base.OnNavigatedTo(eventArgs);

currentIconSize = FolderSettings.GetIconSize();
currentIconSize = FolderSettings.GetRoundedIconSize();
FolderSettings.GroupOptionPreferenceUpdated -= ZoomIn;
FolderSettings.GroupOptionPreferenceUpdated += ZoomIn;
FolderSettings.LayoutModeChangeRequested -= FolderSettings_LayoutModeChangeRequested;
Expand Down Expand Up @@ -148,7 +148,7 @@ private async void FolderSettings_LayoutModeChangeRequested(object? sender, Layo
// Set ItemTemplate
SetItemTemplate();

var requestedIconSize = FolderSettings.GetIconSize();
var requestedIconSize = FolderSettings.GetRoundedIconSize();
if (requestedIconSize != currentIconSize)
{
currentIconSize = requestedIconSize;
Expand Down Expand Up @@ -446,7 +446,7 @@ private async void FolderSettings_GridViewSizeChangeRequested(object? sender, Ev
SetItemMinWidth();

// Get new icon size
var requestedIconSize = FolderSettings.GetIconSize();
var requestedIconSize = FolderSettings.GetRoundedIconSize();

// Prevents reloading icons when the icon size hasn't changed
if (requestedIconSize != currentIconSize)
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Views/Shells/BaseShellPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ public async Task Refresh_Click()
{
Query = InstanceViewModel.CurrentSearchQuery ?? (string)TabItemParameter.NavigationParameter,
Folder = FilesystemViewModel.WorkingDirectory,
ThumbnailSize = InstanceViewModel.FolderSettings.GetIconSize(),
ThumbnailSize = InstanceViewModel.FolderSettings.GetRoundedIconSize(),
};

await FilesystemViewModel.SearchAsync(searchInstance);
Expand Down