2017-12-01 17:59:38 +01:00
|
|
|
|
using System.Collections.ObjectModel;
|
2020-04-06 20:20:45 +02:00
|
|
|
|
using System.Linq;
|
2018-06-20 18:41:56 +02:00
|
|
|
|
using System.Windows.Input;
|
2020-04-21 13:07:17 +02:00
|
|
|
|
using GalaSoft.MvvmLight.Command;
|
2020-04-06 20:20:45 +02:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using ModernKeePass.Application.Common.Interfaces;
|
|
|
|
|
using ModernKeePass.Domain.AOP;
|
2020-03-30 19:43:04 +02:00
|
|
|
|
using ModernKeePass.Domain.Interfaces;
|
2020-04-20 20:02:43 +02:00
|
|
|
|
using ModernKeePass.ViewModels.ListItems;
|
2017-09-29 17:23:35 -04:00
|
|
|
|
|
|
|
|
|
namespace ModernKeePass.ViewModels
|
|
|
|
|
{
|
2017-11-07 18:45:35 +01:00
|
|
|
|
public class RecentVm : NotifyPropertyChangedBase, IHasSelectableObject
|
2017-09-29 17:23:35 -04:00
|
|
|
|
{
|
2020-04-06 20:20:45 +02:00
|
|
|
|
private readonly IRecentProxy _recent;
|
2017-11-07 18:45:35 +01:00
|
|
|
|
private ISelectableModel _selectedItem;
|
2020-04-06 20:20:45 +02:00
|
|
|
|
private ObservableCollection<RecentItemVm> _recentItems;
|
2017-10-16 16:16:58 +02:00
|
|
|
|
|
2020-04-06 20:20:45 +02:00
|
|
|
|
public ObservableCollection<RecentItemVm> RecentItems
|
2017-10-03 16:06:49 +02:00
|
|
|
|
{
|
|
|
|
|
get { return _recentItems; }
|
|
|
|
|
set { SetProperty(ref _recentItems, value); }
|
|
|
|
|
}
|
2017-09-29 17:23:35 -04:00
|
|
|
|
|
2017-11-07 18:45:35 +01:00
|
|
|
|
public ISelectableModel SelectedItem
|
2017-09-29 17:23:35 -04:00
|
|
|
|
{
|
2017-10-03 16:06:49 +02:00
|
|
|
|
get { return _selectedItem; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (_selectedItem == value) return;
|
|
|
|
|
if (_selectedItem != null)
|
|
|
|
|
{
|
|
|
|
|
_selectedItem.IsSelected = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SetProperty(ref _selectedItem, value);
|
2017-10-12 10:36:58 +02:00
|
|
|
|
|
|
|
|
|
if (_selectedItem == null) return;
|
|
|
|
|
_selectedItem.IsSelected = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-06-20 18:41:56 +02:00
|
|
|
|
|
|
|
|
|
public ICommand ClearAllCommand { get; }
|
2017-10-03 16:06:49 +02:00
|
|
|
|
|
2020-04-21 17:13:39 +02:00
|
|
|
|
public RecentVm() : this (App.Services.GetRequiredService<IRecentProxy>()) { }
|
2017-12-01 17:59:38 +01:00
|
|
|
|
|
2020-04-06 20:20:45 +02:00
|
|
|
|
public RecentVm(IRecentProxy recent)
|
2017-10-12 10:36:58 +02:00
|
|
|
|
{
|
2017-12-04 10:46:01 +01:00
|
|
|
|
_recent = recent;
|
2018-06-20 18:41:56 +02:00
|
|
|
|
ClearAllCommand = new RelayCommand(ClearAll);
|
2020-04-09 19:43:06 +02:00
|
|
|
|
|
|
|
|
|
var recentItems = _recent.GetAll().Select(r => new RecentItemVm(r));
|
2020-04-08 20:02:13 +02:00
|
|
|
|
RecentItems = new ObservableCollection<RecentItemVm>(recentItems);
|
2017-10-11 14:30:07 +02:00
|
|
|
|
if (RecentItems.Count > 0)
|
2020-04-07 12:48:18 +02:00
|
|
|
|
SelectedItem = RecentItems[0];
|
2017-10-11 14:30:07 +02:00
|
|
|
|
}
|
2020-04-21 17:13:39 +02:00
|
|
|
|
|
|
|
|
|
public void UpdateAccessTime(string token)
|
|
|
|
|
{
|
|
|
|
|
_recent.Get(token, true).Wait();
|
|
|
|
|
}
|
2017-10-11 14:30:07 +02:00
|
|
|
|
|
2018-06-20 18:41:56 +02:00
|
|
|
|
private void ClearAll()
|
2017-12-04 10:46:01 +01:00
|
|
|
|
{
|
|
|
|
|
_recent.ClearAll();
|
|
|
|
|
RecentItems.Clear();
|
|
|
|
|
}
|
2017-09-29 17:23:35 -04:00
|
|
|
|
}
|
|
|
|
|
}
|