Skip to content

Commit

Permalink
Improve JsonNavigationService
Browse files Browse the repository at this point in the history
  • Loading branch information
ghost1372 committed Dec 27, 2024
1 parent 4ebed6f commit e7b4c53
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 30 deletions.
15 changes: 1 addition & 14 deletions dev/DevWinUI/Services/NavigationService/Services/DataSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,6 @@ public async Task<IEnumerable<DataGroup>> GetGroupsAsync(string jsonFilePath, Pa

return _instance.Groups;
}

/// <summary>
/// Load Assets\NavViewMenu\AppData.json
/// </summary>
/// <returns></returns>
public async Task<IEnumerable<DataGroup>> GetGroupsAsync()
{
_jsonFilePath = @"Assets\NavViewMenu\AppData.json";
_pathType = PathType.Relative;
await _instance.GetControlInfoDataAsync();

return _instance.Groups;
}

public static async Task<DataGroup> GetGroupAsync(string uniqueId)
{
Expand Down Expand Up @@ -170,4 +157,4 @@ public static async Task<string> LoadText(string filePath, PathType pathType)
}
return await FileIO.ReadTextAsync(file);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,24 @@ public JsonNavigationService ConfigureJsonFile(string jsonFilePath, PathType pat
ConfigJsonBase(jsonFilePath, pathType, orderItems);
return this;
}

public JsonNavigationService ConfigureJsonFile()
{
EnsureInitialized();
ConfigJsonBase(@"Assets\NavViewMenu\AppData.json", PathType.Relative, OrderItemsType.AscendingTopLevel);
return this;
}
public JsonNavigationService ConfigureJsonFile(string jsonFilePath)
{
EnsureInitialized();
ConfigJsonBase(jsonFilePath, PathType.Relative, OrderItemsType.AscendingTopLevel);
return this;
}

public JsonNavigationService ConfigureJsonFile(string jsonFilePath, OrderItemsType orderItems)
{
EnsureInitialized();
ConfigJsonBase(jsonFilePath, PathType.Relative, orderItems);
return this;
}

public JsonNavigationService ConfigureJsonFile(string jsonFilePath, PathType pathType)
{
EnsureInitialized();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ public partial class JsonNavigationService
private async void ConfigJsonBase(string jsonFilePath, PathType pathType, OrderItemsType orderItems)
{
JsonFilePath = jsonFilePath;
await DataSource.Instance.GetGroupsAsync();
await DataSource.Instance.GetGroupsAsync(jsonFilePath, pathType);

AddNavigationMenuItems(orderItems);

EnsureNavigationSelection(_defaultPage?.ToString());
}

private void ConfigAutoSuggestBox(AutoSuggestBox autoSuggestBox, bool useItemTemplate = true, string autoSuggestBoxNotFoundString = null, string autoSuggestBoxNotFoundImagePath = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ private void AddNavigationMenuItems(OrderItemsType orderItems)
}
}
}

EnsureNavigationSelection(_defaultPage?.ToString());
}

private IEnumerable<DataGroup> GetOrderedDataGroups(OrderItemsType orderItems)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ private void InitializeBase(NavigationView navigationView, Frame frame, Dictiona
this.Frame = frame ?? throw new ArgumentNullException(nameof(frame));
this._pageKeyToTypeMap = pages ?? throw new ArgumentNullException(nameof(pages));

_navigationView.BackRequested -= OnBackRequested;
_navigationView.BackRequested += OnBackRequested;
_navigationView.SelectionChanged -= OnSelectionChanged;
_navigationView.SelectionChanged += OnSelectionChanged;
_navigationView.BackRequested -= OnNavigationViewBackRequested;
_navigationView.BackRequested += OnNavigationViewBackRequested;
_navigationView.SelectionChanged -= OnNavigationViewSelectionChanged;
_navigationView.SelectionChanged += OnNavigationViewSelectionChanged;

var settingItem = (NavigationViewItem)SettingsItem;
if (settingItem != null)
Expand All @@ -26,6 +26,7 @@ private void InitializeBase(NavigationView navigationView, Frame frame, Dictiona
FrameNavigated -= OnNavigated;
FrameNavigated += OnNavigated;
}

private void OnNavigated(object sender, NavigationEventArgs e)
{
_navigationView.IsBackEnabled = CanGoBack;
Expand Down Expand Up @@ -56,8 +57,8 @@ public void Reset()
{
_navigationView.MenuItems?.Clear();
_navigationView.FooterMenuItems?.Clear();
_navigationView.BackRequested -= OnBackRequested;
_navigationView.SelectionChanged -= OnSelectionChanged;
_navigationView.BackRequested -= OnNavigationViewBackRequested;
_navigationView.SelectionChanged -= OnNavigationViewSelectionChanged;
}

_pageKeyToTypeMap?.Clear();
Expand All @@ -67,7 +68,7 @@ public void Reset()
Frame = null;
}

private void OnSelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
private void OnNavigationViewSelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
{
if (args.IsSettingsSelected)
{
Expand Down Expand Up @@ -103,12 +104,12 @@ public void UnregisterEvents()
{
if (_navigationView != null)
{
_navigationView.BackRequested -= OnBackRequested;
_navigationView.SelectionChanged -= OnSelectionChanged;
_navigationView.BackRequested -= OnNavigationViewBackRequested;
_navigationView.SelectionChanged -= OnNavigationViewSelectionChanged;
}
}

private void OnBackRequested(NavigationView sender, NavigationViewBackRequestedEventArgs args) => GoBack();
private void OnNavigationViewBackRequested(NavigationView sender, NavigationViewBackRequestedEventArgs args) => GoBack();

private void OnAutoSuggestBox_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args)
{
Expand Down

0 comments on commit e7b4c53

Please sign in to comment.