[Hosts]Big hosts file loading fix and feedback (#24091)

This commit is contained in:
Davide Giacometti 2023-02-22 17:19:01 +01:00 committed by GitHub
parent a2e05b771b
commit c819b287f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 3 deletions

View File

@ -52,6 +52,9 @@ namespace Hosts.ViewModels
[ObservableProperty]
private string _additionalLines;
[ObservableProperty]
private bool _isLoading;
private ObservableCollection<Entry> _entries;
public ObservableCollection<Entry> Entries => _filtered || _showOnlyDuplicates ? GetFilteredEntries() : _entries;
@ -125,6 +128,7 @@ namespace Hosts.ViewModels
public void ReadHosts()
{
FileChanged = false;
IsLoading = true;
Task.Run(async () =>
{
@ -141,8 +145,10 @@ namespace Hosts.ViewModels
_entries.CollectionChanged += Entries_CollectionChanged;
OnPropertyChanged(nameof(Entries));
FindDuplicates();
IsLoading = false;
});
FindDuplicates();
});
}
@ -243,10 +249,12 @@ namespace Hosts.ViewModels
{
var hosts = entry.SplittedHosts;
entry.Duplicate = _entries.FirstOrDefault(e =>
var duplicate = _entries.FirstOrDefault(e =>
e != entry
&& (string.Equals(e.Address, entry.Address, StringComparison.InvariantCultureIgnoreCase)
|| hosts.Intersect(e.SplittedHosts, StringComparer.InvariantCultureIgnoreCase).Any())) != null;
_dispatcherQueue.TryEnqueue(DispatcherQueuePriority.Low, () => entry.Duplicate = duplicate);
}
private ObservableCollection<Entry> GetFilteredEntries()

View File

@ -26,6 +26,10 @@
NotEmptyValue="Visible" />
<converters:BoolNegationConverter x:Key="BoolNegationConverter" />
<converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
<converters:BoolToVisibilityConverter
x:Key="BoolToInvertedVisibilityConverter"
TrueValue="Collapsed"
FalseValue="Visible" />
</Page.Resources>
<Grid>
@ -194,7 +198,8 @@
IsItemClickEnabled="True"
ItemClick="Entries_ItemClick"
ItemsSource="{Binding Entries, Mode=TwoWay}"
SelectedItem="{Binding Selected, Mode=TwoWay}">
SelectedItem="{Binding Selected, Mode=TwoWay}"
Visibility="{x:Bind ViewModel.IsLoading, Converter={StaticResource BoolToInvertedVisibilityConverter}, Mode=OneWay}">
<ListView.ItemTemplate>
<DataTemplate x:DataType="models:Entry">
<Grid
@ -333,6 +338,12 @@
</ListView.ItemTemplate>
</ListView>
<ProgressRing
Width="48"
Height="48"
Grid.Row="1"
IsActive="{x:Bind ViewModel.IsLoading, Mode=OneWay}" />
<ContentDialog
x:Name="EntryDialog"
x:Uid="EntryDialog"