using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Threading.Tasks; using Avalonia.Threading; namespace Flawless.Client; public static class ObserverHelper { public static void SubscribeOnUIThread(this IObservable observer, Action onNext) { var dispatcher = Dispatcher.UIThread; observer.Subscribe(val => dispatcher.Invoke(() => onNext(val))); } public static void Sort(this ObservableCollection collection, Comparison comparison) { var sortableList = new List(collection); sortableList.Sort(comparison); for (int i = 0; i < sortableList.Count; i++) collection.Move(collection.IndexOf(sortableList[i]), i); } }