Skip to content

Code Quality: Added default icon sizes to LayoutSettingsService #14645

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

Merged
merged 1 commit into from
Feb 5, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions src/Files.App/Helpers/Layout/LayoutPreferencesItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ public class LayoutPreferencesItem
public bool SortDirectoriesAlongsideFiles;
public bool SortFilesFirst;
public bool IsAdaptiveLayoutOverridden;
public int GridViewSize;

// Icon sizes
public int IconSizeDetailsView;
public int IconSizeListView;
public int IconSizeTilesView;
public int IconSizeGridView;
public int IconSizeColumnsView;

public FolderLayoutModes LayoutMode;

Expand All @@ -37,7 +43,11 @@ public LayoutPreferencesItem()
var defaultLayout = UserSettingsService.FoldersSettingsService.DefaultLayoutMode;

LayoutMode = defaultLayout is FolderLayoutModes.Adaptive ? FolderLayoutModes.DetailsView : defaultLayout;
GridViewSize = UserSettingsService.LayoutSettingsService.DefaultGridViewSize;
IconSizeDetailsView = UserSettingsService.LayoutSettingsService.DefaultIconSizeDetailsView;
IconSizeListView = UserSettingsService.LayoutSettingsService.DefaultIconSizeListView;
IconSizeTilesView = UserSettingsService.LayoutSettingsService.DefaulIconSizeTilesView;
IconSizeGridView = UserSettingsService.LayoutSettingsService.DefaulIconSizeGridView;
IconSizeColumnsView = UserSettingsService.LayoutSettingsService.DefaultIconSizeColumnsView;
DirectorySortOption = UserSettingsService.FoldersSettingsService.DefaultSortOption;
DirectoryGroupOption = UserSettingsService.FoldersSettingsService.DefaultGroupOption;
DirectorySortDirection = UserSettingsService.FoldersSettingsService.DefaultDirectorySortDirection;
Expand Down Expand Up @@ -68,11 +78,11 @@ public LayoutPreferencesItem()
ColumnsViewModel.DateCreatedColumn.UserLengthPixels = UserSettingsService.FoldersSettingsService.DateCreatedColumnWidth;
ColumnsViewModel.ItemTypeColumn.UserLengthPixels = UserSettingsService.FoldersSettingsService.TypeColumnWidth;
ColumnsViewModel.SizeColumn.UserLengthPixels = UserSettingsService.FoldersSettingsService.SizeColumnWidth;
ColumnsViewModel.GitStatusColumn.UserLengthPixels= UserSettingsService.FoldersSettingsService.GitStatusColumnWidth;
ColumnsViewModel.GitLastCommitDateColumn.UserLengthPixels= UserSettingsService.FoldersSettingsService.GitLastCommitDateColumnWidth;
ColumnsViewModel.GitLastCommitMessageColumn.UserLengthPixels= UserSettingsService.FoldersSettingsService.GitLastCommitMessageColumnWidth;
ColumnsViewModel.GitCommitAuthorColumn.UserLengthPixels= UserSettingsService.FoldersSettingsService.GitCommitAuthorColumnWidth;
ColumnsViewModel.GitLastCommitShaColumn.UserLengthPixels= UserSettingsService.FoldersSettingsService.GitLastCommitShaColumnWidth;
ColumnsViewModel.GitStatusColumn.UserLengthPixels = UserSettingsService.FoldersSettingsService.GitStatusColumnWidth;
ColumnsViewModel.GitLastCommitDateColumn.UserLengthPixels = UserSettingsService.FoldersSettingsService.GitLastCommitDateColumnWidth;
ColumnsViewModel.GitLastCommitMessageColumn.UserLengthPixels = UserSettingsService.FoldersSettingsService.GitLastCommitMessageColumnWidth;
ColumnsViewModel.GitCommitAuthorColumn.UserLengthPixels = UserSettingsService.FoldersSettingsService.GitCommitAuthorColumnWidth;
ColumnsViewModel.GitLastCommitShaColumn.UserLengthPixels = UserSettingsService.FoldersSettingsService.GitLastCommitShaColumnWidth;
ColumnsViewModel.TagColumn.UserLengthPixels = UserSettingsService.FoldersSettingsService.TagColumnWidth;
ColumnsViewModel.DateDeletedColumn.UserLengthPixels = UserSettingsService.FoldersSettingsService.DateDeletedColumnWidth;
ColumnsViewModel.PathColumn.UserLengthPixels = UserSettingsService.FoldersSettingsService.PathColumnWidth;
Expand All @@ -94,7 +104,11 @@ public override bool Equals(object? obj)
{
return (
item.LayoutMode == LayoutMode &&
item.GridViewSize == GridViewSize &&
item.IconSizeDetailsView == IconSizeDetailsView &&
item.IconSizeListView == IconSizeListView &&
item.IconSizeTilesView == IconSizeTilesView &&
item.IconSizeGridView == IconSizeGridView &&
item.IconSizeColumnsView == IconSizeColumnsView &&
item.DirectoryGroupOption == DirectoryGroupOption &&
item.DirectorySortOption == DirectorySortOption &&
item.DirectorySortDirection == DirectorySortDirection &&
Expand All @@ -113,7 +127,11 @@ public override int GetHashCode()
HashCode hash = new();

hash.Add(LayoutMode);
hash.Add(GridViewSize);
hash.Add(IconSizeDetailsView);
hash.Add(IconSizeListView);
hash.Add(IconSizeTilesView);
hash.Add(IconSizeGridView);
hash.Add(IconSizeColumnsView);
hash.Add(DirectoryGroupOption);
hash.Add(DirectorySortOption);
hash.Add(DirectorySortDirection);
Expand Down
36 changes: 22 additions & 14 deletions src/Files.App/Helpers/Layout/LayoutPreferencesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ public bool IsAdaptiveLayoutEnabled

public int GridViewSize
{
get => LayoutPreferencesItem.GridViewSize;
get => LayoutPreferencesItem.IconSizeGridView;
set
{
// Size down
if (value < LayoutPreferencesItem.GridViewSize)
if (value < LayoutPreferencesItem.IconSizeGridView)
{
// Size down from List to Details
if (LayoutMode == FolderLayoutModes.ListView)
Expand Down Expand Up @@ -74,7 +74,7 @@ public int GridViewSize
{
// Set grid size to allow immediate UI update
var newValue = (value >= Constants.Browser.GridViewBrowser.GridViewSizeSmall) ? value : Constants.Browser.GridViewBrowser.GridViewSizeSmall;
SetProperty(ref LayoutPreferencesItem.GridViewSize, newValue, nameof(GridViewSize));
SetProperty(ref LayoutPreferencesItem.IconSizeGridView, newValue, nameof(GridViewSize));

// Only update layout mode if it isn't already in grid view
if (LayoutMode != FolderLayoutModes.GridView)
Expand All @@ -92,7 +92,7 @@ public int GridViewSize
}
}
// Size up
else if (value > LayoutPreferencesItem.GridViewSize)
else if (value > LayoutPreferencesItem.IconSizeGridView)
{
// Size up from Details to List
if (LayoutMode == FolderLayoutModes.DetailsView)
Expand All @@ -112,7 +112,7 @@ public int GridViewSize
{
// Set grid size to allow immediate UI update
var newValue = (LayoutMode == FolderLayoutModes.TilesView) ? Constants.Browser.GridViewBrowser.GridViewSizeSmall : (value <= Constants.Browser.GridViewBrowser.GridViewSizeLarge) ? value : Constants.Browser.GridViewBrowser.GridViewSizeLarge;
SetProperty(ref LayoutPreferencesItem.GridViewSize, newValue, nameof(GridViewSize));
SetProperty(ref LayoutPreferencesItem.IconSizeGridView, newValue, nameof(GridViewSize));

// Only update layout mode if it isn't already in grid view
if (LayoutMode != FolderLayoutModes.GridView)
Expand Down Expand Up @@ -329,13 +329,17 @@ public uint GetIconSize()
=> Constants.DefaultIconSizes.Large,
FolderLayoutModes.TilesView
=> Constants.Browser.GridViewBrowser.TilesView,
_ when GridViewSize <= Constants.Browser.GridViewBrowser.GridViewSizeSmall
=> Constants.Browser.GridViewBrowser.GridViewSizeSmall,
_ when GridViewSize <= Constants.Browser.GridViewBrowser.GridViewSizeMedium
=> Constants.Browser.GridViewBrowser.GridViewSizeMedium,
_ when GridViewSize <= Constants.Browser.GridViewBrowser.GridViewSizeLarge
=> Constants.Browser.GridViewBrowser.GridViewSizeLarge,
_ => Constants.Browser.GridViewBrowser.GridViewSizeLarge,
_ when GridViewSize <= 64
=> 64,
_ when GridViewSize <= 72
=> 72,
_ when GridViewSize <= 96
=> 96,
_ when GridViewSize <= 128
=> 128,
_ when GridViewSize <= 180
=> 180,
_ => 256,
};
}

Expand Down Expand Up @@ -431,7 +435,7 @@ public void ToggleLayoutModeTiles(bool manuallySet)

LayoutModeChangeRequested?.Invoke(this, new LayoutModeEventArgs(FolderLayoutModes.TilesView, GridViewSize));
}

public void ToggleLayoutModeList(bool manuallySet)
{
IsAdaptiveLayoutEnabled &= !manuallySet;
Expand Down Expand Up @@ -534,7 +538,11 @@ public static void SetLayoutPreferencesForPath(string path, LayoutPreferencesIte
else
{
UserSettingsService.FoldersSettingsService.DefaultLayoutMode = preferencesItem.LayoutMode;
UserSettingsService.LayoutSettingsService.DefaultGridViewSize = preferencesItem.GridViewSize;
UserSettingsService.LayoutSettingsService.DefaultIconSizeDetailsView = preferencesItem.IconSizeDetailsView;
UserSettingsService.LayoutSettingsService.DefaultIconSizeListView = preferencesItem.IconSizeListView;
UserSettingsService.LayoutSettingsService.DefaulIconSizeTilesView = preferencesItem.IconSizeTilesView;
UserSettingsService.LayoutSettingsService.DefaulIconSizeGridView = preferencesItem.IconSizeGridView;
UserSettingsService.LayoutSettingsService.DefaultIconSizeColumnsView = preferencesItem.IconSizeColumnsView;

// Do not save options which only work in recycle bin or cloud folders or search results as global
if (preferencesItem.DirectorySortOption != SortOption.Path &&
Expand Down
29 changes: 25 additions & 4 deletions src/Files.App/Services/Settings/LayoutSettingsService.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Utils.Serialization;
using Files.Core.Services.Settings;

namespace Files.App.Services.Settings
{
internal sealed class LayoutSettingsService : BaseObservableJsonSettings, ILayoutSettingsService
Expand All @@ -14,10 +11,34 @@ public LayoutSettingsService(ISettingsSharingContext settingsSharingContext)
RegisterSettingsContext(settingsSharingContext);
}

public int DefaultGridViewSize
public int DefaultIconSizeDetailsView
{
get => (int)Get((long)Constants.DefaultIconSizes.Large);
set => Set((long)value);
}

public int DefaultIconSizeListView
{
get => (int)Get((long)Constants.DefaultIconSizes.Large);
set => Set((long)value);
}

public int DefaulIconSizeTilesView
{
get => (int)Get((long)Constants.Browser.GridViewBrowser.GridViewSizeMedium);
set => Set((long)value);
}

public int DefaulIconSizeGridView
{
get => (int)Get((long)Constants.Browser.GridViewBrowser.GridViewSizeMedium);
set => Set((long)value);
}

public int DefaultIconSizeColumnsView
{
get => (int)Get((long)Constants.DefaultIconSizes.Large);
set => Set((long)value);
}
}
}
27 changes: 24 additions & 3 deletions src/Files.Core/Services/Settings/ILayoutSettingsService.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,33 @@
// Copyright (c) 2023 Files Community
// Licensed under the MIT License. See the LICENSE.

using System.ComponentModel;

namespace Files.Core.Services.Settings
{
public interface ILayoutSettingsService : IBaseSettingsService, INotifyPropertyChanged
{
int DefaultGridViewSize { get; set; }
/// <summary>
/// Default icon size in the Details View
/// </summary>
int DefaultIconSizeDetailsView { get; set; }

/// <summary>
/// Default icon size in the List View
/// </summary>
int DefaultIconSizeListView { get; set; }

/// <summary>
/// Default icon size in the Tiles View
/// </summary>
int DefaulIconSizeTilesView { get; set; }

/// <summary>
/// Default icon size in the Grid View
/// </summary>
int DefaulIconSizeGridView { get; set; }

/// <summary>
/// Default icon size in the Columns View
/// </summary>
int DefaultIconSizeColumnsView { get; set; }
}
}