forked from apple1417/bagpipe
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProfileEntryViewModel.cs
More file actions
60 lines (51 loc) · 1.84 KB
/
ProfileEntryViewModel.cs
File metadata and controls
60 lines (51 loc) · 1.84 KB
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
using System.Collections.Generic;
namespace bagpipe {
class ProfileEntryViewModel : ViewModelBase {
private readonly ProfileEntry entry;
public ProfileEntryViewModel(ProfileEntry entry, ProfileViewModel profileVM) {
this.entry = entry;
UpdateName(profileVM.DisplayGame);
profileVM.PropertyChanged += (sender, e) => {
if (e.PropertyName == nameof(ProfileViewModel.DisplayGame)) {
UpdateName(((ProfileViewModel)sender).DisplayGame);
}
};
}
private void UpdateName(Game game) {
Name = (game == Game.None)
? $"ID {entry.ID}"
: KnownSettings.ByGame.GetValueOrDefault(game)?.GetValueOrDefault(entry.ID)?.Name ?? $"Unknown ID {entry.ID}";
}
// These don't get setters since updating them live gets awkward
public int ID => entry.ID;
// Would also need to update data template for this
public SettingsDataType Type => entry.Type;
private string _name;
public string Name {
get => _name;
private set => SetProperty(ref _name, value);
}
public OnlineProfilePropertyOwner Owner {
get => entry.Owner;
set => SetProperty(ref entry.Owner, value);
}
public object Value {
get => entry.Value;
set {
if (entry.Value != value) {
bool dateTimeNull = Type == SettingsDataType.DateTime && value is null;
ValidationCheck(!dateTimeNull, "Unable to convert to valid time!");
ValidationCheck(dateTimeNull || entry.IsValidValue(value), $"Invalid value for data type {Type}!");
if (PropertyValid()) {
entry.Value = value;
InvokePropertyChanged();
}
}
}
}
public OnlineDataAdvertisementType AdvertisementType {
get => entry.AdvertisementType;
set => SetProperty(ref entry.AdvertisementType, value);
}
}
}