Container size scan, improvements

This commit is contained in:
2023-08-03 00:00:45 +02:00
parent 1713973c3a
commit f4d361f767
57 changed files with 814 additions and 532 deletions

View File

@@ -5,6 +5,8 @@ using DeclarativeProperty;
using DynamicData;
using FileTime.App.Core.Models.Enums;
using FileTime.App.Core.ViewModels.Timeline;
using FileTime.Core.Models;
using FileTime.Core.Models.ContainerTraits;
using MvvmGen;
using MoreLinq;
@@ -27,6 +29,8 @@ public abstract partial class AppStateBase : IAppState
public IDeclarativeProperty<ITabViewModel?> SelectedTab { get; private set; }
public DeclarativeProperty<string?> RapidTravelText { get; private set; }
public IDeclarativeProperty<string?> ContainerStatus { get; private set; }
partial void OnInitialize()
{
RapidTravelText = new("");
@@ -40,6 +44,12 @@ public abstract partial class AppStateBase : IAppState
);
Tabs = new ReadOnlyObservableCollection<ITabViewModel>(_tabs);
ContainerStatus = SelectedTab
.Map(t => t?.CurrentLocation)
.Switch()
.Map(c => c is IStatusProviderContainer statusProvider ? statusProvider.Status : null)
.Switch();
}
public void AddTab(ITabViewModel tabViewModel)

View File

@@ -1,20 +0,0 @@
using FileTime.App.Core.Models.Enums;
using FileTime.App.Core.Services;
using FileTime.Core.Models;
using MvvmGen;
namespace FileTime.App.Core.ViewModels;
[ViewModel(GenerateConstructor = false)]
public partial class ContainerSizeContainerViewModel : ItemViewModel, IContainerSizeContainerViewModel
{
[Property]
private long _size;
public ContainerSizeContainerViewModel(IItemNameConverterService itemNameConverterService, IAppState appState) : base(itemNameConverterService, appState)
{
}
public void Init(IContainer item, ITabViewModel parentTab, ItemViewModelType itemViewModelType)
=> Init((IItem)item, parentTab, itemViewModelType);
}

View File

@@ -1,3 +1,4 @@
using DeclarativeProperty;
using FileTime.App.Core.Models.Enums;
using FileTime.App.Core.Services;
using FileTime.Core.Models;
@@ -9,9 +10,6 @@ namespace FileTime.App.Core.ViewModels;
public partial class ElementViewModel : ItemViewModel, IElementViewModel
{
public IElement? Element => BaseItem as Element;
[Property]
private long? _size;
public ElementViewModel(IItemNameConverterService itemNameConverterService, IAppState appState) : base(itemNameConverterService, appState)
{
@@ -19,4 +17,6 @@ public partial class ElementViewModel : ItemViewModel, IElementViewModel
public void Init(IElement item, ITabViewModel parentTab, ItemViewModelType itemViewModelType)
=> Init((IItem)item, parentTab, itemViewModelType);
public IDeclarativeProperty<long> Size { get; protected set; } = new DeclarativeProperty<long>(0);
}

View File

@@ -1,3 +1,4 @@
using DeclarativeProperty;
using FileTime.App.Core.Models.Enums;
using FileTime.App.Core.Services;
using FileTime.Core.Models;
@@ -15,7 +16,7 @@ public partial class FileViewModel : ElementViewModel, IFileViewModel
public void Init(IElement item, FileExtension fileExtension, ITabViewModel parentTab, ItemViewModelType itemViewModelType)
{
Init((IElement)item, parentTab, itemViewModelType);
Size = fileExtension.Size;
Init(item, parentTab, itemViewModelType);
Size = new DeclarativeProperty<long>(fileExtension.Size ?? 0);
}
}

View File

@@ -1,3 +1,4 @@
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Reactive.Linq;
using DeclarativeProperty;
@@ -27,7 +28,7 @@ public abstract partial class ItemViewModel : IItemViewModel
[Property] private IDeclarativeProperty<bool>? _isMarked;
[Property] private IObservable<ItemViewMode> _viewMode;
[Property] private IDeclarativeProperty<ItemViewMode> _viewMode;
[Property] private DateTime? _createdAt;
@@ -38,8 +39,8 @@ public abstract partial class ItemViewModel : IItemViewModel
public IDeclarativeProperty<IReadOnlyList<ItemNamePart>>? DisplayName { get; private set; }
public void Init(
IItem item,
ITabViewModel parentTab,
IItem item,
ITabViewModel parentTab,
ItemViewModelType itemViewModelType)
{
_parentTab = parentTab;
@@ -55,7 +56,7 @@ public abstract partial class ItemViewModel : IItemViewModel
var displayName = itemViewModelType switch
{
ItemViewModelType.Main => _appState.RapidTravelText.Map(async (s, _) =>
_appState.ViewMode.Value != Models.Enums.ViewMode.RapidTravel
_appState.ViewMode.Value != Models.Enums.ViewMode.RapidTravel
&& _appState.SelectedTab.Value?.CurrentLocation.Value?.Provider is IItemNameConverterProvider nameConverterProvider
? (IReadOnlyList<ItemNamePart>) await nameConverterProvider.GetItemNamePartsAsync(item)
: _itemNameConverterService.GetDisplayName(item.DisplayName, s)
@@ -75,15 +76,23 @@ public abstract partial class ItemViewModel : IItemViewModel
? parentTab.CurrentSelectedItem.Map(EqualsTo)
: new DeclarativeProperty<bool>(IsInDeepestPath());
IsAlternative = sourceCollection.Map(c => c?.Index().FirstOrDefault(i => EqualsTo(i.Value)).Key % 2 == 0);
IsAlternative = sourceCollection
.Debounce(TimeSpan.FromMilliseconds(100))
.Map(c =>
c?.Index().FirstOrDefault(i => EqualsTo(i.Value)).Key % 2 == 1
);
ViewMode = Observable.CombineLatest(IsMarked, IsSelected, IsAlternative, GenerateViewMode).Throttle(TimeSpan.FromMilliseconds(10));
ViewMode = DeclarativePropertyHelpers
.CombineLatest(IsMarked, IsSelected, IsAlternative, GenerateViewMode)
.DistinctUntilChanged()
.Debounce(TimeSpan.FromMilliseconds(100));
Attributes = item.Attributes;
CreatedAt = item.CreatedAt;
}
private ItemViewMode GenerateViewMode(bool isMarked, bool isSelected, bool isAlternative)
=> (isMarked, isSelected, isAlternative) switch
private Task<ItemViewMode> GenerateViewMode(bool isMarked, bool isSelected, bool isAlternative)
{
var result = (isMarked, isSelected, isAlternative) switch
{
(true, true, _) => ItemViewMode.MarkedSelected,
(true, false, true) => ItemViewMode.MarkedAlternative,
@@ -93,12 +102,13 @@ public abstract partial class ItemViewModel : IItemViewModel
_ => ItemViewMode.Default
};
public bool EqualsTo(IItemViewModel? itemViewModel)
{
return BaseItem?.FullName?.Path is string path && path == itemViewModel?.BaseItem?.FullName?.Path;
return Task.FromResult(result);
}
public bool EqualsTo(IItemViewModel? itemViewModel)
=> BaseItem?.FullName?.Path is { } path && path == itemViewModel?.BaseItem?.FullName?.Path;
private bool IsInDeepestPath()
{
if (_parentTab?.Tab?.LastDeepestSelectedPath is null

View File

@@ -162,7 +162,7 @@ public partial class TabViewModel : ITabViewModel
.Selecting(i => MapItem(i))
.Ordering(i => i.Type)
.ThenOrdering(i => i.Name)
.Selecting(i => MapItemToViewModel(i, ItemViewModelType.SelectedChild));
.Selecting(i => MapItemToViewModel(i, ItemViewModelType.Parent));
return items;
});