-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWatchLaterManager.cs
53 lines (43 loc) · 1.44 KB
/
WatchLaterManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System.Collections.Generic;
using Newtonsoft.Json;
using Windows.Storage;
public class WatchLaterManager
{
private const string WatchLaterKey = "WatchLaterVideos";
public void AddWatchLaterVideo(string videoId)
{
var watchLaterVideos = GetWatchLaterVideos();
if (!watchLaterVideos.Contains(videoId))
{
watchLaterVideos.Add(videoId);
SaveWatchLaterVideos(watchLaterVideos);
}
}
public bool IsVideoInWatchLater(string videoId)
{
var watchLaterVideos = GetWatchLaterVideos();
return watchLaterVideos.Contains(videoId);
}
public List<string> GetWatchLaterVideos()
{
var localSettings = ApplicationData.Current.LocalSettings;
if (localSettings.Values.ContainsKey(WatchLaterKey))
{
return JsonConvert.DeserializeObject<List<string>>(localSettings.Values[WatchLaterKey].ToString());
}
return new List<string>();
}
public void RemoveWatchLaterVideo(string videoId)
{
var watchLaterVideos = GetWatchLaterVideos();
if (watchLaterVideos.Remove(videoId))
{
SaveWatchLaterVideos(watchLaterVideos);
}
}
private void SaveWatchLaterVideos(List<string> watchLaterVideos)
{
var localSettings = ApplicationData.Current.LocalSettings;
localSettings.Values[WatchLaterKey] = JsonConvert.SerializeObject(watchLaterVideos);
}
}