GroupDetailPage uses navigation service

This commit is contained in:
Geoffroy BONNEVILLE
2020-04-21 13:33:15 +02:00
parent c81f8bc835
commit ac66faa9e2
5 changed files with 70 additions and 46 deletions

View File

@@ -5,7 +5,7 @@ using System.Collections.Specialized;
using System.Linq;
using System.Threading.Tasks;
using Windows.UI.Xaml.Controls;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Views;
using MediatR;
using Microsoft.Extensions.DependencyInjection;
using ModernKeePass.Application.Database.Commands.SaveDatabase;
@@ -25,9 +25,12 @@ using ModernKeePass.Application.Group.Commands.UpdateGroup;
using ModernKeePass.Application.Group.Models;
using ModernKeePass.Application.Group.Queries.GetGroup;
using ModernKeePass.Application.Group.Queries.SearchEntries;
using ModernKeePass.Common;
using ModernKeePass.Domain.AOP;
using ModernKeePass.Domain.Enums;
using ModernKeePass.Interfaces;
using ModernKeePass.Models;
using RelayCommand = GalaSoft.MvvmLight.Command.RelayCommand;
namespace ModernKeePass.ViewModels
{
@@ -77,25 +80,23 @@ namespace ModernKeePass.ViewModels
}
}
public bool IsRecycleOnDelete
{
get
{
var database = Database;
return database.IsRecycleBinEnabled && _parent != null && _parent.Id != database.RecycleBinId;
}
}
public bool IsRecycleOnDelete => Database.IsRecycleBinEnabled && !IsInRecycleBin;
public bool IsInRecycleBin => _parent != null && _parent.Id == Database.RecycleBinId;
public IEnumerable<GroupVm> BreadCrumb { get; }
public RelayCommand SaveCommand { get; }
public RelayCommand SortEntriesCommand { get; }
public RelayCommand SortGroupsCommand { get; }
public RelayCommand MoveCommand { get; }
public RelayCommand CreateEntryCommand { get; }
public RelayCommand CreateGroupCommand { get; }
private DatabaseVm Database => _mediator.Send(new GetDatabaseQuery()).GetAwaiter().GetResult();
private readonly IMediator _mediator;
private readonly INavigationService _navigation;
private readonly GroupVm _group;
private readonly GroupVm _parent;
private bool _isEditMode;
@@ -103,12 +104,13 @@ namespace ModernKeePass.ViewModels
public GroupDetailVm() {}
internal GroupDetailVm(string groupId) : this(groupId, App.Services.GetRequiredService<IMediator>())
internal GroupDetailVm(string groupId) : this(groupId, App.Services.GetRequiredService<IMediator>(), App.Services.GetRequiredService<INavigationService>())
{ }
public GroupDetailVm(string groupId, IMediator mediator)
public GroupDetailVm(string groupId, IMediator mediator, INavigationService navigation)
{
_mediator = mediator;
_navigation = navigation;
_group = _mediator.Send(new GetGroupQuery { Id = groupId }).GetAwaiter().GetResult();
if (!string.IsNullOrEmpty(_group.ParentGroupId))
{
@@ -120,20 +122,32 @@ namespace ModernKeePass.ViewModels
SortEntriesCommand = new RelayCommand(async () => await SortEntriesAsync(), () => IsEditMode);
SortGroupsCommand = new RelayCommand(async () => await SortGroupsAsync(), () => IsEditMode);
MoveCommand = new RelayCommand(async () => await Move(_parent), () => IsNotRoot);
CreateEntryCommand = new RelayCommand(async () => await AddNewEntry(), () => !IsInRecycleBin);
CreateGroupCommand = new RelayCommand(async () => await AddNewGroup(), () => !IsInRecycleBin);
Entries = new ObservableCollection<EntryVm>(_group.Entries);
Entries.CollectionChanged += Entries_CollectionChanged;
Groups = new ObservableCollection<GroupVm>(_group.SubGroups);
}
public async Task<string> AddNewGroup(string name = "")
public async Task AddNewGroup(string name = "")
{
return (await _mediator.Send(new CreateGroupCommand {Name = name, ParentGroup = _group})).Id;
var group = await _mediator.Send(new CreateGroupCommand {Name = name, ParentGroup = _group});
_navigation.NavigateTo(Constants.Navigation.GroupPage, new NavigationItem
{
Id = group.Id,
IsNew = true
});
}
public async Task<string> AddNewEntry()
public async Task AddNewEntry()
{
return (await _mediator.Send(new CreateEntryCommand { ParentGroup = _group })).Id;
var entry = await _mediator.Send(new CreateEntryCommand { ParentGroup = _group });
_navigation.NavigateTo(Constants.Navigation.EntryPage, new NavigationItem
{
Id = entry.Id,
IsNew = true
});
}
public async Task MarkForDelete(string recycleBinTitle)

View File

@@ -48,7 +48,14 @@
<ColumnDefinition Width="{StaticResource ExpandedMenuGridLength}" x:Name="LeftListViewColumn" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<userControls:HamburgerMenuUserControl x:Uid="GroupsLeftListView" ItemsSource="{Binding Groups}" SelectionChanged="groups_SelectionChanged" ButtonClicked="CreateGroup_ButtonClick" ResizeTarget="{Binding ElementName=LeftListViewColumn}" IsOpen="True" IsButtonVisible="Visible" />
<userControls:HamburgerMenuUserControl
x:Uid="GroupsLeftListView"
ItemsSource="{Binding Groups}"
SelectionChanged="groups_SelectionChanged"
ActionButtonCommand="{Binding CreateGroupCommand}"
ResizeTarget="{Binding ElementName=LeftListViewColumn}"
IsOpen="True"
IsButtonVisible="Visible" />
<Grid Grid.Column="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
@@ -61,7 +68,7 @@
</Grid.RowDefinitions>
<TextBlock Grid.Column="0" Grid.Row="0" x:Uid="ReorderEntriesLabel" Margin="10,10,0,0" Visibility="{Binding IsEditMode, Converter={StaticResource BooleanToVisibilityConverter}}" Style="{StaticResource BodyTextBlockStyle}" />
<!--<TextBlock Grid.Column="1" Grid.Row="0" x:Uid="EntrySymbol" Margin="40,20,0,0" Visibility="{Binding IsEditMode, Converter={StaticResource BooleanToVisibilityConverter}}" Style="{StaticResource BodyTextBlockStyle}" />-->
<HyperlinkButton Grid.Column="2" Grid.Row="0" VerticalAlignment="Top" Click="CreateEntry_ButtonClick" HorizontalAlignment="Right" Foreground="{StaticResource MainColor}" Style="{StaticResource MainColorHyperlinkButton}">
<HyperlinkButton Grid.Column="2" Grid.Row="0" VerticalAlignment="Top" Command="{Binding CreateEntryCommand}" HorizontalAlignment="Right" Foreground="{StaticResource MainColor}" Style="{StaticResource MainColorHyperlinkButton}">
<StackPanel Orientation="Horizontal">
<SymbolIcon Symbol="Add">
<ToolTipService.ToolTip>

View File

@@ -5,6 +5,7 @@ using Windows.Storage.Streams;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
using GalaSoft.MvvmLight.Views;
using Microsoft.Extensions.DependencyInjection;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Application.Entry.Models;
@@ -24,6 +25,7 @@ namespace ModernKeePass.Views
public sealed partial class GroupDetailPage
{
private readonly IResourceProxy _resource;
private readonly INavigationService _navigation;
/// <summary>
/// NavigationHelper is used on each page to aid in navigation and
@@ -32,11 +34,12 @@ namespace ModernKeePass.Views
public NavigationHelper NavigationHelper { get; }
public GroupDetailVm Model => (GroupDetailVm)DataContext;
public GroupDetailPage(): this (App.Services.GetRequiredService<IResourceProxy>()) { }
public GroupDetailPage(IResourceProxy resource)
public GroupDetailPage(): this (App.Services.GetRequiredService<IResourceProxy>(), App.Services.GetRequiredService<INavigationService>()) { }
public GroupDetailPage(IResourceProxy resource, INavigationService navigation)
{
InitializeComponent();
_resource = resource;
_navigation = navigation;
NavigationHelper = new NavigationHelper(this);
}
@@ -84,7 +87,7 @@ namespace ModernKeePass.Views
return;
default:
var group = listView?.SelectedItem as Application.Group.Models.GroupVm;
Frame.Navigate(typeof(GroupDetailPage), new NavigationItem { Id = group?.Id });
_navigation.NavigateTo(Constants.Navigation.GroupPage, new NavigationItem { Id = group?.Id });
break;
}
}
@@ -97,7 +100,7 @@ namespace ModernKeePass.Views
return;
default:
var entry = GridView.SelectedItem as EntryVm;
Frame.Navigate(typeof(EntryDetailPage), new NavigationItem { Id = entry?.Id });
_navigation.NavigateTo(Constants.Navigation.EntryPage, new NavigationItem { Id = entry?.Id });
break;
}
}
@@ -110,22 +113,6 @@ namespace ModernKeePass.Views
e.DestinationItem.Item = e.SourceItem.Item;
}
}
private async void CreateEntry_ButtonClick(object sender, RoutedEventArgs e)
{
Frame.Navigate(typeof(EntryDetailPage), new NavigationItem
{
Id = await Model.AddNewEntry(),
IsNew = true
});
}
private async void CreateGroup_ButtonClick(object sender, RoutedEventArgs e)
{
Frame.Navigate(typeof(GroupDetailPage), new NavigationItem
{
Id = await Model.AddNewGroup(),
IsNew = true
});
}
private void GridView_DragItemsStarting(object sender, DragItemsStartingEventArgs e)
{
@@ -145,7 +132,7 @@ namespace ModernKeePass.Views
private void SearchBox_OnResultSuggestionChosen(SearchBox sender, SearchBoxResultSuggestionChosenEventArgs args)
{
Frame.Navigate(typeof(EntryDetailPage), new NavigationItem { Id = args.Tag });
_navigation.NavigateTo(Constants.Navigation.EntryPage, new NavigationItem { Id = args.Tag });
}
private void GroupDetailPage_OnSizeChanged(object sender, SizeChangedEventArgs e)

View File

@@ -72,7 +72,15 @@
<DataTemplate>
<StackPanel Orientation="Vertical">
<Border BorderBrush="White" BorderThickness="0,0,0,1" />
<Button Padding="0" Height="{StaticResource MenuSize}" Margin="0" Visibility="{Binding IsButtonVisible, ElementName=UserControl}" Style="{StaticResource NoBorderButtonStyle}" Background="Transparent" BorderThickness="0" Width="{StaticResource ExpandedMenuSize}" HorizontalContentAlignment="Left" Click="ButtonBase_OnClick">
<Button Padding="0" Margin="0"
Height="{StaticResource MenuSize}"
Visibility="{Binding IsButtonVisible, ElementName=UserControl}"
Style="{StaticResource NoBorderButtonStyle}"
Background="Transparent"
BorderThickness="0"
Width="{StaticResource ExpandedMenuSize}"
HorizontalContentAlignment="Left"
Command="{Binding ActionButtonCommand, ElementName=UserControl}">
<StackPanel Orientation="Horizontal" Margin="17,0,5,0">
<SymbolIcon Symbol="Add">
<ToolTipService.ToolTip>

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using GalaSoft.MvvmLight.Command;
using ModernKeePass.Application.Common.Interfaces;
// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236
@@ -124,16 +125,23 @@ namespace ModernKeePass.Views.UserControls
typeof(HamburgerMenuUserControl),
new PropertyMetadata(false, (o, args) => { }));
public RelayCommand ActionButtonCommand
{
get { return (RelayCommand)GetValue(ActionButtonCommandProperty); }
set { SetValue(ActionButtonCommandProperty, value); }
}
public static readonly DependencyProperty ActionButtonCommandProperty =
DependencyProperty.Register(
nameof(ActionButtonCommand),
typeof(RelayCommand),
typeof(HamburgerMenuUserControl),
new PropertyMetadata(null, (o, args) => { }));
public event EventHandler<SelectionChangedEventArgs> SelectionChanged;
private void Selector_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
SelectionChanged?.Invoke(sender, e);
}
public event EventHandler<RoutedEventArgs> ButtonClicked;
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
ButtonClicked?.Invoke(sender, e);
}
}
}