-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFormattingPage.m
397 lines (330 loc) · 14.8 KB
/
FormattingPage.m
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
//
// FormattingPage.m
//
//
// Created by Developer on 05/04/16.
//
//
#import "FormattingPage.h"
@implementation FormattingPage
@end
//
// ContactViewController.m
// SimpleMessaging
//
// Created by Subhasis Saha on 17/03/15.
// Copyright (c) 2015 Technologies33. All rights reserved.
#import "ContactViewController.h"
#import "SettingViewController.h"
#import "SendMessageViewController.h"
#import "InviteContactViewController.h"
#import "MessageListViewController.h"
#import "EditProfileViewController.h"
#import "ChangePasscodeViewController.h"
#import "CommunityBoardViewController.h"
#import "LeaderBoardViewController.h"
#import "ContactTVCell.h"
#import "ContactData.h"
#import "SVProgressHUD.h"
#import "ContactManager.h"
#import "ContactViewController.h"
#import "DAKeyboardControl.h"
NSInteger const kTagUnblockUserAlert = 101;
@interface ContactViewController ()
{
NSMutableArray * arrContactList;
NSMutableArray * arrSelectedContacts;
}
@end
@implementation ContactViewController
#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [arrContactList count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"ContactTVCell";
ContactTVCell *cell = (ContactTVCell*) [tableView dequeueReusableCellWithIdentifier: cellIdentifier];
//set
[cell.btnCheckbox setHidden:YES];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
[cell.btnCheckbox addTarget:self action:@selector(btnCheckBoxTapped:) forControlEvents:UIControlEventTouchUpInside];
[cell.btnCheckbox setHidden:NO];
[cell.btnCheckbox setTag:indexPath.row];
//
for (ContactData * contact in arrSelectedContacts) {
if ([objContactData.memberid isEqualToString:contact.memberid]) {
[cell.btnCheckbox setSelected:YES];
break;
}
else
[cell.btnCheckbox setSelected:NO];
}
}
return cell;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
if (self.pageWorkingType == enumForshowingBlockedFriend) {
return nil;
}
return _footerView;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
if (self.pageWorkingType == enumForshowingBlockedFriend) return 0.0f;
return 70.0f;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
// you need to implement this method too or nothing will work:
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Remove the row from data model
//sif showing
[_contactManager block:(self.pageWorkingType != enumForshowingBlockedFriend) contact:arrContactList[indexPath.row]];
[arrContactList removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
[tableView reloadData];
}
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewCellEditingStyleDelete;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES; //tableview must be editable or nothing will work...
}
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
if (self.pageWorkingType == enumForshowingBlockedFriend) {
return @"Unblock";
}
return @"Block";
}
#pragma mark - TableView cell Button Action
- (void) btnCheckBoxTapped:(UIButton *) sender {
ContactData * objContactData = [arrContactList objectAtIndex:sender.tag];
if ([sender isSelected]) {
[sender setSelected:NO];
[arrSelectedContacts removeObject:objContactData];
}
else {
[sender setSelected:YES];
[arrSelectedContacts addObject:objContactData];
}
}
#pragma mark - SettingViewControllerDelegate Methods
- (void) performActionForEnum:(SettingActionType)actionEnum
{
[self setCurrentActionType:actionEnum];
switch (actionEnum)
{
case enumUsername:
break;
case enumFindFriend:
{
[self NavigateToContactViewControllerForPageWorkingType:enumForFindingFriend];
break;
}
case enumInvite:
{
[self NavigateToInviteContactViewController];
break;
}
case enumEditProfile:
{
[self NavigateToEditProfileViewController];
break;
}
case enumSentCount:
break;
case enumReceivedCount:
break;
case enumChangePasscode:
{
[self NavigateToChangePasscodeViewController];
break;
}
case enumContactUs:
break;
case enumRating:
break;
case enumCommunityBoard:
{
[self NavigateToCommunityBoardViewController];
break;
}
case enumLeaderBoard:
{
[self NavigateToLeaderBoardViewController];
break;
}
case enumUnblock://open contact list with contact you have blocked (or create a new page)
{
[self NavigateToContactViewControllerForPageWorkingType:enumForshowingBlockedFriend];
break;
}
case enumAboutUS://open contact list with contact you have blocked (or create a new page)
{
InformationTableViewController * ContactVC = (InformationTableViewController *)[[UIStoryboard storyboardWithName:keyStoryBoardName bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier: NSStringFromClass([InformationTableViewController class])];
[self.navigationController pushViewController:ContactVC animated:YES];
break;
}
case enumLogout:
[self.navigationController popToRootViewControllerAnimated:NO];
break;
default:
break;
}
}
#pragma mark - Navigation
- (void) NavigateToContactViewControllerForPageWorkingType:(PageWorkingType)pageWorkingType
{
ContactViewController * ContactVC = (ContactViewController *)[[UIStoryboard storyboardWithName:keyStoryBoardName bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier: NSStringFromClass([ContactViewController class])];
[ContactVC setPageWorkingType:pageWorkingType];
[ContactVC setCurrentActionType:self.currentActionType];
[self.navigationController pushViewController:ContactVC animated:YES];
}
- (void) NavigateToInviteContactViewController
{
InviteContactViewController * ContactListVC = (InviteContactViewController *)[[UIStoryboard storyboardWithName:keyStoryBoardName bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier: NSStringFromClass([InviteContactViewController class])];
[ContactListVC setCurrentActionType:self.currentActionType];
[self.navigationController pushViewController:ContactListVC animated:NO];
}
- (void) NavigateToEditProfileViewController
{
EditProfileViewController * EditProfileVC = (EditProfileViewController *)[[UIStoryboard storyboardWithName:keyStoryBoardName bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier: NSStringFromClass([EditProfileViewController class])];
[EditProfileVC setCurrentActionType:self.currentActionType];
[self.navigationController pushViewController:EditProfileVC animated:NO];
}
- (void) NavigateToChangePasscodeViewController
{
ChangePasscodeViewController* ChangePasscodeVC = (ChangePasscodeViewController *)[[UIStoryboard storyboardWithName:keyStoryBoardName bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier: NSStringFromClass([ChangePasscodeViewController class])];
[self.navigationController pushViewController:ChangePasscodeVC animated:NO];
}
- (void) NavigateToMessageListViewController
{
MessageListViewController * MessageListVC = (MessageListViewController *)[[UIStoryboard storyboardWithName:keyStoryBoardName bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier: NSStringFromClass([MessageListViewController class])];
[self.navigationController pushViewController:MessageListVC animated:YES];
}
- (void) NavigateToCommunityBoardViewController
{
CommunityBoardViewController * CommunityBoardVC = (CommunityBoardViewController *)[[UIStoryboard storyboardWithName:keyStoryBoardName bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier: NSStringFromClass([CommunityBoardViewController class])];
[CommunityBoardVC setNavigateFrom:enumNavigateFromOther];
[CommunityBoardVC setCurrentActionType:self.currentActionType];
[self.navigationController pushViewController:CommunityBoardVC animated:YES];
}
- (void) NavigateToLeaderBoardViewController
{
LeaderBoardViewController * LeaderBoardVC = (LeaderBoardViewController *)[[UIStoryboard storyboardWithName:keyStoryBoardName bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier: NSStringFromClass([LeaderBoardViewController class])];
[LeaderBoardVC setCurrentActionType:self.currentActionType];
[self.navigationController pushViewController:LeaderBoardVC animated:YES];
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
#pragma mark - IBAction Method
- (IBAction)btnGoToSetting:(UIButton *)sender
{
SettingViewController * SettingVC = (SettingViewController *)[[UIStoryboard storyboardWithName:keyStoryBoardName bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier: NSStringFromClass([SettingViewController class])];
[SettingVC setDelegate:self];
[SettingVC setLastAction:self.currentActionType];
UINavigationController * navcontroller = [[UINavigationController alloc] initWithRootViewController:SettingVC];
[navcontroller setNavigationBarHidden:YES];
[navcontroller setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentViewController:navcontroller animated:YES completion:nil];
}
- (IBAction)btnDone_Tapped:(UIButton *)sender
{
if ([arrSelectedContacts count])
{
SendMessageViewController * SendMessageVC = (SendMessageViewController *)[[UIStoryboard storyboardWithName:keyStoryBoardName bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier: NSStringFromClass([SendMessageViewController class])];
[SendMessageVC setMessageType:self.messageType];
[SendMessageVC setConversationType:self.conversationType];
if (self.conversationType == enumExistingConversation)
[SendMessageVC setObjReceivedMessages:self.objReceivedMessages];
else
[SendMessageVC setObjMessageData:self.objMessageData];
[SendMessageVC setSelectedContacts:arrSelectedContacts];
[self.navigationController pushViewController:SendMessageVC animated:YES];
}
else
Show_ToastView(@"Please select atleast one contact");
}
- (IBAction)btnBack_Tapped:(UIButton *)sender {
[self setCurrentActionType:0];
[self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - UITextFieldDelegate
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
return YES;
}
- (void)textFieldDidBeginEditing:(UITextField *)textField {
CGSize size = _contactListTableView.contentSize;
size.height += 120.0f;
[_contactListTableView setContentSize:size];
[textField setTextAlignment:NSTextAlignmentCenter];
[_imgAdd setHidden:YES];
}
- (void)textFieldDidEndEditing:(UITextField *)textField {
CGSize size = _contactListTableView.contentSize;
size.height -= 120.0f;
[_contactListTableView setContentSize:size];
if ([textField.text length]) [textField setTextAlignment:NSTextAlignmentCenter];
else [_imgAdd setHidden:NO];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
//service call for search
if ([textField.text length]) [_contactManager searchContacts:textField.text];
return YES;
}
#pragma mark - ContactManagerDelegate
- (void) contactManager : (ContactManager *) manager blocked : (BOOL) blocked contact : (ContactData *) contact {
[_refreshControl endRefreshing];
if (!blocked)
[self loadTableViewWithContactList];
}
- (void) contactManager : (ContactManager *) manager
searched: (NSString *) searchedTerm
contacts : (NSArray *) contactArray {
[_refreshControl endRefreshing];
if (contactArray!=nil && contactArray.count) {
_serchedUser = [contactArray lastObject];
//if returned user have blocked this user don't show him in results just act user not found
if ([_serchedUser[@"blockedMe"] integerValue] == 1) {
Show_ToastView(@"Not found!");
_serchedUser = nil;
return;
}
//if this user have blocked returned user prompt him to ask if he wants to unblock returned user
if ([_serchedUser[@"blocked"] integerValue] == 1) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Blocked User!", nil)
message:NSLocalizedString(@"You have blocked this user.", nil)
delegate:self
cancelButtonTitle:NSLocalizedString(@"Cancel", nil)
otherButtonTitles:NSLocalizedString(@"Unblock", nil), nil];
alert.tag = kTagUnblockUserAlert;
[alert show];
}
else{
[SVProgressHUD showSuccessWithStatus:nil];
[self loadTableViewWithContactList];
}
}else{
Show_ToastView(@"Not found!");
}
}
//Alert Delegate
- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
switch (alertView.tag) {
case kTagUnblockUserAlert:
if (buttonIndex == 1) {
ContactData *contactData = (ContactData *)[Utility getRecord:NSStringFromClass([ContactData class]) where:[NSString stringWithFormat:@"memberid = '%@'", _serchedUser[@"memberid"]]];
[_contactManager block:NO contact:contactData];
}
break;
default:
break;
}
}
@end