32 lines
811 B
C#
32 lines
811 B
C#
using Newtonsoft.Json;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Windows.Storage;
|
|
|
|
namespace FoxTube.Services
|
|
{
|
|
public static class History
|
|
{
|
|
static readonly ApplicationDataContainer storage = ApplicationData.Current.RoamingSettings;
|
|
|
|
public static string[] SearchHistory
|
|
{
|
|
get => JsonConvert.DeserializeObject<string[]>(storage.Values["SearchHistory"] as string) ?? new string[0];
|
|
private set => JsonConvert.SerializeObject(value);
|
|
}
|
|
|
|
public static void AddSearchHistoryEntry(string term)
|
|
{
|
|
List<string> history = SearchHistory.ToList();
|
|
history.Insert(0, term);
|
|
|
|
if (history.Count > 5)
|
|
history.RemoveRange(5, history.Count - 5);
|
|
|
|
SearchHistory = history.ToArray();
|
|
}
|
|
|
|
public static void ClearSearchHistory() =>
|
|
SearchHistory = new string[0];
|
|
}
|
|
} |