using XFEEDToolBox.Core.Navigation;
namespace XFEEDToolBox.Core.Presentation;
public static class SystemLocationUpdates
{
public static ListDelta ApplyLocations(this LiveCollection<SystemLocationLiveRow,SystemLocation,string> rows,IReadOnlyList<SystemLocation> sorted,bool sortExisting=false)
{
if(sortExisting||rows.Count==0)return rows.Apply(sorted);
var incoming=sorted.ToDictionary(x=>x.Identity,StringComparer.Ordinal);
// Distances and selection bind to the existing row. Automatic samples
// do not reshuffle surviving items underneath the user's scroll/click.
var ordered=rows.Where(x=>incoming.ContainsKey(x.Record.Identity)).Select(x=>incoming[x.Record.Identity]).ToList();
var kept=ordered.Select(x=>x.Identity).ToHashSet(StringComparer.Ordinal);
foreach(var added in sorted.Where(x=>!kept.Contains(x.Identity)))
{
var position=ordered.FindIndex(x=>(x.DistanceMetres??double.MaxValue)>(added.DistanceMetres??double.MaxValue));
if(position<0)ordered.Add(added);else ordered.Insert(position,added);
}
return rows.Apply(ordered);
}
}
using XFEEDToolBox.Core.Navigation;
namespace XFEEDToolBox.Core.Presentation;
public static class SystemLocationUpdates
{
public static ListDelta ApplyLocations(this LiveCollection<SystemLocationLiveRow,SystemLocation,string> rows,IReadOnlyList<SystemLocation> sorted,bool sortExisting=false)
{
if(sortExisting||rows.Count==0)return rows.Apply(sorted);
var incoming=sorted.ToDictionary(x=>x.Identity,StringComparer.Ordinal);
// Distances and selection bind to the existing row. Automatic samples
// do not reshuffle surviving items underneath the user's scroll/click.
var ordered=rows.Where(x=>incoming.ContainsKey(x.Record.Identity)).Select(x=>incoming[x.Record.Identity]).ToList();
var kept=ordered.Select(x=>x.Identity).ToHashSet(StringComparer.Ordinal);
foreach(var added in sorted.Where(x=>!kept.Contains(x.Identity)))
{
var position=ordered.FindIndex(x=>(x.DistanceMetres??double.MaxValue)>(added.DistanceMetres??double.MaxValue));
if(position<0)ordered.Add(added);else ordered.Insert(position,added);
}
return rows.Apply(ordered);
}
}