From eefffee45e9b68e20b24738ebe7f807bd3bf94ca Mon Sep 17 00:00:00 2001 From: cinqmilleans Date: Tue, 20 Dec 2022 20:33:04 +0100 Subject: [PATCH 1/5] refactor AdaptiveLayoutHelpers --- .../Helpers/AdaptiveLayoutHelpers.cs | 208 +++++++++--------- 1 file changed, 106 insertions(+), 102 deletions(-) diff --git a/src/Files.App/Helpers/AdaptiveLayoutHelpers.cs b/src/Files.App/Helpers/AdaptiveLayoutHelpers.cs index 2e7385e3718a..58c898681ad6 100644 --- a/src/Files.App/Helpers/AdaptiveLayoutHelpers.cs +++ b/src/Files.App/Helpers/AdaptiveLayoutHelpers.cs @@ -3,124 +3,128 @@ using Files.App.ViewModels; using Files.App.ViewModels.Previews; using Files.Backend.Services.Settings; +using IniParser.Model; using System; using System.Collections.Generic; using System.Linq; using Windows.Storage; +using static Files.App.Constants.AdaptiveLayout; +using IO = System.IO; namespace Files.App.Helpers { public static class AdaptiveLayoutHelpers { + private static readonly IFoldersSettingsService foldersSettingsService = Ioc.Default.GetRequiredService(); + public static bool PredictLayoutMode(FolderSettingsViewModel folderSettings, string path, IList filesAndFolders) { - IUserSettingsService userSettingsService = Ioc.Default.GetRequiredService(); + if (!foldersSettingsService.EnableOverridingFolderPreferences) + return false; + if (string.IsNullOrWhiteSpace(path)) + return false; + if (folderSettings.IsLayoutModeFixed || !folderSettings.IsAdaptiveLayoutEnabled) + return false; - if (userSettingsService.FoldersSettingsService.EnableOverridingFolderPreferences - && folderSettings.IsAdaptiveLayoutEnabled - && !folderSettings.IsLayoutModeFixed) + var layout = GetAdaptiveLayout(path, filesAndFolders); + switch (layout) { - Action layoutDetails = () => folderSettings.ToggleLayoutModeDetailsView(false); - Action layoutGridView = () => folderSettings.ToggleLayoutModeGridView(folderSettings.GridViewSize); - - bool desktopIniFound = false; - - if (string.IsNullOrWhiteSpace(path)) - { - return false; - } - - var iniPath = System.IO.Path.Combine(path, "desktop.ini"); - var iniContents = NativeFileOperationsHelper.ReadStringFromFile(iniPath)?.Trim(); - if (!string.IsNullOrEmpty(iniContents)) - { - var parser = new IniParser.Parser.IniDataParser(); - parser.Configuration.ThrowExceptionsOnError = false; - var data = parser.Parse(iniContents); - if (data is not null) - { - var viewModeSection = data.Sections.FirstOrDefault(x => "ViewState".Equals(x.SectionName, StringComparison.OrdinalIgnoreCase)); - if (viewModeSection is not null) - { - var folderTypeKey = viewModeSection.Keys.FirstOrDefault(s => "FolderType".Equals(s.KeyName, StringComparison.OrdinalIgnoreCase)); - if (folderTypeKey is not null) - { - var setLayout = (folderTypeKey.Value) switch - { - "Documents" => layoutDetails, - "Pictures" => layoutGridView, - "Music" => layoutDetails, - "Videos" => layoutGridView, - _ => layoutDetails - }; - setLayout(); - desktopIniFound = true; - } - } - } - } - - if (desktopIniFound) - { + case Layouts.Detail: + folderSettings.ToggleLayoutModeDetailsView(false); return true; - } - if (filesAndFolders.Count == 0) - { + case Layouts.Grid: + folderSettings.ToggleLayoutModeGridView(folderSettings.GridViewSize); + return true; + default: return false; - } - - int allItemsCount = filesAndFolders.Count; - - int mediaCount; - int imagesCount; - int foldersCount; - int miscFilesCount; - - float mediaPercentage; - float imagesPercentage; - float foldersPercentage; - float miscFilesPercentage; - - mediaCount = filesAndFolders.Where((item) => - { - return !string.IsNullOrEmpty(item.FileExtension) && MediaPreviewViewModel.ContainsExtension(item.FileExtension.ToLowerInvariant()); - }).Count(); - imagesCount = filesAndFolders.Where((item) => - { - return !string.IsNullOrEmpty(item.FileExtension) && ImagePreviewViewModel.ContainsExtension(item.FileExtension.ToLowerInvariant()); - }).Count(); - foldersCount = filesAndFolders.Where((item) => item.PrimaryItemAttribute == StorageItemTypes.Folder).Count(); - miscFilesCount = allItemsCount - (mediaCount + imagesCount + foldersCount); - - mediaPercentage = (float)((float)mediaCount / (float)allItemsCount) * 100.0f; - imagesPercentage = (float)((float)imagesCount / (float)allItemsCount) * 100.0f; - foldersPercentage = (float)((float)foldersCount / (float)allItemsCount) * 100.0f; - miscFilesPercentage = (float)((float)miscFilesCount / (float)allItemsCount) * 100.0f; - - // Decide layout mode - - // Mostly files + folders, lesser media and image files | Mostly folders - if ((foldersPercentage + miscFilesPercentage) > Constants.AdaptiveLayout.LargeThreshold) - { - layoutDetails(); - } - // Mostly images, probably an images folder - else if (imagesPercentage > Constants.AdaptiveLayout.ExtraLargeThreshold - || (imagesPercentage > Constants.AdaptiveLayout.MediumThreshold - && (mediaPercentage + miscFilesPercentage + foldersPercentage) > Constants.AdaptiveLayout.SmallThreshold - && (miscFilesPercentage + foldersPercentage) < Constants.AdaptiveLayout.ExtraSmallThreshold)) - { - layoutGridView(); - } - else - { - layoutDetails(); - } - - return true; } + } + + private static Layouts GetAdaptiveLayout(string path, IList filesAndFolders) + { + var pathLayout = GetPathLayout(path); + if (pathLayout is not Layouts.None) + return pathLayout; + + return GetContentLayout(filesAndFolders); + } + + private static Layouts GetPathLayout(string path) + { + var iniPath = IO.Path.Combine(path, "desktop.ini"); + + var iniContents = NativeFileOperationsHelper.ReadStringFromFile(iniPath)?.Trim(); + if (string.IsNullOrEmpty(iniContents)) + return Layouts.None; + + var parser = new IniParser.Parser.IniDataParser(); + parser.Configuration.ThrowExceptionsOnError = false; + var data = parser.Parse(iniContents); + if (data is null) + return Layouts.None; + + var viewModeSection = data.Sections.FirstOrDefault(IsViewState); + if (viewModeSection is null) + return Layouts.None; - return false; + var folderTypeKey = viewModeSection.Keys.FirstOrDefault(IsFolderType); + if (folderTypeKey is null) + return Layouts.None; + + return folderTypeKey.Value switch + { + "Pictures" => Layouts.Grid, + "Videos" => Layouts.Grid, + _ => Layouts.Detail, + }; + + static bool IsViewState(SectionData data) + => "ViewState".Equals(data.SectionName, StringComparison.OrdinalIgnoreCase); + + static bool IsFolderType(KeyData data) + => "FolderType".Equals(data.KeyName, StringComparison.OrdinalIgnoreCase); + } + + private static Layouts GetContentLayout(IList filesAndFolders) + { + int itemCount = filesAndFolders.Count; + 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) + 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()); + + static bool IsMedia(ListedItem item) + => !string.IsNullOrEmpty(item.FileExtension) + && MediaPreviewViewModel.ContainsExtension(item.FileExtension.ToLowerInvariant()); + } + + private enum Layouts + { + None, + Detail, + Grid, } } -} \ No newline at end of file +} From 09f3f6c59daa3e6813e823b99884cec5227e7c33 Mon Sep 17 00:00:00 2001 From: cinqmilleans Date: Fri, 30 Dec 2022 16:03:50 +0100 Subject: [PATCH 2/5] Apply requested changes --- .../Helpers/AdaptiveLayoutHelpers.cs | 20 +++++++++---------- src/Files.App/ViewModels/ItemViewModel.cs | 2 +- src/Files.App/Views/ModernShellPage.xaml.cs | 2 +- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/Files.App/Helpers/AdaptiveLayoutHelpers.cs b/src/Files.App/Helpers/AdaptiveLayoutHelpers.cs index 58c898681ad6..3b9233eaa6cc 100644 --- a/src/Files.App/Helpers/AdaptiveLayoutHelpers.cs +++ b/src/Files.App/Helpers/AdaptiveLayoutHelpers.cs @@ -17,26 +17,24 @@ public static class AdaptiveLayoutHelpers { private static readonly IFoldersSettingsService foldersSettingsService = Ioc.Default.GetRequiredService(); - public static bool PredictLayoutMode(FolderSettingsViewModel folderSettings, string path, IList filesAndFolders) + public static void ApplyAdaptativeLayout(FolderSettingsViewModel folderSettings, string path, IList filesAndFolders) { if (!foldersSettingsService.EnableOverridingFolderPreferences) - return false; + return; if (string.IsNullOrWhiteSpace(path)) - return false; + return; if (folderSettings.IsLayoutModeFixed || !folderSettings.IsAdaptiveLayoutEnabled) - return false; + return; var layout = GetAdaptiveLayout(path, filesAndFolders); switch (layout) { case Layouts.Detail: folderSettings.ToggleLayoutModeDetailsView(false); - return true; + break; case Layouts.Grid: folderSettings.ToggleLayoutModeGridView(folderSettings.GridViewSize); - return true; - default: - return false; + break; } } @@ -122,9 +120,9 @@ static bool IsMedia(ListedItem item) private enum Layouts { - None, - Detail, - Grid, + None, // Don't decide. Another function to decide can be called afterwards if available. + Detail, // Apply the layout Detail. + Grid, // Apply the layout Grid. } } } diff --git a/src/Files.App/ViewModels/ItemViewModel.cs b/src/Files.App/ViewModels/ItemViewModel.cs index bee620a072ad..7edace63439f 100644 --- a/src/Files.App/ViewModels/ItemViewModel.cs +++ b/src/Files.App/ViewModels/ItemViewModel.cs @@ -1260,7 +1260,7 @@ private async void RapidAddItemsToCollectionAsync(string path, string previousDi ItemLoadStatusChanged?.Invoke(this, new ItemLoadStatusChangedEventArgs() { Status = ItemLoadStatusChangedEventArgs.ItemLoadStatus.Complete, PreviousDirectory = previousDir, Path = path }); IsLoadingItems = false; - AdaptiveLayoutHelpers.PredictLayoutMode(folderSettings, WorkingDirectory, filesAndFolders); + AdaptiveLayoutHelpers.ApplyAdaptativeLayout(folderSettings, WorkingDirectory, filesAndFolders); if (App.PaneViewModel.IsPreviewSelected) { diff --git a/src/Files.App/Views/ModernShellPage.xaml.cs b/src/Files.App/Views/ModernShellPage.xaml.cs index 469657d3bf78..ff58ab5fcdac 100644 --- a/src/Files.App/Views/ModernShellPage.xaml.cs +++ b/src/Files.App/Views/ModernShellPage.xaml.cs @@ -286,7 +286,7 @@ private void FolderSettings_LayoutPreferencesUpdateRequired(object sender, Layou FolderSettingsViewModel.SetLayoutPreferencesForPath(FilesystemViewModel.WorkingDirectory, e.LayoutPreference); if (e.IsAdaptiveLayoutUpdateRequired) - AdaptiveLayoutHelpers.PredictLayoutMode(InstanceViewModel.FolderSettings, FilesystemViewModel.WorkingDirectory, FilesystemViewModel.FilesAndFolders); + AdaptiveLayoutHelpers.ApplyAdaptativeLayout(InstanceViewModel.FolderSettings, FilesystemViewModel.WorkingDirectory, FilesystemViewModel.FilesAndFolders); } /* From c20e66876e2fb6a67fe41eb31fcc6df904d95cbc Mon Sep 17 00:00:00 2001 From: cinqmilleans Date: Mon, 13 Feb 2023 16:10:16 +0100 Subject: [PATCH 3/5] apply merge --- src/Files.App/Helpers/AdaptiveLayoutHelpers.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Files.App/Helpers/AdaptiveLayoutHelpers.cs b/src/Files.App/Helpers/AdaptiveLayoutHelpers.cs index 3b9233eaa6cc..21917d37f586 100644 --- a/src/Files.App/Helpers/AdaptiveLayoutHelpers.cs +++ b/src/Files.App/Helpers/AdaptiveLayoutHelpers.cs @@ -19,7 +19,7 @@ public static class AdaptiveLayoutHelpers public static void ApplyAdaptativeLayout(FolderSettingsViewModel folderSettings, string path, IList filesAndFolders) { - if (!foldersSettingsService.EnableOverridingFolderPreferences) + if (foldersSettingsService.SyncFolderPreferencesAcrossDirectories) return; if (string.IsNullOrWhiteSpace(path)) return; From 040c645ce2b2decfde9b09756d1c9447a81772d7 Mon Sep 17 00:00:00 2001 From: cinqmilleans Date: Mon, 13 Feb 2023 16:11:35 +0100 Subject: [PATCH 4/5] merge --- .../Helpers/AdaptiveLayoutHelpers.cs | 163 +++++++++++------- 1 file changed, 99 insertions(+), 64 deletions(-) diff --git a/src/Files.App/Helpers/AdaptiveLayoutHelpers.cs b/src/Files.App/Helpers/AdaptiveLayoutHelpers.cs index c94d01a46d41..fe5c142e322a 100644 --- a/src/Files.App/Helpers/AdaptiveLayoutHelpers.cs +++ b/src/Files.App/Helpers/AdaptiveLayoutHelpers.cs @@ -3,83 +3,112 @@ using Files.App.ViewModels; using Files.App.ViewModels.Previews; using Files.Backend.Services.Settings; +using IniParser.Model; using System; using System.Collections.Generic; using System.Linq; using Windows.Storage; +using static Files.App.Constants.AdaptiveLayout; +using IO = System.IO; namespace Files.App.Helpers { public static class AdaptiveLayoutHelpers { - public static bool PredictLayoutMode(FolderSettingsViewModel folderSettings, string path, IList filesAndFolders) + private static readonly IFoldersSettingsService foldersSettingsService = Ioc.Default.GetRequiredService(); + + public static void ApplyAdaptativeLayout(FolderSettingsViewModel folderSettings, string path, IList filesAndFolders) { - IUserSettingsService userSettingsService = Ioc.Default.GetRequiredService(); + if (foldersSettingsService.SyncFolderPreferencesAcrossDirectories) + return; + if (string.IsNullOrWhiteSpace(path)) + return; + if (folderSettings.IsLayoutModeFixed || !folderSettings.IsAdaptiveLayoutEnabled) + return; - if (!userSettingsService.FoldersSettingsService.SyncFolderPreferencesAcrossDirectories + if (userSettingsService.FoldersSettingsService.EnableOverridingFolderPreferences && folderSettings.IsAdaptiveLayoutEnabled && !folderSettings.IsLayoutModeFixed) { - Action layoutDetails = () => folderSettings.ToggleLayoutModeDetailsView(false); - Action layoutGridView = () => folderSettings.ToggleLayoutModeGridView(folderSettings.GridViewSize); + case Layouts.Detail: + folderSettings.ToggleLayoutModeDetailsView(false); + break; + case Layouts.Grid: + folderSettings.ToggleLayoutModeGridView(folderSettings.GridViewSize); + break; + } + } - bool desktopIniFound = false; + private static Layouts GetAdaptiveLayout(string path, IList filesAndFolders) + { + var pathLayout = GetPathLayout(path); + if (pathLayout is not Layouts.None) + return pathLayout; - if (string.IsNullOrWhiteSpace(path)) - { - return false; - } + return GetContentLayout(filesAndFolders); + } - var iniPath = System.IO.Path.Combine(path, "desktop.ini"); - var iniContents = NativeFileOperationsHelper.ReadStringFromFile(iniPath)?.Trim(); - if (!string.IsNullOrEmpty(iniContents)) - { - var parser = new IniParser.Parser.IniDataParser(); - parser.Configuration.ThrowExceptionsOnError = false; - var data = parser.Parse(iniContents); - if (data is not null) - { - var viewModeSection = data.Sections.FirstOrDefault(x => "ViewState".Equals(x.SectionName, StringComparison.OrdinalIgnoreCase)); - if (viewModeSection is not null) - { - var folderTypeKey = viewModeSection.Keys.FirstOrDefault(s => "FolderType".Equals(s.KeyName, StringComparison.OrdinalIgnoreCase)); - if (folderTypeKey is not null) - { - var setLayout = (folderTypeKey.Value) switch - { - "Documents" => layoutDetails, - "Pictures" => layoutGridView, - "Music" => layoutDetails, - "Videos" => layoutGridView, - _ => layoutDetails - }; - setLayout(); - desktopIniFound = true; - } - } - } - } + private static Layouts GetPathLayout(string path) + { + var iniPath = IO.Path.Combine(path, "desktop.ini"); - if (desktopIniFound) - { - return true; - } - if (filesAndFolders.Count == 0) - { - return false; - } + var iniContents = NativeFileOperationsHelper.ReadStringFromFile(iniPath)?.Trim(); + if (string.IsNullOrEmpty(iniContents)) + return Layouts.None; - int allItemsCount = filesAndFolders.Count; + var parser = new IniParser.Parser.IniDataParser(); + parser.Configuration.ThrowExceptionsOnError = false; + var data = parser.Parse(iniContents); + if (data is null) + return Layouts.None; - int mediaCount; - int imagesCount; - int foldersCount; - int miscFilesCount; + var viewModeSection = data.Sections.FirstOrDefault(IsViewState); + if (viewModeSection is null) + return Layouts.None; - float mediaPercentage; - float imagesPercentage; - float foldersPercentage; - float miscFilesPercentage; + var folderTypeKey = viewModeSection.Keys.FirstOrDefault(IsFolderType); + if (folderTypeKey is null) + return Layouts.None; + + return folderTypeKey.Value switch + { + "Pictures" => Layouts.Grid, + "Videos" => Layouts.Grid, + _ => Layouts.Detail, + }; + + static bool IsViewState(SectionData data) + => "ViewState".Equals(data.SectionName, StringComparison.OrdinalIgnoreCase); + + static bool IsFolderType(KeyData data) + => "FolderType".Equals(data.KeyName, StringComparison.OrdinalIgnoreCase); + } + + private static Layouts GetContentLayout(IList filesAndFolders) + { + int itemCount = filesAndFolders.Count; + 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) + 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; mediaCount = filesAndFolders.Where((item) => { @@ -92,10 +121,10 @@ public static bool PredictLayoutMode(FolderSettingsViewModel folderSettings, str foldersCount = filesAndFolders.Where((item) => item.PrimaryItemAttribute == StorageItemTypes.Folder).Count(); miscFilesCount = allItemsCount - (mediaCount + imagesCount + foldersCount); - mediaPercentage = mediaCount * 100.0f / allItemsCount; - imagesPercentage = imagesCount * 100.0f / allItemsCount; - foldersPercentage = foldersCount * 100.0f / allItemsCount; - miscFilesPercentage = miscFilesCount * 100.0f / allItemsCount; + mediaPercentage = (float)((float)mediaCount / (float)allItemsCount) * 100.0f; + imagesPercentage = (float)((float)imagesCount / (float)allItemsCount) * 100.0f; + foldersPercentage = (float)((float)foldersCount / (float)allItemsCount) * 100.0f; + miscFilesPercentage = (float)((float)miscFilesCount / (float)allItemsCount) * 100.0f; // Decide layout mode @@ -117,10 +146,16 @@ public static bool PredictLayoutMode(FolderSettingsViewModel folderSettings, str layoutDetails(); } - return true; - } + static bool IsMedia(ListedItem item) + => !string.IsNullOrEmpty(item.FileExtension) + && MediaPreviewViewModel.ContainsExtension(item.FileExtension.ToLowerInvariant()); + } - return false; + private enum Layouts + { + None, // Don't decide. Another function to decide can be called afterwards if available. + Detail, // Apply the layout Detail. + Grid, // Apply the layout Grid. } } -} \ No newline at end of file +} From 89e35a2b19fcbcf49a3e8016d751c619fdd05cac Mon Sep 17 00:00:00 2001 From: cinqmilleans Date: Mon, 13 Feb 2023 16:25:22 +0100 Subject: [PATCH 5/5] merge --- .../Helpers/AdaptiveLayoutHelpers.cs | 43 +++---------------- 1 file changed, 5 insertions(+), 38 deletions(-) diff --git a/src/Files.App/Helpers/AdaptiveLayoutHelpers.cs b/src/Files.App/Helpers/AdaptiveLayoutHelpers.cs index fe5c142e322a..21917d37f586 100644 --- a/src/Files.App/Helpers/AdaptiveLayoutHelpers.cs +++ b/src/Files.App/Helpers/AdaptiveLayoutHelpers.cs @@ -26,9 +26,8 @@ public static void ApplyAdaptativeLayout(FolderSettingsViewModel folderSettings, if (folderSettings.IsLayoutModeFixed || !folderSettings.IsAdaptiveLayoutEnabled) return; - if (userSettingsService.FoldersSettingsService.EnableOverridingFolderPreferences - && folderSettings.IsAdaptiveLayoutEnabled - && !folderSettings.IsLayoutModeFixed) + var layout = GetAdaptiveLayout(path, filesAndFolders); + switch (layout) { case Layouts.Detail: folderSettings.ToggleLayoutModeDetailsView(false); @@ -110,41 +109,9 @@ private static Layouts GetContentLayout(IList filesAndFolders) static bool IsFolder(ListedItem item) => item.PrimaryItemAttribute is StorageItemTypes.Folder; - mediaCount = filesAndFolders.Where((item) => - { - return !string.IsNullOrEmpty(item.FileExtension) && MediaPreviewViewModel.ContainsExtension(item.FileExtension.ToLowerInvariant()); - }).Count(); - imagesCount = filesAndFolders.Where((item) => - { - return !string.IsNullOrEmpty(item.FileExtension) && ImagePreviewViewModel.ContainsExtension(item.FileExtension.ToLowerInvariant()); - }).Count(); - foldersCount = filesAndFolders.Where((item) => item.PrimaryItemAttribute == StorageItemTypes.Folder).Count(); - miscFilesCount = allItemsCount - (mediaCount + imagesCount + foldersCount); - - mediaPercentage = (float)((float)mediaCount / (float)allItemsCount) * 100.0f; - imagesPercentage = (float)((float)imagesCount / (float)allItemsCount) * 100.0f; - foldersPercentage = (float)((float)foldersCount / (float)allItemsCount) * 100.0f; - miscFilesPercentage = (float)((float)miscFilesCount / (float)allItemsCount) * 100.0f; - - // Decide layout mode - - // Mostly files + folders, lesser media and image files | Mostly folders - if ((foldersPercentage + miscFilesPercentage) > Constants.AdaptiveLayout.LargeThreshold) - { - layoutDetails(); - } - // Mostly images, probably an images folder - else if (imagesPercentage > Constants.AdaptiveLayout.ExtraLargeThreshold - || (imagesPercentage > Constants.AdaptiveLayout.MediumThreshold - && (mediaPercentage + miscFilesPercentage + foldersPercentage) > Constants.AdaptiveLayout.SmallThreshold - && (miscFilesPercentage + foldersPercentage) < Constants.AdaptiveLayout.ExtraSmallThreshold)) - { - layoutGridView(); - } - else - { - layoutDetails(); - } + static bool IsImage(ListedItem item) + => !string.IsNullOrEmpty(item.FileExtension) + && ImagePreviewViewModel.ContainsExtension(item.FileExtension.ToLowerInvariant()); static bool IsMedia(ListedItem item) => !string.IsNullOrEmpty(item.FileExtension)