File attachment UI work

This commit is contained in:
TheXamlGuy
2024-07-24 21:51:51 +01:00
parent e28e0d615a
commit c6f71c3d0b
13 changed files with 103 additions and 18 deletions
+2
View File
@@ -192,6 +192,8 @@ public partial class App : Application
services.AddTemplate<CommentEntryCollectionViewModel, CommentEntryCollectionView>();
services.AddTemplate<AttachmentEntryCollectionViewModel, AttachmentEntryCollectionView>();
services.AddTemplate<AttachmentEntryViewModel, AttachmentEntryView>();
services.AddTemplate<LocalAttachmentEntryViewModel, AttachmentEntryView>();
services.AddTemplate<TextEntryViewModel, TextEntryView>();
services.AddTemplate<PasswordEntryViewModel, PasswordEntryView>();
@@ -0,0 +1,6 @@
<SettingsExpanderItem
x:Class="Wallet.Avalonia.AttachmentEntryView"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
Welcome to Avalonia!
</SettingsExpanderItem>
@@ -0,0 +1,10 @@
using Toolkit.UI.Controls.Avalonia;
namespace Wallet.Avalonia;
public partial class AttachmentEntryView :
SettingsExpanderItem
{
public AttachmentEntryView() =>
InitializeComponent();
}
+2 -2
View File
@@ -4,5 +4,5 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:Wallet"
x:DataType="vm:CommentEntryViewModel"
Content="{Binding Value}"
Description="{Binding Key}" />
Content="{Binding Comment}"
Description="{Binding Created}" />
+13 -5
View File
@@ -9,14 +9,17 @@ public partial class AttachmentEntryCollectionViewModel(IServiceProvider provide
IPublisher publisher,
ISubscriber subscriber,
IDisposer disposer,
IContentTemplate template,
ItemState state,
IItemEntryConfiguration<ICollection<Attachment>> configuration,
string key,
ICollection<Attachment> value,
bool isConcealed,
bool isRevealed,
double width) : ItemEntryCollectionViewModel<AttachmentEntryViewModel, ICollection<Attachment>>(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value, isConcealed, isRevealed, width)
double width) : ItemEntryCollectionViewModel<IAttachmentEntryViewModel, ICollection<Attachment>>(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value, isConcealed, isRevealed, width)
{
public IContentTemplate Template { get; set; } = template;
[RelayCommand]
private async Task Invoke()
{
@@ -25,14 +28,19 @@ public partial class AttachmentEntryCollectionViewModel(IServiceProvider provide
{
foreach (IFileDescriptor file in fileDescriptors)
{
string path = file.Path;
DateTimeOffset created = DateTimeOffset.Now;
string name = file.Name;
int size = file.Size;
Attachment attachment = new()
{
Name = file.Name,
Path = file.Path,
DateTime = DateTimeOffset.Now
Name = name,
Path = path,
DateTime = created
};
Add<AttachmentEntryViewModel>(attachment);
Add<LocalAttachmentEntryViewModel>(path, created, size, name);
Value.Add(attachment);
}
}
+20 -2
View File
@@ -1,4 +1,5 @@
using Toolkit.Foundation;
using CommunityToolkit.Mvvm.ComponentModel;
using Toolkit.Foundation;
namespace Wallet;
@@ -8,4 +9,21 @@ public partial class AttachmentEntryViewModel(IServiceProvider provider,
IPublisher publisher,
ISubscriber subscriber,
IDisposer disposer,
Attachment? value = default) : Observable<Attachment>(provider, factory, mediator, publisher, subscriber, disposer, value);
Guid id,
DateTimeOffset created,
int size,
string name) : Observable(provider, factory, mediator, publisher, subscriber, disposer),
IAttachmentEntryViewModel
{
[ObservableProperty]
private DateTimeOffset? created = created;
[ObservableProperty]
private Guid id = id;
[ObservableProperty]
private int size = size;
[ObservableProperty]
private string name = name;
}
+1 -1
View File
@@ -2,7 +2,7 @@
public record Comment
{
public DateTimeOffset DateTime { get; set; }
public DateTimeOffset Created { get; set; }
public string? Text { get; set; }
}
+1 -1
View File
@@ -30,7 +30,7 @@ public partial class CommentEntryCollectionViewModel : ItemEntryCollectionViewMo
{
if (args.Sender is Comment comment)
{
Insert<CommentEntryViewModel>(0, comment.DateTime, comment.Text);
Insert<CommentEntryViewModel>(0, comment.Created, comment.Text);
Value.Add(comment);
}
@@ -18,9 +18,9 @@ public class CommentEntryCollectionViewModelHandler(IServiceFactory serviceFacto
[.. args.Parameters, configuration, label, values, false, false, width])
is CommentEntryCollectionViewModel viewModel)
{
foreach (Comment value in values.OrderByDescending(x => x.DateTime))
foreach (Comment value in values.OrderByDescending(x => x.Created))
{
viewModel.Add<CommentEntryViewModel>(value.DateTime, value.Text);
viewModel.Add<CommentEntryViewModel>(value.Created, value.Text);
}
return Task.FromResult<IItemEntryViewModel?>(viewModel);
+12 -4
View File
@@ -1,4 +1,5 @@
using Toolkit.Foundation;
using CommunityToolkit.Mvvm.ComponentModel;
using Toolkit.Foundation;
namespace Wallet;
@@ -8,6 +9,13 @@ public partial class CommentEntryViewModel(IServiceProvider provider,
IPublisher publisher,
ISubscriber subscriber,
IDisposer disposer,
DateTimeOffset key,
string? value = default) : Observable<DateTimeOffset, string>(provider, factory, mediator, publisher, subscriber, disposer, key, value),
ICommentEntryViewModel;
DateTimeOffset created,
string comment) : Observable(provider, factory, mediator, publisher, subscriber, disposer),
ICommentEntryViewModel
{
[ObservableProperty]
private DateTimeOffset created = created;
[ObservableProperty]
private string comment = comment;
}
+1 -1
View File
@@ -14,7 +14,7 @@ public partial class CreateCommentEntryViewModel(IServiceProvider provider,
[RelayCommand]
private void Invoke()
{
Publisher.Publish(Create.As(new Comment { Text = Value, DateTime = DateTimeOffset.Now }));
Publisher.Publish(Create.As(new Comment { Text = Value, Created = DateTimeOffset.Now }));
Value = null;
}
}
+4
View File
@@ -0,0 +1,4 @@
namespace Wallet;
public interface IAttachmentEntryViewModel :
IDisposable;
+29
View File
@@ -0,0 +1,29 @@
using CommunityToolkit.Mvvm.ComponentModel;
using Toolkit.Foundation;
namespace Wallet;
public partial class LocalAttachmentEntryViewModel(IServiceProvider provider,
IServiceFactory factory,
IMediator mediator,
IPublisher publisher,
ISubscriber subscriber,
IDisposer disposer,
string path,
DateTimeOffset created,
int size,
string name) : Observable(provider, factory, mediator, publisher, subscriber, disposer),
IAttachmentEntryViewModel
{
[ObservableProperty]
private DateTimeOffset created = created;
[ObservableProperty]
private string path = path;
[ObservableProperty]
private int size = size;
[ObservableProperty]
private string name = name;
}