Advertisement
Guest User

Untitled

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