Skip to content

Commit

Permalink
chore: Tried couple additional things in attempt to get some form of …
Browse files Browse the repository at this point in the history
…navigation to work.

Attempted to:
- Use Visibility directly without the use of Regions, via bindings.
- Tried to use ICommands to trigger change of visibility.
  • Loading branch information
andr9528 committed Dec 5, 2024
1 parent dd6be0f commit 1f2e9b2
Show file tree
Hide file tree
Showing 13 changed files with 309 additions and 12 deletions.
22 changes: 21 additions & 1 deletion Frontend.sln
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,15 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Module", "Module", "{3B82A2
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Budget", "Budget", "{342B2F60-01B4-46B6-BBEB-1E1EB2571F82}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tracker.Module.Budget.Presentation", "Tracker.Module.Budget.Presentation\Tracker.Module.Budget.Presentation.csproj", "{834D2CA9-7836-4139-AFCC-C105DAF040A9}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tracker.Module.Budget.Presentation", "Tracker.Module.Budget.Presentation\Tracker.Module.Budget.Presentation.csproj", "{834D2CA9-7836-4139-AFCC-C105DAF040A9}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Dining", "Dining", "{587F4172-1A53-4F80-8470-D216C5476841}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Time", "Time", "{839E3E59-F583-418D-AF8B-FE322C8588DA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tracker.Module.Dining.Presentation", "Tracker.Module.Dining.Presentation\Tracker.Module.Dining.Presentation.csproj", "{F3F293E0-14F1-4032-8DD3-69D61D2475E2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tracker.Module.Time.Presentation", "Tracker.Module.Time.Presentation\Tracker.Module.Time.Presentation.csproj", "{AAB0A19A-A79D-4367-AD6E-B7E6E8EE2584}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -76,6 +84,14 @@ Global
{834D2CA9-7836-4139-AFCC-C105DAF040A9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{834D2CA9-7836-4139-AFCC-C105DAF040A9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{834D2CA9-7836-4139-AFCC-C105DAF040A9}.Release|Any CPU.Build.0 = Release|Any CPU
{F3F293E0-14F1-4032-8DD3-69D61D2475E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F3F293E0-14F1-4032-8DD3-69D61D2475E2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F3F293E0-14F1-4032-8DD3-69D61D2475E2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F3F293E0-14F1-4032-8DD3-69D61D2475E2}.Release|Any CPU.Build.0 = Release|Any CPU
{AAB0A19A-A79D-4367-AD6E-B7E6E8EE2584}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AAB0A19A-A79D-4367-AD6E-B7E6E8EE2584}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AAB0A19A-A79D-4367-AD6E-B7E6E8EE2584}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AAB0A19A-A79D-4367-AD6E-B7E6E8EE2584}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -90,6 +106,10 @@ Global
{DB048A19-B0A5-4A9E-947F-A2E0CC542CD1} = {881ED950-F9CF-4A11-902E-4E52F718C1C5}
{342B2F60-01B4-46B6-BBEB-1E1EB2571F82} = {3B82A29D-7B8D-498A-A0C2-3EA3521233D6}
{834D2CA9-7836-4139-AFCC-C105DAF040A9} = {342B2F60-01B4-46B6-BBEB-1E1EB2571F82}
{587F4172-1A53-4F80-8470-D216C5476841} = {3B82A29D-7B8D-498A-A0C2-3EA3521233D6}
{839E3E59-F583-418D-AF8B-FE322C8588DA} = {3B82A29D-7B8D-498A-A0C2-3EA3521233D6}
{F3F293E0-14F1-4032-8DD3-69D61D2475E2} = {587F4172-1A53-4F80-8470-D216C5476841}
{AAB0A19A-A79D-4367-AD6E-B7E6E8EE2584} = {839E3E59-F583-418D-AF8B-FE322C8588DA}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {03BF2203-899D-4783-BD4B-B67969D7A79A}
Expand Down
12 changes: 9 additions & 3 deletions Tracker.Frontend.Uno/Models/TrackerModule.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
using System.Globalization;
using System.Text;
using Tracker.Module.Budget.Presentation;
using Tracker.Module.Dining.Presentation;
using Tracker.Module.Time.Presentation;

namespace Tracker.Frontend.Uno.Models;

public class TrackerModule
{
public enum Module
{
TIME,
DINING,
BUDGET,
BUDGET = 0,
DINING = 1,
TIME = 2,
}

private readonly Module typeModule;

public Module TypeModule => typeModule;

public TrackerModule(Module typeModule)
{
this.typeModule = typeModule;
Expand Down Expand Up @@ -48,7 +52,9 @@ public UserControl GetModuleControl()
switch (typeModule)
{
case Module.TIME:
return new TimeTabs();
case Module.DINING:
return new DiningTabs();
case Module.BUDGET:
default:
return new BudgetTabs();
Expand Down
40 changes: 37 additions & 3 deletions Tracker.Frontend.Uno/Presentation/ModulesNavigationPage.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
using Microsoft.UI.Xaml;
using TextBlock = Microsoft.UI.Xaml.Controls.TextBlock;

namespace Tracker.Frontend.Uno.Presentation;

public sealed partial class ModulesNavigationPage : Page
Expand Down Expand Up @@ -47,25 +50,44 @@ private NavigationBar BuildNavigationBar(ModulesNavigationViewModel viewModel)
private ListView BuildNavigationListView(ModulesNavigationViewModel viewModel)
{
var listView = new ListView();
listView.Region(true);
//listView.Region(true);

var listOptions = Modules.Select(module =>
{
var block = new TextBlock()
{
Text = module.GetModuleAsReadableString(),
Margin = new Thickness(10, 0, 0, 0),
Padding = new Thickness(10, 0, 10, 0),
VerticalAlignment = VerticalAlignment.Stretch,
HorizontalAlignment = HorizontalAlignment.Stretch,
Background = listView.Background,
FocusVisualPrimaryBrush = listView.Background,
FocusVisualSecondaryBrush = listView.Background,
};
block.Region(name: module.GetModuleAsReadableString());
//button.Region(name: module.GetModuleAsReadableString());
//button.SetRequest(module.GetModuleAsReadableString());
//button.SetData(module.GetModuleControl());

//button.Command(() => GetModuleCommand(viewModel, module.TypeModule));
//button.Style(new Style(typeof(TextBlock)));

return block;
});

listView.SelectionChanged += (sender, args) => ListViewOnSelectionChanged(sender, args, viewModel);
listView.ItemsSource = listOptions;

return listView;
}

private void ListViewOnSelectionChanged(
object sender, SelectionChangedEventArgs e, ModulesNavigationViewModel viewModel)
{
Console.WriteLine($"Listview Selection Changed Called");
viewModel.ListViewOnSelectionChanged(sender, e);
// Not Fired...
Console.WriteLine($"View Model Called");
}

private Grid BuildContentGrid(ModulesNavigationViewModel viewModel)
{
Expand All @@ -83,6 +105,7 @@ private Grid BuildContentGrid(ModulesNavigationViewModel viewModel)
VerticalAlignment = VerticalAlignment.Stretch,
Visibility = Visibility.Collapsed,
};
contentGrid.Visibility(() => GetModuleVisibility(viewModel, module.TypeModule));
contentGrid.Region(name: module.GetModuleAsReadableString());
contentGrid.Children.Add(module.GetModuleControl());

Expand All @@ -91,4 +114,15 @@ private Grid BuildContentGrid(ModulesNavigationViewModel viewModel)

return grid;
}

private Visibility GetModuleVisibility(ModulesNavigationViewModel viewModel, TrackerModule.Module module)
{
return module switch
{
TrackerModule.Module.TIME => viewModel.TimeModuleVisibility,
TrackerModule.Module.DINING => viewModel.DiningModuleVisibility,
TrackerModule.Module.BUDGET => viewModel.BudgetModuleVisibility,
_ => viewModel.BudgetModuleVisibility,
};
}
}
27 changes: 25 additions & 2 deletions Tracker.Frontend.Uno/Presentation/ModulesNavigationViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,43 @@
using Tracker.Module.Budget.Presentation.ViewModel;
using Uno.Extensions.Equality;

namespace Tracker.Frontend.Uno.Presentation;

public partial class ModulesNavigationViewModel : ObservableObject
{
private readonly INavigator _navigator;

[ObservableProperty] private TrackerModule.Module activeModule;

[ObservableProperty] private Visibility budgetModuleVisibility;
[ObservableProperty] private Visibility diningModuleVisibility;
[ObservableProperty] private Visibility timeModuleVisibility;

public ModulesNavigationViewModel(IOptions<AppConfig> appInfo, INavigator navigator)
{
_navigator = navigator;
Title = "Tracker";

//GoToSecond = new AsyncRelayCommand(GoToSecondView);
SetActiveModule(ModulesNavigationPage.Modules[0].TypeModule);
}

public string? Title { get; }

//public ICommand GoToSecond { get; }
public void ListViewOnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
var listView = (ListView) sender;
TrackerModule trackerModule = ModulesNavigationPage.Modules[listView.SelectedIndex];

SetActiveModule(trackerModule.TypeModule);
}

private void SetActiveModule(TrackerModule.Module module)
{
ActiveModule = module;
BudgetModuleVisibility =
ActiveModule == TrackerModule.Module.BUDGET ? Visibility.Visible : Visibility.Collapsed;
DiningModuleVisibility =
ActiveModule == TrackerModule.Module.DINING ? Visibility.Visible : Visibility.Collapsed;
TimeModuleVisibility = ActiveModule == TrackerModule.Module.TIME ? Visibility.Visible : Visibility.Collapsed;
}
}
33 changes: 31 additions & 2 deletions Tracker.Frontend.Uno/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
using Tracker.Module.Budget.Presentation;
using Tracker.Module.Budget.Presentation.ViewModel;
using Tracker.Module.Budget.Startup;
using Tracker.Module.Dining.Presentation;
using Tracker.Module.Dining.Presentation.ViewModel;
using Tracker.Module.Time.Presentation;
using Tracker.Module.Time.Presentation.ViewModel;
using Tracker.Shared.Startup;

namespace Tracker.Frontend.Uno;
Expand Down Expand Up @@ -47,7 +51,6 @@ private IHostBuilder ConfigureConfigurationSource(IConfigBuilder configBuilder)
return configBuilder.EmbeddedSource<App>().Section<AppConfig>();
}


private void ConfigureLogging(HostBuilderContext context, ILoggingBuilder logBuilder)
{
// Configure log levels for different categories of logging
Expand Down Expand Up @@ -79,16 +82,30 @@ private void RegisterRoutes(IViewRegistry views, IRouteRegistry routes)
RegisterViews(views);

string budgetPath = TrackerModule.GetModuleAsReadableString(TrackerModule.Module.BUDGET);
string diningPath = TrackerModule.GetModuleAsReadableString(TrackerModule.Module.DINING);
string timePath = TrackerModule.GetModuleAsReadableString(TrackerModule.Module.TIME);
const string modulePath = "Module";

var budgetRoutes = new RouteMap[]
{
new(BudgetTabs.BUDGET_TAB_REGION_NAME_ONE),
new(BudgetTabs.TAB_REGION_NAME_ONE),
};

var diningRoutes = new RouteMap[]
{
new(DiningTabs.TAB_REGION_NAME_ONE),
};

var timeRoutes = new RouteMap[]
{
new(TimeTabs.TAB_REGION_NAME_ONE),
};

var routeLevelThree = new RouteMap[]
{
new(budgetPath, views.FindByViewModel<BudgetTabsViewModel>(), Nested: budgetRoutes),
new(diningPath, views.FindByViewModel<DiningTabsViewModel>(), Nested: diningRoutes),
new(timePath, views.FindByViewModel<TimeTabsViewModel>(), Nested: timeRoutes),
};
var routeLevelTwo = new RouteMap[]
{
Expand All @@ -108,13 +125,25 @@ private void RegisterViews(IViewRegistry views)
new ViewMap<PaymentsTab, PaymentsTab>(),
};

var diningViewMaps = new List<ViewMap>
{
new ViewMap<DiningTabs, DiningTabsViewModel>(),
};

var timeViewMaps = new List<ViewMap>
{
new ViewMap<TimeTabs, TimeTabsViewModel>(),
};

var viewMaps = new List<ViewMap>
{
new ViewMap<Shell, ShellViewModel>(),
new ViewMap<ModulesNavigationPage, ModulesNavigationViewModel>(),
};

viewMaps.AddRange(budgetViewMaps);
viewMaps.AddRange(diningViewMaps);
viewMaps.AddRange(timeViewMaps);

views.Register(viewMaps.ToArray());
}
Expand Down
2 changes: 2 additions & 0 deletions Tracker.Frontend.Uno/Tracker.Frontend.Uno.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
<ItemGroup>
<ProjectReference Include="..\Tracker.Module.Budget.Presentation\Tracker.Module.Budget.Presentation.csproj" />
<ProjectReference Include="..\Tracker.Module.Budget.Startup\Tracker.Module.Budget.Startup.csproj" />
<ProjectReference Include="..\Tracker.Module.Dining.Presentation\Tracker.Module.Dining.Presentation.csproj" />
<ProjectReference Include="..\Tracker.Module.Time.Presentation\Tracker.Module.Time.Presentation.csproj" />
<ProjectReference Include="..\Tracker.Shared.Startup\Tracker.Shared.Startup.csproj" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion Tracker.Module.Budget.Presentation/BudgetTabs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Tracker.Module.Budget.Presentation;

public sealed partial class BudgetTabs : UserControl
{
public const string BUDGET_TAB_REGION_NAME_ONE = "PaymentsTab";
public const string TAB_REGION_NAME_ONE = "PaymentsTab";

public BudgetTabs()
{
Expand Down
65 changes: 65 additions & 0 deletions Tracker.Module.Dining.Presentation/DiningTabs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using Microsoft.UI;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Tracker.Module.Dining.Presentation.ViewModel;

namespace Tracker.Module.Dining.Presentation;

public sealed partial class DiningTabs : UserControl
{
public const string TAB_REGION_NAME_ONE = "DiningTabOne";

public DiningTabs()
{
this.DataContext<DiningTabsViewModel>((userControl, vm) =>
userControl.TabNavigation(KeyboardNavigationMode.Cycle).Background(Theme.Brushes.Background.Default)
.Content(BuildContent(vm)));
}

private Grid BuildContent(DiningTabsViewModel viewModel)
{
var grid = new Grid();

grid.SafeArea(SafeArea.InsetMask.VisibleBounds);
grid.RowDefinitions(new GridLength(8, GridUnitType.Star), new GridLength(92, GridUnitType.Star));

TabBar tabBar = BuildTabBar(viewModel).Grid(row: 0);
Grid contentGrid = BuildContentGrid(viewModel).Grid(row: 1);

grid.Children.Add(tabBar);
grid.Children.Add(contentGrid);

return grid;
}

private TabBar BuildTabBar(DiningTabsViewModel viewModel)
{
var tabBarItems = new TabBarItem[]
{
new() {Content = TAB_REGION_NAME_ONE,},
};

var tabBar = new TabBar
{
VerticalAlignment = VerticalAlignment.Top,
ItemsSource = tabBarItems,
Background = new SolidColorBrush(Colors.DarkGray),
};

return tabBar;
}

private Grid BuildContentGrid(DiningTabsViewModel viewModel)
{
var grid = new Grid();

var tabOne = new Grid() {Visibility = Visibility.Collapsed,};
//tabOne.Children.Add(new PaymentsTab());

grid.Children.Add(tabOne);

return grid;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<Folder Include="ViewModel\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" />
<PackageReference Include="Uno.Themes.WinUI.Markup" />
<PackageReference Include="Uno.Toolkit.WinUI.Markup" />
<PackageReference Include="Uno.WinUI" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using CommunityToolkit.Mvvm.ComponentModel;

namespace Tracker.Module.Dining.Presentation.ViewModel;

public partial class DiningTabsViewModel : ObservableObject
{
}
Loading

0 comments on commit 1f2e9b2

Please sign in to comment.