playlist loading from json and displaying it properly
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Media;
|
||||
using ModuleManager.Modules;
|
||||
@@ -10,12 +11,20 @@ public class Catagory
|
||||
public readonly string name;
|
||||
List<Item> items = new List<Item>();
|
||||
|
||||
private WrapPanel wrapPanel;
|
||||
|
||||
StringConversions conv = new StringConversions();
|
||||
|
||||
public Catagory(string name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Catagory(string name,WrapPanel wrapPanel)
|
||||
{
|
||||
this.name = name;
|
||||
this.wrapPanel = wrapPanel;
|
||||
}
|
||||
|
||||
public void addItem(Item item)
|
||||
{
|
||||
@@ -58,4 +67,9 @@ public class Catagory
|
||||
return -1; // Not found
|
||||
}
|
||||
|
||||
public WrapPanel getWrapPanel()
|
||||
{
|
||||
return wrapPanel;
|
||||
}
|
||||
|
||||
}
|
@@ -70,6 +70,7 @@ namespace ShadowStream.Obejeckte
|
||||
this.isFoto = isFoto;
|
||||
|
||||
Console.WriteLine(path);
|
||||
Console.WriteLine(playButton.Tag);
|
||||
}
|
||||
|
||||
// Old methods needed by main window
|
||||
|
@@ -2,17 +2,17 @@ namespace ShadowStream.Obejeckte;
|
||||
|
||||
public class ObjListBP
|
||||
{
|
||||
public List<object> SharedRefs;
|
||||
public List<Catagory> SharedRefs;
|
||||
|
||||
private string _name;
|
||||
|
||||
public ObjListBP(string name)
|
||||
{
|
||||
_name = name;
|
||||
SharedRefs = new List<object>();
|
||||
SharedRefs = new List<Catagory>();
|
||||
}
|
||||
public ObjListBP()
|
||||
{
|
||||
SharedRefs = new List<object>();
|
||||
SharedRefs = new List<Catagory>();
|
||||
}
|
||||
}
|
@@ -54,4 +54,69 @@ public class Jason_Writer
|
||||
string filePath = Path.Combine(_folderPath, $"{listName}.json");
|
||||
return File.Exists(filePath);
|
||||
}
|
||||
|
||||
|
||||
public async Task SavePlaylistListAsync(string listName, List<locJasonPlaylist> list)
|
||||
{
|
||||
Console.WriteLine($"Saving playlist list '{listName}' with {list.Count} items.");
|
||||
|
||||
foreach (var item in list)
|
||||
{
|
||||
Console.WriteLine($" - Name: {item.name}, Path: {item.path}, Type: {item.type}");
|
||||
}
|
||||
|
||||
string filePath = Path.Combine(_folderPath, $"{listName}.json"); // keep same naming as original
|
||||
string jsonString = JsonConvert.SerializeObject(list, Formatting.Indented);
|
||||
await File.WriteAllTextAsync(filePath, jsonString);
|
||||
|
||||
Console.WriteLine($"Saved JSON to: {filePath}");
|
||||
}
|
||||
|
||||
public async Task<List<locJasonPlaylist>> LoadPlaylistListAsync(string listName)
|
||||
{
|
||||
string filePath = Path.Combine(_folderPath, $"{listName}.json");
|
||||
|
||||
if (!File.Exists(filePath))
|
||||
{
|
||||
Console.WriteLine($"List file '{filePath}' not found. Returning empty list.");
|
||||
return new List<locJasonPlaylist>();
|
||||
}
|
||||
|
||||
string jsonString = await File.ReadAllTextAsync(filePath);
|
||||
var list = JsonConvert.DeserializeObject<List<locJasonPlaylist>>(jsonString);
|
||||
return list ?? new List<locJasonPlaylist>();
|
||||
}
|
||||
public async Task<List<string>> GetSavedPlaylistNamesAsync()
|
||||
{
|
||||
string playlistFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Temp Data");
|
||||
|
||||
if (!Directory.Exists(playlistFolder))
|
||||
return new List<string>();
|
||||
|
||||
var files = Directory.GetFiles(playlistFolder, "*.json");
|
||||
var playlistNames = new List<string>();
|
||||
|
||||
foreach (var file in files)
|
||||
{
|
||||
string name = Path.GetFileNameWithoutExtension(file);
|
||||
if (IsPlaylistFile(name)) // uses the updated method
|
||||
{
|
||||
playlistNames.Add(name);
|
||||
}
|
||||
}
|
||||
|
||||
return playlistNames;
|
||||
}
|
||||
|
||||
|
||||
private bool IsPlaylistFile(string fileName)
|
||||
{
|
||||
// Exclude main media files and the favorites file
|
||||
var reserved = new[] { "Muvies", "Series", "Photos", "Music", "Favorit" };
|
||||
return !reserved.Contains(fileName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@@ -1,3 +1,5 @@
|
||||
using System.IO;
|
||||
|
||||
namespace ShadowStream.ObjecktForJason;
|
||||
|
||||
public class locJason
|
||||
@@ -5,4 +7,10 @@ public class locJason
|
||||
public string path;
|
||||
public string imageData;
|
||||
public string type;
|
||||
}
|
||||
}
|
||||
public class locJasonPlaylist
|
||||
{
|
||||
public string name { get; set; }
|
||||
public string type { get; set; }
|
||||
public string path { get; set; }
|
||||
}
|
||||
|
Reference in New Issue
Block a user