-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFacebookAppForm.cs
437 lines (375 loc) · 16 KB
/
FacebookAppForm.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using A18_Ex01_Rahel_206082703_Avihay_203766035.Logic;
using FacebookWrapper;
using Facebook;
using FacebookWrapper.ObjectModel;
using A18_Ex01_Rahel_206082703_Avihay_203766035.DesignPatterns;
using A18_Ex01_Rahel_206082703_Avihay_203766035.DesignPatterns.Adapters;
using A18_Ex01_Rahel_206082703_Avihay_203766035.DesignPatterns.Adapters.Facebook;
namespace A18_Ex01_Rahel_206082703_Avihay_203766035
{
public partial class FacebookAppForm : Form
{
private FBAdapter m_LogIn;
private LogOut m_LogOut;
private int m_countButtonDiscoverClicked = 0;
public FacebookAppForm(FBAdapter i_LoggedUser)
{
InitializeComponent();
FacebookWrapper.FacebookService.s_CollectionLimit = 300;
FacebookWrapper.FacebookService.s_FbApiVersion = 2.8f;
if (!this.IsHandleCreated)
{
this.CreateHandle();
}
m_LogIn = LogInSingleton.GetLogInInstance;
m_LogIn = i_LoggedUser;
m_LogOut = new LogOut();
new Thread(fetchUserInfo).Start();
}
private void fetchUserInfo()
{
fetchIntroUser();
fetchProfileAndCoverPicture();
fetchUserPosts();
fetchFriends();
fetchLikedPages();
fetchEvents();
fetchFriendsCheckins();
loadMainFormdPicsBox();
}
private void loadMainFormdPicsBox()
{
try
{
if (m_LogIn.LoggedUserInfo.GetFBObjectList.GetFriends().Count != 0)
{
FriendPicturebox.Load(m_LogIn.LoggedUserInfo.GetFBObjectList.GetFriends()[0].PictureNormalURL);
}
}
catch
{
FriendPicturebox.Image = FriendPicturebox.ErrorImage;
}
try
{
if (m_LogIn.LoggedUserInfo.GetFBObjectList.GetLikedPages().Count != 0)
{
pictureBoxLikedPages.Load(m_LogIn.LoggedUserInfo.GetFBObjectList.GetLikedPages()[0].PictureNormalURL);
}
}
catch
{
pictureBoxLikedPages.Image = pictureBoxLikedPages.ErrorImage;
}
}
/// <summary>
/// Profile Page:
/// </summary>
private void fetchProfileAndCoverPicture()
{
pictureBoxProfilePicture.Invoke(new Action(() => pictureBoxProfilePicture.Load(m_LogIn.LoggedUserInfo.UserProfileInfo.GetProfilePictureUrl())));
pictureBoxProfilePicture.Invoke(new Action(() => pictureBoxCoverPicture.Load(m_LogIn.LoggedUserInfo.UserProfileInfo.GetCoverPictureUrl())));
}
private void fetchIntroUser()
{
labelUserName.Text = m_LogIn.LoggedUserInfo.UserName;
labelUserBirthday.Text = m_LogIn.LoggedUserInfo.UserBirthday;
labelUserGender.Text = m_LogIn.LoggedUserInfo.UserGender;
labelUserRelationshipStatus.Text = m_LogIn.LoggedUserInfo.UserRelationshipStatus;
////labelUserName.Invoke(new Action(() => labelUserName.Text = m_LogIn.LoggedUserInfo.UserName));
////labelUserBirthday.Invoke(new Action(() => labelUserBirthday.Text = "Born on: " + m_LogIn.LoggedUserInfo.UserBirthday));
////labelUserGender.Invoke(new Action(() => labelUserGender.Text = "Gender: " + m_LogIn.LoggedUserInfo.UserGender));
////labelUserRelationshipStatus.Invoke(new Action(() => labelUserRelationshipStatus.Text = m_LogIn.LoggedUserInfo.UserRelationshipStatus));
}
private void fetchUserPosts()
{
m_LogIn.LoggedUserInfo.UserProfileInfo.LoadUserPosts(listBoxUserPosts, m_LogIn.LoggedUserInfo.GetFBObjectList.GetPosts());
}
private void fetchFriends()
{
m_LogIn.LoggedUserInfo.UserProfileInfo.LoadUserFriends(FriendslistBox, m_LogIn.LoggedUserInfo.GetFBObjectList.GetFriends());
}
private void fetchLikedPages()
{
m_LogIn.LoggedUserInfo.UserProfileInfo.LoadLikedPages(listBoxLikedPages, m_LogIn.LoggedUserInfo.GetFBObjectList.GetLikedPages());
}
private void fetchEvents()
{
m_LogIn.LoggedUserInfo.UserProfileInfo.LoadEvents(listBoxAllEvents, m_LogIn.LoggedUserInfo.GetFBObjectList.GetEvents());
m_LogIn.LoggedUserInfo.UserProfileInfo.LoadUpComingEvents(listBoxUpEvents, m_LogIn.LoggedUserInfo.GetFBObjectList.GetUpComingEvents());
}
private void listBoxAllEvents_SelectedIndexChanged_1(object sender, EventArgs e)
{
if (listBoxAllEvents.SelectedItem != null && m_LogIn.LoggedUserInfo.GetFBObjectList.GetEvents().Count != 0)
{
Event selectedEvent = listBoxAllEvents.SelectedItem as Event;
textBoxDescEvent.Text = selectedEvent.Description;
}
else
{
textBoxDescEvent.Text = "No Events To Describe";
}
}
private void listBoxUpEvents_SelectedIndexChanged_1(object sender, EventArgs e)
{
if (listBoxUpEvents.SelectedItem != null && m_LogIn.LoggedUserInfo.GetFBObjectList.GetUpComingEvents().Count != 0)
{
Event selectedEvent = listBoxUpEvents.SelectedItem as Event;
textBoxDescEvent.Text = selectedEvent.Description;
}
else
{
textBoxDescEvent.Text = "No Events To Describe";
}
}
private void textBoxDescEvent_Validating(object sender, CancelEventArgs e)
{
Event selectedEvent1 = listBoxAllEvents.SelectedItem as Event;
Event selectedEvent2 = listBoxUpEvents.SelectedItem as Event;
if (selectedEvent1 != null)
{
selectedEvent1.Description = textBoxDescEvent.Text;
}
if (selectedEvent2 != null)
{
selectedEvent2.Description = textBoxDescEvent.Text;
}
}
private void displaySelectedFriend()
{
m_LogIn.LoggedUserInfo.UserProfileInfo.DisplaySelectedFriend(FriendslistBox, FriendPicturebox);
}
private void displaySelectPage()
{
m_LogIn.LoggedUserInfo.UserProfileInfo.DisplaySelectPage(listBoxLikedPages, pictureBoxLikedPages);
}
private void PostNewStatus()
{
if (string.IsNullOrEmpty(textBoxNewStatus.Text))
{
MessageBox.Show("Not exist new status to publish");
}
else
{
m_LogIn.LoggedUserInfo.UserProfileInfo.PostStatus(textBoxNewStatus.Text);
MessageBox.Show("Status Posted!");
}
textBoxNewStatus.Clear();
}
private void buttonSelectFriend_Click(object sender, EventArgs e)
{
displaySelectedFriend();
}
private void buttonSelectPage_Click(object sender, EventArgs e)
{
displaySelectPage();
}
private void buttonPostNewStatus_Click(object sender, EventArgs e)
{
PostNewStatus();
}
private void buttonLogout_Click(object sender, EventArgs e)
{
m_LogOut.LogOutFunc();
}
/// <summary>
/// feature 1 page:
/// </summary>
private void fetchFriendsCheckins()
{
m_LogIn.LoggedUserInfo.GetCheckInInfo.LoadFriendsCheckIns(listBoxCheckIns);
}
private void listBoxCheckIns_SelectedIndexChanged(object sender, EventArgs e)
{
textBoxLocation.Text = listBoxCheckIns.SelectedItem.ToString();
}
private void fetchFriendsInlocationEqualCheckin()
{
string[] locationInput = textBoxLocation.Text.ToUpper().Split();
m_LogIn.LoggedUserInfo.GetCheckInInfo.FetchFriendsInlocationEqualCheckin(ListBoxFriendsInLocation, locationInput);
}
private void loadCheckInInformation()
{
User selectedFriend = new User();
Checkin selectedCheckIn = new Checkin();
if (ListBoxFriendsInLocation.SelectedItem != null)
{
string selectedFriendName = ListBoxFriendsInLocation.SelectedItem.ToString();
m_LogIn.LoggedUserInfo.GetCheckInInfo.LoadCheckInInformation(selectedFriendName, ref selectedFriend, ref selectedCheckIn);
fetchCheckInInfo(selectedFriend, selectedCheckIn);
}
else
{
MessageBox.Show("Please choose location first!");
}
}
private void fetchCheckInInfo(User i_selectedFriendName, Checkin i_selectedCheckIn)
{
try
{
labelName.Text = "Friend Name: " + i_selectedFriendName.Name;
labelLocation.Text = "Location: " + i_selectedCheckIn.Place.Name;
labelDate.Text = "Date and Time: " + i_selectedCheckIn.UpdateTime.ToString();
if (i_selectedCheckIn.PictureURL != null)
{
pictureBoxCheckinFriendPicture.Load(i_selectedCheckIn.PictureURL);
}
else
{
pictureBoxCheckinFriendPicture.Image = pictureBoxCheckinFriendPicture.ErrorImage;
}
}
catch
{
labelName.Text = "Friend Name: ";
labelLocation.Text = "Location: ";
labelDate.Text = "Date and Time: ";
pictureBoxCheckinFriendPicture.Image = pictureBoxCheckinFriendPicture.ErrorImage;
MessageBox.Show("There is no information!");
}
}
private void resetCheckInInfo()
{
textBoxLocation.Clear();
ListBoxFriendsInLocation.Items.Clear();
labelName.Text = "Friend Name: ";
labelLocation.Text = "Location: ";
labelDate.Text = "Date and Time: ";
pictureBoxCheckinFriendPicture.Image = null;
}
private void buttonReset_Click(object sender, EventArgs e)
{
resetCheckInInfo();
}
private void buttonShowCheckInInformation_Click(object sender, EventArgs e)
{
loadCheckInInformation();
}
private void buttonSearchLocation_Click(object sender, EventArgs e)
{
fetchFriendsInlocationEqualCheckin();
}
/// <summary>
/// feature 2 page:
/// </summary>
private void fetchUserMostLikedPictures(bool i_IsFirstFetch)
{
int SizeOfDicPicAndLikesByValueOrder = m_LogIn.LoggedUserInfo.GetPhotosAndLikesInfo[0].SizeOfPhotosAndLikesByValueOrder;
////Tempale Method subclasses
int classMethodToActive = 0;
if (SizeOfDicPicAndLikesByValueOrder >= 3)
{
if(!i_IsFirstFetch)
{
classMethodToActive = 1;
}
////Fetch Photos
m_LogIn.LoggedUserInfo.GetPhotosAndLikesInfo[classMethodToActive].FetchUserMostLikedPictures(pictureBoxMostLikedPhoto1, pictureBoxMostLikedPhoto2, pictureBoxMostLikedPhoto3);
////Show Likes
m_LogIn.LoggedUserInfo.GetPhotosAndLikesInfo[classMethodToActive].ShowLikes(label1Place, label2Place, label3Place, labelnumber1, labelNumber2, labelNumber3);
buttonDiscoverMostLikedPhotos.Enabled = false;
buttonChangeProfilePic.Enabled = true;
buttonChangePic1.Enabled = true;
buttonChangePic2.Enabled = true;
buttonChangePic3.Enabled = true;
buttonHidePictures.Enabled = true;
}
else
{
MessageBox.Show("You need to have at least 3 photos on facebook");
}
}
private void buttonDiscoverMostLikedPhotos_Click(object sender, EventArgs e)
{
m_countButtonDiscoverClicked++;
bool isDiscoverClickedOnce = true;
if (m_countButtonDiscoverClicked > 1)
{
isDiscoverClickedOnce = false;
}
fetchUserMostLikedPictures(isDiscoverClickedOnce);
}
private void changeProfilePic()
{
bool isProfileChanged = true;
if (checkBoxPic1.Checked && !checkBoxPic2.Checked && !checkBoxPic3.Checked)
{
m_LogIn.LoggedUserInfo.UserProfileInfo.ChangeProfilePic(pictureBoxProfilePicture, pictureBoxMostLikedPhoto1.ImageLocation);
isProfileChanged = true;
}
else if (!checkBoxPic1.Checked && checkBoxPic2.Checked && !checkBoxPic3.Checked)
{
m_LogIn.LoggedUserInfo.UserProfileInfo.ChangeProfilePic(pictureBoxProfilePicture, pictureBoxMostLikedPhoto2.ImageLocation);
isProfileChanged = true;
}
else if (!checkBoxPic1.Checked && !checkBoxPic2.Checked && checkBoxPic3.Checked)
{
m_LogIn.LoggedUserInfo.UserProfileInfo.ChangeProfilePic(pictureBoxProfilePicture, pictureBoxMostLikedPhoto3.ImageLocation);
isProfileChanged = true;
}
else
{
MessageBox.Show("Please select only one picture!");
isProfileChanged = false;
}
if (isProfileChanged)
{
MessageBox.Show("Your profile picture has changed!");
}
}
private void hideAllInfoAndSaveit()
{
string pic1Url = pictureBoxMostLikedPhoto1.ImageLocation;
string pic2Url = pictureBoxMostLikedPhoto2.ImageLocation;
string pic3Url = pictureBoxMostLikedPhoto3.ImageLocation;
////Save the photos before the hiding action
m_LogIn.LoggedUserInfo.GetPhotosAndLikesInfo[1].SaveCurrPicBoxPicsUrl(pictureBoxMostLikedPhoto1.ImageLocation, pictureBoxMostLikedPhoto2.ImageLocation, pictureBoxMostLikedPhoto3.ImageLocation);
////Hide information
pictureBoxMostLikedPhoto1.Image = null;
pictureBoxMostLikedPhoto2.Image = null;
pictureBoxMostLikedPhoto3.Image = null;
label1Place.Text = "1";
label2Place.Text = "2";
label3Place.Text = "3";
labelnumber1.Text = "1";
labelNumber2.Text = "2";
labelNumber3.Text = "3";
buttonChangePic1.Enabled = false;
buttonChangePic2.Enabled = false;
buttonChangePic3.Enabled = false;
buttonChangeProfilePic.Enabled = false;
buttonDiscoverMostLikedPhotos.Enabled = true;
}
private void buttonHidePictures_Click(object sender, EventArgs e)
{
buttonDiscoverMostLikedPhotos.Text = "Restore !";
buttonHidePictures.Enabled = false;
hideAllInfoAndSaveit();
}
private void buttonChangeProfilePic_Click_1(object sender, EventArgs e)
{
changeProfilePic();
}
private void buttonChangePic1_Click(object sender, EventArgs e)
{
m_LogIn.LoggedUserInfo.GetPhotosAndLikesInfo[0].ChangePicInPicBox1(pictureBoxMostLikedPhoto1, labelnumber1, label1Place);
}
private void buttonChangePic2_Click(object sender, EventArgs e)
{
m_LogIn.LoggedUserInfo.GetPhotosAndLikesInfo[0].ChangePicInPicBox2(pictureBoxMostLikedPhoto2, labelNumber2, label2Place);
}
private void buttonChangePic3_Click(object sender, EventArgs e)
{
m_LogIn.LoggedUserInfo.GetPhotosAndLikesInfo[0].ChangePicInPicBox3(pictureBoxMostLikedPhoto3, labelNumber3, label3Place);
}
}
}