/
VM_AniDB_AnimeDetailed.cs
156 lines (133 loc) · 5.5 KB
/
VM_AniDB_AnimeDetailed.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Web.Script.Serialization;
using System.Windows.Data;
using System.Xml.Serialization;
using Newtonsoft.Json;
using Shoko.Commons.Extensions;
using Shoko.Commons.Notification;
using Shoko.Commons.Properties;
using Shoko.Desktop.Properties;
using Shoko.Desktop.ViewModel.Helpers;
using Shoko.Models;
using Shoko.Models.Client;
using Shoko.Models.Server;
using Formatting = Shoko.Commons.Utils.Formatting;
// ReSharper disable InconsistentNaming
namespace Shoko.Desktop.ViewModel.Server
{
public class VM_AniDB_AnimeDetailed : CL_AniDB_AnimeDetailed, INotifyPropertyChanged, INotifyPropertyChangedExt
{
private int AnimeID => AniDBAnime.AnimeID;
public new VM_AniDB_Anime AniDBAnime
{
get { return (VM_AniDB_Anime) base.AniDBAnime; }
set { base.AniDBAnime = value; }
}
public new List<VM_AnimeTitle> AnimeTitles
{
get { return base.AnimeTitles.CastList<VM_AnimeTitle>(); }
set
{
base.AnimeTitles = value.CastList<CL_AnimeTitle>();
AnimeTitlesMain = value.Where(a => a.TitleType.Trim().ToUpper() == Constants.AnimeTitleType.Main.ToUpper()).ToList();
AnimeTitlesOfficial = value.Where(a => a.TitleType.Trim().ToUpper() == Constants.AnimeTitleType.Official.ToUpper()).ToList();
AnimeTitlesSynonym = value.Where(a => a.TitleType.Trim().ToUpper() == Constants.AnimeTitleType.Synonym.ToUpper()).ToList();
AnimeTitlesShort = value.Where(a => a.TitleType.Trim().ToUpper() == Constants.AnimeTitleType.ShortName.ToUpper()).ToList();
AnimeTitlesSummary = AnimeTitlesOfficial.Take(5).ToList();
}
}
public new List<VM_AnimeTag> Tags
{
get { return base.Tags.CastList<VM_AnimeTag>(); }
set { base.Tags = value.OrderByDescending(a => a.Weight).ToList().CastList<CL_AnimeTag>(); }
}
[ScriptIgnore, JsonIgnore, XmlIgnore]
public List<VM_AnimeTag> TagsSummary => Tags.Take(5).ToList();
public new List<CustomTag> CustomTags
{
get { return base.CustomTags; }
set
{
base.CustomTags = value.OrderBy(a => a.TagName.ToLowerInvariant()).ToList();
ViewCustomTags = CollectionViewSource.GetDefaultView(CustomTags);
ViewCustomTags.Refresh();
}
}
[ScriptIgnore, JsonIgnore, XmlIgnore]
public ICollectionView ViewCustomTags { get; set; }
[ScriptIgnore, JsonIgnore, XmlIgnore]
public List<VM_AnimeTitle> AnimeTitlesSummary { get; set; }
[ScriptIgnore, JsonIgnore, XmlIgnore]
public List<VM_AnimeTitle> AnimeTitlesMain { get; set; }
[ScriptIgnore, JsonIgnore, XmlIgnore]
public List<VM_AnimeTitle> AnimeTitlesOfficial { get; set; }
[ScriptIgnore, JsonIgnore, XmlIgnore]
public List<VM_AnimeTitle> AnimeTitlesSynonym { get; set; }
[ScriptIgnore, JsonIgnore, XmlIgnore]
public List<VM_AnimeTitle> AnimeTitlesShort { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged(string propname)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propname));
}
public VM_AniDB_AnimeDetailed()
{
}
public new AniDB_Vote UserVote
{
get { return base.UserVote; }
set { this.SetField(()=>base.UserVote,(r)=> base.UserVote = r, value, () => UserHasVoted, () => UserHasNotVoted, ()=>UserRating, ()=>UserRatingFormatted); }
}
[ScriptIgnore, JsonIgnore, XmlIgnore]
public bool UserHasVoted => UserVote!=null;
[ScriptIgnore, JsonIgnore, XmlIgnore]
public bool UserHasNotVoted => UserVote==null;
[ScriptIgnore, JsonIgnore, XmlIgnore]
public decimal UserRating
{
get
{
if (UserVote == null)
return 0m;
return Convert.ToDecimal(UserVote.VoteValue) / 100m;
}
set
{
if (UserVote == null)
return;
UserVote.VoteValue = Convert.ToInt32(value / 100);
}
}
[ScriptIgnore, JsonIgnore, XmlIgnore]
public string UserRatingFormatted
{
get
{
string val = Formatting.FormatAniDBRating((double)UserRating);
if (UserVote != null)
{
val += " (";
if (UserVote.VoteType == 1) val += Resources.VoteTypeAnimePermanent;
if (UserVote.VoteType == 2) val += Resources.VoteTypeAnimeTemporary;
val += ")";
}
return val;
}
}
public void Populate(VM_AniDB_AnimeDetailed contract)
{
AniDBAnime = contract.AniDBAnime;
UserVote = contract.UserVote;
Stat_AllVideoQuality =contract.Stat_AllVideoQuality;
Stat_AllVideoQuality_Episodes = contract.Stat_AllVideoQuality_Episodes;
Stat_AudioLanguages = contract.Stat_AudioLanguages;
Stat_SubtitleLanguages = contract.Stat_SubtitleLanguages;
Tags = contract.Tags;
CustomTags = contract.CustomTags;
AnimeTitles = contract.AnimeTitles;
}
}
}