File attachment UI work
This commit is contained in:
@@ -192,6 +192,8 @@ public partial class App : Application
|
|||||||
services.AddTemplate<CommentEntryCollectionViewModel, CommentEntryCollectionView>();
|
services.AddTemplate<CommentEntryCollectionViewModel, CommentEntryCollectionView>();
|
||||||
|
|
||||||
services.AddTemplate<AttachmentEntryCollectionViewModel, AttachmentEntryCollectionView>();
|
services.AddTemplate<AttachmentEntryCollectionViewModel, AttachmentEntryCollectionView>();
|
||||||
|
services.AddTemplate<AttachmentEntryViewModel, AttachmentEntryView>();
|
||||||
|
services.AddTemplate<LocalAttachmentEntryViewModel, AttachmentEntryView>();
|
||||||
|
|
||||||
services.AddTemplate<TextEntryViewModel, TextEntryView>();
|
services.AddTemplate<TextEntryViewModel, TextEntryView>();
|
||||||
services.AddTemplate<PasswordEntryViewModel, PasswordEntryView>();
|
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();
|
||||||
|
}
|
||||||
@@ -4,5 +4,5 @@
|
|||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:vm="using:Wallet"
|
xmlns:vm="using:Wallet"
|
||||||
x:DataType="vm:CommentEntryViewModel"
|
x:DataType="vm:CommentEntryViewModel"
|
||||||
Content="{Binding Value}"
|
Content="{Binding Comment}"
|
||||||
Description="{Binding Key}" />
|
Description="{Binding Created}" />
|
||||||
|
|||||||
@@ -9,14 +9,17 @@ public partial class AttachmentEntryCollectionViewModel(IServiceProvider provide
|
|||||||
IPublisher publisher,
|
IPublisher publisher,
|
||||||
ISubscriber subscriber,
|
ISubscriber subscriber,
|
||||||
IDisposer disposer,
|
IDisposer disposer,
|
||||||
|
IContentTemplate template,
|
||||||
ItemState state,
|
ItemState state,
|
||||||
IItemEntryConfiguration<ICollection<Attachment>> configuration,
|
IItemEntryConfiguration<ICollection<Attachment>> configuration,
|
||||||
string key,
|
string key,
|
||||||
ICollection<Attachment> value,
|
ICollection<Attachment> value,
|
||||||
bool isConcealed,
|
bool isConcealed,
|
||||||
bool isRevealed,
|
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]
|
[RelayCommand]
|
||||||
private async Task Invoke()
|
private async Task Invoke()
|
||||||
{
|
{
|
||||||
@@ -25,14 +28,19 @@ public partial class AttachmentEntryCollectionViewModel(IServiceProvider provide
|
|||||||
{
|
{
|
||||||
foreach (IFileDescriptor file in fileDescriptors)
|
foreach (IFileDescriptor file in fileDescriptors)
|
||||||
{
|
{
|
||||||
|
string path = file.Path;
|
||||||
|
DateTimeOffset created = DateTimeOffset.Now;
|
||||||
|
string name = file.Name;
|
||||||
|
int size = file.Size;
|
||||||
|
|
||||||
Attachment attachment = new()
|
Attachment attachment = new()
|
||||||
{
|
{
|
||||||
Name = file.Name,
|
Name = name,
|
||||||
Path = file.Path,
|
Path = path,
|
||||||
DateTime = DateTimeOffset.Now
|
DateTime = created
|
||||||
};
|
};
|
||||||
|
|
||||||
Add<AttachmentEntryViewModel>(attachment);
|
Add<LocalAttachmentEntryViewModel>(path, created, size, name);
|
||||||
Value.Add(attachment);
|
Value.Add(attachment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Toolkit.Foundation;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
using Toolkit.Foundation;
|
||||||
|
|
||||||
namespace Wallet;
|
namespace Wallet;
|
||||||
|
|
||||||
@@ -8,4 +9,21 @@ public partial class AttachmentEntryViewModel(IServiceProvider provider,
|
|||||||
IPublisher publisher,
|
IPublisher publisher,
|
||||||
ISubscriber subscriber,
|
ISubscriber subscriber,
|
||||||
IDisposer disposer,
|
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
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
public record Comment
|
public record Comment
|
||||||
{
|
{
|
||||||
public DateTimeOffset DateTime { get; set; }
|
public DateTimeOffset Created { get; set; }
|
||||||
|
|
||||||
public string? Text { get; set; }
|
public string? Text { get; set; }
|
||||||
}
|
}
|
||||||
@@ -30,7 +30,7 @@ public partial class CommentEntryCollectionViewModel : ItemEntryCollectionViewMo
|
|||||||
{
|
{
|
||||||
if (args.Sender is Comment comment)
|
if (args.Sender is Comment comment)
|
||||||
{
|
{
|
||||||
Insert<CommentEntryViewModel>(0, comment.DateTime, comment.Text);
|
Insert<CommentEntryViewModel>(0, comment.Created, comment.Text);
|
||||||
Value.Add(comment);
|
Value.Add(comment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,9 +18,9 @@ public class CommentEntryCollectionViewModelHandler(IServiceFactory serviceFacto
|
|||||||
[.. args.Parameters, configuration, label, values, false, false, width])
|
[.. args.Parameters, configuration, label, values, false, false, width])
|
||||||
is CommentEntryCollectionViewModel viewModel)
|
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);
|
return Task.FromResult<IItemEntryViewModel?>(viewModel);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Toolkit.Foundation;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
using Toolkit.Foundation;
|
||||||
|
|
||||||
namespace Wallet;
|
namespace Wallet;
|
||||||
|
|
||||||
@@ -8,6 +9,13 @@ public partial class CommentEntryViewModel(IServiceProvider provider,
|
|||||||
IPublisher publisher,
|
IPublisher publisher,
|
||||||
ISubscriber subscriber,
|
ISubscriber subscriber,
|
||||||
IDisposer disposer,
|
IDisposer disposer,
|
||||||
DateTimeOffset key,
|
DateTimeOffset created,
|
||||||
string? value = default) : Observable<DateTimeOffset, string>(provider, factory, mediator, publisher, subscriber, disposer, key, value),
|
string comment) : Observable(provider, factory, mediator, publisher, subscriber, disposer),
|
||||||
ICommentEntryViewModel;
|
ICommentEntryViewModel
|
||||||
|
{
|
||||||
|
[ObservableProperty]
|
||||||
|
private DateTimeOffset created = created;
|
||||||
|
|
||||||
|
[ObservableProperty]
|
||||||
|
private string comment = comment;
|
||||||
|
}
|
||||||
@@ -14,7 +14,7 @@ public partial class CreateCommentEntryViewModel(IServiceProvider provider,
|
|||||||
[RelayCommand]
|
[RelayCommand]
|
||||||
private void Invoke()
|
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;
|
Value = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
namespace Wallet;
|
||||||
|
|
||||||
|
public interface IAttachmentEntryViewModel :
|
||||||
|
IDisposable;
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user