Added some logging and dialog stuff, as well as made the add profile button actually add a critter to the db
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Avalonia.Android" />
|
||||
<PackageReference Include="AvaloniaDialogs" />
|
||||
<PackageReference Include="sqlite-net-pcl" />
|
||||
<PackageReference Include="SQLitePCLRaw.bundle_green" />
|
||||
<PackageReference Include="Xamarin.AndroidX.Core.SplashScreen" />
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Avalonia.Browser" />
|
||||
<PackageReference Include="AvaloniaDialogs" />
|
||||
<PackageReference Include="SkiaSharp.NativeAssets.WebAssembly" />
|
||||
<PackageReference Include="sqlite-net-pcl" />
|
||||
<PackageReference Include="SQLitePCLRaw.bundle_green" />
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
<IncludeAssets Condition="'$(Configuration)' != 'Debug'">None</IncludeAssets>
|
||||
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="AvaloniaDialogs" />
|
||||
<PackageReference Include="sqlite-net-pcl" />
|
||||
<PackageReference Include="SQLitePCLRaw.bundle_green" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:CritterFolio"
|
||||
x:Class="CritterFolio.App"
|
||||
xmlns:dialogHostAvalonia="using:DialogHostAvalonia"
|
||||
RequestedThemeVariant="Default">
|
||||
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
|
||||
|
||||
@@ -11,6 +12,7 @@
|
||||
|
||||
<Application.Styles>
|
||||
<FluentTheme />
|
||||
<dialogHostAvalonia:DialogHostStyles />
|
||||
<StyleInclude Source="Styles/MainStyles.axaml" />
|
||||
</Application.Styles>
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
<IncludeAssets Condition="'$(Configuration)' != 'Debug'">None</IncludeAssets>
|
||||
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="AvaloniaDialogs" />
|
||||
<PackageReference Include="CommunityToolkit.Mvvm" />
|
||||
<PackageReference Include="SkiaSharp.NativeAssets.WebAssembly" />
|
||||
<PackageReference Include="sqlite-net-pcl" />
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.Media;
|
||||
using AvaloniaDialogs.Views;
|
||||
using CritterFolio.Controls;
|
||||
using CritterFolio.DataModels;
|
||||
using CritterFolio.Services;
|
||||
@@ -63,13 +66,31 @@ public partial class HomePage : Page
|
||||
}
|
||||
}
|
||||
|
||||
private void AddProfileButton(Critter critter)
|
||||
private async void AddProfileButton(Critter critter)
|
||||
{
|
||||
var newProfButton = new ProfileButton();
|
||||
newProfButton.Init(critter);
|
||||
CritterStack.Children.Add(newProfButton);
|
||||
|
||||
|
||||
|
||||
newProfButton.Clicked += (o, args) => { Console.WriteLine($"{critter.Name} button clicked"); };
|
||||
newProfButton.Clicked += async (sender, args) =>
|
||||
{
|
||||
await ProfileButtonClicked(critter);
|
||||
};
|
||||
}
|
||||
|
||||
private async Task ProfileButtonClicked(Critter critter)
|
||||
{
|
||||
try
|
||||
{
|
||||
await DialogHelper.ShowMessage($"{critter.Name} was clicked");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
Logger.LogToFile(e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private async void AddButtonClicked(object? sender, RoutedEventArgs e)
|
||||
@@ -79,6 +100,7 @@ public partial class HomePage : Page
|
||||
{
|
||||
var result = await DatabaseService.AddCritter(newCritter);
|
||||
AddProfileButton(newCritter);
|
||||
Logger.LogToFile("New critter was added");
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
<Button HorizontalAlignment="Stretch" Classes="normal">Insert test data</Button>
|
||||
<Button x:Name="ClearDbButton" HorizontalAlignment="Stretch" Classes="normal">Clear database</Button>
|
||||
<Button x:Name="ReInitButton" HorizontalAlignment="Stretch" Classes="normal">Re-init Database</Button>
|
||||
<Label FontSize="20" HorizontalAlignment="Stretch">Logger</Label>
|
||||
<Button x:Name="OpenLogButton" HorizontalAlignment="Stretch" Classes="normal">Open Log File</Button>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</UserControl>
|
||||
|
||||
@@ -4,6 +4,7 @@ using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.Platform.Storage;
|
||||
using CritterFolio.Services;
|
||||
|
||||
namespace CritterFolio.Pages;
|
||||
@@ -18,12 +19,31 @@ public partial class TestPage : Page
|
||||
|
||||
ClearDbButton.Click += ClearDbButtonClicked;
|
||||
ReInitButton.Click += ReInitButtonClicked;
|
||||
OpenLogButton.Click += OpenLogButtonClicked;
|
||||
}
|
||||
|
||||
private void ClearDbButtonClicked(object? sender, RoutedEventArgs e)
|
||||
private void OpenLogButtonClicked(object? sender, RoutedEventArgs args)
|
||||
{
|
||||
var databasePath = Path.Combine(AppContext.BaseDirectory, "CritterFolio.db");
|
||||
File.Delete(databasePath);
|
||||
var logFilePath = Path.Combine(AppContext.BaseDirectory, "log.txt");
|
||||
if (!File.Exists(logFilePath)) return;
|
||||
var launcher = TopLevel.GetTopLevel(this)?.Launcher;
|
||||
if (launcher is null) return;
|
||||
|
||||
launcher.LaunchUriAsync(new Uri("file://" + logFilePath));
|
||||
}
|
||||
|
||||
|
||||
private async void ClearDbButtonClicked(object? sender, RoutedEventArgs args)
|
||||
{
|
||||
try
|
||||
{
|
||||
await DatabaseService.ClearAllTables();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogToFile(ex.ToString());
|
||||
Console.WriteLine(ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private async void ReInitButtonClicked(object? sender, RoutedEventArgs e)
|
||||
|
||||
@@ -31,6 +31,13 @@ public static class DatabaseService
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task ClearAllTables()
|
||||
{
|
||||
await Init();
|
||||
await _db?.DeleteAllAsync<Critter>()!;
|
||||
await _db?.DeleteAllAsync<Document>()!;
|
||||
}
|
||||
|
||||
#region Critter operations
|
||||
|
||||
public static async Task<bool> AddCritter(Critter critter)
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using AvaloniaDialogs.Views;
|
||||
|
||||
namespace CritterFolio.Services;
|
||||
|
||||
public static class DialogHelper
|
||||
{
|
||||
public static async Task ShowMessage(string message)
|
||||
{
|
||||
try
|
||||
{
|
||||
await new SingleActionDialog()
|
||||
{
|
||||
Message = message,
|
||||
ButtonText = "OK"
|
||||
}.ShowAsync();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
15
critterfolio/CritterFolio/CritterFolio/Services/Logger.cs
Normal file
15
critterfolio/CritterFolio/CritterFolio/Services/Logger.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace CritterFolio.Services;
|
||||
|
||||
public class Logger
|
||||
{
|
||||
public static void LogToFile(string text)
|
||||
{
|
||||
var logFilePath = Path.Combine(AppContext.BaseDirectory, "log.txt");
|
||||
|
||||
File.AppendAllText(logFilePath, $"{DateTime.UtcNow} : {text}\n");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,20 +4,25 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:vm="using:CritterFolio.ViewModels"
|
||||
xmlns:critterFolio="clr-namespace:CritterFolio"
|
||||
xmlns:views="clr-namespace:AvaloniaDialogs.Views;assembly=AvaloniaDialogs"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="CritterFolio.Views.MainView"
|
||||
x:DataType="vm:MainViewModel">
|
||||
<Design.DataContext>
|
||||
<!-- This only sets the DataContext for the previewer in an IDE,
|
||||
|
||||
<views:ReactiveDialogHost CloseOnClickAway="True">
|
||||
<Design.DataContext>
|
||||
<!-- This only sets the DataContext for the previewer in an IDE,
|
||||
to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) -->
|
||||
<vm:MainViewModel />
|
||||
</Design.DataContext>
|
||||
<vm:MainViewModel />
|
||||
</Design.DataContext>
|
||||
|
||||
<Grid RowDefinitions="Auto, *" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Background="{DynamicResource PrimaryBackground}">
|
||||
<Grid RowDefinitions="Auto, *" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Background="{DynamicResource PrimaryBackground}">
|
||||
|
||||
<critterFolio:Navigation Grid.Row="0" x:Name="Nav"/>
|
||||
<ScrollViewer Grid.Row="1" x:Name="ScrollView" Margin="20"/>
|
||||
<critterFolio:Navigation Grid.Row="0" x:Name="Nav"/>
|
||||
<ScrollViewer Grid.Row="1" x:Name="ScrollView" Margin="20"/>
|
||||
|
||||
</Grid>
|
||||
</Grid>
|
||||
</views:ReactiveDialogHost>
|
||||
|
||||
|
||||
</UserControl>
|
||||
|
||||
@@ -4,9 +4,12 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:views="using:CritterFolio.Views"
|
||||
xmlns:dialogs="using:AvaloniaDialogs.Views"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="CritterFolio.Views.MainWindow"
|
||||
Icon="/Assets/icon.ico"
|
||||
Title="CritterFolio">
|
||||
<views:MainView />
|
||||
<dialogs:ReactiveDialogHost CloseOnClickAway="True">
|
||||
<views:MainView />
|
||||
</dialogs:ReactiveDialogHost>
|
||||
</Window>
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
<PackageVersion Include="Avalonia.iOS" Version="11.3.10" />
|
||||
<PackageVersion Include="Avalonia.Browser" Version="11.3.10" />
|
||||
<PackageVersion Include="Avalonia.Android" Version="11.3.10" />
|
||||
<PackageVersion Include="AvaloniaDialogs" Version="3.7.0" />
|
||||
<PackageVersion Include="CommunityToolkit.Mvvm" Version="8.4.0" />
|
||||
<PackageVersion Include="SkiaSharp.NativeAssets.WebAssembly" Version="3.119.0" />
|
||||
<PackageVersion Include="sqlite-net-pcl" Version="1.9.172" />
|
||||
|
||||
Reference in New Issue
Block a user