Skip to content

Commit

Permalink
Feature: Added an option to group by day (files-community#14299)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcofranzen99 authored Dec 28, 2023
1 parent 496e03f commit a481974
Show file tree
Hide file tree
Showing 12 changed files with 135 additions and 25 deletions.
3 changes: 3 additions & 0 deletions docs/rich-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | |
Expand Down
55 changes: 54 additions & 1 deletion src/Files.App/Actions/Display/GroupAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 3 additions & 0 deletions src/Files.App/Data/Commands/CommandCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,13 @@ public enum CommandCodes
GroupByFolderPath,
GroupByDateModifiedYear,
GroupByDateModifiedMonth,
GroupByDateModifiedDay,
GroupByDateCreatedYear,
GroupByDateCreatedMonth,
GroupByDateCreatedDay,
GroupByDateDeletedYear,
GroupByDateDeletedMonth,
GroupByDateDeletedDay,
GroupAscending,
GroupDescending,
ToggleGroupDirection,
Expand Down
6 changes: 6 additions & 0 deletions src/Files.App/Data/Commands/Manager/CommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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(),
Expand Down
3 changes: 3 additions & 0 deletions src/Files.App/Data/Commands/Manager/ICommandManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,13 @@ public interface ICommandManager : IEnumerable<IRichCommand>
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; }
Expand Down
12 changes: 12 additions & 0 deletions src/Files.App/Helpers/MenuFlyout/ContextFlyoutItemHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
{
IsToggle = true
}.Build(),
new ContextMenuFlyoutItemViewModelBuilder(commands.GroupByDateModifiedDay)
{
IsToggle = true
}.Build(),
},
},
new ContextMenuFlyoutItemViewModel()
Expand All @@ -264,6 +268,10 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
{
IsToggle = true
}.Build(),
new ContextMenuFlyoutItemViewModelBuilder(commands.GroupByDateCreatedDay)
{
IsToggle = true
}.Build(),
},
},
new ContextMenuFlyoutItemViewModelBuilder(commands.GroupByType)
Expand Down Expand Up @@ -301,6 +309,10 @@ public static List<ContextMenuFlyoutItemViewModel> GetBaseItemMenuItems(
{
IsToggle = true
}.Build(),
new ContextMenuFlyoutItemViewModelBuilder(commands.GroupByDateDeletedDay)
{
IsToggle = true
}.Build(),
},
},
new ContextMenuFlyoutItemViewModelBuilder(commands.GroupByFolderPath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
Expand Down
16 changes: 14 additions & 2 deletions src/Files.App/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -2998,6 +2998,9 @@
<data name="Month" xml:space="preserve">
<value>Month</value>
</data>
<data name="Day" xml:space="preserve">
<value>Day</value>
</data>
<data name="ToggleGroupByDateUnitDescription" xml:space="preserve">
<value>Toggle unit for grouping by date</value>
</data>
Expand All @@ -3007,21 +3010,30 @@
<data name="Year" xml:space="preserve">
<value>Year</value>
</data>
<data name="GroupByMonthInsteadOfYear" xml:space="preserve">
<value>Group by month instead of year</value>
<data name="GroupByDateUnit" xml:space="preserve">
<value>Group by date unit</value>
</data>
<data name="GroupByDateCreatedDayDescription" xml:space="preserve">
<value>Group items by day of date created</value>
</data>
<data name="GroupByDateCreatedMonthDescription" xml:space="preserve">
<value>Group items by month of date created</value>
</data>
<data name="GroupByDateCreatedYearDescription" xml:space="preserve">
<value>Group items by year of date created</value>
</data>
<data name="GroupByDateDeletedDayDescription" xml:space="preserve">
<value>Group items by day of date deleted</value>
</data>
<data name="GroupByDateDeletedMonthDescription" xml:space="preserve">
<value>Group items by month of date deleted</value>
</data>
<data name="GroupByDateDeletedYearDescription" xml:space="preserve">
<value>Group items by year of date deleted</value>
</data>
<data name="GroupByDateModifiedDayDescription" xml:space="preserve">
<value>Group items by day of date modified</value>
</data>
<data name="GroupByDateModifiedMonthDescription" xml:space="preserve">
<value>Group items by month of date modified</value>
</data>
Expand Down
3 changes: 3 additions & 0 deletions src/Files.App/UserControls/InnerNavigationToolbar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -552,10 +552,12 @@
<MenuFlyoutSubItem Text="{x:Bind Commands.GroupByDateModified.Label}">
<ToggleMenuFlyoutItem IsChecked="{x:Bind Commands.GroupByDateModifiedYear.IsOn, Mode=TwoWay}" Text="{x:Bind Commands.GroupByDateModifiedYear.Label}" />
<ToggleMenuFlyoutItem IsChecked="{x:Bind Commands.GroupByDateModifiedMonth.IsOn, Mode=TwoWay}" Text="{x:Bind Commands.GroupByDateModifiedMonth.Label}" />
<ToggleMenuFlyoutItem IsChecked="{x:Bind Commands.GroupByDateModifiedDay.IsOn, Mode=TwoWay}" Text="{x:Bind Commands.GroupByDateModifiedDay.Label}" />
</MenuFlyoutSubItem>
<MenuFlyoutSubItem Text="{x:Bind Commands.GroupByDateCreated.Label}">
<ToggleMenuFlyoutItem IsChecked="{x:Bind Commands.GroupByDateCreatedYear.IsOn, Mode=TwoWay}" Text="{x:Bind Commands.GroupByDateCreatedYear.Label}" />
<ToggleMenuFlyoutItem IsChecked="{x:Bind Commands.GroupByDateCreatedMonth.IsOn, Mode=TwoWay}" Text="{x:Bind Commands.GroupByDateCreatedMonth.Label}" />
<ToggleMenuFlyoutItem IsChecked="{x:Bind Commands.GroupByDateCreatedDay.IsOn, Mode=TwoWay}" Text="{x:Bind Commands.GroupByDateCreatedDay.Label}" />
</MenuFlyoutSubItem>
<ToggleMenuFlyoutItem IsChecked="{x:Bind Commands.GroupBySize.IsOn, Mode=TwoWay}" Text="{x:Bind Commands.GroupBySize.Label}" />
<ToggleMenuFlyoutItem IsChecked="{x:Bind Commands.GroupByType.IsOn, Mode=TwoWay}" Text="{x:Bind Commands.GroupByType.Label}" />
Expand All @@ -571,6 +573,7 @@
<MenuFlyoutSubItem IsEnabled="{x:Bind Commands.GroupByDateDeleted.IsExecutable, Mode=OneWay}" Text="{x:Bind Commands.GroupByDateDeleted.Label}">
<ToggleMenuFlyoutItem IsChecked="{x:Bind Commands.GroupByDateDeletedYear.IsOn, Mode=TwoWay}" Text="{x:Bind Commands.GroupByDateDeletedYear.Label}" />
<ToggleMenuFlyoutItem IsChecked="{x:Bind Commands.GroupByDateDeletedMonth.IsOn, Mode=TwoWay}" Text="{x:Bind Commands.GroupByDateDeletedMonth.Label}" />
<ToggleMenuFlyoutItem IsChecked="{x:Bind Commands.GroupByDateDeletedDay.IsOn, Mode=TwoWay}" Text="{x:Bind Commands.GroupByDateDeletedDay.Label}" />
</MenuFlyoutSubItem>
<ToggleMenuFlyoutItem
IsChecked="{x:Bind Commands.GroupByFolderPath.IsOn, Mode=TwoWay}"
Expand Down
12 changes: 7 additions & 5 deletions src/Files.App/ViewModels/Settings/FoldersViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public FoldersViewModel()
SelectedDefaultLayoutModeIndex = (int)DefaultLayoutMode;
SelectedDefaultSortingIndex = UserSettingsService.FoldersSettingsService.DefaultSortOption == SortOption.FileTag ? FileTagSortingIndex : (int)UserSettingsService.FoldersSettingsService.DefaultSortOption;
SelectedDefaultGroupingIndex = UserSettingsService.FoldersSettingsService.DefaultGroupOption == GroupOption.FileTag ? FileTagGroupingIndex : (int)UserSettingsService.FoldersSettingsService.DefaultGroupOption;
SelectedDefaultGroupByDateUnitIndex = (int)UserSettingsService.FoldersSettingsService.DefaultGroupByDateUnit;
SelectedDefaultSortPriorityIndex = UserSettingsService.FoldersSettingsService.DefaultSortDirectoriesAlongsideFiles ? 2 : UserSettingsService.FoldersSettingsService.DefaultSortFilesFirst ? 1 : 0;
SelectedDeleteConfirmationPolicyIndex = (int)DeleteConfirmationPolicy;
}
Expand Down Expand Up @@ -276,15 +277,16 @@ public bool GroupInDescendingOrder
public bool IsDefaultGrouped
=> 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;
}
}
}
Expand Down
15 changes: 9 additions & 6 deletions src/Files.App/Views/Settings/FoldersPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,16 @@
Style="{StaticResource RightAlignedToggleSwitchStyle}" />
</local:SettingsBlockControl>

<!-- Group by Month -->
<local:SettingsBlockControl Title="{helpers:ResourceString Name=GroupByMonthInsteadOfYear}" HorizontalAlignment="Stretch">
<ToggleSwitch
AutomationProperties.Name="{helpers:ResourceString Name=GroupByMonthInsteadOfYear}"
<!-- Group by date unit -->
<local:SettingsBlockControl Title="{helpers:ResourceString Name=GroupByDateUnit}" HorizontalAlignment="Stretch">
<ComboBox
AutomationProperties.Name="{helpers:ResourceString Name=GroupByDateUnit}"
IsEnabled="{x:Bind ViewModel.IsGroupByDate, Mode=OneWay}"
IsOn="{x:Bind ViewModel.GroupByMonth, Mode=TwoWay}"
Style="{StaticResource RightAlignedToggleSwitchStyle}" />
SelectedIndex="{x:Bind ViewModel.SelectedDefaultGroupByDateUnitIndex, Mode=TwoWay}">
<ComboBoxItem Content="{helpers:ResourceString Name=Year}" />
<ComboBoxItem Content="{helpers:ResourceString Name=Month}" />
<ComboBoxItem Content="{helpers:ResourceString Name=Day}" />
</ComboBox>
</local:SettingsBlockControl>

<!-- Sort Priority -->
Expand Down
7 changes: 6 additions & 1 deletion src/Files.Core/Data/Enums/GroupByDateUnit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ public enum GroupByDateUnit : byte
/// <summary>
/// Group items by month.
/// </summary>
Month = 1
Month = 1,

/// <summary>
/// Group items by day.
/// </summary>
Day = 2,
}
}

0 comments on commit a481974

Please sign in to comment.