Advertisement
Guest User

Untitled

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