account management UI

This commit is contained in:
Robert McRackan 2020-08-24 16:22:55 -04:00
parent e9e380dbe6
commit 743644c4e9
8 changed files with 132 additions and 84 deletions

View File

@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using AudibleApi;
@ -25,7 +26,11 @@ namespace InternalUtilities
protected override JsonSerializerSettings GetSerializerSettings()
=> Identity.GetJsonSerializerSettings();
}
public class Accounts : Updatable
// 'Accounts' is intentionally not IEnumerable<> so that properties can be added/extended
// from newtonsoft (https://www.newtonsoft.com/json/help/html/SerializationGuide.htm):
// .NET : IList, IEnumerable, IList<T>, Array
// JSON : Array (properties on the collection will not be serialized)
public class Accounts : IUpdatable
{
public event EventHandler Updated;
private void update(object sender = null, EventArgs e = null)
@ -143,7 +148,7 @@ namespace InternalUtilities
throw new InvalidOperationException("Cannot add an account with the same account Id and Locale");
}
}
public class Account : Updatable
public class Account : IUpdatable
{
public event EventHandler Updated;
private void update(object sender = null, EventArgs e = null)
@ -169,6 +174,10 @@ namespace InternalUtilities
}
}
// whether to include this account when scanning libraries.
// technically this is an app setting; not an attribute of account. but since it's managed with accounts, it makes sense to put this exception-to-the-rule here
public bool LibraryScan { get; set; }
private string _decryptKey = "";
public string DecryptKey
{

View File

@ -13,7 +13,7 @@
<!-- <PublishSingleFile>true</PublishSingleFile> -->
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<Version>3.1.12.229</Version>
<Version>3.1.12.249</Version>
</PropertyGroup>
<ItemGroup>

View File

@ -157,6 +157,7 @@ namespace LibationLauncher
var account = new Account(email)
{
AccountName = $"{email} - {locale.Name}",
LibraryScan = true,
IdentityTokens = identity
};

View File

@ -35,8 +35,8 @@
this.DeleteAccount = new System.Windows.Forms.DataGridViewButtonColumn();
this.LibraryScan = new System.Windows.Forms.DataGridViewCheckBoxColumn();
this.AccountId = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.AccountName = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Locale = new System.Windows.Forms.DataGridViewComboBoxColumn();
this.AccountName = new System.Windows.Forms.DataGridViewTextBoxColumn();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
this.SuspendLayout();
//
@ -75,8 +75,8 @@
this.DeleteAccount,
this.LibraryScan,
this.AccountId,
this.AccountName,
this.Locale});
this.Locale,
this.AccountName});
this.dataGridView1.Location = new System.Drawing.Point(12, 12);
this.dataGridView1.MultiSelect = false;
this.dataGridView1.Name = "dataGridView1";
@ -118,18 +118,18 @@
this.AccountId.Name = "AccountId";
this.AccountId.Width = 111;
//
// AccountName
//
this.AccountName.HeaderText = "Account nickname (optional)";
this.AccountName.Name = "AccountName";
this.AccountName.Width = 152;
//
// Locale
//
this.Locale.HeaderText = "Locale";
this.Locale.Name = "Locale";
this.Locale.Width = 45;
//
// AccountName
//
this.AccountName.HeaderText = "Account nickname (optional)";
this.AccountName.Name = "AccountName";
this.AccountName.Width = 152;
//
// AccountsDialog
//
this.AcceptButton = this.saveBtn;
@ -156,7 +156,7 @@
private System.Windows.Forms.DataGridViewButtonColumn DeleteAccount;
private System.Windows.Forms.DataGridViewCheckBoxColumn LibraryScan;
private System.Windows.Forms.DataGridViewTextBoxColumn AccountId;
private System.Windows.Forms.DataGridViewTextBoxColumn AccountName;
private System.Windows.Forms.DataGridViewComboBoxColumn Locale;
private System.Windows.Forms.DataGridViewTextBoxColumn AccountName;
}
}

View File

@ -1,36 +1,99 @@
using System;
using System.Linq;
using System.Windows.Forms;
using AudibleApi;
using FileManager;
using InternalUtilities;
namespace LibationWinForms.Dialogs
{
public partial class AccountsDialog : Form
{
const string COL_Original = "Original";
const string COL_Delete = "Delete";
const string COL_Filter = "Filter";
const string COL_MoveUp = "MoveUp";
const string COL_MoveDown = "MoveDown";
const string NON_BREAKING_SPACE = "\u00a0";
const string COL_Original = nameof(Original);
const string COL_Delete = nameof(DeleteAccount);
const string COL_LibraryScan = nameof(LibraryScan);
const string COL_AccountId = nameof(AccountId);
const string COL_AccountName = nameof(AccountName);
const string COL_Locale = nameof(Locale);
public AccountsDialog()
{
InitializeComponent();
dataGridView1.Columns[COL_AccountName].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
populateDropDown();
populateGridValues();
}
private void populateDropDown()
=> (dataGridView1.Columns[COL_Locale] as DataGridViewComboBoxColumn).DataSource
= Localization.Locales
.Select(l => l.Name)
.OrderBy(a => a).ToList();
private void populateGridValues()
{
var accounts = AudibleApiStorage.GetAccounts().AccountsSettings;
if (!accounts.Any())
return;
foreach (var account in accounts)
dataGridView1.Rows.Add(
new { account.AccountId, account.Locale.Name },
"X",
account.LibraryScan,
account.AccountId,
account.Locale.Name,
account.AccountName);
}
private void dataGridView1_DefaultValuesNeeded(object sender, DataGridViewRowEventArgs e)
{
e.Row.Cells[COL_Delete].Value = "X";
e.Row.Cells[COL_LibraryScan].Value = true;
}
private void DataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
var dgv = (DataGridView)sender;
var col = dgv.Columns[e.ColumnIndex];
if (col is DataGridViewButtonColumn && e.RowIndex >= 0)
{
var row = dgv.Rows[e.RowIndex];
switch (col.Name)
{
case COL_Delete:
// if final/edit row: do nothing
if (e.RowIndex < dgv.RowCount - 1)
dgv.Rows.Remove(row);
break;
//case COL_MoveUp:
// // if top: do nothing
// if (e.RowIndex < 1)
// break;
// dgv.Rows.Remove(row);
// dgv.Rows.Insert(e.RowIndex - 1, row);
// break;
//case COL_MoveDown:
// // if final/edit row or bottom filter row: do nothing
// if (e.RowIndex >= dgv.RowCount - 2)
// break;
// dgv.Rows.Remove(row);
// dgv.Rows.Insert(e.RowIndex + 1, row);
// break;
}
}
}
private void cancelBtn_Click(object sender, EventArgs e) => this.Close();
#region TEMP
private void dataGridView1_DefaultValuesNeeded(object sender, DataGridViewRowEventArgs e)
{
//e.Row.Cells["Region"].Value = "WA";
//e.Row.Cells["CustomerID"].Value = NewCustomerId();
}
private void saveBtn_Click(object sender, EventArgs e)
{
@ -65,39 +128,6 @@ namespace LibationWinForms.Dialogs
{
}
private void DataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
//var dgv = (DataGridView)sender;
//var col = dgv.Columns[e.ColumnIndex];
//if (col is DataGridViewButtonColumn && e.RowIndex >= 0)
//{
// var row = dgv.Rows[e.RowIndex];
// switch (col.Name)
// {
// case COL_Delete:
// // if final/edit row: do nothing
// if (e.RowIndex < dgv.RowCount - 1)
// dgv.Rows.Remove(row);
// break;
// case COL_MoveUp:
// // if top: do nothing
// if (e.RowIndex < 1)
// break;
// dgv.Rows.Remove(row);
// dgv.Rows.Insert(e.RowIndex - 1, row);
// break;
// case COL_MoveDown:
// // if final/edit row or bottom filter row: do nothing
// if (e.RowIndex >= dgv.RowCount - 2)
// break;
// dgv.Rows.Remove(row);
// dgv.Rows.Insert(e.RowIndex + 1, row);
// break;
// }
//}
}
#endregion
}
}

View File

@ -81,6 +81,7 @@
this.dataGridView1.Size = new System.Drawing.Size(776, 397);
this.dataGridView1.TabIndex = 0;
this.dataGridView1.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.DataGridView1_CellContentClick);
this.dataGridView1.DefaultValuesNeeded += new System.Windows.Forms.DataGridViewRowEventHandler(this.dataGridView1_DefaultValuesNeeded);
//
// Original
//

View File

@ -10,11 +10,11 @@ namespace LibationWinForms.Dialogs
const string BLACK_UP_POINTING_TRIANGLE = "\u25B2";
const string BLACK_DOWN_POINTING_TRIANGLE = "\u25BC";
const string COL_Original = "Original";
const string COL_Delete = "Delete";
const string COL_Filter = "Filter";
const string COL_MoveUp = "MoveUp";
const string COL_MoveDown = "MoveDown";
const string COL_Original = nameof(Original);
const string COL_Delete = nameof(Delete);
const string COL_Filter = nameof(Filter);
const string COL_MoveUp = nameof(MoveUp);
const string COL_MoveDown = nameof(MoveDown);
Form1 _parent { get; }
@ -26,10 +26,10 @@ namespace LibationWinForms.Dialogs
dataGridView1.Columns[COL_Filter].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
populateFilters();
populateGridValues();
}
private void populateFilters()
private void populateGridValues()
{
var filters = QuickFilters.Filters;
if (!filters.Any())
@ -39,6 +39,13 @@ namespace LibationWinForms.Dialogs
dataGridView1.Rows.Add(filter, "X", filter, BLACK_UP_POINTING_TRIANGLE, BLACK_DOWN_POINTING_TRIANGLE);
}
private void dataGridView1_DefaultValuesNeeded(object sender, DataGridViewRowEventArgs e)
{
e.Row.Cells[COL_Delete].Value = "X";
e.Row.Cells[COL_MoveUp].Value = BLACK_UP_POINTING_TRIANGLE;
e.Row.Cells[COL_MoveDown].Value = BLACK_DOWN_POINTING_TRIANGLE;
}
private void saveBtn_Click(object sender, EventArgs e)
{
var list = dataGridView1.Rows

View File

@ -35,8 +35,8 @@
this.DeleteAccount = new System.Windows.Forms.DataGridViewButtonColumn();
this.LibraryScan = new System.Windows.Forms.DataGridViewCheckBoxColumn();
this.AccountId = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.AccountName = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Locale = new System.Windows.Forms.DataGridViewComboBoxColumn();
this.AccountName = new System.Windows.Forms.DataGridViewTextBoxColumn();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
this.SuspendLayout();
//
@ -63,18 +63,18 @@
//
// dataGridView1
//
this.dataGridView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dataGridView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dataGridView1.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.AllCells;
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.Original,
this.DeleteAccount,
this.LibraryScan,
this.AccountId,
this.AccountName,
this.Locale});
this.Original,
this.DeleteAccount,
this.LibraryScan,
this.AccountId,
this.Locale,
this.AccountName});
this.dataGridView1.Location = new System.Drawing.Point(12, 12);
this.dataGridView1.MultiSelect = false;
this.dataGridView1.Name = "dataGridView1";
@ -110,18 +110,18 @@
this.AccountId.Name = "AccountId";
this.AccountId.Width = 111;
//
// AccountName
//
this.AccountName.HeaderText = "Account nickname (optional)";
this.AccountName.Name = "AccountName";
this.AccountName.Width = 152;
//
// Locale
//
this.Locale.HeaderText = "Locale";
this.Locale.Name = "Locale";
this.Locale.Width = 45;
//
// AccountName
//
this.AccountName.HeaderText = "Account nickname (optional)";
this.AccountName.Name = "AccountName";
this.AccountName.Width = 152;
//
// AccountsDialog
//
this.AcceptButton = this.saveBtn;
@ -148,7 +148,7 @@
private System.Windows.Forms.DataGridViewButtonColumn DeleteAccount;
private System.Windows.Forms.DataGridViewCheckBoxColumn LibraryScan;
private System.Windows.Forms.DataGridViewTextBoxColumn AccountId;
private System.Windows.Forms.DataGridViewTextBoxColumn AccountName;
private System.Windows.Forms.DataGridViewComboBoxColumn Locale;
private System.Windows.Forms.DataGridViewTextBoxColumn AccountName;
}
}