Add user rating editing to grid
This commit is contained in:
parent
3a44bef0d9
commit
c900fe8461
24 changed files with 942 additions and 62 deletions
|
|
@ -1,6 +1,8 @@
|
|||
using Avalonia.Media;
|
||||
using ApplicationServices;
|
||||
using Avalonia.Media;
|
||||
using DataLayer;
|
||||
using Dinah.Core;
|
||||
using FileLiberator;
|
||||
using LibationFileManager;
|
||||
using ReactiveUI;
|
||||
using System;
|
||||
|
|
@ -8,6 +10,7 @@ using System.Collections;
|
|||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LibationAvalonia.ViewModels
|
||||
{
|
||||
|
|
@ -42,7 +45,19 @@ namespace LibationAvalonia.ViewModels
|
|||
public string Misc { get; protected set; }
|
||||
public string Description { get; protected set; }
|
||||
public string ProductRating { get; protected set; }
|
||||
public string MyRating { get; protected set; }
|
||||
public string MyRatingString => Book.UserDefinedItem.Rating?.ToStarString()?.DefaultIfNullOrWhiteSpace("");
|
||||
protected Rating _myRating;
|
||||
public Rating MyRating
|
||||
{
|
||||
get => _myRating;
|
||||
set
|
||||
{
|
||||
if (_myRating != value && updateReviewTask?.IsCompleted is not false)
|
||||
{
|
||||
updateReviewTask = UpdateRating(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected bool? _remove = false;
|
||||
public abstract bool? Remove { get; set; }
|
||||
|
|
@ -56,6 +71,23 @@ namespace LibationAvalonia.ViewModels
|
|||
|
||||
#endregion
|
||||
|
||||
#region User rating
|
||||
|
||||
private Task updateReviewTask;
|
||||
private async Task UpdateRating(Rating rating)
|
||||
{
|
||||
var api = await LibraryBook.GetApiAsync();
|
||||
|
||||
if (await api.ReviewAsync(Book.AudibleProductId, (int)rating.OverallRating, (int)rating.PerformanceRating, (int)rating.StoryRating))
|
||||
{
|
||||
_myRating = rating;
|
||||
LibraryBook.Book.UpdateUserDefinedItem(null, null, null, rating);
|
||||
}
|
||||
|
||||
this.RaisePropertyChanged(nameof(MyRating));
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Sorting
|
||||
|
||||
public GridEntry() => _memberValues = CreateMemberValueDictionary();
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ namespace LibationAvalonia.ViewModels
|
|||
Title = Book.Title;
|
||||
Series = Book.SeriesNames();
|
||||
Length = Book.LengthInMinutes == 0 ? "" : $"{Book.LengthInMinutes / 60} hr {Book.LengthInMinutes % 60} min";
|
||||
MyRating = Book.UserDefinedItem.Rating?.ToStarString()?.DefaultIfNullOrWhiteSpace("");
|
||||
_myRating = Book.UserDefinedItem.Rating;
|
||||
PurchaseDate = libraryBook.DateAdded.ToString("d");
|
||||
ProductRating = Book.Rating?.ToStarString()?.DefaultIfNullOrWhiteSpace("");
|
||||
Authors = Book.AuthorNames();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
using Avalonia.Media;
|
||||
using DataLayer;
|
||||
using DataLayer;
|
||||
using Dinah.Core;
|
||||
using ReactiveUI;
|
||||
using System;
|
||||
|
|
@ -69,7 +68,7 @@ namespace LibationAvalonia.ViewModels
|
|||
|
||||
Title = Book.Title;
|
||||
Series = Book.SeriesNames();
|
||||
MyRating = Book.UserDefinedItem.Rating?.ToStarString()?.DefaultIfNullOrWhiteSpace("");
|
||||
_myRating = Book.UserDefinedItem.Rating;
|
||||
ProductRating = Book.Rating?.ToStarString()?.DefaultIfNullOrWhiteSpace("");
|
||||
Authors = Book.AuthorNames();
|
||||
Narrators = Book.NarratorNames();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue