Archived
1
0
This repository has been archived on 2026-04-22. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
FoxTube/FoxTube.Core/Services/History.cs
T
2020-05-09 23:16:19 +03:00

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];
}
}