Merge pull request #87 from Mbucari/master

Make sure DataGridView updates the display immediately after Details are changed.
This commit is contained in:
rmcrackan 2021-08-21 13:37:05 -04:00 committed by GitHub
commit 2da25edafd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 57 additions and 50 deletions

View File

@ -224,6 +224,8 @@ namespace AaxDecrypter
isCanceled = true; isCanceled = true;
aaxFile?.Cancel(); aaxFile?.Cancel();
aaxFile?.Dispose(); aaxFile?.Dispose();
nfsPersister?.NetworkFileStream?.Close();
nfsPersister?.Dispose();
} }
} }
} }

View File

@ -241,9 +241,12 @@ namespace AaxDecrypter
} while (downloadPosition < ContentLength && !isCancelled); } while (downloadPosition < ContentLength && !isCancelled);
_writeFile.Close(); _writeFile.Close();
_networkStream.Close();
WritePosition = downloadPosition; WritePosition = downloadPosition;
Update(); Update();
_networkStream.Close();
downloadedPiece.Set();
downloadEnded.Set();
if (!isCancelled && WritePosition < ContentLength) if (!isCancelled && WritePosition < ContentLength)
throw new WebException($"Downloaded size (0x{WritePosition:X10}) is less than {nameof(ContentLength)} (0x{ContentLength:X10})."); throw new WebException($"Downloaded size (0x{WritePosition:X10}) is less than {nameof(ContentLength)} (0x{ContentLength:X10}).");
@ -251,7 +254,6 @@ namespace AaxDecrypter
if (WritePosition > ContentLength) if (WritePosition > ContentLength)
throw new WebException($"Downloaded size (0x{WritePosition:X10}) is greater than {nameof(ContentLength)} (0x{ContentLength:X10})."); throw new WebException($"Downloaded size (0x{WritePosition:X10}) is greater than {nameof(ContentLength)} (0x{ContentLength:X10}).");
downloadEnded.Set();
} }
#endregion #endregion

View File

@ -8,7 +8,7 @@ namespace LibationWinForms
{ {
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;
protected void NotifyPropertyChanged([CallerMemberName] string propertyName = "") public void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
=> this.UIThread(() => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName))); => this.UIThread(() => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)));
} }
} }

View File

@ -39,7 +39,6 @@ namespace LibationWinForms.BookLiberation
#endregion #endregion
#region IStreamable event handler overrides #region IStreamable event handler overrides
public override void OnStreamingBegin(object sender, string beginString) { }
public override void OnStreamingProgressChanged(object sender, DownloadProgress downloadProgress) public override void OnStreamingProgressChanged(object sender, DownloadProgress downloadProgress)
{ {
if (!downloadProgress.ProgressPercentage.HasValue) if (!downloadProgress.ProgressPercentage.HasValue)
@ -54,7 +53,6 @@ namespace LibationWinForms.BookLiberation
public override void OnStreamingTimeRemaining(object sender, TimeSpan timeRemaining) public override void OnStreamingTimeRemaining(object sender, TimeSpan timeRemaining)
=> updateRemainingTime((int)timeRemaining.TotalSeconds); => updateRemainingTime((int)timeRemaining.TotalSeconds);
public override void OnStreamingCompleted(object sender, string completedString) { }
#endregion #endregion
#region IAudioDecodable event handlers #region IAudioDecodable event handlers

View File

@ -48,7 +48,7 @@ namespace LibationWinForms.BookLiberation.BaseForms
streamable.StreamingCompleted += OnStreamingCompleted; streamable.StreamingCompleted += OnStreamingCompleted;
streamable.StreamingCompleted += OnStreamingCompletedClose; streamable.StreamingCompleted += OnStreamingCompletedClose;
FormClosed += UnsubscribeStreamable; Disposed += UnsubscribeStreamable;
} }
private void Subscribe(IProcessable processable) private void Subscribe(IProcessable processable)
{ {
@ -81,7 +81,7 @@ namespace LibationWinForms.BookLiberation.BaseForms
} }
private void UnsubscribeStreamable(object sender, EventArgs e) private void UnsubscribeStreamable(object sender, EventArgs e)
{ {
FormClosed -= UnsubscribeStreamable; Disposed -= UnsubscribeStreamable;
Streamable.StreamingBegin -= OnStreamingBeginShow; Streamable.StreamingBegin -= OnStreamingBeginShow;
Streamable.StreamingBegin -= OnStreamingBegin; Streamable.StreamingBegin -= OnStreamingBegin;

View File

@ -22,12 +22,12 @@ namespace LibationWinForms
var foreColor = tagsString?.Contains("hidden") == true ? HiddenForeColor : DataGridView.DefaultCellStyle.ForeColor; var foreColor = tagsString?.Contains("hidden") == true ? HiddenForeColor : DataGridView.DefaultCellStyle.ForeColor;
if (DataGridView.Rows[RowIndex].DefaultCellStyle.ForeColor != foreColor) if (DataGridView.Rows[rowIndex].DefaultCellStyle.ForeColor != foreColor)
{ {
DataGridView.Rows[RowIndex].DefaultCellStyle.ForeColor = foreColor; DataGridView.Rows[rowIndex].DefaultCellStyle.ForeColor = foreColor;
} }
if (tagsString.Length == 0) if (tagsString?.Length == 0)
{ {
base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, null, null, null, cellStyle, advancedBorderStyle, paintParts); base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, null, null, null, cellStyle, advancedBorderStyle, paintParts);
DrawButtonImage(graphics, ButtonImage, cellBounds); DrawButtonImage(graphics, ButtonImage, cellBounds);

View File

@ -155,37 +155,7 @@ namespace LibationWinForms
#endregion #endregion
#region Static library display functions #region Static library display functions
public static (string mouseoverText, Bitmap buttonImage) GetLiberateDisplay(LiberatedState liberatedStatus, PdfState pdfStatus)
{
(string libState, string image_lib) = liberatedStatus switch
{
LiberatedState.Liberated => ("Liberated", "green"),
LiberatedState.PartialDownload => ("File has been at least\r\npartially downloaded", "yellow"),
LiberatedState.NotDownloaded => ("Book NOT downloaded", "red"),
_ => throw new Exception("Unexpected liberation state")
};
(string pdfState, string image_pdf) = pdfStatus switch
{
PdfState.Downloaded => ("\r\nPDF downloaded", "_pdf_yes"),
PdfState.NotDownloaded => ("\r\nPDF NOT downloaded", "_pdf_no"),
PdfState.NoPdf => ("", ""),
_ => throw new Exception("Unexpected PDF state")
};
var mouseoverText = libState + pdfState;
if (liberatedStatus == LiberatedState.NotDownloaded ||
liberatedStatus == LiberatedState.PartialDownload ||
pdfStatus == PdfState.NotDownloaded)
mouseoverText += "\r\nClick to complete";
var buttonImage = (Bitmap)Properties.Resources.ResourceManager.GetObject($"liberate_{image_lib}{image_pdf}");
return (mouseoverText, buttonImage);
}
/// <summary> /// <summary>
/// This information should not change during <see cref="GridEntry"/> lifetime, so call only once. /// This information should not change during <see cref="GridEntry"/> lifetime, so call only once.
/// </summary> /// </summary>

View File

@ -22,12 +22,42 @@ namespace LibationWinForms
if (value is (LiberatedState liberatedState, PdfState pdfState)) if (value is (LiberatedState liberatedState, PdfState pdfState))
{ {
(string mouseoverText, Bitmap buttonImage) = GridEntry.GetLiberateDisplay(liberatedState, pdfState); (string mouseoverText, Bitmap buttonImage) = GetLiberateDisplay(liberatedState, pdfState);
DrawButtonImage(graphics, buttonImage, cellBounds); DrawButtonImage(graphics, buttonImage, cellBounds);
ToolTipText = mouseoverText; ToolTipText = mouseoverText;
} }
} }
private static (string mouseoverText, Bitmap buttonImage) GetLiberateDisplay(LiberatedState liberatedStatus, PdfState pdfStatus)
{
(string libState, string image_lib) = liberatedStatus switch
{
LiberatedState.Liberated => ("Liberated", "green"),
LiberatedState.PartialDownload => ("File has been at least\r\npartially downloaded", "yellow"),
LiberatedState.NotDownloaded => ("Book NOT downloaded", "red"),
_ => throw new Exception("Unexpected liberation state")
};
(string pdfState, string image_pdf) = pdfStatus switch
{
PdfState.Downloaded => ("\r\nPDF downloaded", "_pdf_yes"),
PdfState.NotDownloaded => ("\r\nPDF NOT downloaded", "_pdf_no"),
PdfState.NoPdf => ("", ""),
_ => throw new Exception("Unexpected PDF state")
};
var mouseoverText = libState + pdfState;
if (liberatedStatus == LiberatedState.NotDownloaded ||
liberatedStatus == LiberatedState.PartialDownload ||
pdfStatus == PdfState.NotDownloaded)
mouseoverText += "\r\nClick to complete";
var buttonImage = (Bitmap)Properties.Resources.ResourceManager.GetObject($"liberate_{image_lib}{image_pdf}");
return (mouseoverText, buttonImage);
}
} }
} }

View File

@ -67,7 +67,7 @@ namespace LibationWinForms
await Liberate_Click(liveGridEntry); await Liberate_Click(liveGridEntry);
break; break;
case nameof(liveGridEntry.DisplayTags): case nameof(liveGridEntry.DisplayTags):
Details_Click(liveGridEntry.LibraryBook); Details_Click(liveGridEntry);
break; break;
} }
} }
@ -89,18 +89,21 @@ namespace LibationWinForms
await BookLiberation.ProcessorAutomationController.BackupSingleBookAsync(libraryBook, (_, __) => RefreshRow(libraryBook.Book.AudibleProductId)); await BookLiberation.ProcessorAutomationController.BackupSingleBookAsync(libraryBook, (_, __) => RefreshRow(libraryBook.Book.AudibleProductId));
} }
private void Details_Click(LibraryBook libraryBook) private void Details_Click(GridEntry liveGridEntry)
{ {
var bookDetailsForm = new BookDetailsDialog(libraryBook); var bookDetailsForm = new BookDetailsDialog(liveGridEntry.LibraryBook);
if (bookDetailsForm.ShowDialog() != DialogResult.OK) if (bookDetailsForm.ShowDialog() != DialogResult.OK)
return; return;
var qtyChanges = LibraryCommands.UpdateUserDefinedItem(libraryBook.Book, bookDetailsForm.NewTags, bookDetailsForm.BookLiberatedStatus, bookDetailsForm.PdfLiberatedStatus); var qtyChanges = LibraryCommands.UpdateUserDefinedItem(liveGridEntry.LibraryBook.Book, bookDetailsForm.NewTags, bookDetailsForm.BookLiberatedStatus, bookDetailsForm.PdfLiberatedStatus);
if (qtyChanges == 0) if (qtyChanges == 0)
return; return;
//Re-apply filters //Re-apply filters
Filter(); Filter();
//Update whole GridEntry row
liveGridEntry.NotifyPropertyChanged();
} }
#endregion #endregion
@ -149,10 +152,10 @@ namespace LibationWinForms
public void RefreshRow(string productId) public void RefreshRow(string productId)
{ {
var rowIndex = getRowIndex((ge) => ge.AudibleProductId == productId); var liveGridEntry = getGridEntry((ge) => ge.AudibleProductId == productId);
// update cells incl Liberate button text // update GridEntry Liberate cell
_dataGridView.InvalidateRow(rowIndex); liveGridEntry?.NotifyPropertyChanged(nameof(liveGridEntry.Liberate));
// needed in case filtering by -IsLiberated and it gets changed to Liberated. want to immediately show the change // needed in case filtering by -IsLiberated and it gets changed to Liberated. want to immediately show the change
Filter(); Filter();
@ -193,7 +196,9 @@ namespace LibationWinForms
#region DataGridView Macro #region DataGridView Macro
private int getRowIndex(Func<GridEntry, bool> func) => _dataGridView.GetRowIdOfBoundItem(func); private GridEntry getGridEntry(Func<GridEntry, bool> predicate)
=> ((SortableBindingList<GridEntry>)gridEntryBindingSource.DataSource).FirstOrDefault(predicate);
private GridEntry getGridEntry(int rowIndex) => _dataGridView.GetBoundItem<GridEntry>(rowIndex); private GridEntry getGridEntry(int rowIndex) => _dataGridView.GetBoundItem<GridEntry>(rowIndex);
#endregion #endregion