Skip to content
Merged
8 changes: 4 additions & 4 deletions src/Files.Shared/Extensions/LinqExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,25 +78,25 @@ public static void ForEach<T>(this IEnumerable<T> collection, Action<T> action)
action(value);
}

public static IList<T> AddSorted<T>(this IList<T> list, T item) where T : IComparable<T>
public static int AddSorted<T>(this IList<T> list, T item) where T : IComparable<T>
{
if (!list.Any() || list.Last().CompareTo(item) <= 0)
{
list.Add(item);
return list;
return list.Count;
}
if (list[0].CompareTo(item) >= 0)
{
list.Insert(0, item);
return list;
return 0;
}
int index = list.ToList().BinarySearch(item);
if (index < 0)
{
index = ~index;
}
list.Insert(index, item);
return list;
return index;
}

/// <summary>
Expand Down
3 changes: 3 additions & 0 deletions src/Files.Uwp/Controllers/SidebarPinnedController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@
using Windows.Storage;
using Windows.Storage.Search;
using Files.Shared.Extensions;
using System.Collections.Specialized;

namespace Files.Uwp.Controllers
{
public class SidebarPinnedController : IJson
{
public SidebarPinnedModel Model { get; set; }

public EventHandler<NotifyCollectionChangedEventArgs> DataChanged;

private StorageFileQueryResult query;

private bool suppressChangeEvent;
Expand Down
44 changes: 31 additions & 13 deletions src/Files.Uwp/DataModels/NavigationControlItems/DriveItem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using ByteSizeLib;
using Files.Shared;
using Files.Uwp.Extensions;
using Files.Uwp.Filesystem;
using Files.Uwp.Helpers;
Expand All @@ -18,8 +17,14 @@ namespace Files.Uwp.DataModels.NavigationControlItems
{
public class DriveItem : ObservableObject, INavigationControlItem
{
public BitmapImage Icon { get; set; }
public Uri IconSource { get; set; }
private BitmapImage icon;
public BitmapImage Icon
{
get => icon;
set => SetProperty(ref icon, value);
}

//public Uri IconSource { get; set; }
public byte[] IconData { get; set; }

private string path;
Expand Down Expand Up @@ -142,7 +147,11 @@ public static async Task<DriveItem> CreateFromPropertiesAsync(StorageFolder root
{
var item = new DriveItem();

await CoreApplication.MainView.DispatcherQueue.EnqueueAsync(async () => await item.SetBitmapImage(imageStream));
if (imageStream != null)
{
item.IconData = await imageStream.ToByteArrayAsync();
}

item.Text = root.DisplayName;
item.Type = type;
item.MenuOptions = new ContextMenuOptions
Expand All @@ -155,20 +164,12 @@ public static async Task<DriveItem> CreateFromPropertiesAsync(StorageFolder root
item.Path = string.IsNullOrEmpty(root.Path) ? $"\\\\?\\{root.Name}\\" : root.Path;
item.DeviceID = deviceId;
item.Root = root;

_ = CoreApplication.MainView.DispatcherQueue.EnqueueAsync(() => item.UpdatePropertiesAsync());

return item;
}

public async Task SetBitmapImage(IRandomAccessStream imageStream)
{
if (imageStream != null)
{
IconData = await imageStream.ToByteArrayAsync();
Icon = await IconData.ToBitmapAsync();
}
}

public async Task UpdateLabelAsync()
{
try
Expand Down Expand Up @@ -227,6 +228,23 @@ public int CompareTo(INavigationControlItem other)
}
return result;
}

public async Task LoadDriveIcon()
{
if (IconData == null)
{
if (!string.IsNullOrEmpty(DeviceID))
{
IconData = await FileThumbnailHelper.LoadIconWithoutOverlayAsync(DeviceID, 24);
}
if (IconData == null)
{
var resource = await UIHelpers.GetIconResourceInfo(Constants.ImageRes.Folder);
IconData = resource?.IconDataBytes;
}
}
Icon = await IconData.ToBitmapAsync();
}
}

public enum DriveType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public interface INavigationControlItem : IComparable<INavigationControlItem>

public enum NavigationControlItemType
{
Header,
Drive,
LinuxDistro,
Location,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using CommunityToolkit.Mvvm.ComponentModel;
using Microsoft.Toolkit.Uwp;
using System;
using System.Collections.ObjectModel;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
using Files.Uwp.Helpers;
Expand All @@ -20,7 +19,7 @@ public BitmapImage Icon
set => SetProperty(ref icon, value);
}

public Uri IconSource { get; set; }
//public Uri IconSource { get; set; }
public byte[] IconData { get; set; }

public string Text { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public string Path

public Uri Logo { get; set; }

public SectionType Section { get; private set; }
public SectionType Section { get; set; }

public ContextMenuOptions MenuOptions { get; set; }

Expand Down
Loading