From a481974d86f10f3874930ea5da699256b92957c8 Mon Sep 17 00:00:00 2001 From: Marco Franzen Date: Thu, 28 Dec 2023 16:12:24 +0100 Subject: [PATCH] Feature: Added an option to group by day (#14299) --- docs/rich-commands.md | 3 + src/Files.App/Actions/Display/GroupAction.cs | 55 ++++++++++++++++++- src/Files.App/Data/Commands/CommandCodes.cs | 3 + .../Data/Commands/Manager/CommandManager.cs | 6 ++ .../Data/Commands/Manager/ICommandManager.cs | 3 + .../MenuFlyout/ContextFlyoutItemHelper.cs | 12 ++++ .../AbstractDateTimeFormatter.cs | 25 +++++---- src/Files.App/Strings/en-US/Resources.resw | 16 +++++- .../UserControls/InnerNavigationToolbar.xaml | 3 + .../ViewModels/Settings/FoldersViewModel.cs | 12 ++-- src/Files.App/Views/Settings/FoldersPage.xaml | 15 +++-- src/Files.Core/Data/Enums/GroupByDateUnit.cs | 7 ++- 12 files changed, 135 insertions(+), 25 deletions(-) diff --git a/docs/rich-commands.md b/docs/rich-commands.md index 316ea0829b85..1a02acf20f05 100644 --- a/docs/rich-commands.md +++ b/docs/rich-commands.md @@ -114,10 +114,13 @@ This is the list of all commands defined in `CommandCodes` enum except `None`. | | GroupByFolderPath | Folder path | Group items by folder path | | | | GroupByDateModifiedYear | Year | Group items by year of date modified | | | | GroupByDateModifiedMonth | Month | Group items by month of date modified | | +| | GroupByDateModifiedDay | Day | Group items by day of date modified | | | | GroupByDateCreatedYear | Year | Group items by year of date created | | | | GroupByDateCreatedMonth | Month | Group items by month of date created | | +| | GroupByDateCreatedDay | Day | Group items by day of date created | | | | GroupByDateDeletedYear | Year | Group items by year of date deleted | | | | GroupByDateDeletedMonth | Month | Group items by month of date deleted | | +| | GroupByDateDeletedDay | Day | Group items by day of date deleted | | | | GroupAscending | Ascending | Sort groups in ascending order | | | | GroupDescending | Descending | Sort groups in descending order | | | | ToggleGroupDirection | Toggle sort direction | Toggle group sort direction | | diff --git a/src/Files.App/Actions/Display/GroupAction.cs b/src/Files.App/Actions/Display/GroupAction.cs index 49669cb6f269..0e64c0d9da46 100644 --- a/src/Files.App/Actions/Display/GroupAction.cs +++ b/src/Files.App/Actions/Display/GroupAction.cs @@ -229,6 +229,21 @@ public override string Description => "GroupByDateModifiedMonthDescription".GetLocalizedResource(); } + internal class GroupByDateModifiedDayAction : GroupByDateAction + { + protected override GroupOption GroupOption + => GroupOption.DateModified; + + protected override GroupByDateUnit GroupByDateUnit + => GroupByDateUnit.Day; + + public override string Label + => "Day".GetLocalizedResource(); + + public override string Description + => "GroupByDateModifiedDayDescription".GetLocalizedResource(); + } + internal class GroupByDateCreatedYearAction : GroupByDateAction { protected override GroupOption GroupOption @@ -259,6 +274,21 @@ public override string Description => "GroupByDateCreatedMonthDescription".GetLocalizedResource(); } + internal class GroupByDateCreatedDayAction : GroupByDateAction + { + protected override GroupOption GroupOption + => GroupOption.DateCreated; + + protected override GroupByDateUnit GroupByDateUnit + => GroupByDateUnit.Day; + + public override string Label + => "Day".GetLocalizedResource(); + + public override string Description + => "GroupByDateCreatedDayDescription".GetLocalizedResource(); + } + internal class GroupByDateDeletedYearAction : GroupByDateAction { protected override GroupOption GroupOption @@ -295,6 +325,24 @@ protected override bool GetIsExecutable(ContentPageTypes pageType) => pageType is ContentPageTypes.RecycleBin; } + internal class GroupByDateDeletedDayAction : GroupByDateAction + { + protected override GroupOption GroupOption + => GroupOption.DateDeleted; + + protected override GroupByDateUnit GroupByDateUnit + => GroupByDateUnit.Day; + + public override string Label + => "Day".GetLocalizedResource(); + + public override string Description + => "GroupByDateDeletedDayDescription".GetLocalizedResource(); + + protected override bool GetIsExecutable(ContentPageTypes pageType) + => pageType is ContentPageTypes.RecycleBin; + } + internal abstract class GroupByDateAction : ObservableObject, IToggleAction { protected IContentPageContext ContentContext; @@ -567,7 +615,12 @@ public ToggleGroupByDateUnitAction() public Task ExecuteAsync() { - context.GroupByDateUnit = context.GroupByDateUnit is GroupByDateUnit.Month ? GroupByDateUnit.Year : GroupByDateUnit.Month; + context.GroupByDateUnit = context.GroupByDateUnit switch + { + GroupByDateUnit.Year => GroupByDateUnit.Month, + GroupByDateUnit.Month => GroupByDateUnit.Day, + _ => GroupByDateUnit.Year + }; return Task.CompletedTask; } diff --git a/src/Files.App/Data/Commands/CommandCodes.cs b/src/Files.App/Data/Commands/CommandCodes.cs index 7bfcf167ab3a..f429ef771331 100644 --- a/src/Files.App/Data/Commands/CommandCodes.cs +++ b/src/Files.App/Data/Commands/CommandCodes.cs @@ -151,10 +151,13 @@ public enum CommandCodes GroupByFolderPath, GroupByDateModifiedYear, GroupByDateModifiedMonth, + GroupByDateModifiedDay, GroupByDateCreatedYear, GroupByDateCreatedMonth, + GroupByDateCreatedDay, GroupByDateDeletedYear, GroupByDateDeletedMonth, + GroupByDateDeletedDay, GroupAscending, GroupDescending, ToggleGroupDirection, diff --git a/src/Files.App/Data/Commands/Manager/CommandManager.cs b/src/Files.App/Data/Commands/Manager/CommandManager.cs index 7fac5a3add36..ffa31135b7c9 100644 --- a/src/Files.App/Data/Commands/Manager/CommandManager.cs +++ b/src/Files.App/Data/Commands/Manager/CommandManager.cs @@ -147,10 +147,13 @@ public IRichCommand this[HotKey hotKey] public IRichCommand GroupByFolderPath => commands[CommandCodes.GroupByFolderPath]; public IRichCommand GroupByDateModifiedYear => commands[CommandCodes.GroupByDateModifiedYear]; public IRichCommand GroupByDateModifiedMonth => commands[CommandCodes.GroupByDateModifiedMonth]; + public IRichCommand GroupByDateModifiedDay => commands[CommandCodes.GroupByDateModifiedDay]; public IRichCommand GroupByDateCreatedYear => commands[CommandCodes.GroupByDateCreatedYear]; public IRichCommand GroupByDateCreatedMonth => commands[CommandCodes.GroupByDateCreatedMonth]; + public IRichCommand GroupByDateCreatedDay => commands[CommandCodes.GroupByDateCreatedDay]; public IRichCommand GroupByDateDeletedYear => commands[CommandCodes.GroupByDateDeletedYear]; public IRichCommand GroupByDateDeletedMonth => commands[CommandCodes.GroupByDateDeletedMonth]; + public IRichCommand GroupByDateDeletedDay => commands[CommandCodes.GroupByDateDeletedDay]; public IRichCommand GroupAscending => commands[CommandCodes.GroupAscending]; public IRichCommand GroupDescending => commands[CommandCodes.GroupDescending]; public IRichCommand ToggleGroupDirection => commands[CommandCodes.ToggleGroupDirection]; @@ -314,10 +317,13 @@ public CommandManager() [CommandCodes.GroupByFolderPath] = new GroupByFolderPathAction(), [CommandCodes.GroupByDateModifiedYear] = new GroupByDateModifiedYearAction(), [CommandCodes.GroupByDateModifiedMonth] = new GroupByDateModifiedMonthAction(), + [CommandCodes.GroupByDateModifiedDay] = new GroupByDateModifiedDayAction(), [CommandCodes.GroupByDateCreatedYear] = new GroupByDateCreatedYearAction(), [CommandCodes.GroupByDateCreatedMonth] = new GroupByDateCreatedMonthAction(), + [CommandCodes.GroupByDateCreatedDay] = new GroupByDateCreatedDayAction(), [CommandCodes.GroupByDateDeletedYear] = new GroupByDateDeletedYearAction(), [CommandCodes.GroupByDateDeletedMonth] = new GroupByDateDeletedMonthAction(), + [CommandCodes.GroupByDateDeletedDay] = new GroupByDateDeletedDayAction(), [CommandCodes.GroupAscending] = new GroupAscendingAction(), [CommandCodes.GroupDescending] = new GroupDescendingAction(), [CommandCodes.ToggleGroupDirection] = new ToggleGroupDirectionAction(), diff --git a/src/Files.App/Data/Commands/Manager/ICommandManager.cs b/src/Files.App/Data/Commands/Manager/ICommandManager.cs index 2122b133ca79..b817eccb428d 100644 --- a/src/Files.App/Data/Commands/Manager/ICommandManager.cs +++ b/src/Files.App/Data/Commands/Manager/ICommandManager.cs @@ -135,10 +135,13 @@ public interface ICommandManager : IEnumerable IRichCommand GroupByFolderPath { get; } IRichCommand GroupByDateModifiedYear { get; } IRichCommand GroupByDateModifiedMonth { get; } + IRichCommand GroupByDateModifiedDay { get; } IRichCommand GroupByDateCreatedYear { get; } IRichCommand GroupByDateCreatedMonth { get; } + IRichCommand GroupByDateCreatedDay { get; } IRichCommand GroupByDateDeletedYear { get; } IRichCommand GroupByDateDeletedMonth { get; } + IRichCommand GroupByDateDeletedDay { get; } IRichCommand GroupAscending { get; } IRichCommand GroupDescending { get; } IRichCommand ToggleGroupDirection { get; } diff --git a/src/Files.App/Helpers/MenuFlyout/ContextFlyoutItemHelper.cs b/src/Files.App/Helpers/MenuFlyout/ContextFlyoutItemHelper.cs index f0a61cb82ef1..5bdb48bbf9a2 100644 --- a/src/Files.App/Helpers/MenuFlyout/ContextFlyoutItemHelper.cs +++ b/src/Files.App/Helpers/MenuFlyout/ContextFlyoutItemHelper.cs @@ -245,6 +245,10 @@ public static List GetBaseItemMenuItems( { IsToggle = true }.Build(), + new ContextMenuFlyoutItemViewModelBuilder(commands.GroupByDateModifiedDay) + { + IsToggle = true + }.Build(), }, }, new ContextMenuFlyoutItemViewModel() @@ -264,6 +268,10 @@ public static List GetBaseItemMenuItems( { IsToggle = true }.Build(), + new ContextMenuFlyoutItemViewModelBuilder(commands.GroupByDateCreatedDay) + { + IsToggle = true + }.Build(), }, }, new ContextMenuFlyoutItemViewModelBuilder(commands.GroupByType) @@ -301,6 +309,10 @@ public static List GetBaseItemMenuItems( { IsToggle = true }.Build(), + new ContextMenuFlyoutItemViewModelBuilder(commands.GroupByDateDeletedDay) + { + IsToggle = true + }.Build(), }, }, new ContextMenuFlyoutItemViewModelBuilder(commands.GroupByFolderPath) diff --git a/src/Files.App/Services/DateTimeFormatter/AbstractDateTimeFormatter.cs b/src/Files.App/Services/DateTimeFormatter/AbstractDateTimeFormatter.cs index 448cb2f7cfd3..39ca9cd3277d 100644 --- a/src/Files.App/Services/DateTimeFormatter/AbstractDateTimeFormatter.cs +++ b/src/Files.App/Services/DateTimeFormatter/AbstractDateTimeFormatter.cs @@ -28,29 +28,34 @@ public ITimeSpanLabel ToTimeSpanLabel(DateTimeOffset offset, GroupByDateUnit uni return 0 switch { _ when now.Date < time.Date - => new Label("Future".GetLocalizedResource(), "\uED28", 1000006), + => new Label("Future".GetLocalizedResource(), "\uED28", 1000000006), _ when now.Date == time.Date - => new Label("Today".GetLocalizedResource(), "\uE8D1", 1000005), + => new Label("Today".GetLocalizedResource(), "\uE8D1", 1000000005), _ when now.AddDays(-1).Date == time.Date - => new Label("Yesterday".GetLocalizedResource(), "\uE8BF", 1000004), + => new Label("Yesterday".GetLocalizedResource(), "\uE8BF", 1000000004), + + // Group by day + _ when unit == GroupByDateUnit.Day + => new Label(ToString(time, "D"), "\uE8BF", time.Year * 10000 + time.Month * 100 + time.Day), + _ when diff.Days <= 7 && GetWeekOfYear(now) == GetWeekOfYear(time) - => new Label("EarlierThisWeek".GetLocalizedResource(), "\uE8C0", 1000003), + => new Label("EarlierThisWeek".GetLocalizedResource(), "\uE8C0", 1000000003), _ when diff.Days <= 14 && GetWeekOfYear(now.AddDays(-7)) == GetWeekOfYear(time) - => new Label("LastWeek".GetLocalizedResource(), "\uE8C0", 1000002), + => new Label("LastWeek".GetLocalizedResource(), "\uE8C0", 1000000002), _ when now.Year == time.Year && now.Month == time.Month - => new Label("EarlierThisMonth".GetLocalizedResource(), "\uE787", 1000001), + => new Label("EarlierThisMonth".GetLocalizedResource(), "\uE787", 1000000001), _ when now.AddMonths(-1).Year == time.Year && now.AddMonths(-1).Month == time.Month - => new Label("LastMonth".GetLocalizedResource(), "\uE787", 1000000), + => new Label("LastMonth".GetLocalizedResource(), "\uE787", 1000000000), // Group by month _ when unit == GroupByDateUnit.Month - => new Label(ToString(time, "Y"), "\uE787", time.Year * 100 + time.Month), + => new Label(ToString(time, "Y"), "\uE787", time.Year * 10000 + time.Month * 100), // Group by year _ when now.Year == time.Year - => new Label("EarlierThisYear".GetLocalizedResource(), "\uEC92", 10001), + => new Label("EarlierThisYear".GetLocalizedResource(), "\uEC92", 10000001), _ when now.AddYears(-1).Year == time.Year - => new Label("LastYear".GetLocalizedResource(), "\uEC92", 10000), + => new Label("LastYear".GetLocalizedResource(), "\uEC92", 10000000), _ => new Label(string.Format("YearN".GetLocalizedResource(), time.Year), "\uEC92", time.Year), }; diff --git a/src/Files.App/Strings/en-US/Resources.resw b/src/Files.App/Strings/en-US/Resources.resw index 0d87104497a7..597de27e3526 100644 --- a/src/Files.App/Strings/en-US/Resources.resw +++ b/src/Files.App/Strings/en-US/Resources.resw @@ -2998,6 +2998,9 @@ Month + + Day + Toggle unit for grouping by date @@ -3007,14 +3010,20 @@ Year - - Group by month instead of year + + Group by date unit + + + Group items by day of date created Group items by month of date created Group items by year of date created + + + Group items by day of date deleted Group items by month of date deleted @@ -3022,6 +3031,9 @@ Group items by year of date deleted + + Group items by day of date modified + Group items by month of date modified diff --git a/src/Files.App/UserControls/InnerNavigationToolbar.xaml b/src/Files.App/UserControls/InnerNavigationToolbar.xaml index 115d2e3b2693..f8d9b0f7bcc0 100644 --- a/src/Files.App/UserControls/InnerNavigationToolbar.xaml +++ b/src/Files.App/UserControls/InnerNavigationToolbar.xaml @@ -552,10 +552,12 @@ + + @@ -571,6 +573,7 @@ + UserSettingsService.FoldersSettingsService.DefaultGroupOption != GroupOption.None; - public bool GroupByMonth + private int defaultGroupByDateUnitIndex; + public int SelectedDefaultGroupByDateUnitIndex { - get => UserSettingsService.FoldersSettingsService.DefaultGroupByDateUnit == GroupByDateUnit.Month; + get => defaultGroupByDateUnitIndex; set { - if (value != (UserSettingsService.FoldersSettingsService.DefaultGroupByDateUnit == GroupByDateUnit.Month)) + if (SetProperty(ref defaultGroupByDateUnitIndex, value)) { - UserSettingsService.FoldersSettingsService.DefaultGroupByDateUnit = value ? GroupByDateUnit.Month : GroupByDateUnit.Year; - OnPropertyChanged(); + OnPropertyChanged(nameof(SelectedDefaultGroupByDateUnitIndex)); + UserSettingsService.FoldersSettingsService.DefaultGroupByDateUnit = (GroupByDateUnit)value; } } } diff --git a/src/Files.App/Views/Settings/FoldersPage.xaml b/src/Files.App/Views/Settings/FoldersPage.xaml index 419051ca5161..ae5a74294d4b 100644 --- a/src/Files.App/Views/Settings/FoldersPage.xaml +++ b/src/Files.App/Views/Settings/FoldersPage.xaml @@ -141,13 +141,16 @@ Style="{StaticResource RightAlignedToggleSwitchStyle}" /> - - - + + + SelectedIndex="{x:Bind ViewModel.SelectedDefaultGroupByDateUnitIndex, Mode=TwoWay}"> + + + + diff --git a/src/Files.Core/Data/Enums/GroupByDateUnit.cs b/src/Files.Core/Data/Enums/GroupByDateUnit.cs index 26351e4159d8..5db103ca67d6 100644 --- a/src/Files.Core/Data/Enums/GroupByDateUnit.cs +++ b/src/Files.Core/Data/Enums/GroupByDateUnit.cs @@ -13,6 +13,11 @@ public enum GroupByDateUnit : byte /// /// Group items by month. /// - Month = 1 + Month = 1, + + /// + /// Group items by day. + /// + Day = 2, } }