Advertisement
Guest User

Untitled

a guest
Aug 26th, 2015
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 61.01 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. }
  803. }
  804.  
  805. - (void)openLoginView {
  806.  
  807. LoginViewController *controller = [[LoginViewController alloc] init];
  808. [ApplicationData sharedInstance].userDetail.avatarImg = nil;
  809.  
  810. int k = [controller LogincheckDict];
  811. if (k == 1) {
  812.  
  813. [controller LoginDone];
  814. [self viewWillAppear:NO];
  815. }
  816. else if (k==2)
  817. {
  818. [controller FBLoginDone];
  819. [self viewWillAppear:NO];
  820. }
  821. else
  822. {
  823. [self presentModalViewController:controller animated:YES];
  824. }
  825.  
  826. [controller release];
  827. }
  828.  
  829. #pragma mark --
  830. #pragma mark setImages
  831.  
  832. - (void)setImages {
  833. // set images in a row of custom table view
  834. int x = 42;
  835. int y = yPos;
  836. float width = 60;
  837. float height = 60;
  838. int i = 0;
  839. int row = 1;
  840. BOOL isGetNew = YES;
  841. for (Photo *record in selectedWall.imageList) {
  842.  
  843. isGetNew = YES;
  844. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  845. btn.frame = CGRectMake(x, y, width, height);
  846. btn.tag = (NSInteger)i;
  847. if (record.thumbImg) {
  848. [btn setImage:record.thumbImg forState:UIControlStateNormal];
  849. [headerView insertSubview:btn atIndex:1];
  850. x += 62;
  851. if ((i+1) % 4 == 0) {
  852. row++;
  853. x = 42;
  854. y += 62;
  855. isGetNew = NO;
  856. }
  857. i++;
  858. }
  859. }
  860. if (isGetNew) {
  861. yPos = y + 62;
  862. } else {
  863. yPos = y;
  864. }
  865. [textView bringSubviewToFront:self.view];
  866. }
  867.  
  868. - (float)getTextSize:(NSString *)text Font:(UIFont *)font MaxWidth:(float)width {
  869. // get the value of text fot the text height
  870. CGSize maximumLabelSize = CGSizeMake(width,9999);
  871. CGSize expectedLabelSize = [text sizeWithFont:font
  872. constrainedToSize:maximumLabelSize
  873. lineBreakMode:UILineBreakModeWordWrap];
  874.  
  875. return expectedLabelSize.height;
  876. }
  877.  
  878. #pragma mark --
  879. #pragma mark ButtonPressed
  880.  
  881. - (void)setData2 {
  882.  
  883. [textView resignFirstResponder];
  884. [textView setHidden:YES];
  885. [self setData];
  886. }
  887.  
  888. #pragma mark --
  889. #pragma mark TableView
  890.  
  891. - (NSInteger)tableView:(UITableView *)tableView1 numberOfRowsInSection:(NSInteger)section {
  892.  
  893. if ([selectedWall.commentList count] > 0 && self.pageNo > 1){
  894. tableView.hidden = NO;
  895. return [commentArray count] + 2;
  896. }
  897. else if ([selectedWall.commentList count] > 0) {
  898. tableView.hidden = NO;
  899. return [commentArray count] + 1;
  900. }
  901.  
  902. return 0;
  903. }
  904.  
  905. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  906.  
  907. if(indexPath.row < [commentArray count])
  908. {
  909. Comment *record = [commentArray objectAtIndex:indexPath.row];
  910. CGSize size = [record.creatorname sizeWithFont:[UIFont boldSystemFontOfSize:11] constrainedToSize:CGSizeMake(240, 9999) lineBreakMode:UILineBreakModeWordWrap];
  911. CGFloat height = size.height;
  912. size = [record.commentText sizeWithFont:[UIFont systemFontOfSize:11] constrainedToSize:CGSizeMake(240, 9999) lineBreakMode:UILineBreakModeWordWrap];
  913. height += size.height;
  914. size = [record.dateTime sizeWithFont:[UIFont systemFontOfSize:11] constrainedToSize:CGSizeMake(240, 9999) lineBreakMode:UILineBreakModeWordWrap];
  915. height += size.height +14;
  916. if([record.commentLink isEqual: @""]){
  917. return MAX(height, 72);
  918. }else{
  919. return MAX(height+115, 72);
  920. }
  921. }else{
  922. return 44;
  923. }
  924.  
  925.  
  926. }
  927.  
  928. - (UITableViewCell *)tableView:(UITableView *)tableViewController cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  929.  
  930.  
  931. if(indexPath.row == 0 && self.pageNo > 1){
  932. static NSString *CellIdentifier = @"Cell";
  933. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  934. cell.backgroundColor = [ApplicationData sharedInstance].tintColor;
  935. if (cell == nil)
  936. {
  937. cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil]autorelease];
  938. // cell.backgroundColor = [ApplicationData sharedInstance].themeColor;
  939. cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:13];
  940. //cell.textLabel.textColor = [ApplicationData sharedInstance].textcolor;
  941. }
  942. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  943. cell.textLabel.text = NSLocalizedString(@"moreresult_title", @"Get more results...");
  944. cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:13];
  945. cell.textLabel.textColor = [UIColor blackColor];
  946. self.hasPrev = 1;
  947. return cell;
  948.  
  949. }else if(indexPath.row < [commentArray count] + self.hasPrev)
  950. {
  951. if (event) {
  952. JomCommentCell *cell = (JomCommentCell *)[tableView dequeueReusableCellWithIdentifier:kCellIdentifier1];
  953. cell.backgroundColor = [UIColor clearColor];
  954.  
  955. Comment *record = [commentArray objectAtIndex:indexPath.row];
  956.  
  957. if (cell == nil) {
  958.  
  959. //kCellIdentifier will call the wallCell
  960. [cellOwner loadMyNibFile:kCellIdentifier1];
  961. cell = (JomCommentCell *)cellOwner.cell;
  962. }
  963. [cell.btnDelete addTarget:self action:@selector(deleteButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
  964. [cell.btnPlay addTarget:self action:@selector(PlayCommentcontentButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
  965. if (record.thumbURL > 0 && !record.thumbImg) {
  966. [self performSelectorOnMainThread:@selector(startIconDownload:) withObject:record waitUntilDone:NO];
  967. }
  968. cell.btnPlay.tag = (NSInteger)indexPath.row;
  969. cell.btnDelete.tag = (NSInteger)indexPath.row;
  970. cell.commentRecord = record;
  971. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  972. [cell reloadCell];
  973. return cell;
  974. }
  975. else {
  976. commentListCell *cell = (commentListCell *)[tableView dequeueReusableCellWithIdentifier:kCellIdentifiercommentListCell];
  977. cell.backgroundColor = [UIColor clearColor];
  978. Comment *record = [commentArray objectAtIndex:indexPath.row];
  979. if (cell == nil) {
  980.  
  981. //kCellIdentifier will call the wallCell
  982. [cellOwner loadMyNibFile:kCellIdentifiercommentListCell];
  983. cell = (commentListCell *)cellOwner.cell;
  984. }
  985. [cell.btnUser addTarget:self action:@selector(userButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
  986. [cell.btnDelete addTarget:self action:@selector(deleteButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
  987. [cell.btnPlay addTarget:self action:@selector(PlayCommentcontentButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
  988. cell.btnUser.tag = (NSInteger)indexPath.row;
  989. cell.btnDelete.tag = (NSInteger)indexPath.row;
  990. cell.btnPlay.tag = (NSInteger)indexPath.row;
  991. if (record.thumbURL > 0 && !record.thumbImg) {
  992. [self performSelectorOnMainThread:@selector(startIconDownload:) withObject:record waitUntilDone:NO];
  993. }
  994. cell.commentRecord = record;
  995. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  996. [cell reloadCell];
  997. return cell;
  998. }
  999. }else{
  1000. if([commentArray count] < 29){ /// 29 because we get 30 comments from the server ///
  1001.  
  1002. static NSString *CellIdentifier = @"Cell";
  1003. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  1004. cell.backgroundColor = [ApplicationData sharedInstance].tintColor;
  1005. if (cell == nil)
  1006. {
  1007. cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil]autorelease];
  1008. // cell.backgroundColor = [ApplicationData sharedInstance].themeColor;
  1009. cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:13];
  1010. //cell.textLabel.textColor = [ApplicationData sharedInstance].textcolor;
  1011. }
  1012. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  1013. cell.textLabel.text = NSLocalizedString(@"moreresult_title", @"Get more results...");
  1014. cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:13];
  1015. cell.textLabel.textColor = [UIColor blackColor];
  1016. cell.hidden = YES;
  1017. return cell;
  1018. }else{
  1019. static NSString *CellIdentifier = @"Cell";
  1020. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  1021. cell.backgroundColor = [ApplicationData sharedInstance].tintColor;
  1022. if (cell == nil)
  1023. {
  1024. cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil]autorelease];
  1025. // cell.backgroundColor = [ApplicationData sharedInstance].themeColor;
  1026. cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:13];
  1027. //cell.textLabel.textColor = [ApplicationData sharedInstance].textcolor;
  1028. }
  1029. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  1030. cell.textLabel.text = NSLocalizedString(@"moreresult_title", @"Get more results...");
  1031. cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:13];
  1032. cell.textLabel.textColor = [UIColor blackColor];
  1033. return cell;
  1034. }
  1035. }
  1036. }
  1037.  
  1038. - (void)tableView:(UITableView *)tableViewController didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  1039. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  1040. if(indexPath.row == 0 && self.pageNo > 1){
  1041. --self.pageNo;
  1042. NSLog([NSString stringWithFormat:@"Auto : %d", self.pageNo]);
  1043. [spinner startAnimating];
  1044. [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(fetchComments) userInfo:nil repeats:NO];
  1045.  
  1046. }
  1047. else if(indexPath.row < [commentArray count]){
  1048. NSLog(@"tipota");
  1049. }else{
  1050. ++self.pageNo;
  1051. NSLog([NSString stringWithFormat:@"Auto : %d", self.pageNo]);
  1052. [spinner startAnimating];
  1053. [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(fetchComments) userInfo:nil repeats:NO];
  1054.  
  1055. }
  1056.  
  1057. }
  1058.  
  1059. - (IBAction)userButtonPressed:(id)sender {
  1060. /*
  1061. Comment *record = [commentArray objectAtIndex:[sender tag]];
  1062. MainPageViewController *controller = [[MainPageViewController alloc] init];
  1063. controller.userDetail.userId = record.userId;
  1064. controller.userDetail.userName = record.creatorname;
  1065. [self.navigationController pushViewController:controller animated:YES];
  1066. [controller release];
  1067. */
  1068.  
  1069. Comment *recorda = [commentArray objectAtIndex:[sender tag]];
  1070. Wall *record = [[ApplicationData sharedInstance].updatesList objectAtIndex:[sender tag]];
  1071. MainPageViewController *controller = [[MainPageViewController alloc] init];
  1072. controller.userDetail = record.userdetail;
  1073. controller.userDetail.userId = recorda.userId;
  1074. [self.navigationController pushViewController:controller animated:YES];
  1075. [controller release];
  1076.  
  1077.  
  1078.  
  1079. }
  1080.  
  1081. -(IBAction)deleteButtonPressed:(id)sender {
  1082. Comment *record = [commentArray objectAtIndex:[sender tag]];
  1083. NSMutableDictionary *postVariables = [[NSMutableDictionary alloc]init];
  1084. NSDictionary *dict;
  1085. [postVariables setObject:[NSString stringWithFormat:@"%d",record.commentId] forKey:@"uniqueID"];
  1086. [postVariables setObject:@"1" forKey:@"comment"];
  1087. NSString *jsonString = [Jomsocial CreateDictionary_joomsocial:@"wall" ExtTask:@"remove" TaskdataDictionary:postVariables Imagedata:nil];
  1088. dict = [JoomlaRegistration JoomSocialDictionary:jsonString Imagedata:nil];
  1089. // newWall = [GlobalObjects Share:dict];
  1090. currentRequestType = jDeleteWallQuery;
  1091. [ApplicationData sharedInstance].errorCode = [[dict objectForKey:@"code"] intValue];
  1092. [self requestCompleted];
  1093. }
  1094.  
  1095. -(IBAction)Send1ButtonPressed:(id)sender{
  1096.  
  1097. if (txtComment.text.length == 0) {
  1098. [self showAlert:NSLocalizedString(@"no_text",@"") Content:NSLocalizedString(@"Please_enter_text", @"")];
  1099. return;
  1100. }
  1101. [[self.view findFirstResponder] resignFirstResponder];
  1102. NSMutableDictionary *postVariables = [[NSMutableDictionary alloc]init];
  1103. [postVariables setObject:txtComment.text forKey:@"message"];
  1104. [postVariables setObject:[NSString stringWithFormat:@"%d",selectedWall.wallId] forKey:@"uniqueID"];
  1105. [postVariables setObject:[NSString stringWithFormat:@"%d",1] forKey:@"comment"];
  1106. // [postVariables setObject:[NSString stringWithFormat:@"%d",permissionValue] forKey:@"permissions"];
  1107. NSString *jsonString = [Jomsocial CreateDictionary_joomsocial:@"wall" ExtTask:@"add" TaskdataDictionary:postVariables Imagedata:nil];
  1108. NSDictionary *dict = [JoomlaRegistration JoomSocialDictionary:jsonString Imagedata:nil];
  1109. [ApplicationData sharedInstance].errorCode = [[dict objectForKey:TAG_CODE] intValue];
  1110. currentRequestType = jPostQuery;
  1111. [self requestCompleted];
  1112. }
  1113. -(IBAction)SendButtonPressed:(id)sender {
  1114. [spinner startAnimating];
  1115. [self voiceoverHide];
  1116. [txtComment resignFirstResponder];
  1117. [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(Send1ButtonPressed:) userInfo:nil repeats:NO];
  1118.  
  1119. }
  1120. -(IBAction)voiceSendButtonPressed:(id)sender {
  1121.  
  1122. [Voiceover HoldAndSpeakButtonPressed:nil];
  1123.  
  1124. if ([[ApplicationData sharedInstance].VoiceCurrentTime isEqualToString:@"00:00"]) {
  1125. [spinner stopAnimating];
  1126. DLog(@"return update...");
  1127. return;
  1128. }
  1129. NSMutableDictionary *postVariables = [[NSMutableDictionary alloc]init];
  1130. if (group) {
  1131. [postVariables setObject:txtComment.text forKey:@"message"];
  1132. [postVariables setObject:[NSString stringWithFormat:@"%d",selectedWall.wallId] forKey:@"uniqueID"];
  1133. [postVariables setObject:[NSString stringWithFormat:@"%d",1] forKey:@"comment"];
  1134.  
  1135. NSDictionary *dict = [Jomsocial JomsocialCommonDictfunctionVoice:@"group" ExtTask:@"addWall" TaskdataDictionary:postVariables Voicedata:[ApplicationData sharedInstance].Voicedata voicename:@"voice"];
  1136.  
  1137. [ApplicationData sharedInstance].errorCode = [[dict objectForKey:TAG_CODE] intValue];
  1138. }else if (event) {
  1139. [postVariables setObject:txtComment.text forKey:@"message"];
  1140. [postVariables setObject:[NSString stringWithFormat:@"%d",selectedWall.wallId] forKey:@"uniqueID"];
  1141. [postVariables setObject:[NSString stringWithFormat:@"%d",1] forKey:@"comment"];
  1142.  
  1143.  
  1144. NSDictionary *dict = [Jomsocial JomsocialCommonDictfunctionVoice:@"event" ExtTask:@"addWall" TaskdataDictionary:postVariables Voicedata:[ApplicationData sharedInstance].Voicedata voicename:@"voice"];
  1145.  
  1146. [ApplicationData sharedInstance].errorCode = [[dict objectForKey:TAG_CODE] intValue];
  1147. }else {
  1148. [self voiceoverHide];
  1149. [postVariables setObject:txtComment.text forKey:@"message"];
  1150. [postVariables setObject:[NSString stringWithFormat:@"%d",selectedWall.wallId] forKey:@"uniqueID"];
  1151. [postVariables setObject:[NSString stringWithFormat:@"%d",1] forKey:@"comment"];
  1152. [postVariables setObject:@"0" forKey:@"privacy"];
  1153.  
  1154. NSDictionary *dict = [Jomsocial JomsocialCommonDictfunctionVoice:@"wall" ExtTask:@"add" TaskdataDictionary:postVariables Voicedata:[ApplicationData sharedInstance].Voicedata voicename:@"voice"];
  1155.  
  1156. [ApplicationData sharedInstance].errorCode = [[dict objectForKey:TAG_CODE] intValue];
  1157. }
  1158. currentRequestType = jPostQuery;
  1159. [self requestCompleted];
  1160. }
  1161.  
  1162.  
  1163. -(IBAction)VoiceButtonPressed:(id)sender {
  1164. // self.view.userInteractionEnabled = NO;
  1165. [spinner startAnimating];
  1166. Voiceover.SpeakerView.hidden = YES;
  1167. [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(voiceSendButtonPressed:) userInfo:nil repeats:NO];
  1168.  
  1169. }
  1170.  
  1171. #pragma mark --
  1172. #pragma mark AlertView
  1173.  
  1174. - (void)showAlert:(NSString *)title Content:(NSString *)bodyText {
  1175. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:bodyText
  1176. delegate:self cancelButtonTitle:NSLocalizedString(@"alert_cancel_btn_title",@"") otherButtonTitles: nil];
  1177. [alert setContentMode:UIViewContentModeScaleAspectFit];
  1178. [alert show];
  1179. [alert release];
  1180. }
  1181.  
  1182. - (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex {
  1183. if ((buttonIndex == 0) && (alertView.tag == 1)) {
  1184. [textView resignFirstResponder];
  1185. [textView setHidden:YES];
  1186. self.navigationItem.leftBarButtonItem = nil;
  1187. if (group) {
  1188. self.navigationItem.rightBarButtonItem = nil;
  1189. } else {
  1190. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"like_btn",@"")
  1191. style:UIBarButtonItemStyleBordered target:self action:@selector(likeButtonPressed:)];
  1192. for (Like *record in selectedWall.likeList) {
  1193. if ([ApplicationData sharedInstance].loggedUser == record.userId) {
  1194. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"unlike_btn",@"")
  1195. style:UIBarButtonItemStyleBordered target:self action:@selector(likeButtonPressed:)];
  1196. break;
  1197. }
  1198. }
  1199. }
  1200. }
  1201. }
  1202.  
  1203. - (void)viewWillDisappear:(BOOL)animated {
  1204. [mp stop];
  1205.  
  1206. [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
  1207. [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
  1208. [NSObject cancelPreviousPerformRequestsWithTarget:self];
  1209.  
  1210. if([spinner isAnimating]) {
  1211. RequestResponseManager *requestManager = [RequestResponseManager sharedInstance];
  1212. [requestManager cancleRequest];
  1213. }
  1214. if([imageDownloadsInProgress count] > 0) {
  1215. IconDownloader *downloader;
  1216. for(downloader in [imageDownloadsInProgress objectEnumerator]) {
  1217. [downloader cancelDownload];
  1218. }
  1219. [imageDownloadsInProgress removeAllObjects];
  1220. }
  1221. [spinner stopAnimating];
  1222. [super viewDidDisappear:animated];
  1223. }
  1224.  
  1225. - (void)dealloc {
  1226. [NSObject cancelPreviousPerformRequestsWithTarget:self];
  1227.  
  1228. [txtContent release];
  1229. [textView release];
  1230. [thumbImg release];
  1231. [txtStatusMessage release];
  1232. [btnStatusMessage release];
  1233. [spinner release];
  1234. [backImg release];
  1235. [headerView release];
  1236. [super dealloc];
  1237. }
  1238.  
  1239. //////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1240. ////////////////////////////////////// IconDownloaderDelegate ////////////////////////////////////////////////
  1241. //////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1242. #pragma mark --
  1243. #pragma mark IconDownloader
  1244.  
  1245. - (void)startIconDownload:(Comment *)appRecord {
  1246. IconDownloader *iconDownloader = [imageDownloadsInProgress objectForKey:appRecord.thumbURL];;
  1247. if (iconDownloader == nil && [appRecord.thumbURL length] > 0) {
  1248. [spinner startAnimating];
  1249. iconDownloader = [[IconDownloader alloc] init];
  1250. iconDownloader.appRecord = appRecord;
  1251. iconDownloader.delegate = self;
  1252. iconDownloader.imageKey = appRecord.thumbURL;
  1253. [imageDownloadsInProgress setObject:iconDownloader forKey:appRecord.thumbURL];
  1254. [iconDownloader startDownload];
  1255. [iconDownloader release];
  1256. [multipleDownloadRecord setObject:[[NSMutableArray alloc] initWithObjects:appRecord, nil] forKey:appRecord.thumbURL];
  1257. } else {
  1258. NSMutableArray *downloadingRecords = [multipleDownloadRecord objectForKey:appRecord.thumbURL];
  1259. [downloadingRecords addObject:appRecord];
  1260. }
  1261. }
  1262.  
  1263. - (void)appImageDidLoad:(NSObject *)imageKey {
  1264. [imageDownloadsInProgress removeObjectForKey:imageKey];
  1265.  
  1266. // for same url of multiple records
  1267. NSMutableArray *downloadingRecords = [multipleDownloadRecord objectForKey:imageKey];
  1268. if([downloadingRecords count] > 1) {
  1269. if([[downloadingRecords objectAtIndex:0] isKindOfClass:[Comment class]]) {
  1270. Comment *record = [downloadingRecords objectAtIndex:0];
  1271. for(id<IconRecord> otherRecord in downloadingRecords) {
  1272. [otherRecord setImage:record.thumbImg ImageKey:imageKey];
  1273. }
  1274. }
  1275. }
  1276. [downloadingRecords removeAllObjects];
  1277. [multipleDownloadRecord removeObjectForKey:imageKey];
  1278. if([imageDownloadsInProgress count] == 0) {
  1279. [spinner stopAnimating];
  1280. [[ApplicationData sharedInstance] stopImage];
  1281. [tableView reloadData];
  1282. }
  1283. }
  1284.  
  1285. - (void)keyboardWillShow:(NSNotification *)notification {
  1286. if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
  1287. {
  1288. CGSize result = [[UIScreen mainScreen] bounds].size;
  1289. if(result.height == 480)
  1290. {
  1291. tableView.frame = CGRectMake(5, 0, 310, 170);
  1292. viewComment.frame = CGRectMake(0, 170, 320, 30);
  1293.  
  1294. // iPhone Classic
  1295. }
  1296. if(result.height == 568)
  1297. {
  1298. tableView.frame = CGRectMake(5, 0, 310, 250);
  1299. viewComment.frame = CGRectMake(0, 250, 320, 30);
  1300. // iPhone 5
  1301. }
  1302. }
  1303.  
  1304. }
  1305.  
  1306. - (void)keyboardDidHide:(NSNotification *)notification {
  1307. [self voiceoverHide];
  1308. }
  1309.  
  1310. -(BOOL)textFieldShouldReturn:(UITextField *)textField {
  1311. [textField resignFirstResponder];
  1312. return YES;
  1313. }
  1314. - (void)textViewDidBeginEditing:(UITextView *)textView {
  1315.  
  1316. if ([[[UIDevice currentDevice]systemVersion]floatValue] >= 8.0) {
  1317. if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
  1318. {
  1319. CGSize result = [[UIScreen mainScreen] bounds].size;
  1320. if(result.height == 480)
  1321. {
  1322. Voiceover.frame = CGRectMake(5, 110, Voiceover.frame.size.width
  1323. , Voiceover.frame.size.height);
  1324.  
  1325. }
  1326. if(result.height == 568)
  1327. {
  1328. Voiceover.frame = CGRectMake(5,200, Voiceover.frame.size.width
  1329. , Voiceover.frame.size.height);
  1330.  
  1331. }
  1332. }
  1333.  
  1334. }
  1335.  
  1336. else{
  1337. if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
  1338. {
  1339. CGSize result = [[UIScreen mainScreen] bounds].size;
  1340. if(result.height == 480)
  1341. {
  1342. Voiceover.frame = CGRectMake(5, 150, Voiceover.frame.size.width
  1343. , Voiceover.frame.size.height);
  1344.  
  1345. }
  1346. if(result.height == 568)
  1347. {
  1348. Voiceover.frame = CGRectMake(5,240, Voiceover.frame.size.width
  1349. , Voiceover.frame.size.height);
  1350.  
  1351. }
  1352. }
  1353. }
  1354.  
  1355. }
  1356.  
  1357. - (void)viewDidUnload {
  1358. [NSObject cancelPreviousPerformRequestsWithTarget:self];
  1359.  
  1360. [headerView release];
  1361. headerView = nil;
  1362. [super viewDidUnload];
  1363. }
  1364.  
  1365. ///------------------------------- Pull down to Refresh start ---------------------------------///
  1366.  
  1367.  
  1368. - (void)addPullToRefreshHeader {
  1369. textPull = [[NSString alloc] initWithString:@"Pull down to refresh..."];
  1370. textRelease = [[NSString alloc] initWithString:@"Release to refresh..."];
  1371. textLoading = [[NSString alloc] initWithString:@"Loading..."];
  1372. refreshHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0 - REFRESH_HEADER_HEIGHT, 320, REFRESH_HEADER_HEIGHT)];
  1373. refreshHeaderView.backgroundColor = [UIColor clearColor];
  1374.  
  1375. refreshLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, pullTable.frame.size.width, REFRESH_HEADER_HEIGHT)];
  1376. refreshLabel.backgroundColor = [UIColor clearColor];
  1377. refreshLabel.font = [UIFont boldSystemFontOfSize:12.0];
  1378. refreshLabel.textColor = [ApplicationData sharedInstance].textcolor;//[UIColor whiteColor];
  1379. refreshLabel.textAlignment = UITextAlignmentCenter;
  1380.  
  1381. refreshArrow = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrowpull.png"]];
  1382. [refreshArrow setContentMode:UIViewContentModeCenter];
  1383. refreshArrow.frame = CGRectMake((REFRESH_HEADER_HEIGHT - 27) / 2,
  1384. (REFRESH_HEADER_HEIGHT - 44) / 2,
  1385. 27, 44);
  1386.  
  1387. [refreshHeaderView addSubview:refreshLabel];
  1388. [refreshHeaderView addSubview:refreshArrow];
  1389. [self->pullTable addSubview:refreshHeaderView];
  1390. }
  1391.  
  1392.  
  1393. - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView1 {
  1394. tablescroll_Y = [scrollView1 contentOffset].y;
  1395. if (txtComment.text.length == 0)
  1396. {
  1397. btnWriteComment.hidden = NO;
  1398.  
  1399. }else{
  1400. btnWriteComment.hidden = YES;
  1401.  
  1402. }
  1403.  
  1404. if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  1405. CGSize result = [[UIScreen mainScreen] bounds].size;
  1406. if(result.height == 480) {
  1407. if (isTabbarHidden == YES) {
  1408. Voiceover.frame = CGRectMake(5, 360, Voiceover.frame.size.width, Voiceover.frame.size.height);
  1409.  
  1410. }
  1411. else {
  1412. Voiceover.frame = CGRectMake(5, 310, Voiceover.frame.size.width, Voiceover.frame.size.height);
  1413. }
  1414. }
  1415. else if(result.height == 568) {
  1416. if (isTabbarHidden == YES) {
  1417. Voiceover.frame = CGRectMake(5, 445, Voiceover.frame.size.width
  1418. , Voiceover.frame.size.height);
  1419.  
  1420. }
  1421. else {
  1422. Voiceover.frame = CGRectMake(5, 400, Voiceover.frame.size.width
  1423. , Voiceover.frame.size.height);
  1424. } // iPhone 5
  1425. }
  1426. }
  1427.  
  1428. if (isLoading) return;
  1429. isDragging = YES;
  1430.  
  1431. }
  1432.  
  1433. - (void)scrollViewDidScroll:(UIScrollView *)scrollView1 {
  1434. if (isLoading) {
  1435. // Update the content inset, good for section headers
  1436. if (scrollView1.contentOffset.y > 0)
  1437. self->pullTable.contentInset = UIEdgeInsetsZero;
  1438. else if (scrollView1.contentOffset.y >= -REFRESH_HEADER_HEIGHT)
  1439. self->pullTable.contentInset = UIEdgeInsetsMake(-scrollView1.contentOffset.y, 0, 0, 0);
  1440. } else if (isDragging && scrollView1.contentOffset.y < 0) {
  1441. // Update the arrow direction and label
  1442. [UIView beginAnimations:nil context:NULL];
  1443. if (scrollView1.contentOffset.y < -REFRESH_HEADER_HEIGHT) {
  1444. // User is scrolling above the header
  1445. refreshLabel.text = self->textRelease;
  1446. [refreshArrow layer].transform = CATransform3DMakeRotation(M_PI, 0, 0, 1);
  1447. } else { // User is scrolling somewhere within the header
  1448. refreshLabel.text = self->textPull;
  1449. [refreshArrow layer].transform = CATransform3DMakeRotation(M_PI * 2, 0, 0, 1);
  1450. }
  1451. [UIView commitAnimations];
  1452. }
  1453. }
  1454.  
  1455. - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView1 willDecelerate:(BOOL)decelerate {
  1456. [txtComment resignFirstResponder];
  1457. [Voiceover.txtStaus resignFirstResponder];
  1458. if (isLoading) return;
  1459. isDragging = NO;
  1460. if (scrollView1.contentOffset.y <= -REFRESH_HEADER_HEIGHT) {
  1461. // Released above the header
  1462. [self startLoading];
  1463. }
  1464.  
  1465. }
  1466.  
  1467. - (void)startLoading {
  1468. isLoading = YES;
  1469.  
  1470. // Show the header
  1471. [UIView beginAnimations:nil context:NULL];
  1472. [UIView setAnimationDuration:0.3];
  1473. self->pullTable.contentInset = UIEdgeInsetsMake(REFRESH_HEADER_HEIGHT, 0, 0, 0);
  1474. refreshLabel.text = self->textLoading;
  1475. refreshArrow.hidden = YES;
  1476. [refreshSpinner startAnimating];
  1477. [UIView commitAnimations];
  1478.  
  1479. // Refresh action!
  1480. [self refresh];
  1481. }
  1482.  
  1483. - (void)stopLoading {
  1484. isLoading = NO;
  1485.  
  1486. // Hide the header
  1487. [UIView beginAnimations:nil context:NULL];
  1488. [UIView setAnimationDelegate:self];
  1489. [UIView setAnimationDuration:0.3];
  1490. [UIView setAnimationDidStopSelector:@selector(stopLoadingComplete:finished:context:)];
  1491. self->pullTable.contentInset = UIEdgeInsetsZero;
  1492. [refreshArrow layer].transform = CATransform3DMakeRotation(M_PI * 2, 0, 0, 1);
  1493. [UIView commitAnimations];
  1494. }
  1495.  
  1496. - (void)stopLoadingComplete:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
  1497. // Reset the header
  1498. refreshLabel.text = self->textPull;
  1499. refreshArrow.hidden = NO;
  1500. [refreshSpinner stopAnimating];
  1501. }
  1502.  
  1503. ///------------------------------- Pull down to Refresh end ---------------------------------///
  1504.  
  1505. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement