mirror of
https://github.com/rmcrackan/Libation.git
synced 2025-12-23 22:17:52 -05:00
Improve ScanAccountsDialog usability
This commit is contained in:
@@ -1,15 +1,23 @@
|
||||
<Window xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="200"
|
||||
x:Class="LibationAvalonia.Dialogs.ScanAccountsDialog"
|
||||
MinWidth="500" MinHeight="160"
|
||||
Width="500" Height="200"
|
||||
Title="Which Accounts?"
|
||||
WindowStartupLocation="CenterOwner">
|
||||
<Window
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d"
|
||||
d:DesignWidth="500" d:DesignHeight="340"
|
||||
MinWidth="200" MinHeight="210"
|
||||
Width="500" Height="500"
|
||||
x:Class="LibationAvalonia.Dialogs.ScanAccountsDialog"
|
||||
xmlns:dialogs="clr-namespace:LibationAvalonia.Dialogs"
|
||||
x:DataType="dialogs:ScanAccountsDialog"
|
||||
x:CompileBindings="True"
|
||||
Title="Which Accounts?"
|
||||
WindowStartupLocation="CenterOwner">
|
||||
|
||||
<Grid ColumnDefinitions="*,Auto" RowDefinitions="Auto,*,Auto">
|
||||
<Grid
|
||||
ColumnDefinitions="*,Auto"
|
||||
RowDefinitions="Auto,*,Auto"
|
||||
Margin="10">
|
||||
|
||||
<Grid.Styles>
|
||||
<Style Selector="Button:focus">
|
||||
@@ -22,54 +30,38 @@
|
||||
Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
Grid.ColumnSpan="2"
|
||||
Margin="10"
|
||||
Text="Check the accounts to scan and import.
To change default selections, go to: Settings > Accounts"/>
|
||||
|
||||
<ScrollViewer
|
||||
<DockPanel
|
||||
Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Grid.ColumnSpan="2"
|
||||
Margin="10,0"
|
||||
VerticalAlignment="Stretch"
|
||||
HorizontalScrollBarVisibility="Disabled"
|
||||
VerticalScrollBarVisibility="Auto">
|
||||
Margin="0,10"
|
||||
VerticalAlignment="Stretch">
|
||||
|
||||
<ListBox ItemsSource="{Binding Accounts}">
|
||||
<ListBox Name="lbAccounts" ItemsSource="{Binding Accounts}">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
|
||||
<StackPanel Height="20" Orientation="Horizontal">
|
||||
|
||||
<CheckBox
|
||||
Margin="0,0,10,0"
|
||||
IsChecked="{Binding IsChecked, Mode=TwoWay}" />
|
||||
<TextBlock
|
||||
FontSize="12"
|
||||
VerticalAlignment="Center"
|
||||
Text="{Binding Text}" />
|
||||
|
||||
</StackPanel>
|
||||
|
||||
<CheckBox
|
||||
IsChecked="{Binding IsChecked, Mode=TwoWay}">
|
||||
<TextBlock Text="{Binding Text}" />
|
||||
</CheckBox>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
|
||||
</ListBox>
|
||||
|
||||
</ScrollViewer>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
</DockPanel>
|
||||
|
||||
<Button
|
||||
Grid.Row="2"
|
||||
Grid.Column="0"
|
||||
Padding="20,5"
|
||||
Margin="10"
|
||||
Padding="20,6"
|
||||
Content="Edit Accounts"
|
||||
Command="{Binding EditAccountsAsync}"/>
|
||||
|
||||
<Button
|
||||
Grid.Row="2"
|
||||
Grid.Column="1"
|
||||
Padding="30,5"
|
||||
Margin="10"
|
||||
Padding="30,6"
|
||||
HorizontalAlignment="Right"
|
||||
Content="Import"
|
||||
Name="ImportButton"
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using AudibleUtilities;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Collections;
|
||||
using LibationUiBase.Forms;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
@@ -10,41 +9,36 @@ namespace LibationAvalonia.Dialogs
|
||||
{
|
||||
public partial class ScanAccountsDialog : DialogWindow
|
||||
{
|
||||
public List<Account> CheckedAccounts { get; } = new();
|
||||
private List<listItem> _accounts { get; } = new();
|
||||
public IList Accounts => _accounts;
|
||||
private class listItem
|
||||
public IEnumerable<Account> CheckedAccounts => Accounts.Where(a => a.IsChecked).Select(a => a.Account);
|
||||
public AvaloniaList<ListItem> Accounts { get; } = new();
|
||||
public class ListItem
|
||||
{
|
||||
public Account Account { get; set; }
|
||||
public string Text { get; set; }
|
||||
public bool IsChecked { get; set; } = true;
|
||||
public ListItem(Account account)
|
||||
{
|
||||
Account = account;
|
||||
IsChecked = account.LibraryScan;
|
||||
Text = $"{account.AccountName} ({account.AccountId} - {account.Locale.Name})";
|
||||
}
|
||||
public Account Account { get; }
|
||||
public string Text { get; }
|
||||
public bool IsChecked { get; set; }
|
||||
public override string ToString() => Text;
|
||||
}
|
||||
|
||||
public ScanAccountsDialog()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
ControlToFocusOnShow = this.FindControl<Button>(nameof(ImportButton));
|
||||
|
||||
ControlToFocusOnShow = ImportButton;
|
||||
DataContext = this;
|
||||
LoadAccounts();
|
||||
}
|
||||
|
||||
private void LoadAccounts()
|
||||
{
|
||||
_accounts.Clear();
|
||||
Accounts.Clear();
|
||||
using var persister = AudibleApiStorage.GetAccountsSettingsPersister();
|
||||
var accounts = persister.AccountsSettings.Accounts;
|
||||
|
||||
foreach (var account in accounts)
|
||||
_accounts.Add(new listItem
|
||||
{
|
||||
Account = account,
|
||||
IsChecked = account.LibraryScan,
|
||||
Text = $"{account.AccountName} ({account.AccountId} - {account.Locale.Name})"
|
||||
});
|
||||
|
||||
DataContext = this;
|
||||
Accounts.AddRange(accounts.Select(account => new ListItem(account)));
|
||||
}
|
||||
|
||||
public async Task EditAccountsAsync()
|
||||
@@ -56,12 +50,7 @@ namespace LibationAvalonia.Dialogs
|
||||
}
|
||||
}
|
||||
|
||||
protected override void SaveAndClose()
|
||||
{
|
||||
foreach (listItem item in _accounts.Where(a => a.IsChecked))
|
||||
CheckedAccounts.Add(item.Account);
|
||||
|
||||
base.SaveAndClose();
|
||||
}
|
||||
public new void SaveAndClose()
|
||||
=> base.SaveAndClose();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user