Advertisement
Guest User

Untitled

a guest
Aug 26th, 2015
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 58.57 KB | None | 0 0
  1. //
  2. // CommentViewController.m
  3. // iJoomer
  4. //
  5. // Created by Tailored Solutions on 21/09/12.
  6. // Copyright 2013 Tailored Solutions. All rights reserved.
  7. //
  8.  
  9. #import "CommentViewController.h"
  10. #import "Wall.h"
  11. #import "Comment.h"
  12. #import "Like.h"
  13. #import "ApplicationData.h"
  14. #import "TableCellOwner.h"
  15. #import "Image.h"
  16. #import "CommentCell.h"
  17. #import "User.h"
  18. #import <QuartzCore/QuartzCore.h>
  19. #import "Event.h"
  20. #import "JomCommentCell.h"
  21. #import "LoginViewController.h"
  22. #import "Jomsocial.h"
  23. #import "JoomlaRegistration.h"
  24. #import "Core_joomer.h"
  25. #import "GlobalObjects.h"
  26. #import "MainPageViewController.h"
  27. #import "User.h"
  28. #import "FindFirstResponder.h"
  29. #import "iJoomerAppDelegate.h"
  30. #import "VoiceoverView.h"
  31. #import <MediaPlayer/MediaPlayer.h>
  32. #import <AVFoundation/AVFoundation.h>
  33. #import "commentListCell.h"
  34. #import "NSString+Emoticonizer.h"
  35.  
  36. static NSString *kCellIdentifier = @"CommentCell";
  37. static NSString *kCellIdentifier1 = @"JomCommentCell";
  38. static NSString *kCellIdentifiercommentListCell = @"commentListCell";
  39.  
  40.  
  41. @implementation CommentViewController
  42.  
  43. static int width = 250;
  44. static int posx = 40;
  45.  
  46. @synthesize selectedWall;
  47. @synthesize userDetail;
  48. @synthesize imageDownloadsInProgress;
  49. @synthesize group;
  50. @synthesize event;
  51. @synthesize btnSend;
  52. @synthesize txtComment;
  53. @synthesize btnWriteComment;
  54.  
  55. #pragma mark --
  56. #pragma mark viewDidLoad
  57.  
  58. - (void)viewDidLoad {
  59. [super viewDidLoad];
  60. self->pullTable = tableView;
  61. [self addPullToRefreshHeader];
  62. [spinner startAnimating];
  63. likeArray = [[NSMutableArray alloc]init ];
  64. commentArray = [[NSMutableArray alloc]init];
  65. cellOwner = [[TableCellOwner alloc] init];
  66. self.imageDownloadsInProgress = [NSMutableDictionary dictionary];
  67. multipleDownloadRecord = [[NSMutableDictionary alloc] init];
  68.  
  69. UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"button_back",@"") style:UIBarButtonItemStyleBordered target:nil action:nil];
  70. self.navigationItem.backBarButtonItem = backButton;
  71. [backButton release];
  72. NSLog(@"Edw einai auto pou 8es");
  73.  
  74. textView.layer.cornerRadius = 14;
  75. textView.layer.borderColor = [[UIColor grayColor] CGColor];
  76. textView.layer.borderWidth = 1;
  77. backImg.image = [UIImage imageNamed:[ApplicationData sharedInstance].bgImage];
  78. lblLikes.textColor= [ApplicationData sharedInstance].tintColor;
  79. //lblLikes.font = [UIFont boldSystemFontOfSize:14];
  80. [tableView setBackgroundColor:[UIColor clearColor]];
  81. [btncomment setTitle:NSLocalizedString(@"Comment",@"Comment") forState:UIControlStateNormal];
  82. txtComment.delegate = self;
  83. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
  84. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];
  85. [[NSNotificationCenter defaultCenter] addObserver:self
  86. selector:@selector(movieFinished:)
  87. name:MPMoviePlayerPlaybackDidFinishNotification
  88. object:mp];
  89.  
  90. self.pageNo = 1;
  91. self.hasPrev = 0;
  92. }
  93.  
  94. -(void)viewWillAppear:(BOOL)animated {
  95. [super viewWillAppear:YES];
  96. btnReportContent.hidden = YES;
  97. btnReport.hidden = YES;
  98. self.title = @"";
  99. [spinner startAnimating];
  100. [spinner setBackgroundColor:palleteBlue];
  101. spinner.layer.cornerRadius = 8;
  102. spinner.layer.masksToBounds = YES;
  103. [btnSend setBackgroundColor:palletePurple];
  104. btnSend.layer.cornerRadius = 8;
  105. btnSend.layer.masksToBounds = YES;
  106. //layer for Send Button
  107. CALayer *imgLayerSend = [btnSend layer];
  108. [btnSend setBackgroundColor:palletePurple];
  109. [imgLayerSend setMasksToBounds:YES];
  110. [imgLayerSend setCornerRadius:3.0];
  111. [imgLayerSend setBorderWidth:0.0];
  112. [imgLayerSend setBorderColor:[[UIColor clearColor] CGColor]];
  113.  
  114. txtComment.layer.cornerRadius = 4;
  115. txtComment.layer.masksToBounds = YES;
  116.  
  117. //tablist
  118. //##########################################################################################################
  119. iJoomerAppDelegate *appdelegate = (iJoomerAppDelegate *) [[UIApplication sharedApplication]delegate];
  120. NSMutableArray *arr = [[NSMutableArray alloc] init];
  121. arr = [ApplicationData sharedInstance].tabList;
  122. if ([arr count] == 0) {
  123. isTabbarHidden = YES;
  124. }
  125. else {
  126. isTabbarHidden = NO;
  127. }
  128. appdelegate.viewTop.hidden = NO;
  129. appdelegate.SelfViewcontroller = self;
  130. [appdelegate TabReset];
  131. //##########################################################################################################
  132.  
  133. self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  134. Voiceover.Commentcontroller = self;
  135. [Voiceover intialize];
  136.  
  137. if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  138. CGSize result = [[UIScreen mainScreen] bounds].size;
  139. if(result.height == 480) {
  140. if (isTabbarHidden == YES) {
  141. Voiceover.frame = CGRectMake(5, 360, Voiceover.frame.size.width, Voiceover.frame.size.height);
  142. tableView.frame = CGRectMake(5, 0, 310, 360);
  143.  
  144. }
  145. else {
  146.  
  147. Voiceover.frame = CGRectMake(5, 315, Voiceover.frame.size.width, Voiceover.frame.size.height);
  148. tableView.frame = CGRectMake(5, 0, 310, 310);
  149.  
  150. }
  151. }
  152. else if(result.height == 568) {
  153. if (isTabbarHidden == YES) {
  154.  
  155. Voiceover.frame = CGRectMake(5, 445, Voiceover.frame.size.width
  156. , Voiceover.frame.size.height);
  157. tableView.frame = CGRectMake(5, 0, 310, 445);
  158.  
  159.  
  160. }
  161. else {
  162.  
  163. Voiceover.frame = CGRectMake(5, 400, Voiceover.frame.size.width
  164. , Voiceover.frame.size.height);
  165. tableView.frame = CGRectMake(5, 0, 310, 400);
  166.  
  167. } // iPhone 5
  168. }
  169. }
  170. [btnWriteComment setTitle:NSLocalizedString(@"write_comment", @"") forState:UIControlStateNormal];
  171. [btnSend setTitleColor:[ApplicationData sharedInstance].textcolorWhite forState:UIControlStateNormal];
  172. [Voiceover setBackgroundColor:palleteBlue];
  173. if(self.pageNo >1){
  174. self.hasPrev = 1;
  175. }
  176. }
  177.  
  178.  
  179. - (IBAction)WriteCommentButtonPressed{
  180. btnWriteComment.hidden = YES;
  181. [txtComment becomeFirstResponder];
  182. if ([[[UIDevice currentDevice]systemVersion]floatValue] >= 8.0) {
  183. if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
  184. {
  185. CGSize result = [[UIScreen mainScreen] bounds].size;
  186. if(result.height == 480)
  187. {
  188. Voiceover.frame = CGRectMake(5, 110, Voiceover.frame.size.width
  189. , Voiceover.frame.size.height);
  190.  
  191. }
  192. if(result.height == 568)
  193. {
  194. Voiceover.frame = CGRectMake(5,200, Voiceover.frame.size.width
  195. , Voiceover.frame.size.height);
  196.  
  197. }
  198. }
  199.  
  200. }
  201.  
  202. else{
  203. if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
  204. {
  205. CGSize result = [[UIScreen mainScreen] bounds].size;
  206. if(result.height == 480)
  207. {
  208. Voiceover.frame = CGRectMake(5, 150, Voiceover.frame.size.width
  209. , Voiceover.frame.size.height);
  210.  
  211. }
  212. if(result.height == 568)
  213. {
  214. Voiceover.frame = CGRectMake(5,240, Voiceover.frame.size.width
  215. , Voiceover.frame.size.height);
  216.  
  217. }
  218. }
  219. }
  220. }
  221.  
  222.  
  223. -(void)voiceoverHide{
  224. if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  225. CGSize result = [[UIScreen mainScreen] bounds].size;
  226. if(result.height == 480) {
  227. if (isTabbarHidden == YES) {
  228. Voiceover.frame = CGRectMake(5, 360, Voiceover.frame.size.width, Voiceover.frame.size.height);
  229. tableView.frame = CGRectMake(5, 0, 310, 360);
  230. }
  231. else {
  232. Voiceover.frame = CGRectMake(5, 315, Voiceover.frame.size.width, Voiceover.frame.size.height);
  233. tableView.frame = CGRectMake(5, 0, 310, 310);
  234. }
  235. }
  236. else if(result.height == 568) {
  237. if (isTabbarHidden == YES) {
  238. Voiceover.frame = CGRectMake(5, 445, Voiceover.frame.size.width
  239. , Voiceover.frame.size.height);
  240. tableView.frame = CGRectMake(5, 0, 310, 445);
  241. }
  242. else {
  243. Voiceover.frame = CGRectMake(5, 400, Voiceover.frame.size.width
  244. , Voiceover.frame.size.height);
  245. tableView.frame = CGRectMake(5, 0, 310, 400);
  246. } // iPhone 5
  247. }
  248. }
  249.  
  250. }
  251.  
  252. - (void) viewDidAppear:(BOOL)animated {
  253. [super viewDidAppear:animated];
  254. if ([selectedWall.commentList count] > 0) {
  255. [commentArray addObjectsFromArray: selectedWall.commentList];
  256. if ([selectedWall.likeList count] > 0) {
  257. [self performSelectorOnMainThread:@selector(setData) withObject:nil waitUntilDone:NO];
  258. [tableView reloadData];
  259.  
  260. }else {
  261. [self fetchLikes];
  262. }
  263. } else {
  264. [self fetchComments];
  265. [self fetchLikes];
  266. }
  267. // [self setData];
  268. }
  269.  
  270. #pragma mark --
  271. #pragma mark setData & requestCompleted
  272.  
  273. -(void)fetchLikes {
  274. NSMutableDictionary *postVariables = [[NSMutableDictionary alloc]init];
  275. if (selectedWall.likes > 0) {
  276. [postVariables setObject:[NSString stringWithFormat:@"%d",selectedWall.wallId] forKey:@"wallID"];
  277. NSString *jsonString = [Jomsocial CreateDictionary_joomsocial:@"wall" ExtTask:@"getLikes" TaskdataDictionary:postVariables Imagedata:nil];
  278.  
  279. NSDictionary *dict = [JoomlaRegistration JoomSocialDictionary:jsonString Imagedata:nil];
  280. // newWall = [GlobalObjects Share:dict];
  281. if ([dict objectForKey:TAG_CODE]) {
  282. likeArray = [GlobalObjects Like:dict];
  283. //DLog(@"arr:%@",likeArray);
  284. selectedWall.likeList = [likeArray retain];
  285. [ApplicationData sharedInstance].errorCode = [[dict objectForKey:TAG_CODE] intValue];
  286.  
  287. currentRequestType = jlikeUnlikeQuery;
  288. [self requestCompleted];
  289. }
  290. } else {
  291. [spinner stopAnimating];
  292. tableView.hidden = NO;
  293. [self setData];
  294. [self stopLoading];
  295. }
  296. }
  297.  
  298. -(void)fetchComments {
  299. NSMutableDictionary *postVariables = [[NSMutableDictionary alloc]init];
  300. if (selectedWall.comments > 0) {
  301.  
  302. [postVariables setObject:[NSString stringWithFormat:@"%d",selectedWall.wallId] forKey:@"wallID"];
  303. [postVariables setObject:[NSString stringWithFormat:@"%d",self.pageNo] forKey:@"pageNo"];
  304. NSString *jsonString = [Jomsocial CreateDictionary_joomsocial:@"wall" ExtTask:@"getComments" TaskdataDictionary:postVariables Imagedata:nil];
  305.  
  306. NSDictionary *dict = [JoomlaRegistration JoomSocialDictionary:jsonString Imagedata:nil];
  307. DLog(@"response : %@",dict);
  308. [ApplicationData sharedInstance].errorCode = [[dict objectForKey:TAG_CODE] intValue];
  309. if ([ApplicationData sharedInstance].errorCode == 204) {
  310. [selectedWall.commentList removeAllObjects];
  311. [commentArray removeAllObjects];
  312. selectedWall.comments = 0;
  313. }
  314. if ([ApplicationData sharedInstance].errorCode != 200) {
  315. [self fetchLikes];
  316. } else {
  317. commentArray = [GlobalObjects Comments:dict];
  318. [selectedWall.commentList addObjectsFromArray: commentArray];
  319. selectedWall.comments = selectedWall.comments + [commentArray count];
  320. currentRequestType = jGeneralQuery;
  321. [self requestCompleted];
  322. }
  323. }
  324. else {
  325. [spinner stopAnimating];
  326. tableView.hidden = NO;
  327. [self setData];
  328. [self stopLoading];
  329. }
  330.  
  331. }
  332.  
  333. - (void)setData {
  334. lblHeader.textColor = [ApplicationData sharedInstance].textcolorhead;
  335. lblContent.textColor = [ApplicationData sharedInstance].textcolorhead;
  336. txtContent.textColor = [ApplicationData sharedInstance].textcolorhead;
  337.  
  338. lblTime.textColor = [ApplicationData sharedInstance].textcolortime;
  339. lblLikes.textColor= [ApplicationData sharedInstance].textcolor;
  340.  
  341. float height = 0;
  342. float y = 10;
  343. if (event) {
  344. // self.title = event.title;
  345. }
  346. else {
  347. // self.title = selectedWall.title;
  348. }
  349.  
  350. lblContent.text = selectedWall.content;
  351. lblContent.text = [NSString emoticonizedString: selectedWall.content];
  352. NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData:[lblContent.text dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil ];
  353. lblContent.attributedText = attributedString;
  354.  
  355. txtContent.text = selectedWall.content;
  356. lblHeader.font = [ApplicationData sharedInstance].header7;
  357. lblContent.font= [ApplicationData sharedInstance].header5;
  358. //lblLikes.font= [ApplicationData sharedInstance].header7;
  359. lblTime.font= [ApplicationData sharedInstance].header6;
  360.  
  361.  
  362. lblHeader.text = selectedWall.title;
  363. lblHeader.text = [NSString emoticonizedString: selectedWall.title];
  364. lblHeader.text = [lblHeader.text stringByAppendingString:[NSString stringWithFormat:@"<style>body{font-family: 'Helvetica'; font-size:13.0px;}</style>"]];
  365. NSAttributedString *attributedString1 = [[NSAttributedString alloc] initWithData:[lblHeader.text dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil ];
  366. lblHeader.attributedText = attributedString1;
  367.  
  368.  
  369. NSLog(@"selectedWall.title %@",selectedWall.title);
  370. NSLog(@"selectedWall.content %@",selectedWall.content);
  371.  
  372.  
  373.  
  374. lblTime.text = [NSString stringWithFormat:@"%@", selectedWall.date];
  375. lblLikes.text = @"";
  376.  
  377. NSString *likeString = @"";
  378. for (Like *record in selectedWall.likeList) {
  379. if (likeString == @"") {
  380. likeString = record.name;
  381. } else {
  382. likeString = [NSString stringWithFormat:@"%@, %@", likeString, record.name];
  383. }
  384. }
  385.  
  386. if (likeString != @"") {
  387. lblLikes.text = [NSString stringWithFormat:@"%@ %@-", likeString, NSLocalizedString(@"like_this_comment", @"xyz Person like this comment")];
  388. }
  389. if ([selectedWall.title rangeOfString:@"{voice}"].location != NSNotFound) {
  390. Voiceview.hidden = NO;
  391. NSString *strTitle = selectedWall.title;
  392. strTitle = [strTitle stringByReplacingOccurrencesOfString: @"{voice}" withString:@""];
  393. strTitle = [strTitle stringByReplacingOccurrencesOfString: @"{/voice}" withString:@""];
  394. NSArray *arr = [strTitle componentsSeparatedByString:@"&"];
  395. selectedWall.playVoice = [arr objectAtIndex:0];
  396. lblSecond.text = [NSString stringWithFormat:@"%@ s",[arr objectAtIndex:1]];
  397.  
  398. lblHeader.hidden = YES;
  399. }else{
  400. Voiceview.hidden = YES;
  401. lblHeader.hidden = NO;
  402. }
  403.  
  404. if ([selectedWall.content rangeOfString:@"{voice}"].location != NSNotFound) {
  405. VoiceviewContent.hidden = NO;
  406. NSString *strTitle = selectedWall.content;
  407. strTitle = [strTitle stringByReplacingOccurrencesOfString: @"{voice}" withString:@""];
  408. strTitle = [strTitle stringByReplacingOccurrencesOfString: @"{/voice}" withString:@""];
  409. NSArray *arr = [strTitle componentsSeparatedByString:@"&"];
  410. selectedWall.playVoiceContent = [arr objectAtIndex:0];
  411. lblSecondContent.text = [NSString stringWithFormat:@"%@ s",[arr objectAtIndex:1]];
  412. lblContent.hidden = YES;
  413. txtContent.hidden = YES;
  414. VoiceviewContent.hidden = NO;
  415.  
  416. }else{
  417. VoiceviewContent.hidden = YES;
  418. lblContent.hidden = NO;
  419. txtContent.hidden = NO;
  420. }
  421.  
  422.  
  423.  
  424. height = [self getTextSize:lblHeader.text Font:lblHeader.font MaxWidth:280];
  425. lblHeader.frame = CGRectMake(posx, y, width, height);
  426. y += height+2;
  427.  
  428. if ([selectedWall.imageList count] > 0) {
  429. yPos = y;
  430. [self setImages];
  431. y = yPos;
  432. }
  433. height = [self getTextSize:lblContent.text Font:lblContent.font MaxWidth:255];
  434. if ([selectedWall.content rangeOfString:@"{voice}"].location != NSNotFound) {
  435. VoiceviewContent.frame = CGRectMake(posx, y, 45, 25);
  436.  
  437.  
  438. }else{
  439. if (height <= 90) {
  440. lblContent.frame = CGRectMake(posx, y, width, height+2);
  441. lblContent.hidden = NO;
  442. txtContent.hidden = YES;
  443. } else {
  444. height = MIN(90, height);
  445. //txtContent.font = [UIFont fontWithName:[ApplicationData sharedInstance].fontname size:13];
  446. txtContent.frame = CGRectMake(posx, y, width, height+2);
  447. lblContent.hidden = YES;
  448. txtContent.hidden = NO;
  449. }}
  450.  
  451. y += height+4;
  452. height = [self getTextSize:lblTime.text Font:lblTime.font MaxWidth:255];
  453. lblTime.frame = CGRectMake(posx, y, width, height);
  454. y += height+4;
  455. if (lblLikes.text.length > 0) {
  456. height = [self getTextSize:lblLikes.text Font:lblLikes.font MaxWidth:280];
  457. lblLikes.frame = CGRectMake(posx, y, width, height);
  458. y += height+4;
  459. }
  460. if (selectedWall.thumbImg) {
  461. thumbImg.image = selectedWall.thumbImg;
  462. }
  463. //tableView.hidden = YES;
  464. headerView.frame = CGRectMake(5, 0, 310, y);
  465. tableView.tableHeaderView = headerView;
  466. [tableView reloadData];
  467. [spinner stopAnimating];
  468. }
  469. - (IBAction) movieFinished: (id) sender {
  470. [mp stop];
  471.  
  472. }
  473. - (IBAction)PlayButtonPressed:(id)sender {
  474. // Make sure the audio is at the start of the stream.
  475. if(![sender isSelected]) {
  476.  
  477. NSString *strTitle = selectedWall.title;
  478. strTitle = [self stringBetweenString:@"{voice}" andString:@"{/voice}"];
  479. NSArray *arr = [strTitle componentsSeparatedByString:@"&"];
  480. selectedWall.playVoice = [arr objectAtIndex:0];
  481. [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
  482. [[AVAudioSession sharedInstance] setActive: YES error: nil];
  483. NSURL *url;
  484. url = [NSURL URLWithString:selectedWall.playVoice];
  485. DLog(@"url : %@",url);
  486. mp = [[MPMoviePlayerController alloc] initWithContentURL:url];
  487. [mp prepareToPlay];
  488. [mp play];
  489. DLog(@"Play...");
  490. }else{
  491. [mp stop];
  492. DLog(@"Stop...");
  493.  
  494. }
  495. [sender setSelected:![sender isSelected]];
  496.  
  497.  
  498. }
  499.  
  500. - (IBAction)PlayButtonPressed1:(id)sender {
  501. // Make sure the audio is at the start of the stream.
  502. if(![sender isSelected]) {
  503.  
  504. NSString *strTitle = selectedWall.content;
  505. strTitle = [self stringBetweenString1:@"{voice}" andString:@"{/voice}"];
  506. NSArray *arr = [strTitle componentsSeparatedByString:@"&"];
  507. selectedWall.playVoiceContent = [arr objectAtIndex:0];
  508. [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
  509. [[AVAudioSession sharedInstance] setActive: YES error: nil];
  510. NSURL *url;
  511. url = [NSURL URLWithString:selectedWall.playVoiceContent];
  512. DLog(@"url : %@",url);
  513. mp = [[MPMoviePlayerController alloc] initWithContentURL:url];
  514. [mp prepareToPlay];
  515. [mp play];
  516. DLog(@"Play1...");
  517. }else{
  518. [mp stop];
  519. DLog(@"Stop1...");
  520.  
  521. }
  522. [sender setSelected:![sender isSelected]];
  523.  
  524. }
  525.  
  526.  
  527. -(NSString*)stringBetweenString:(NSString*)start andString:(NSString*)end {
  528. NSRange startRange = [selectedWall.title rangeOfString:start];
  529. if (startRange.location != NSNotFound) {
  530. NSRange targetRange;
  531. targetRange.location = startRange.location + startRange.length;
  532. targetRange.length = [selectedWall.title length] - targetRange.location;
  533. NSRange endRange = [selectedWall.title rangeOfString:end options:0 range:targetRange];
  534. if (endRange.location != NSNotFound) {
  535. targetRange.length = endRange.location - targetRange.location;
  536. DLog(@"title : %@",selectedWall.title);
  537. return [selectedWall.title substringWithRange:targetRange];
  538. }
  539. }
  540. return nil;
  541. }
  542.  
  543. -(NSString*)stringBetweenString1:(NSString*)start andString:(NSString*)end1 {
  544. NSRange startRange = [selectedWall.content rangeOfString:start];
  545. if (startRange.location != NSNotFound) {
  546. NSRange targetRange;
  547. targetRange.location = startRange.location + startRange.length;
  548. targetRange.length = [selectedWall.content length] - targetRange.location;
  549. NSRange endRange = [selectedWall.content rangeOfString:end1 options:0 range:targetRange];
  550. if (endRange.location != NSNotFound) {
  551. targetRange.length = endRange.location - targetRange.location;
  552. DLog(@"title : %@",selectedWall.content);
  553. return [selectedWall.content substringWithRange:targetRange];
  554. }
  555. }
  556. return nil;
  557. }
  558.  
  559. - (IBAction)PlayCommentcontentButtonPressed:(id)sender {
  560. // Make sure the audio is at the start of the stream.
  561. if(![sender isSelected]) {
  562. Comment *record = [commentArray objectAtIndex:[sender tag]];
  563. newAddedComment = record;
  564. NSString *strTitle = record.commentText;
  565. strTitle = [self stringBetweenStringComment:@"{voice}" andString:@"{/voice}"];
  566. NSArray *arr = [strTitle componentsSeparatedByString:@"&"];
  567. record.playVoice = [arr objectAtIndex:0];
  568. [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
  569. [[AVAudioSession sharedInstance] setActive: YES error: nil];
  570. NSURL *url;
  571. url = [NSURL URLWithString:record.playVoice];
  572. DLog(@"url : %@",url);
  573. mp = [[MPMoviePlayerController alloc] initWithContentURL:url];
  574. [mp prepareToPlay];
  575. [mp play];
  576. DLog(@"Play...");
  577. }else{
  578. [mp stop];
  579. DLog(@"Stop...");
  580.  
  581. }
  582. [sender setSelected:![sender isSelected]];
  583.  
  584.  
  585. }
  586.  
  587. -(NSString*)stringBetweenStringComment:(NSString*)start andString:(NSString*)end {
  588.  
  589. NSRange startRange = [newAddedComment.commentText rangeOfString:start];
  590. if (startRange.location != NSNotFound) {
  591. NSRange targetRange;
  592. targetRange.location = startRange.location + startRange.length;
  593. targetRange.length = [newAddedComment.commentText length] - targetRange.location;
  594. NSRange endRange = [newAddedComment.commentText rangeOfString:end options:0 range:targetRange];
  595. if (endRange.location != NSNotFound) {
  596. targetRange.length = endRange.location - targetRange.location;
  597. DLog(@"title : %@",newAddedComment.commentText);
  598. return [newAddedComment.commentText substringWithRange:targetRange];
  599. }
  600. }
  601. return nil;
  602. }
  603.  
  604. -(void)approvalmsg{
  605. [self showAlert:NSLocalizedString(@"Success",@"") Content:NSLocalizedString(@"approval_msg", @"")];
  606.  
  607. }
  608.  
  609. -(void)jBadRequest{
  610. [self showAlert:NSLocalizedString(@"alert_error",@"Error title") Content:NSLocalizedString(@"Wrong Data.", @"")];
  611. }
  612.  
  613. -(void)jErroronServer{
  614. [self showAlert:NSLocalizedString(@"alert_error",@"Error title") Content:NSLocalizedString(@"Server Error.", @"")];
  615. }
  616.  
  617. -(void)jErrorMessage{
  618. [self showAlert:NSLocalizedString(@"alert_error",@"Error title") Content:@"No Such Request Found."];
  619. }
  620. -(void)jNoContent{
  621. [self showAlert:NSLocalizedString(@"alert_error",@"Error title") Content:NSLocalizedString(@"No Content Found.", @"")];
  622. }
  623.  
  624. -(void)jUnsupportedFile {
  625. [self showAlert:NSLocalizedString(@"alert_error",@"Error title") Content:NSLocalizedString(@"Unsupported File Type.", @"")];
  626. }
  627.  
  628. -(void)jInvalidData {
  629. [self showAlert:NSLocalizedString(@"alert_error",@"Error title") Content:NSLocalizedString(@"Upload Limit Exceeded.", @"")];
  630. }
  631.  
  632. -(void)jUserNameError {
  633. [self showAlert:NSLocalizedString(@"alert_error",@"Error title") Content:NSLocalizedString(@"Username Already Exists.", @"")];
  634. }
  635.  
  636. -(void)jEmailError {
  637. [self showAlert:NSLocalizedString(@"alert_error",@"Error title") Content:NSLocalizedString(@"Email Already Exists.", @"")];
  638. }
  639.  
  640. -(void)jFBOption {
  641. [self showAlert:NSLocalizedString(@"alert_error",@"Error title") Content:NSLocalizedString(@"Facebook User Not Found.", @"")];
  642. }
  643.  
  644. -(void)jReportedContent {
  645. [self showAlert:NSLocalizedString(@"alert_error",@"Error title") Content:NSLocalizedString(@"Permission Denied.", @"")];
  646. }
  647.  
  648. -(void)JPermissionError {
  649. txtComment.text = @"";
  650. [self showAlert:NSLocalizedString(@"alert_error",@"Error title") Content:NSLocalizedString(@"Restricted Access.", @"")];
  651. }
  652.  
  653. -(void)jDuplicateData {
  654. [self showAlert:NSLocalizedString(@"alert_error",@"Error title") Content:NSLocalizedString(@"Request already exists.", @"")];
  655. }
  656.  
  657. -(void)jWaitingForPermission {
  658. [self showAlert:NSLocalizedString(@"alert_error",@"Error title") Content:NSLocalizedString(@"Awaiting approval.", @"")];
  659. }
  660.  
  661. - (void)requestCompleted {
  662. [spinner stopAnimating];
  663. self.view.userInteractionEnabled = YES;
  664.  
  665. [self stopLoading];
  666.  
  667. switch ([ApplicationData sharedInstance].errorCode) {
  668. case jBadRequest:
  669. [self performSelectorOnMainThread:@selector(jBadRequest) withObject:nil waitUntilDone:NO];
  670. break;
  671.  
  672. case jLoginRequired:
  673. [[ApplicationData sharedInstance] logout:self];
  674. [self performSelectorOnMainThread:@selector(openLoginView) withObject:nil waitUntilDone:YES];
  675. break;
  676.  
  677. case jErroronServer:
  678. [self performSelectorOnMainThread:@selector(jErrorMessage) withObject:nil waitUntilDone:NO];
  679. break;
  680.  
  681. case jNoContent:
  682. [self performSelectorOnMainThread:@selector(jNoContent) withObject:nil waitUntilDone:NO];
  683. break;
  684.  
  685. case jErrorMessage:
  686. [self performSelectorOnMainThread:@selector(jErrorMessage) withObject:nil waitUntilDone:NO];
  687. break;
  688.  
  689. case jUnsupportedFile:
  690. [self performSelectorOnMainThread:@selector(jUnsupportedFile) withObject:nil waitUntilDone:NO];
  691. break;
  692.  
  693. case jInvalidData:
  694. [self performSelectorOnMainThread:@selector(jInvalidData) withObject:nil waitUntilDone:NO];
  695. break;
  696.  
  697. case jUserNameError:
  698. [self performSelectorOnMainThread:@selector(jUserNameError) withObject:nil waitUntilDone:NO];
  699. break;
  700.  
  701. case jEmailError:
  702. [self performSelectorOnMainThread:@selector(jEmailError) withObject:nil waitUntilDone:NO];
  703. break;
  704.  
  705. case jFBOption:
  706. [self performSelectorOnMainThread:@selector(jFBOption) withObject:nil waitUntilDone:NO];
  707. break;
  708.  
  709. case jSessionExpire:
  710. DLog(@"Session Expired Logging in Again");
  711. [[ApplicationData sharedInstance] LoginCheck:self];
  712. break;
  713. break;
  714.  
  715. case jReportedContent:
  716. [self performSelectorOnMainThread:@selector(jReportedContent) withObject:nil waitUntilDone:NO];
  717. break;
  718.  
  719. case JPermissionError:
  720. [self performSelectorOnMainThread:@selector(JPermissionError) withObject:nil waitUntilDone:NO];
  721. break;
  722.  
  723. case jDuplicateData:
  724. [self performSelectorOnMainThread:@selector(jDuplicateData) withObject:nil waitUntilDone:NO];
  725. break;
  726.  
  727. case jWaitingForPermission:
  728. [self performSelectorOnMainThread:@selector(jWaitingForPermission) withObject:nil waitUntilDone:NO];
  729. break;
  730.  
  731. case jSuccess:
  732. switch (currentRequestType) {
  733. case jGeneralQuery:
  734. if ([selectedWall.likeList count] > 0) {
  735. [self performSelectorOnMainThread:@selector(setData) withObject:nil waitUntilDone:NO];
  736. [tableView reloadData];
  737. }else {
  738. [self fetchLikes];
  739. }
  740.  
  741. break;
  742. case jlikeUnlikeQuery:
  743. [self performSelectorOnMainThread:@selector(setData) withObject:nil waitUntilDone:NO];
  744. [tableView reloadData];
  745. break;
  746.  
  747. case jPostQuery:
  748. {
  749. txtComment.text = @"";
  750. btnWriteComment.hidden = NO;
  751.  
  752. selectedWall.comments++;
  753.  
  754. [self performSelectorOnMainThread:@selector(fetchComments) withObject:nil waitUntilDone:NO];
  755.  
  756. [self performSelectorOnMainThread:@selector(setData) withObject:nil waitUntilDone:NO];
  757. [tableView reloadData];
  758.  
  759. }
  760. break;
  761. case jDeleteWallQuery:
  762. [self performSelectorOnMainThread:@selector(fetchComments) withObject:nil waitUntilDone:NO];
  763.  
  764. [self performSelectorOnMainThread:@selector(setData) withObject:nil waitUntilDone:NO];
  765. [tableView reloadData];
  766. break;
  767. case jLikeQuery:
  768. self.navigationItem.rightBarButtonItem.title = NSLocalizedString(@"unlike_btn",@"");
  769. likeRecord.userId = [ApplicationData sharedInstance].loggedUser;
  770. likeRecord.name = [ApplicationData sharedInstance].userDetail.userName;
  771. [selectedWall.likeList addObject:likeRecord];
  772. [self performSelectorOnMainThread:@selector(setData2) withObject:nil waitUntilDone:NO];
  773. break;
  774. case jUnlikeQuery:
  775. self.navigationItem.rightBarButtonItem.title = NSLocalizedString(@"like_btn",@"");
  776. for (Like *record in selectedWall.likeList) {
  777. if ([ApplicationData sharedInstance].loggedUser == record.userId) {
  778. [selectedWall.likeList removeObject:record];
  779. break;
  780. }
  781. }
  782. [self performSelectorOnMainThread:@selector(setData2) withObject:nil waitUntilDone:NO];
  783. break;
  784. case jAddFriendQuery:
  785. [self performSelectorOnMainThread:@selector(approvalmsg) withObject:nil waitUntilDone:NO];
  786. break;
  787.  
  788. default:
  789. break;
  790. }
  791. break;
  792. default:
  793. break;
  794. }
  795. }
  796.  
  797. - (void)refresh {
  798. if (![spinner isAnimating]) {
  799. [spinner startAnimating];
  800. tableView.hidden = YES;
  801. // commentArray = [[NSMutableArray alloc] init];
  802. // likeArray = [[NSMutableArray alloc] init];
  803. [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(fetchComments) userInfo:nil repeats:NO];
  804. self.pageNo = 1;
  805. self.hasPrev = 0;
  806. }
  807. }
  808.  
  809. - (void)openLoginView {
  810.  
  811. LoginViewController *controller = [[LoginViewController alloc] init];
  812. [ApplicationData sharedInstance].userDetail.avatarImg = nil;
  813.  
  814. int k = [controller LogincheckDict];
  815. if (k == 1) {
  816.  
  817. [controller LoginDone];
  818. [self viewWillAppear:NO];
  819. }
  820. else if (k==2)
  821. {
  822. [controller FBLoginDone];
  823. [self viewWillAppear:NO];
  824. }
  825. else
  826. {
  827. [self presentModalViewController:controller animated:YES];
  828. }
  829.  
  830. [controller release];
  831. }
  832.  
  833. #pragma mark --
  834. #pragma mark setImages
  835.  
  836. - (void)setImages {
  837. // set images in a row of custom table view
  838. int x = 42;
  839. int y = yPos;
  840. float width = 60;
  841. float height = 60;
  842. int i = 0;
  843. int row = 1;
  844. BOOL isGetNew = YES;
  845. for (Photo *record in selectedWall.imageList) {
  846.  
  847. isGetNew = YES;
  848. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  849. btn.frame = CGRectMake(x, y, width, height);
  850. btn.tag = (NSInteger)i;
  851. if (record.thumbImg) {
  852. [btn setImage:record.thumbImg forState:UIControlStateNormal];
  853. [headerView insertSubview:btn atIndex:1];
  854. x += 62;
  855. if ((i+1) % 4 == 0) {
  856. row++;
  857. x = 42;
  858. y += 62;
  859. isGetNew = NO;
  860. }
  861. i++;
  862. }
  863. }
  864. if (isGetNew) {
  865. yPos = y + 62;
  866. } else {
  867. yPos = y;
  868. }
  869. [textView bringSubviewToFront:self.view];
  870. }
  871.  
  872. - (float)getTextSize:(NSString *)text Font:(UIFont *)font MaxWidth:(float)width {
  873. // get the value of text fot the text height
  874. CGSize maximumLabelSize = CGSizeMake(width,9999);
  875. CGSize expectedLabelSize = [text sizeWithFont:font
  876. constrainedToSize:maximumLabelSize
  877. lineBreakMode:UILineBreakModeWordWrap];
  878.  
  879. return expectedLabelSize.height;
  880. }
  881.  
  882. #pragma mark --
  883. #pragma mark ButtonPressed
  884.  
  885. - (void)setData2 {
  886.  
  887. [textView resignFirstResponder];
  888. [textView setHidden:YES];
  889. [self setData];
  890. }
  891.  
  892. #pragma mark --
  893. #pragma mark TableView
  894.  
  895. - (NSInteger)tableView:(UITableView *)tableView1 numberOfRowsInSection:(NSInteger)section {
  896.  
  897. if ([selectedWall.commentList count] > 0) {
  898. tableView.hidden = NO;
  899. return [commentArray count] + 1;
  900. }
  901.  
  902. return 0;
  903. }
  904.  
  905. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  906.  
  907. if(indexPath.row < [commentArray count])
  908. {
  909. Comment *record = [commentArray objectAtIndex:indexPath.row];
  910. CGSize size = [record.creatorname sizeWithFont:[UIFont boldSystemFontOfSize:11] constrainedToSize:CGSizeMake(240, 9999) lineBreakMode:UILineBreakModeWordWrap];
  911. CGFloat height = size.height;
  912. size = [record.commentText sizeWithFont:[UIFont systemFontOfSize:11] constrainedToSize:CGSizeMake(240, 9999) lineBreakMode:UILineBreakModeWordWrap];
  913. height += size.height;
  914. size = [record.dateTime sizeWithFont:[UIFont systemFontOfSize:11] constrainedToSize:CGSizeMake(240, 9999) lineBreakMode:UILineBreakModeWordWrap];
  915. height += size.height +14;
  916. if([record.commentLink isEqual: @""]){
  917. return MAX(height, 72);
  918. }else{
  919. return MAX(height+115, 72);
  920. }
  921. }else{
  922. return 44;
  923. }
  924.  
  925.  
  926. }
  927.  
  928. - (UITableViewCell *)tableView:(UITableView *)tableViewController cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  929.  
  930.  
  931. if(indexPath.row < [commentArray count])
  932. {
  933. if (event) {
  934. JomCommentCell *cell = (JomCommentCell *)[tableView dequeueReusableCellWithIdentifier:kCellIdentifier1];
  935. cell.backgroundColor = [UIColor clearColor];
  936.  
  937. Comment *record = [commentArray objectAtIndex:indexPath.row];
  938.  
  939. if (cell == nil) {
  940.  
  941. //kCellIdentifier will call the wallCell
  942. [cellOwner loadMyNibFile:kCellIdentifier1];
  943. cell = (JomCommentCell *)cellOwner.cell;
  944. }
  945. [cell.btnDelete addTarget:self action:@selector(deleteButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
  946. [cell.btnPlay addTarget:self action:@selector(PlayCommentcontentButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
  947. if (record.thumbURL > 0 && !record.thumbImg) {
  948. [self performSelectorOnMainThread:@selector(startIconDownload:) withObject:record waitUntilDone:NO];
  949. }
  950. cell.btnPlay.tag = (NSInteger)indexPath.row;
  951. cell.btnDelete.tag = (NSInteger)indexPath.row;
  952. cell.commentRecord = record;
  953. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  954. [cell reloadCell];
  955. return cell;
  956. }
  957. else {
  958. commentListCell *cell = (commentListCell *)[tableView dequeueReusableCellWithIdentifier:kCellIdentifiercommentListCell];
  959. cell.backgroundColor = [UIColor clearColor];
  960. Comment *record = [commentArray objectAtIndex:indexPath.row];
  961. if (cell == nil) {
  962.  
  963. //kCellIdentifier will call the wallCell
  964. [cellOwner loadMyNibFile:kCellIdentifiercommentListCell];
  965. cell = (commentListCell *)cellOwner.cell;
  966. }
  967.  
  968. [cell.btnUser addTarget:self action:@selector(userButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
  969.  
  970. [cell.btnDelete addTarget:self action:@selector(deleteButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
  971. [cell.btnPlay addTarget:self action:@selector(PlayCommentcontentButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
  972. cell.btnUser.tag = (NSInteger)indexPath.row;
  973. cell.btnDelete.tag = (NSInteger)indexPath.row;
  974. cell.btnPlay.tag = (NSInteger)indexPath.row;
  975. if (record.thumbURL > 0 && !record.thumbImg) {
  976. [self performSelectorOnMainThread:@selector(startIconDownload:) withObject:record waitUntilDone:NO];
  977. }
  978. cell.commentRecord = record;
  979. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  980. [cell reloadCell];
  981. return cell;
  982. }
  983. }else{
  984. static NSString *CellIdentifier = @"Cell";
  985. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  986. cell.backgroundColor = [ApplicationData sharedInstance].tintColor;
  987. if (cell == nil)
  988. {
  989. cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil]autorelease];
  990. // cell.backgroundColor = [ApplicationData sharedInstance].themeColor;
  991. cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:13];
  992. //cell.textLabel.textColor = [ApplicationData sharedInstance].textcolor;
  993. }
  994. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  995. cell.textLabel.text = NSLocalizedString(@"moreresult_title", @"Get more results...");
  996. cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:13];
  997. cell.textLabel.textColor = [UIColor blackColor];
  998. return cell;
  999. }
  1000.  
  1001. }
  1002.  
  1003. - (void)tableView:(UITableView *)tableViewController didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  1004. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  1005. if(indexPath.row < [commentArray count]){
  1006. NSLog(@"tipota");
  1007. }else{
  1008. ++self.pageNo;
  1009. NSLog([NSString stringWithFormat:@"Auto : %d", self.pageNo]);
  1010. [spinner startAnimating];
  1011. [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(fetchComments) userInfo:nil repeats:NO];
  1012. [tableView setContentOffset:CGPointZero animated:NO];
  1013. }
  1014.  
  1015. }
  1016.  
  1017. - (IBAction)userButtonPressed:(id)sender {
  1018. /*
  1019. Comment *record = [commentArray objectAtIndex:[sender tag]];
  1020. MainPageViewController *controller = [[MainPageViewController alloc] init];
  1021. controller.userDetail.userId = record.userId;
  1022. controller.userDetail.userName = record.creatorname;
  1023. [self.navigationController pushViewController:controller animated:YES];
  1024. [controller release];
  1025. */
  1026.  
  1027. Comment *recorda = [commentArray objectAtIndex:[sender tag]];
  1028. Wall *record = [[ApplicationData sharedInstance].updatesList objectAtIndex:[sender tag]];
  1029. MainPageViewController *controller = [[MainPageViewController alloc] init];
  1030. controller.userDetail = record.userdetail;
  1031. controller.userDetail.userId = recorda.userId;
  1032. [self.navigationController pushViewController:controller animated:YES];
  1033. [controller release];
  1034.  
  1035.  
  1036.  
  1037. }
  1038.  
  1039. -(IBAction)deleteButtonPressed:(id)sender {
  1040. Comment *record = [commentArray objectAtIndex:[sender tag]];
  1041. NSMutableDictionary *postVariables = [[NSMutableDictionary alloc]init];
  1042. NSDictionary *dict;
  1043. [postVariables setObject:[NSString stringWithFormat:@"%d",record.commentId] forKey:@"uniqueID"];
  1044. [postVariables setObject:@"1" forKey:@"comment"];
  1045. NSString *jsonString = [Jomsocial CreateDictionary_joomsocial:@"wall" ExtTask:@"remove" TaskdataDictionary:postVariables Imagedata:nil];
  1046. dict = [JoomlaRegistration JoomSocialDictionary:jsonString Imagedata:nil];
  1047. // newWall = [GlobalObjects Share:dict];
  1048. currentRequestType = jDeleteWallQuery;
  1049. [ApplicationData sharedInstance].errorCode = [[dict objectForKey:@"code"] intValue];
  1050. [self requestCompleted];
  1051. }
  1052.  
  1053. -(IBAction)Send1ButtonPressed:(id)sender{
  1054.  
  1055. if (txtComment.text.length == 0) {
  1056. [self showAlert:NSLocalizedString(@"no_text",@"") Content:NSLocalizedString(@"Please_enter_text", @"")];
  1057. return;
  1058. }
  1059. [[self.view findFirstResponder] resignFirstResponder];
  1060. NSMutableDictionary *postVariables = [[NSMutableDictionary alloc]init];
  1061. [postVariables setObject:txtComment.text forKey:@"message"];
  1062. [postVariables setObject:[NSString stringWithFormat:@"%d",selectedWall.wallId] forKey:@"uniqueID"];
  1063. [postVariables setObject:[NSString stringWithFormat:@"%d",1] forKey:@"comment"];
  1064. // [postVariables setObject:[NSString stringWithFormat:@"%d",permissionValue] forKey:@"permissions"];
  1065. NSString *jsonString = [Jomsocial CreateDictionary_joomsocial:@"wall" ExtTask:@"add" TaskdataDictionary:postVariables Imagedata:nil];
  1066. NSDictionary *dict = [JoomlaRegistration JoomSocialDictionary:jsonString Imagedata:nil];
  1067. [ApplicationData sharedInstance].errorCode = [[dict objectForKey:TAG_CODE] intValue];
  1068. currentRequestType = jPostQuery;
  1069. [self requestCompleted];
  1070. }
  1071. -(IBAction)SendButtonPressed:(id)sender {
  1072. [spinner startAnimating];
  1073. [self voiceoverHide];
  1074. [txtComment resignFirstResponder];
  1075. [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(Send1ButtonPressed:) userInfo:nil repeats:NO];
  1076.  
  1077. }
  1078. -(IBAction)voiceSendButtonPressed:(id)sender {
  1079.  
  1080. [Voiceover HoldAndSpeakButtonPressed:nil];
  1081.  
  1082. if ([[ApplicationData sharedInstance].VoiceCurrentTime isEqualToString:@"00:00"]) {
  1083. [spinner stopAnimating];
  1084. DLog(@"return update...");
  1085. return;
  1086. }
  1087. NSMutableDictionary *postVariables = [[NSMutableDictionary alloc]init];
  1088. if (group) {
  1089. [postVariables setObject:txtComment.text forKey:@"message"];
  1090. [postVariables setObject:[NSString stringWithFormat:@"%d",selectedWall.wallId] forKey:@"uniqueID"];
  1091. [postVariables setObject:[NSString stringWithFormat:@"%d",1] forKey:@"comment"];
  1092.  
  1093. NSDictionary *dict = [Jomsocial JomsocialCommonDictfunctionVoice:@"group" ExtTask:@"addWall" TaskdataDictionary:postVariables Voicedata:[ApplicationData sharedInstance].Voicedata voicename:@"voice"];
  1094.  
  1095. [ApplicationData sharedInstance].errorCode = [[dict objectForKey:TAG_CODE] intValue];
  1096. }else if (event) {
  1097. [postVariables setObject:txtComment.text forKey:@"message"];
  1098. [postVariables setObject:[NSString stringWithFormat:@"%d",selectedWall.wallId] forKey:@"uniqueID"];
  1099. [postVariables setObject:[NSString stringWithFormat:@"%d",1] forKey:@"comment"];
  1100.  
  1101.  
  1102. NSDictionary *dict = [Jomsocial JomsocialCommonDictfunctionVoice:@"event" ExtTask:@"addWall" TaskdataDictionary:postVariables Voicedata:[ApplicationData sharedInstance].Voicedata voicename:@"voice"];
  1103.  
  1104. [ApplicationData sharedInstance].errorCode = [[dict objectForKey:TAG_CODE] intValue];
  1105. }else {
  1106. [self voiceoverHide];
  1107. [postVariables setObject:txtComment.text forKey:@"message"];
  1108. [postVariables setObject:[NSString stringWithFormat:@"%d",selectedWall.wallId] forKey:@"uniqueID"];
  1109. [postVariables setObject:[NSString stringWithFormat:@"%d",1] forKey:@"comment"];
  1110. [postVariables setObject:@"0" forKey:@"privacy"];
  1111.  
  1112. NSDictionary *dict = [Jomsocial JomsocialCommonDictfunctionVoice:@"wall" ExtTask:@"add" TaskdataDictionary:postVariables Voicedata:[ApplicationData sharedInstance].Voicedata voicename:@"voice"];
  1113.  
  1114. [ApplicationData sharedInstance].errorCode = [[dict objectForKey:TAG_CODE] intValue];
  1115. }
  1116. currentRequestType = jPostQuery;
  1117. [self requestCompleted];
  1118. }
  1119.  
  1120.  
  1121. -(IBAction)VoiceButtonPressed:(id)sender {
  1122. // self.view.userInteractionEnabled = NO;
  1123. [spinner startAnimating];
  1124. Voiceover.SpeakerView.hidden = YES;
  1125. [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(voiceSendButtonPressed:) userInfo:nil repeats:NO];
  1126.  
  1127. }
  1128.  
  1129. #pragma mark --
  1130. #pragma mark AlertView
  1131.  
  1132. - (void)showAlert:(NSString *)title Content:(NSString *)bodyText {
  1133. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:bodyText
  1134. delegate:self cancelButtonTitle:NSLocalizedString(@"alert_cancel_btn_title",@"") otherButtonTitles: nil];
  1135. [alert setContentMode:UIViewContentModeScaleAspectFit];
  1136. [alert show];
  1137. [alert release];
  1138. }
  1139.  
  1140. - (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex {
  1141. if ((buttonIndex == 0) && (alertView.tag == 1)) {
  1142. [textView resignFirstResponder];
  1143. [textView setHidden:YES];
  1144. self.navigationItem.leftBarButtonItem = nil;
  1145. if (group) {
  1146. self.navigationItem.rightBarButtonItem = nil;
  1147. } else {
  1148. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"like_btn",@"")
  1149. style:UIBarButtonItemStyleBordered target:self action:@selector(likeButtonPressed:)];
  1150. for (Like *record in selectedWall.likeList) {
  1151. if ([ApplicationData sharedInstance].loggedUser == record.userId) {
  1152. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"unlike_btn",@"")
  1153. style:UIBarButtonItemStyleBordered target:self action:@selector(likeButtonPressed:)];
  1154. break;
  1155. }
  1156. }
  1157. }
  1158. }
  1159. }
  1160.  
  1161. - (void)viewWillDisappear:(BOOL)animated {
  1162. [mp stop];
  1163.  
  1164. [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
  1165. [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
  1166. [NSObject cancelPreviousPerformRequestsWithTarget:self];
  1167.  
  1168. if([spinner isAnimating]) {
  1169. RequestResponseManager *requestManager = [RequestResponseManager sharedInstance];
  1170. [requestManager cancleRequest];
  1171. }
  1172. if([imageDownloadsInProgress count] > 0) {
  1173. IconDownloader *downloader;
  1174. for(downloader in [imageDownloadsInProgress objectEnumerator]) {
  1175. [downloader cancelDownload];
  1176. }
  1177. [imageDownloadsInProgress removeAllObjects];
  1178. }
  1179. [spinner stopAnimating];
  1180. [super viewDidDisappear:animated];
  1181. }
  1182.  
  1183. - (void)dealloc {
  1184. [NSObject cancelPreviousPerformRequestsWithTarget:self];
  1185.  
  1186. [txtContent release];
  1187. [textView release];
  1188. [thumbImg release];
  1189. [txtStatusMessage release];
  1190. [btnStatusMessage release];
  1191. [spinner release];
  1192. [backImg release];
  1193. [headerView release];
  1194. [super dealloc];
  1195. }
  1196.  
  1197. //////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1198. ////////////////////////////////////// IconDownloaderDelegate ////////////////////////////////////////////////
  1199. //////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1200. #pragma mark --
  1201. #pragma mark IconDownloader
  1202.  
  1203. - (void)startIconDownload:(Comment *)appRecord {
  1204. IconDownloader *iconDownloader = [imageDownloadsInProgress objectForKey:appRecord.thumbURL];;
  1205. if (iconDownloader == nil && [appRecord.thumbURL length] > 0) {
  1206. [spinner startAnimating];
  1207. iconDownloader = [[IconDownloader alloc] init];
  1208. iconDownloader.appRecord = appRecord;
  1209. iconDownloader.delegate = self;
  1210. iconDownloader.imageKey = appRecord.thumbURL;
  1211. [imageDownloadsInProgress setObject:iconDownloader forKey:appRecord.thumbURL];
  1212. [iconDownloader startDownload];
  1213. [iconDownloader release];
  1214. [multipleDownloadRecord setObject:[[NSMutableArray alloc] initWithObjects:appRecord, nil] forKey:appRecord.thumbURL];
  1215. } else {
  1216. NSMutableArray *downloadingRecords = [multipleDownloadRecord objectForKey:appRecord.thumbURL];
  1217. [downloadingRecords addObject:appRecord];
  1218. }
  1219. }
  1220.  
  1221. - (void)appImageDidLoad:(NSObject *)imageKey {
  1222. [imageDownloadsInProgress removeObjectForKey:imageKey];
  1223.  
  1224. // for same url of multiple records
  1225. NSMutableArray *downloadingRecords = [multipleDownloadRecord objectForKey:imageKey];
  1226. if([downloadingRecords count] > 1) {
  1227. if([[downloadingRecords objectAtIndex:0] isKindOfClass:[Comment class]]) {
  1228. Comment *record = [downloadingRecords objectAtIndex:0];
  1229. for(id<IconRecord> otherRecord in downloadingRecords) {
  1230. [otherRecord setImage:record.thumbImg ImageKey:imageKey];
  1231. }
  1232. }
  1233. }
  1234. [downloadingRecords removeAllObjects];
  1235. [multipleDownloadRecord removeObjectForKey:imageKey];
  1236. if([imageDownloadsInProgress count] == 0) {
  1237. [spinner stopAnimating];
  1238. [[ApplicationData sharedInstance] stopImage];
  1239. [tableView reloadData];
  1240. }
  1241. }
  1242.  
  1243. - (void)keyboardWillShow:(NSNotification *)notification {
  1244. if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
  1245. {
  1246. CGSize result = [[UIScreen mainScreen] bounds].size;
  1247. if(result.height == 480)
  1248. {
  1249. tableView.frame = CGRectMake(5, 0, 310, 170);
  1250. viewComment.frame = CGRectMake(0, 170, 320, 30);
  1251.  
  1252. // iPhone Classic
  1253. }
  1254. if(result.height == 568)
  1255. {
  1256. tableView.frame = CGRectMake(5, 0, 310, 250);
  1257. viewComment.frame = CGRectMake(0, 250, 320, 30);
  1258. // iPhone 5
  1259. }
  1260. }
  1261.  
  1262. }
  1263.  
  1264. - (void)keyboardDidHide:(NSNotification *)notification {
  1265. [self voiceoverHide];
  1266. }
  1267.  
  1268. -(BOOL)textFieldShouldReturn:(UITextField *)textField {
  1269. [textField resignFirstResponder];
  1270. return YES;
  1271. }
  1272. - (void)textViewDidBeginEditing:(UITextView *)textView {
  1273.  
  1274. if ([[[UIDevice currentDevice]systemVersion]floatValue] >= 8.0) {
  1275. if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
  1276. {
  1277. CGSize result = [[UIScreen mainScreen] bounds].size;
  1278. if(result.height == 480)
  1279. {
  1280. Voiceover.frame = CGRectMake(5, 110, Voiceover.frame.size.width
  1281. , Voiceover.frame.size.height);
  1282.  
  1283. }
  1284. if(result.height == 568)
  1285. {
  1286. Voiceover.frame = CGRectMake(5,200, Voiceover.frame.size.width
  1287. , Voiceover.frame.size.height);
  1288.  
  1289. }
  1290. }
  1291.  
  1292. }
  1293.  
  1294. else{
  1295. if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
  1296. {
  1297. CGSize result = [[UIScreen mainScreen] bounds].size;
  1298. if(result.height == 480)
  1299. {
  1300. Voiceover.frame = CGRectMake(5, 150, Voiceover.frame.size.width
  1301. , Voiceover.frame.size.height);
  1302.  
  1303. }
  1304. if(result.height == 568)
  1305. {
  1306. Voiceover.frame = CGRectMake(5,240, Voiceover.frame.size.width
  1307. , Voiceover.frame.size.height);
  1308.  
  1309. }
  1310. }
  1311. }
  1312.  
  1313. }
  1314.  
  1315. - (void)viewDidUnload {
  1316. [NSObject cancelPreviousPerformRequestsWithTarget:self];
  1317.  
  1318. [headerView release];
  1319. headerView = nil;
  1320. [super viewDidUnload];
  1321. }
  1322.  
  1323. ///------------------------------- Pull down to Refresh start ---------------------------------///
  1324.  
  1325.  
  1326. - (void)addPullToRefreshHeader {
  1327. textPull = [[NSString alloc] initWithString:@"Pull down to refresh..."];
  1328. textRelease = [[NSString alloc] initWithString:@"Release to refresh..."];
  1329. textLoading = [[NSString alloc] initWithString:@"Loading..."];
  1330. refreshHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0 - REFRESH_HEADER_HEIGHT, 320, REFRESH_HEADER_HEIGHT)];
  1331. refreshHeaderView.backgroundColor = [UIColor clearColor];
  1332.  
  1333. refreshLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, pullTable.frame.size.width, REFRESH_HEADER_HEIGHT)];
  1334. refreshLabel.backgroundColor = [UIColor clearColor];
  1335. refreshLabel.font = [UIFont boldSystemFontOfSize:12.0];
  1336. refreshLabel.textColor = [ApplicationData sharedInstance].textcolor;//[UIColor whiteColor];
  1337. refreshLabel.textAlignment = UITextAlignmentCenter;
  1338.  
  1339. refreshArrow = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrowpull.png"]];
  1340. [refreshArrow setContentMode:UIViewContentModeCenter];
  1341. refreshArrow.frame = CGRectMake((REFRESH_HEADER_HEIGHT - 27) / 2,
  1342. (REFRESH_HEADER_HEIGHT - 44) / 2,
  1343. 27, 44);
  1344.  
  1345. [refreshHeaderView addSubview:refreshLabel];
  1346. [refreshHeaderView addSubview:refreshArrow];
  1347. [self->pullTable addSubview:refreshHeaderView];
  1348. }
  1349.  
  1350.  
  1351. - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView1 {
  1352. tablescroll_Y = [scrollView1 contentOffset].y;
  1353. if (txtComment.text.length == 0)
  1354. {
  1355. btnWriteComment.hidden = NO;
  1356.  
  1357. }else{
  1358. btnWriteComment.hidden = YES;
  1359.  
  1360. }
  1361.  
  1362. if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  1363. CGSize result = [[UIScreen mainScreen] bounds].size;
  1364. if(result.height == 480) {
  1365. if (isTabbarHidden == YES) {
  1366. Voiceover.frame = CGRectMake(5, 360, Voiceover.frame.size.width, Voiceover.frame.size.height);
  1367.  
  1368. }
  1369. else {
  1370. Voiceover.frame = CGRectMake(5, 310, Voiceover.frame.size.width, Voiceover.frame.size.height);
  1371. }
  1372. }
  1373. else if(result.height == 568) {
  1374. if (isTabbarHidden == YES) {
  1375. Voiceover.frame = CGRectMake(5, 445, Voiceover.frame.size.width
  1376. , Voiceover.frame.size.height);
  1377.  
  1378. }
  1379. else {
  1380. Voiceover.frame = CGRectMake(5, 400, Voiceover.frame.size.width
  1381. , Voiceover.frame.size.height);
  1382. } // iPhone 5
  1383. }
  1384. }
  1385.  
  1386. if (isLoading) return;
  1387. isDragging = YES;
  1388.  
  1389. }
  1390.  
  1391. - (void)scrollViewDidScroll:(UIScrollView *)scrollView1 {
  1392. if (isLoading) {
  1393. // Update the content inset, good for section headers
  1394. if (scrollView1.contentOffset.y > 0)
  1395. self->pullTable.contentInset = UIEdgeInsetsZero;
  1396. else if (scrollView1.contentOffset.y >= -REFRESH_HEADER_HEIGHT)
  1397. self->pullTable.contentInset = UIEdgeInsetsMake(-scrollView1.contentOffset.y, 0, 0, 0);
  1398. } else if (isDragging && scrollView1.contentOffset.y < 0) {
  1399. // Update the arrow direction and label
  1400. [UIView beginAnimations:nil context:NULL];
  1401. if (scrollView1.contentOffset.y < -REFRESH_HEADER_HEIGHT) {
  1402. // User is scrolling above the header
  1403. refreshLabel.text = self->textRelease;
  1404. [refreshArrow layer].transform = CATransform3DMakeRotation(M_PI, 0, 0, 1);
  1405. } else { // User is scrolling somewhere within the header
  1406. refreshLabel.text = self->textPull;
  1407. [refreshArrow layer].transform = CATransform3DMakeRotation(M_PI * 2, 0, 0, 1);
  1408. }
  1409. [UIView commitAnimations];
  1410. }
  1411. }
  1412.  
  1413. - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView1 willDecelerate:(BOOL)decelerate {
  1414. [txtComment resignFirstResponder];
  1415. [Voiceover.txtStaus resignFirstResponder];
  1416. if (isLoading) return;
  1417. isDragging = NO;
  1418. if (scrollView1.contentOffset.y <= -REFRESH_HEADER_HEIGHT) {
  1419. // Released above the header
  1420. [self startLoading];
  1421. }
  1422.  
  1423. }
  1424.  
  1425. - (void)startLoading {
  1426. isLoading = YES;
  1427.  
  1428. // Show the header
  1429. [UIView beginAnimations:nil context:NULL];
  1430. [UIView setAnimationDuration:0.3];
  1431. self->pullTable.contentInset = UIEdgeInsetsMake(REFRESH_HEADER_HEIGHT, 0, 0, 0);
  1432. refreshLabel.text = self->textLoading;
  1433. refreshArrow.hidden = YES;
  1434. [refreshSpinner startAnimating];
  1435. [UIView commitAnimations];
  1436.  
  1437. // Refresh action!
  1438. [self refresh];
  1439. }
  1440.  
  1441. - (void)stopLoading {
  1442. isLoading = NO;
  1443.  
  1444. // Hide the header
  1445. [UIView beginAnimations:nil context:NULL];
  1446. [UIView setAnimationDelegate:self];
  1447. [UIView setAnimationDuration:0.3];
  1448. [UIView setAnimationDidStopSelector:@selector(stopLoadingComplete:finished:context:)];
  1449. self->pullTable.contentInset = UIEdgeInsetsZero;
  1450. [refreshArrow layer].transform = CATransform3DMakeRotation(M_PI * 2, 0, 0, 1);
  1451. [UIView commitAnimations];
  1452. }
  1453.  
  1454. - (void)stopLoadingComplete:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
  1455. // Reset the header
  1456. refreshLabel.text = self->textPull;
  1457. refreshArrow.hidden = NO;
  1458. [refreshSpinner stopAnimating];
  1459. }
  1460.  
  1461. ///------------------------------- Pull down to Refresh end ---------------------------------///
  1462.  
  1463.  
  1464. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement