PlaylistHelper.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. namespace FNZCM.BlazorWasm.Helpers
  2. {
  3. public class PlaylistHelper
  4. {
  5. private readonly LocalStorageHelper localStorage;
  6. public PlaylistHelper(LocalStorageHelper localStorage) => this.localStorage = localStorage;
  7. public Dictionary<Guid, string> PlayListLoadSave { get => localStorage.Get<Dictionary<Guid, string>>() ?? new Dictionary<Guid, string>(); set => localStorage.Set(value); }
  8. public List<string> this[Guid playlistId]
  9. {
  10. get => localStorage.Get<List<string>>($"playlist-{playlistId}") ?? new List<string>();
  11. set => localStorage.Set(value, $"playlist-{playlistId}");
  12. }
  13. public void CreateNewPlaylist(string name)
  14. {
  15. var pls = PlayListLoadSave;
  16. pls[Guid.NewGuid()] = name;
  17. PlayListLoadSave = pls;
  18. }
  19. public void AddTrackToPlaylist(string trackPath, Guid playlistId)
  20. {
  21. var p = this[playlistId];
  22. p.Add(trackPath);
  23. this[playlistId] = p;
  24. }
  25. public void DeleteTrackInPlaylist(Guid playlistId, int index, string trackPathForConfirm)
  26. {
  27. var p = this[playlistId];
  28. if (index < p.Count && p[index] == trackPathForConfirm) p.RemoveAt(index);
  29. this[playlistId] = p;
  30. }
  31. public void Deleteplaylist(Guid playlistId)
  32. {
  33. localStorage.Remove($"playlist-{playlistId}");
  34. var pls = PlayListLoadSave;
  35. pls.Remove(playlistId);
  36. PlayListLoadSave = pls;
  37. }
  38. public void UpdatePlaylistName(Guid playlistId,string name)
  39. {
  40. var pls = PlayListLoadSave;
  41. pls[playlistId] = name;
  42. PlayListLoadSave = pls;
  43. }
  44. //TODO: Move order track in playlist
  45. }
  46. }