This repository has been archived by the owner on Dec 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EditCloud.xaml.cs
158 lines (142 loc) · 5.78 KB
/
EditCloud.xaml.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
157
158
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Cloudsdale.Avatars;
using Cloudsdale.Models;
using Microsoft.Phone.Tasks;
namespace Cloudsdale {
public partial class EditCloud {
public bool AfterInit;
public EditCloud() {
DataContext = Connection.CurrentCloud;
InitializeComponent();
Dispatcher.BeginInvoke(() => IsHidden.Checked += IsHiddenChecked);
AfterInit = true;
}
private void NameTap(object sender, GestureEventArgs e) {
if (!ResetTaps()) {
CloudNameText.Visibility = Visibility.Collapsed;
CloudNameBox.Visibility = Visibility.Visible;
}
}
private void StackPanelTap(object sender, GestureEventArgs e) {
ResetTaps();
}
private bool inUpload;
public bool ResetTaps() {
if (inUpload) return true;
if (CloudNameBox.Visibility == Visibility.Visible) {
if (string.IsNullOrWhiteSpace(CloudNameBox.Text)) {
CloudNameBox.Text = Connection.CurrentCloud.name;
MessageBox.Show("Cloud names cannot be blank");
return true;
}
inUpload = true;
CloudNameText.Visibility = Visibility.Visible;
CloudNameBox.Visibility = Visibility.Collapsed;
Pullover.IsOpen = true;
UploadBar.IsEnabled = true;
var text = CloudNameBox.Text;
Connection.CurrentCloud.ChangeProperty("name", text, response => {
if (response == "422 Unprocessable Entity") {
inUpload = false;
Pullover.IsOpen = false;
UploadBar.IsEnabled = false;
CloudNameBox.Text = Connection.CurrentCloud.name;
MessageBox.Show("Invalid cloud name (is it already in use?)");
return;
}
inUpload = false;
Pullover.IsOpen = false;
UploadBar.IsEnabled = false;
ResetTaps();
});
return true;
}
if (RulesBox.Visibility == Visibility.Visible) {
inUpload = true;
RulesText.Visibility = Visibility.Visible;
RulesBox.Visibility = Visibility.Collapsed;
Pullover.IsOpen = true;
UploadBar.IsEnabled = true;
var text = RulesBox.Text;
Connection.CurrentCloud.ChangeProperty("rules", text, response => {
inUpload = false;
Pullover.IsOpen = false;
UploadBar.IsEnabled = false;
ResetTaps();
});
return true;
}
if (DescriptionBox.Visibility == Visibility.Visible) {
inUpload = true;
DescriptionText.Visibility = Visibility.Visible;
DescriptionBox.Visibility = Visibility.Collapsed;
Pullover.IsOpen = true;
UploadBar.IsEnabled = true;
var text = DescriptionBox.Text;
Connection.CurrentCloud.ChangeProperty("description", text, response => {
inUpload = false;
Pullover.IsOpen = false;
UploadBar.IsEnabled = false;
ResetTaps();
});
return true;
}
return false;
}
private void CloudNameBoxKeyDown(object sender, KeyEventArgs e) {
if (e.Key != Key.Enter) return;
ResetTaps();
}
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e) {
if (ResetTaps()) {
e.Cancel = true;
}
}
private void RulesTextDoubleTap(object sender, GestureEventArgs e) {
if (!ResetTaps()) {
RulesText.Visibility = Visibility.Collapsed;
RulesBox.Visibility = Visibility.Visible;
}
}
private void DescriptionTextDoubleTap(object sender, GestureEventArgs e) {
if (!ResetTaps()) {
DescriptionText.Visibility = Visibility.Collapsed;
DescriptionBox.Visibility = Visibility.Visible;
}
}
private void IsHiddenChecked(object sender, RoutedEventArgs e) {
if (!AfterInit) return;
inUpload = true;
Pullover.IsOpen = true;
UploadBar.IsEnabled = true;
Connection.CurrentCloud.ChangeProperty("hidden", true, response => {
inUpload = false;
Pullover.IsOpen = false;
UploadBar.IsEnabled = false;
});
}
private void IsHiddenUnchecked(object sender, RoutedEventArgs e) {
if (!AfterInit) return;
inUpload = true;
Pullover.IsOpen = true;
UploadBar.IsEnabled = true;
Connection.CurrentCloud.ChangeProperty("hidden", false, response => {
inUpload = false;
Pullover.IsOpen = false;
UploadBar.IsEnabled = false;
});
}
private void ChangeAvatarClick(object sender, RoutedEventArgs e) {
ChangeAvatar.target = Connection.CurrentCloud;
NavigationService.Navigate(new Uri("/Avatars/ChangeAvatar.xaml", UriKind.Relative));
}
private void RemoveModeratorClick(object sender, RoutedEventArgs e) {
var btn = (Button) sender;
var user = (User) btn.DataContext;
Connection.CurrentCloud.RemoveModerator(user.id);
}
}
}