-
-
Notifications
You must be signed in to change notification settings - Fork 679
Expand file tree
/
Copy pathRemoveFolderViewModel.cs
More file actions
91 lines (77 loc) · 2.73 KB
/
Copy pathRemoveFolderViewModel.cs
File metadata and controls
91 lines (77 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//
// Copyright (c) Fela Ameghino 2015-2026
//
// Distributed under the GNU General Public License v3.0. (See accompanying
// file LICENSE or copy at https://www.gnu.org/licenses/gpl-3.0.txt)
//
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Threading.Tasks;
using Telegram.Collections;
using Telegram.Navigation;
using Telegram.Navigation.Services;
using Telegram.Services;
using Telegram.Td.Api;
using Windows.UI.Xaml.Navigation;
namespace Telegram.ViewModels.Folders
{
public partial class RemoveFolderViewModel : ViewModelBase
{
public RemoveFolderViewModel(IClientService clientService, ISettingsService settingsService, IEventAggregator aggregator)
: base(clientService, settingsService, aggregator)
{
SelectedItems.CollectionChanged += OnCollectionChanged;
}
private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
RaisePropertyChanged(nameof(SelectedCount));
RaisePropertyChanged(nameof(PrimaryButtonText));
}
protected override Task OnNavigatedToAsync(object parameter, NavigationMode mode, NavigationState state)
{
if (parameter is Tuple<ChatFolder, Td.Api.Chats> tuple)
{
Items.ReplaceWith(ClientService.GetChats(tuple.Item1.IncludedChatIds));
foreach (var item in Items)
{
if (tuple.Item2.ChatIds.Contains(item.Id))
{
SelectedItems.Add(item);
}
}
}
return Task.CompletedTask;
}
public RangeObservableCollection<Chat> Items { get; private set; } = new();
public RangeObservableCollection<Chat> SelectedItems { get; private set; } = new();
public string PrimaryButtonText => SelectedItems.Count > 0
? Strings.FolderLinkButtonRemoveChats
: Strings.FolderLinkButtonRemove;
public int TotalCount => Items.Count;
public int SelectedCount => SelectedItems.Count;
public void SelectAll()
{
if (SelectedItems.Count >= TotalCount)
{
SelectedItems.Clear();
}
else
{
List<Chat> temp = null;
foreach (var chat in Items)
{
if (!SelectedItems.Contains(chat))
{
temp ??= new();
temp.Add(chat);
}
}
if (temp != null)
{
SelectedItems.AddRange(temp);
}
}
}
}
}