Skip to content
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
13 changes: 0 additions & 13 deletions src/Files.App/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,6 @@ namespace Files.App
{
public static class Constants
{
public static class AdaptiveLayout
{
public const float ExtraLargeThreshold = 85.0f;

public const float LargeThreshold = 80.0f;

public const float MediumThreshold = 60.0f;

public const float SmallThreshold = 25.0f;

public const float ExtraSmallThreshold = 15.0f;
}

// The following constants will be replaced with actual values by the Files CI workflow
public static class AutomatedWorkflowInjectionKeys
{
Expand Down
27 changes: 4 additions & 23 deletions src/Files.App/Helpers/Layout/AdaptiveLayoutHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

using Files.App.ViewModels.Previews;
using Files.Shared.Helpers;
using Windows.Storage;
using static Files.App.Constants.AdaptiveLayout;

namespace Files.App.Helpers
{
Expand Down Expand Up @@ -67,34 +65,17 @@ private static Layouts GetContentLayout(IList<ListedItem> filesAndFolders)
if (filesAndFolders.Count is 0)
return Layouts.None;

float folderPercentage = 100f * filesAndFolders.Count(IsFolder) / itemCount;
float imagePercentage = 100f * filesAndFolders.Count(IsImage) / itemCount;
float mediaPercentage = 100f * filesAndFolders.Count(IsMedia) / itemCount;
float miscPercentage = 100f - (folderPercentage + imagePercentage + mediaPercentage);

if (folderPercentage + miscPercentage > LargeThreshold)
return Layouts.Detail;
if (imagePercentage > ExtraLargeThreshold)
if (mediaPercentage > 60f)
return Layouts.Grid;
if (imagePercentage <= MediumThreshold)
return Layouts.Detail;
if (100f - imagePercentage <= SmallThreshold)
return Layouts.Detail;
if (folderPercentage + miscPercentage <= ExtraSmallThreshold)
return Layouts.Detail;
return Layouts.Grid;

static bool IsFolder(ListedItem item)
=> item.PrimaryItemAttribute is StorageItemTypes.Folder;

static bool IsImage(ListedItem item)
=> !string.IsNullOrEmpty(item.FileExtension)
&& ImagePreviewViewModel.ContainsExtension(item.FileExtension.ToLowerInvariant());
return Layouts.Detail;

static bool IsMedia(ListedItem item)
=> !string.IsNullOrEmpty(item.FileExtension)
&& (FileExtensionHelpers.IsAudioFile(item.FileExtension)
|| FileExtensionHelpers.IsVideoFile(item.FileExtension));
|| FileExtensionHelpers.IsVideoFile(item.FileExtension)
|| FileExtensionHelpers.IsImageFile(item.FileExtension));
}

private enum Layouts
Expand Down
2 changes: 1 addition & 1 deletion src/Files.Shared/Helpers/FileExtensionHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static bool IsCompatibleToSetAsWindowsWallpaper(string? fileExtensionToCh
/// <returns><c>true</c> if the fileExtensionToCheck is an audio file; otherwise, <c>false</c>.</returns>
public static bool IsAudioFile(string? fileExtensionToCheck)
{
return HasExtension(fileExtensionToCheck, ".mp3", ".m4a", ".wav", ".wma", ".aac", ".adt", ".adts", ".cda", ".flac");
return HasExtension(fileExtensionToCheck, ".mp3", ".m4a", ".ogg", ".oga", ".wav", ".wma", ".aac", ".adt", ".adts", ".cda", ".flac");
Comment thread
yair100 marked this conversation as resolved.
}

/// <summary>
Expand Down
Loading