1using CommunityToolkit.Mvvm.ComponentModel;
2using CommunityToolkit.Mvvm.Input;
8using System.Collections.ObjectModel;
22 public override async Task OnInitializeAsync()
24 await base.OnInitializeAsync();
31 MainThread.BeginInvokeOnMainThread(() =>
37 if (e.Tokens is not null)
39 foreach (Token Token in e.Tokens)
41 if (!EventsByCateogy.TryGetValue(Token.TokenId, out NotificationEvent[]? Events))
44 this.Tokens.Add(new TokenItem(Token, this.navigationArgs?.TokenItemProvider, Events));
47 this.HasTokens = true;
48 this.HasMoreTokens = e.Tokens.Length == Constants.BatchSizes.TokenBatchSize;
51 this.HasTokens =
false;
54 this.HasTokens =
false;
57 ServiceRef.XmppService.NeuroFeatureAdded += this.Wallet_TokenAdded;
58 ServiceRef.XmppService.NeuroFeatureRemoved += this.Wallet_TokenRemoved;
67 public override Task OnDisposeAsync()
69 ServiceRef.XmppService.NeuroFeatureAdded -= this.Wallet_TokenAdded;
70 ServiceRef.XmppService.NeuroFeatureRemoved -= this.Wallet_TokenRemoved;
72 if (this.navigationArgs?.TokenItemProvider is TaskCompletionSource<TokenItem?> TaskSource)
73 TaskSource.TrySetResult(
null);
75 return base.OnDisposeAsync();
83 MainThread.BeginInvokeOnMainThread(() =>
85 TokenItem Item =
new(e.
Token, this.navigationArgs?.TokenItemProvider, Events);
87 if (this.Tokens.Count == 0)
88 this.Tokens.Add(Item);
90 this.Tokens.Insert(0, Item);
93 return Task.CompletedTask;
98 MainThread.BeginInvokeOnMainThread(() =>
100 int i, c = this.Tokens.Count;
102 for (i = 0; i < c; i++)
108 this.Tokens.RemoveAt(i);
114 return Task.CompletedTask;
123 private bool hasTokens;
129 private bool hasMoreTokens;
134 public ObservableCollection<TokenItem> Tokens {
get; } = [];
144 return this.GoBack();
148 public override Task GoBack()
150 this.navigationArgs?.TokenItemProvider.TrySetResult(
null);
151 return base.GoBack();
158 private async Task LoadMoreTokens()
160 if (this.HasMoreTokens)
162 this.HasMoreTokens =
false;
169 MainThread.BeginInvokeOnMainThread(() =>
173 if (e.Tokens is not null)
175 foreach (Token Token in e.Tokens)
177 if (!EventsByCateogy.TryGetValue(Token.TokenId, out NotificationEvent[]? Events))
180 this.Tokens.Add(new TokenItem(Token, Events));
183 this.HasMoreTokens = e.Tokens.Length == Constants.BatchSizes.TokenBatchSize;
const int TokenBatchSize
Number of tokens to load in a single batch.
A set of never changing property constants and helpful values.
Base class that references services in the app.
static ILogService LogService
Log service.
static INotificationService NotificationService
Service for managing notifications for the user.
static IXmppService XmppService
The XMPP service for XMPP communication.
Holds navigation parameters for viewing tokens.
Encapsulates a Token object.
A view model that holds the XMPP state.
Event arguments for token events.
Event arguments for Tokens responses
bool Ok
If the response is an OK result response (true), or an error response (false).
bool TryGetNotificationEvents(NotificationEventType Type, CaseInsensitiveString Category, [NotNullWhen(true)] out NotificationEvent[]? Events)
Tries to get available notification events.
SortedDictionary< CaseInsensitiveString, NotificationEvent[]> GetEventsByCategory(NotificationEventType Type)
Gets available notification events for a button, sorted by category.
abstract class NotificationEvent()
Abstract base class of notification events.
NotificationEventType
Button on which event is to be displayed.
partial class MyTokensViewModel(MyTokensNavigationArgs? Args)
The view model to bind to for when displaying my tokens.