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: Introduce details layout columns generator phase 1 #14127

Merged
merged 6 commits into from
Dec 5, 2023
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: 18 additions & 18 deletions src/Files.App/Data/Contexts/DisplayPage/DisplayPageContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public SortOption SortOption
get => _SortOption;
set
{
if (FolderSettings is FolderSettingsViewModel viewModel)
if (FolderSettings is LayoutPreferencesManager viewModel)
viewModel.DirectorySortOption = value;
}
}
Expand All @@ -66,7 +66,7 @@ public SortDirection SortDirection
get => _SortDirection;
set
{
if (FolderSettings is FolderSettingsViewModel viewModel)
if (FolderSettings is LayoutPreferencesManager viewModel)
viewModel.DirectorySortDirection = value;
}
}
Expand All @@ -77,7 +77,7 @@ public GroupOption GroupOption
get => _GroupOption;
set
{
if (FolderSettings is FolderSettingsViewModel viewModel)
if (FolderSettings is LayoutPreferencesManager viewModel)
viewModel.DirectoryGroupOption = value;
}
}
Expand All @@ -88,7 +88,7 @@ public SortDirection GroupDirection
get => _GroupDirection;
set
{
if (FolderSettings is FolderSettingsViewModel viewModel)
if (FolderSettings is LayoutPreferencesManager viewModel)
viewModel.DirectoryGroupDirection = value;
}
}
Expand All @@ -99,7 +99,7 @@ public GroupByDateUnit GroupByDateUnit
get => _GroupByDateUnit;
set
{
if (FolderSettings is FolderSettingsViewModel viewModel)
if (FolderSettings is LayoutPreferencesManager viewModel)
viewModel.DirectoryGroupByDateUnit = value;
}
}
Expand All @@ -110,12 +110,12 @@ public bool SortDirectoriesAlongsideFiles
get => _SortDirectoriesAlongsideFiles;
set
{
if (FolderSettings is FolderSettingsViewModel viewModel)
if (FolderSettings is LayoutPreferencesManager viewModel)
viewModel.SortDirectoriesAlongsideFiles = value;
}
}

private FolderSettingsViewModel? FolderSettings => context.PaneOrColumn?.InstanceViewModel?.FolderSettings;
private LayoutPreferencesManager? FolderSettings => context.PaneOrColumn?.InstanceViewModel?.FolderSettings;

public DisplayPageContext()
{
Expand All @@ -126,12 +126,12 @@ public DisplayPageContext()

public void DecreaseLayoutSize()
{
if (FolderSettings is FolderSettingsViewModel viewModel)
if (FolderSettings is LayoutPreferencesManager viewModel)
viewModel.GridViewSize -= GridViewIncrement;
}
public void IncreaseLayoutSize()
{
if (FolderSettings is FolderSettingsViewModel viewModel)
if (FolderSettings is LayoutPreferencesManager viewModel)
viewModel.GridViewSize += GridViewIncrement;
}

Expand All @@ -158,27 +158,27 @@ private void FolderSettings_PropertyChanged(object? sender, PropertyChangedEvent

switch (e.PropertyName)
{
case nameof(FolderSettingsViewModel.LayoutMode):
case nameof(FolderSettingsViewModel.GridViewSize):
case nameof(FolderSettingsViewModel.IsAdaptiveLayoutEnabled):
case nameof(LayoutPreferencesManager.LayoutMode):
case nameof(LayoutPreferencesManager.GridViewSize):
case nameof(LayoutPreferencesManager.IsAdaptiveLayoutEnabled):
SetProperty(ref _LayoutType, GetLayoutType(), nameof(LayoutType));
break;
case nameof(FolderSettingsViewModel.DirectorySortOption):
case nameof(LayoutPreferencesManager.DirectorySortOption):
SetProperty(ref _SortOption, viewModel.DirectorySortOption, nameof(SortOption));
break;
case nameof(FolderSettingsViewModel.DirectorySortDirection):
case nameof(LayoutPreferencesManager.DirectorySortDirection):
SetProperty(ref _SortDirection, viewModel.DirectorySortDirection, nameof(SortDirection));
break;
case nameof(FolderSettingsViewModel.DirectoryGroupOption):
case nameof(LayoutPreferencesManager.DirectoryGroupOption):
SetProperty(ref _GroupOption, viewModel.DirectoryGroupOption, nameof(GroupOption));
break;
case nameof(FolderSettingsViewModel.DirectoryGroupDirection):
case nameof(LayoutPreferencesManager.DirectoryGroupDirection):
SetProperty(ref _GroupDirection, viewModel.DirectoryGroupDirection, nameof(GroupDirection));
break;
case nameof(FolderSettingsViewModel.DirectoryGroupByDateUnit):
case nameof(LayoutPreferencesManager.DirectoryGroupByDateUnit):
SetProperty(ref _GroupByDateUnit, viewModel.DirectoryGroupByDateUnit, nameof(GroupByDateUnit));
break;
case nameof(FolderSettingsViewModel.SortDirectoriesAlongsideFiles):
case nameof(LayoutPreferencesManager.SortDirectoriesAlongsideFiles):
SetProperty(ref _SortDirectoriesAlongsideFiles, viewModel.SortDirectoriesAlongsideFiles, nameof(SortDirectoriesAlongsideFiles));
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ public class LayoutPreferenceEventArgs
{
public readonly bool IsAdaptiveLayoutUpdateRequired;

public readonly LayoutPreferences LayoutPreference;
public readonly LayoutPreferencesItem LayoutPreference;

internal LayoutPreferenceEventArgs(LayoutPreferences layoutPref)
internal LayoutPreferenceEventArgs(LayoutPreferencesItem layoutPref)
=> LayoutPreference = layoutPref;

internal LayoutPreferenceEventArgs(LayoutPreferences layoutPref, bool isAdaptiveLayoutUpdateRequired)
internal LayoutPreferenceEventArgs(LayoutPreferencesItem layoutPref, bool isAdaptiveLayoutUpdateRequired)
=> (LayoutPreference, IsAdaptiveLayoutUpdateRequired) = (layoutPref, isAdaptiveLayoutUpdateRequired);
}
}
Copy link
Member

Choose a reason for hiding this comment

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

GetHashCode() can be improved in the same way as LayoutPreferencesItem.

Copy link
Member Author

@0x5bfa 0x5bfa Dec 5, 2023

Choose a reason for hiding this comment

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

Fixed already in the stage 2 PR. Thanks!

Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,42 @@

using Microsoft.UI.Xaml;

namespace Files.App.Data.Models
namespace Files.App.Data.Items
{
public class ColumnViewModel : ObservableObject
/// <summary>
/// Represents item for a column shown in <see cref="DetailsLayoutPage"/>.
/// </summary>
public class DetailsLayoutColumnItem : ObservableObject
{
private bool isHidden;
private const int GRID_SPLITTER_WIDTH = 12;

[LiteDB.BsonIgnore]
public bool IsHidden
{
get => isHidden;
set => SetProperty(ref isHidden, value);
}

[LiteDB.BsonIgnore]
public double MaxLength
public double UserLengthPixels
{
get => UserCollapsed || IsHidden ? 0 : NormalMaxLength;
get => UserLength.Value;
set => UserLength = new GridLength(value, GridUnitType.Pixel);
}

private double normalMaxLength = 800;

private double _NormalMaxLength = 800;
public double NormalMaxLength
{
get => normalMaxLength;
set => SetProperty(ref normalMaxLength, value);
get => _NormalMaxLength;
set => SetProperty(ref _NormalMaxLength, value);
}

private double normalMinLength = 50;

[LiteDB.BsonIgnore]
public double NormalMinLength
private bool _UserCollapsed;
public bool UserCollapsed
{
get => normalMinLength;
get => _UserCollapsed;
set
{
if (SetProperty(ref normalMinLength, value))
OnPropertyChanged(nameof(MinLength));
if (SetProperty(ref _UserCollapsed, value))
UpdateVisibility();
}
}

[LiteDB.BsonIgnore]
public bool IsResizable { get; set; } = true;

[LiteDB.BsonIgnore]
public double MinLength
=> UserCollapsed || IsHidden ? 0 : NormalMinLength;
Expand All @@ -51,59 +47,55 @@ public double MinLength
public Visibility Visibility
=> UserCollapsed || IsHidden ? Visibility.Collapsed : Visibility.Visible;

private bool userCollapsed;

public bool UserCollapsed
{
get => userCollapsed;
set
{
if (SetProperty(ref userCollapsed, value))
UpdateVisibility();
}
}

[LiteDB.BsonIgnore]
public GridLength Length
{
get => UserCollapsed || IsHidden ? new GridLength(0) : UserLength;
}
=> UserCollapsed || IsHidden ? new GridLength(0) : UserLength;

private const int gridSplitterWidth = 12;
[LiteDB.BsonIgnore]
public GridLength LengthIncludingGridSplitter =>
UserCollapsed || IsHidden
? new(0)
: new(UserLength.Value + (IsResizable ? GRID_SPLITTER_WIDTH : 0));

[LiteDB.BsonIgnore]
public double MaxLength
=> UserCollapsed || IsHidden ? 0 : NormalMaxLength;

private bool _IsHidden;
[LiteDB.BsonIgnore]
public GridLength LengthIncludingGridSplitter
public bool IsHidden
{
get => UserCollapsed || IsHidden
? new(0)
: new(UserLength.Value + (IsResizeable ? gridSplitterWidth : 0));
get => _IsHidden;
set => SetProperty(ref _IsHidden, value);
}

private double _NormalMinLength = 50;
[LiteDB.BsonIgnore]
public bool IsResizeable { get; set; } = true;

private GridLength userLength = new(200, GridUnitType.Pixel);
public double NormalMinLength
{
get => _NormalMinLength;
set
{
if (SetProperty(ref _NormalMinLength, value))
OnPropertyChanged(nameof(MinLength));
}
}

private GridLength _UserLength = new(200, GridUnitType.Pixel);
[LiteDB.BsonIgnore]
public GridLength UserLength
{
get => userLength;
get => _UserLength;
set
{
if (SetProperty(ref userLength, value))
if (SetProperty(ref _UserLength, value))
{
OnPropertyChanged(nameof(Length));
OnPropertyChanged(nameof(LengthIncludingGridSplitter));
}
}
}

public double UserLengthPixels
{
get => UserLength.Value;
set => UserLength = new GridLength(value, GridUnitType.Pixel);
}

public void Hide()
{
IsHidden = true;
Expand All @@ -125,21 +117,6 @@ private void UpdateVisibility()
OnPropertyChanged(nameof(MinLength));
}

public void TryMultiplySize(double factor)
{
var newSize = Length.Value * factor;
if (newSize == 0)
return;

double setLength = newSize;
if (newSize < MinLength)
setLength = MinLength;
else if (newSize >= MaxLength)
setLength = MaxLength;

UserLength = new GridLength(setLength);
}

public override bool Equals(object? obj)
{
if (obj is null)
Expand All @@ -148,7 +125,7 @@ public override bool Equals(object? obj)
if (obj == this)
return true;

if (obj is ColumnViewModel model)
if (obj is DetailsLayoutColumnItem model)
{
return
model.UserCollapsed == UserCollapsed &&
Expand Down
Loading