1using System.Collections.ObjectModel;
2using CommunityToolkit.Mvvm.ComponentModel;
3using CommunityToolkit.Mvvm.Input;
9using Microsoft.Maui.Graphics;
22 private DateTime? lastLoadedOldestTimestamp;
23 private string? currency;
28 private readonly List<TransactionEventItem> allEvents =
new();
35 this.Events =
new ObservableCollection<TransactionEventItem>();
41 public ObservableCollection<TransactionEventItem>
Events {
get; }
44 private bool isLoading;
50 private string? searchText;
52 partial
void OnSearchTextChanged(
string? value)
60 await base.OnInitializeAsync();
61 ServiceRef.XmppService.EDalerBalanceUpdated += this.Wallet_BalanceUpdated;
62 await this.LoadInitialAsync();
68 ServiceRef.XmppService.EDalerBalanceUpdated -= this.Wallet_BalanceUpdated;
69 await base.OnDisposeAsync();
72 private async Task EnsureCurrencyAsync()
74 if (!
string.IsNullOrEmpty(this.currency))
85 this.currency =
string.Empty;
89 private async Task LoadInitialAsync()
94 this.IsLoading =
true;
97 await this.EnsureCurrencyAsync();
99 this.allEvents.Clear();
100 this.lastLoadedOldestTimestamp =
null;
104 await this.AddEventsAsync(
Events);
113 this.IsLoading =
false;
117 private async Task AddEventsAsync(AccountEventModel[] eventsBatch)
119 if (eventsBatch is
null || eventsBatch.Length == 0)
122 Dictionary<string, string> FriendlyNames =
new();
123 string CurrencyLocal = this.currency ??
string.Empty;
126 foreach (AccountEventModel Evt
in eventsBatch)
129 string Remote = Evt.Remote;
130 if (!FriendlyNames.TryGetValue(Remote, out
string? Friendly))
134 string[] FriendlyParts = Friendly.Split(
"@");
138 Friendly = FriendlyParts[0];
139 FriendlyNames[Remote] = Friendly;
146 this.allEvents.Add(Item);
148 if (!this.lastLoadedOldestTimestamp.HasValue || Evt.Timestamp <
this.lastLoadedOldestTimestamp.Value)
149 this.lastLoadedOldestTimestamp = Evt.Timestamp;
153 private void ApplyFilter()
155 string? Filter = this.SearchText;
156 IEnumerable<TransactionEventItem> Query = this.allEvents;
158 if (!
string.IsNullOrWhiteSpace(Filter))
160 string FilterLower = Filter.Trim().ToLowerInvariant();
161 Query = Query.Where(e => (e.FriendlyName ??
string.Empty).ToLowerInvariant().Contains(FilterLower));
165 List<TransactionEventItem> NewItems = Query.ToList();
173 private async Task Refresh()
175 await this.LoadInitialAsync();
179 private async Task LoadMore()
181 if (this.IsLoading || !this.HasMore || !this.lastLoadedOldestTimestamp.HasValue)
184 this.IsLoading =
true;
188 await this.AddEventsAsync(
Events);
198 this.IsLoading =
false;
205 private async Task Wallet_BalanceUpdated(
object? sender,
BalanceEventArgs e)
209 await this.EnsureCurrencyAsync();
214 string Remote = Evt.
Remote;
216 string[] FriendlyParts = Friendly.Split(
'@');
217 Friendly = FriendlyParts[0];
219 string CurrencyLocal = this.currency ??
string.Empty;
223 this.allEvents.Insert(0, Item);
225 bool passesFilter =
true;
226 if (!
string.IsNullOrWhiteSpace(this.SearchText))
228 string filterLower = this.SearchText.Trim().ToLowerInvariant();
229 passesFilter = (Item.FriendlyName ??
string.Empty).ToLowerInvariant().Contains(filterLower);
232 MainThread.BeginInvokeOnMainThread(() =>
236 this.
Events.Insert(0, Item);
239 if (!this.lastLoadedOldestTimestamp.HasValue || Evt.Timestamp <
this.lastLoadedOldestTimestamp.Value)
240 this.lastLoadedOldestTimestamp = Evt.Timestamp;
CaseInsensitiveString Remote
Remote party
Contains information about a balance.
CaseInsensitiveString Currency
Currency of amount.
AccountEvent Event
Any account event associated to the balance message.
Wallet balance event arguments.
const int AccountEventBatchSize
Number of account events to load in a single batch.
static readonly TimeSpan XmppConnect
XMPP Connect timeout
A set of never changing property constants and helpful values.
A strongly-typed resource class, for looking up localized strings, etc.
static string Transfer
Looks up a localized string similar to Transfer.
Base class that references services in the app.
static ILogService LogService
Log service.
static IReportingStringLocalizer Localizer
Localization service
static IXmppService XmppService
The XMPP service for XMPP communication.
virtual async Task GoBack()
Method called when user wants to navigate to the previous screen.
View model for the Transaction History page. Loads and pages through eDaler account events.
TransactionHistoryViewModel()
Creates a new instance of the TransactionHistoryViewModel class.
ObservableCollection< TransactionEventItem > Events
Collection of transaction events (filtered).
override async Task OnInitializeAsync()
Method called when view is initialized for the first time. Use this method to implement registration ...
override async Task OnDisposeAsync()
Method called when the view is disposed, and will not be used more. Use this method to unregister eve...
A view model that holds the XMPP state.
partial class TransactionEventItem(AccountEventModel accountEvent, string friendlyName, string currency, string? transactionType)
Presentation model for a transaction event in history (no notification support).