-
Notifications
You must be signed in to change notification settings - Fork 1
/
LikedVideosManager.cs
53 lines (43 loc) · 1.38 KB
/
LikedVideosManager.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 LikedVideosManager
{
private const string LikedVideosKey = "LikedVideos";
public void AddLikedVideo(string videoId)
{
var likedVideos = GetLikedVideos();
if (!likedVideos.Contains(videoId))
{
likedVideos.Add(videoId);
SaveLikedVideos(likedVideos);
}
}
public bool IsVideoLiked(string videoId)
{
var likedVideos = GetLikedVideos();
return likedVideos.Contains(videoId);
}
public List<string> GetLikedVideos()
{
var localSettings = ApplicationData.Current.LocalSettings;
if (localSettings.Values.ContainsKey(LikedVideosKey))
{
return JsonConvert.DeserializeObject<List<string>>(localSettings.Values[LikedVideosKey].ToString());
}
return new List<string>();
}
public void RemoveLikedVideo(string videoId)
{
var likedVideos = GetLikedVideos();
if (likedVideos.Remove(videoId))
{
SaveLikedVideos(likedVideos);
}
}
private void SaveLikedVideos(List<string> likedVideos)
{
var localSettings = ApplicationData.Current.LocalSettings;
localSettings.Values[LikedVideosKey] = JsonConvert.SerializeObject(likedVideos);
}
}