Skip to content

Commit

Permalink
WinUI - Start Loading Recent Accounts List
Browse files Browse the repository at this point in the history
  • Loading branch information
nlogozzo committed Mar 3, 2024
1 parent 19c9806 commit f23f5be
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<Button x:Name="BtnSwitch" Click="SwitchCurrencies">
<Button.Content>
<FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}" FontSize="18" Glyph="&#xE8AB;"/>
<FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}" FontSize="16" Glyph="&#xE8AB;"/>
</Button.Content>
</Button>
</StackPanel>
Expand Down Expand Up @@ -45,7 +45,7 @@

<Button x:Name="BtnCopy" Click="CopyResult">
<Button.Content>
<FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}" FontSize="18" Glyph="&#xE8C8;"/>
<FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}" FontSize="16" Glyph="&#xE8C8;"/>
</Button.Content>
</Button>
</StackPanel>
Expand Down
7 changes: 3 additions & 4 deletions org.nickvision.money.winui/Controls/SettingsRow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,23 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid HorizontalAlignment="Stretch" CornerRadius="{ThemeResource ControlCornerRadius}" Padding="16" MinWidth="148" MinHeight="68" ColumnSpacing="20"
BorderThickness="1" BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}" Background="{ThemeResource CardBackgroundFillColorDefaultBrush}">
<Grid HorizontalAlignment="Stretch" CornerRadius="{ThemeResource ControlCornerRadius}" Padding="16" MinWidth="148" MinHeight="68" BorderThickness="1" BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}" Background="{ThemeResource CardBackgroundFillColorDefaultBrush}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>

<FontIcon x:Name="Icon" Grid.Column="0" VerticalAlignment="Center" Margin="2,0,0,0" FontFamily="{StaticResource SymbolThemeFontFamily}" FontSize="20" Glyph="{x:Bind Glyph, Mode=OneWay}"/>
<FontIcon x:Name="Icon" Grid.Column="0" VerticalAlignment="Center" Margin="2,0,20,0" FontFamily="{StaticResource SymbolThemeFontFamily}" FontSize="20" Glyph="{x:Bind Glyph, Mode=OneWay}"/>

<StackPanel Grid.Column="1" VerticalAlignment="Center" Orientation="Vertical">
<TextBlock x:Name="LblTitle" Text="{x:Bind Title, Mode=OneWay}"/>

<TextBlock x:Name="LblDescription" FontSize="12" Foreground="{ThemeResource TextFillColorSecondaryBrush}" Text="{x:Bind Description, Mode=OneWay}"/>
</StackPanel>

<ContentControl Grid.Column="3" HorizontalAlignment="Right" VerticalAlignment="Center" HorizontalContentAlignment="Right" Content="{x:Bind Child, Mode=OneWay}">
<ContentControl Grid.Column="3" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="12,0,0,0" HorizontalContentAlignment="Right" Content="{x:Bind Child, Mode=OneWay}">
<ContentControl.Resources>
<ResourceDictionary>
<Style TargetType="ToggleSwitch" BasedOn="{StaticResource DefaultToggleSwitchStyle}">
Expand Down
4 changes: 2 additions & 2 deletions org.nickvision.money.winui/Controls/StatusPage.xaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,15 @@ namespace winrt::Nickvision::Money::WinUI::Controls::implementation
GlyphIcon().FontSize(30);
AppIcon().Width(64);
AppIcon().Height(64);
LblTitle().Style(Helpers::WinUI::LookupAppResource<Microsoft::UI::Xaml::Style>(L"SubtitleTextBlockStyle"));
LblTitle().Style(WinUIHelpers::LookupAppResource<Microsoft::UI::Xaml::Style>(L"SubtitleTextBlockStyle"));
}
else
{
StackPanel().Spacing(12);
GlyphIcon().FontSize(60);
AppIcon().Width(128);
AppIcon().Height(128);
LblTitle().Style(Helpers::WinUI::LookupAppResource<Microsoft::UI::Xaml::Style>(L"TitleTextBlockStyle"));
LblTitle().Style(WinUIHelpers::LookupAppResource<Microsoft::UI::Xaml::Style>(L"TitleTextBlockStyle"));
}
m_propertyChanged(*this, PropertyChangedEventArgs{ L"IsCompact" });
}
Expand Down
4 changes: 0 additions & 4 deletions org.nickvision.money.winui/Helpers/WinUI.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
#include "Helpers/WinUI.h"

namespace Helpers
{

}
2 changes: 1 addition & 1 deletion org.nickvision.money.winui/Helpers/WinUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "includes.h"

namespace Helpers::WinUI
namespace WinUIHelpers
{
/**
* @brief Looks up a WinUI resource for the application.
Expand Down
4 changes: 2 additions & 2 deletions org.nickvision.money.winui/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>

<Button Grid.Column="0" HorizontalAlignment="Stretch" Style="{ThemeResource AccentButtonStyle}">
<Button Grid.Column="0" Height="36" HorizontalAlignment="Stretch" Style="{ThemeResource AccentButtonStyle}">
<Button.Content>
<StackPanel Orientation="Horizontal" Spacing="6">
<FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}" FontSize="16" Glyph="&#xE710;"/>
Expand All @@ -177,7 +177,7 @@
</Button.KeyboardAccelerators>
</Button>

<Button Grid.Column="1" HorizontalAlignment="Stretch">
<Button Grid.Column="1" Height="36" HorizontalAlignment="Stretch">
<Button.Content>
<StackPanel Orientation="Horizontal" Spacing="6">
<FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}" FontSize="16" Glyph="&#xE8E5;"/>
Expand Down
44 changes: 42 additions & 2 deletions org.nickvision.money.winui/MainWindow.xaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
#if __has_include("MainWindow.g.cpp")
#include "MainWindow.g.cpp"
#endif
#include <cmath>
#include <format>
#include <libnick/helpers/stringhelpers.h>
#include <libnick/notifications/shellnotification.h>
#include <libnick/localization/gettext.h>
#include "SettingsPage.xaml.h"
#include "Controls/CurrencyConverterDialog.xaml.h"
#include "Controls/SettingsRow.xaml.h"
#include "Helpers/WinUI.h"

using namespace ::Nickvision;
Expand Down Expand Up @@ -117,6 +117,7 @@ namespace winrt::Nickvision::Money::WinUI::implementation
m_controller->connectTaskbar(m_hwnd);
m_controller->startup();
NavViewHome().IsSelected(true);
LoadRecentAccounts();
m_opened = true;
}
}
Expand Down Expand Up @@ -257,7 +258,7 @@ namespace winrt::Nickvision::Money::WinUI::implementation
ViewStack().CurrentPage(L"Custom");
FrameCustom().Content(winrt::box_value(page));
}
TitleBarSearchBox().Visibility(tag != L"Home" && tag != L"Settings" ? Visibility::Visible : Visibility::Collapsed);
TitleBarSearchBox().Visibility(tag == L"Account" ? Visibility::Visible : Visibility::Collapsed);
SetDragRegionForCustomTitleBar();
}

Expand Down Expand Up @@ -326,4 +327,43 @@ namespace winrt::Nickvision::Money::WinUI::implementation
InputNonClientPointerSource nonClientInputSrc{ InputNonClientPointerSource::GetForWindowId(AppWindow().Id()) };
nonClientInputSrc.SetRegionRects(NonClientRegionKind::Passthrough, rectArray);
}

void MainWindow::LoadRecentAccounts()
{
std::vector<RecentAccount> recentAccounts{ m_controller->getRecentAccounts() };
ListRecentAccounts().Children().Clear();
if(recentAccounts.size() == 0)
{
UserControl row{ winrt::make<Controls::implementation::SettingsRow>() };
row.as<Controls::implementation::SettingsRow>()->Glyph(L"\uE121");
row.as<Controls::implementation::SettingsRow>()->Title(winrt::to_hstring(_("No Recent Accounts")));
ListRecentAccounts().Children().Append(row);
}
for(const RecentAccount& recentAccount : m_controller->getRecentAccounts())
{
Color color{ m_controller->getAccountTypeColor(recentAccount.getType()) };
Shapes::Rectangle rect;
rect.Width(32);
rect.Height(32);
rect.Fill(SolidColorBrush{ Windows::UI::ColorHelper::FromArgb(255, color.getR(), color.getG(), color.getB()) });
FontIcon icon;
icon.FontFamily(WinUIHelpers::LookupAppResource<FontFamily>(L"SymbolThemeFontFamily"));
icon.FontSize(16);
icon.Glyph(L"\uE711");
Button button;
button.Content(winrt::box_value(icon));
ToolTipService::SetToolTip(button, winrt::box_value(winrt::to_hstring(_("Remove"))));
StackPanel stack;
stack.Orientation(Orientation::Horizontal);
stack.Spacing(6);
stack.Children().Append(rect);
stack.Children().Append(button);
UserControl row{ winrt::make<Controls::implementation::SettingsRow>() };
row.as<Controls::implementation::SettingsRow>()->Glyph(L"\uE8C7");
row.as<Controls::implementation::SettingsRow>()->Title(winrt::to_hstring(recentAccount.getName()));
row.as<Controls::implementation::SettingsRow>()->Description(winrt::to_hstring(recentAccount.getPath().string()));
row.as<Controls::implementation::SettingsRow>()->Child(winrt::box_value(stack));
ListRecentAccounts().Children().Append(row);
}
}
}
4 changes: 4 additions & 0 deletions org.nickvision.money.winui/MainWindow.xaml.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ namespace winrt::Nickvision::Money::WinUI::implementation
* @brief Establishes drag regions for the main window's title bar.
*/
void SetDragRegionForCustomTitleBar();
/**
* @brief Loads the recent accounts list.
*/
void LoadRecentAccounts();
std::shared_ptr<::Nickvision::Money::Shared::Controllers::MainWindowController> m_controller;
bool m_opened;
bool m_isActivated;
Expand Down
13 changes: 7 additions & 6 deletions org.nickvision.money.winui/SettingsPage.xaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ using namespace ::Nickvision::Money::Shared::Models;
using namespace winrt::Microsoft::UI::Xaml;
using namespace winrt::Microsoft::UI::Xaml::Controls;
using namespace winrt::Microsoft::UI::Xaml::Media;
using namespace winrt::Windows::UI;

namespace winrt::Nickvision::Money::WinUI::implementation
{
Expand Down Expand Up @@ -51,12 +52,12 @@ namespace winrt::Nickvision::Money::WinUI::implementation
m_constructing = true;
CmbTheme().SelectedIndex(static_cast<int>(m_controller->getTheme()));
TglAutomaticallyCheckForUpdates().IsOn(m_controller->getAutomaticallyCheckForUpdates());
ClrDefaultTransaction().Color(Windows::UI::ColorHelper::FromArgb(m_controller->getTransactionDefaultColor().getA(), m_controller->getTransactionDefaultColor().getR(), m_controller->getTransactionDefaultColor().getG(), m_controller->getTransactionDefaultColor().getB()));
ClrDefaultTransfer().Color(Windows::UI::ColorHelper::FromArgb(m_controller->getTransferDefaultColor().getA(), m_controller->getTransferDefaultColor().getR(), m_controller->getTransferDefaultColor().getG(), m_controller->getTransferDefaultColor().getB()));
ClrDefaultGroup().Color(Windows::UI::ColorHelper::FromArgb(m_controller->getGroupDefaultColor().getA(), m_controller->getGroupDefaultColor().getR(), m_controller->getGroupDefaultColor().getG(), m_controller->getGroupDefaultColor().getB()));
ClrCheckingAccount().Color(Windows::UI::ColorHelper::FromArgb(m_controller->getAccountCheckingColor().getA(), m_controller->getAccountCheckingColor().getR(), m_controller->getAccountCheckingColor().getG(), m_controller->getAccountCheckingColor().getB()));
ClrSavingsAccount().Color(Windows::UI::ColorHelper::FromArgb(m_controller->getAccountSavingsColor().getA(), m_controller->getAccountSavingsColor().getR(), m_controller->getAccountSavingsColor().getG(), m_controller->getAccountSavingsColor().getB()));
ClrBusinessAccount().Color(Windows::UI::ColorHelper::FromArgb(m_controller->getAccountBusinessColor().getA(), m_controller->getAccountBusinessColor().getR(), m_controller->getAccountBusinessColor().getG(), m_controller->getAccountBusinessColor().getB()));
ClrDefaultTransaction().Color(ColorHelper::FromArgb(m_controller->getTransactionDefaultColor().getA(), m_controller->getTransactionDefaultColor().getR(), m_controller->getTransactionDefaultColor().getG(), m_controller->getTransactionDefaultColor().getB()));
ClrDefaultTransfer().Color(ColorHelper::FromArgb(m_controller->getTransferDefaultColor().getA(), m_controller->getTransferDefaultColor().getR(), m_controller->getTransferDefaultColor().getG(), m_controller->getTransferDefaultColor().getB()));
ClrDefaultGroup().Color(ColorHelper::FromArgb(m_controller->getGroupDefaultColor().getA(), m_controller->getGroupDefaultColor().getR(), m_controller->getGroupDefaultColor().getG(), m_controller->getGroupDefaultColor().getB()));
ClrCheckingAccount().Color(ColorHelper::FromArgb(m_controller->getAccountCheckingColor().getA(), m_controller->getAccountCheckingColor().getR(), m_controller->getAccountCheckingColor().getG(), m_controller->getAccountCheckingColor().getB()));
ClrSavingsAccount().Color(ColorHelper::FromArgb(m_controller->getAccountSavingsColor().getA(), m_controller->getAccountSavingsColor().getR(), m_controller->getAccountSavingsColor().getG(), m_controller->getAccountSavingsColor().getB()));
ClrBusinessAccount().Color(ColorHelper::FromArgb(m_controller->getAccountBusinessColor().getA(), m_controller->getAccountBusinessColor().getR(), m_controller->getAccountBusinessColor().getG(), m_controller->getAccountBusinessColor().getB()));
CmbInsertSeparator().SelectedIndex(static_cast<int>(m_controller->getInsertSeparator()));
m_constructing = false;
}
Expand Down

0 comments on commit f23f5be

Please sign in to comment.