Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // CommentViewController.m
- // iJoomer
- //
- // Created by Tailored Solutions on 21/09/12.
- // Copyright 2013 Tailored Solutions. All rights reserved.
- //
- #import "CommentViewController.h"
- #import "Wall.h"
- #import "Comment.h"
- #import "Like.h"
- #import "ApplicationData.h"
- #import "TableCellOwner.h"
- #import "Image.h"
- #import "CommentCell.h"
- #import "User.h"
- #import <QuartzCore/QuartzCore.h>
- #import "Event.h"
- #import "JomCommentCell.h"
- #import "LoginViewController.h"
- #import "Jomsocial.h"
- #import "JoomlaRegistration.h"
- #import "Core_joomer.h"
- #import "GlobalObjects.h"
- #import "MainPageViewController.h"
- #import "User.h"
- #import "FindFirstResponder.h"
- #import "iJoomerAppDelegate.h"
- #import "VoiceoverView.h"
- #import <MediaPlayer/MediaPlayer.h>
- #import <AVFoundation/AVFoundation.h>
- #import "commentListCell.h"
- #import "NSString+Emoticonizer.h"
- static NSString *kCellIdentifier = @"CommentCell";
- static NSString *kCellIdentifier1 = @"JomCommentCell";
- static NSString *kCellIdentifiercommentListCell = @"commentListCell";
- @implementation CommentViewController
- static int width = 250;
- static int posx = 40;
- @synthesize selectedWall;
- @synthesize userDetail;
- @synthesize imageDownloadsInProgress;
- @synthesize group;
- @synthesize event;
- @synthesize btnSend;
- @synthesize txtComment;
- @synthesize btnWriteComment;
- #pragma mark --
- #pragma mark viewDidLoad
- - (void)viewDidLoad {
- [super viewDidLoad];
- self->pullTable = tableView;
- [self addPullToRefreshHeader];
- [spinner startAnimating];
- likeArray = [[NSMutableArray alloc]init ];
- commentArray = [[NSMutableArray alloc]init];
- cellOwner = [[TableCellOwner alloc] init];
- self.imageDownloadsInProgress = [NSMutableDictionary dictionary];
- multipleDownloadRecord = [[NSMutableDictionary alloc] init];
- UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"button_back",@"") style:UIBarButtonItemStyleBordered target:nil action:nil];
- self.navigationItem.backBarButtonItem = backButton;
- [backButton release];
- NSLog(@"Edw einai auto pou 8es");
- textView.layer.cornerRadius = 14;
- textView.layer.borderColor = [[UIColor grayColor] CGColor];
- textView.layer.borderWidth = 1;
- backImg.image = [UIImage imageNamed:[ApplicationData sharedInstance].bgImage];
- lblLikes.textColor= [ApplicationData sharedInstance].tintColor;
- //lblLikes.font = [UIFont boldSystemFontOfSize:14];
- [tableView setBackgroundColor:[UIColor clearColor]];
- [btncomment setTitle:NSLocalizedString(@"Comment",@"Comment") forState:UIControlStateNormal];
- txtComment.delegate = self;
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(movieFinished:)
- name:MPMoviePlayerPlaybackDidFinishNotification
- object:mp];
- self.pageNo = 1;
- self.hasPrev = 0;
- }
- -(void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:YES];
- btnReportContent.hidden = YES;
- btnReport.hidden = YES;
- self.title = @"";
- [spinner startAnimating];
- [spinner setBackgroundColor:palleteBlue];
- spinner.layer.cornerRadius = 8;
- spinner.layer.masksToBounds = YES;
- [btnSend setBackgroundColor:palletePurple];
- btnSend.layer.cornerRadius = 8;
- btnSend.layer.masksToBounds = YES;
- //layer for Send Button
- CALayer *imgLayerSend = [btnSend layer];
- [btnSend setBackgroundColor:palletePurple];
- [imgLayerSend setMasksToBounds:YES];
- [imgLayerSend setCornerRadius:3.0];
- [imgLayerSend setBorderWidth:0.0];
- [imgLayerSend setBorderColor:[[UIColor clearColor] CGColor]];
- txtComment.layer.cornerRadius = 4;
- txtComment.layer.masksToBounds = YES;
- //tablist
- //##########################################################################################################
- iJoomerAppDelegate *appdelegate = (iJoomerAppDelegate *) [[UIApplication sharedApplication]delegate];
- NSMutableArray *arr = [[NSMutableArray alloc] init];
- arr = [ApplicationData sharedInstance].tabList;
- if ([arr count] == 0) {
- isTabbarHidden = YES;
- }
- else {
- isTabbarHidden = NO;
- }
- appdelegate.viewTop.hidden = NO;
- appdelegate.SelfViewcontroller = self;
- [appdelegate TabReset];
- //##########################################################################################################
- self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
- Voiceover.Commentcontroller = self;
- [Voiceover intialize];
- if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
- CGSize result = [[UIScreen mainScreen] bounds].size;
- if(result.height == 480) {
- if (isTabbarHidden == YES) {
- Voiceover.frame = CGRectMake(5, 360, Voiceover.frame.size.width, Voiceover.frame.size.height);
- tableView.frame = CGRectMake(5, 0, 310, 360);
- }
- else {
- Voiceover.frame = CGRectMake(5, 315, Voiceover.frame.size.width, Voiceover.frame.size.height);
- tableView.frame = CGRectMake(5, 0, 310, 310);
- }
- }
- else if(result.height == 568) {
- if (isTabbarHidden == YES) {
- Voiceover.frame = CGRectMake(5, 445, Voiceover.frame.size.width
- , Voiceover.frame.size.height);
- tableView.frame = CGRectMake(5, 0, 310, 445);
- }
- else {
- Voiceover.frame = CGRectMake(5, 400, Voiceover.frame.size.width
- , Voiceover.frame.size.height);
- tableView.frame = CGRectMake(5, 0, 310, 400);
- } // iPhone 5
- }
- }
- [btnWriteComment setTitle:NSLocalizedString(@"write_comment", @"") forState:UIControlStateNormal];
- [btnSend setTitleColor:[ApplicationData sharedInstance].textcolorWhite forState:UIControlStateNormal];
- [Voiceover setBackgroundColor:palleteBlue];
- if(self.pageNo >1){
- self.hasPrev = 1;
- }
- }
- - (IBAction)WriteCommentButtonPressed{
- btnWriteComment.hidden = YES;
- [txtComment becomeFirstResponder];
- if ([[[UIDevice currentDevice]systemVersion]floatValue] >= 8.0) {
- if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
- {
- CGSize result = [[UIScreen mainScreen] bounds].size;
- if(result.height == 480)
- {
- Voiceover.frame = CGRectMake(5, 110, Voiceover.frame.size.width
- , Voiceover.frame.size.height);
- }
- if(result.height == 568)
- {
- Voiceover.frame = CGRectMake(5,200, Voiceover.frame.size.width
- , Voiceover.frame.size.height);
- }
- }
- }
- else{
- if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
- {
- CGSize result = [[UIScreen mainScreen] bounds].size;
- if(result.height == 480)
- {
- Voiceover.frame = CGRectMake(5, 150, Voiceover.frame.size.width
- , Voiceover.frame.size.height);
- }
- if(result.height == 568)
- {
- Voiceover.frame = CGRectMake(5,240, Voiceover.frame.size.width
- , Voiceover.frame.size.height);
- }
- }
- }
- }
- -(void)voiceoverHide{
- if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
- CGSize result = [[UIScreen mainScreen] bounds].size;
- if(result.height == 480) {
- if (isTabbarHidden == YES) {
- Voiceover.frame = CGRectMake(5, 360, Voiceover.frame.size.width, Voiceover.frame.size.height);
- tableView.frame = CGRectMake(5, 0, 310, 360);
- }
- else {
- Voiceover.frame = CGRectMake(5, 315, Voiceover.frame.size.width, Voiceover.frame.size.height);
- tableView.frame = CGRectMake(5, 0, 310, 310);
- }
- }
- else if(result.height == 568) {
- if (isTabbarHidden == YES) {
- Voiceover.frame = CGRectMake(5, 445, Voiceover.frame.size.width
- , Voiceover.frame.size.height);
- tableView.frame = CGRectMake(5, 0, 310, 445);
- }
- else {
- Voiceover.frame = CGRectMake(5, 400, Voiceover.frame.size.width
- , Voiceover.frame.size.height);
- tableView.frame = CGRectMake(5, 0, 310, 400);
- } // iPhone 5
- }
- }
- }
- - (void) viewDidAppear:(BOOL)animated {
- [super viewDidAppear:animated];
- if ([selectedWall.commentList count] > 0) {
- [commentArray addObjectsFromArray: selectedWall.commentList];
- if ([selectedWall.likeList count] > 0) {
- [self performSelectorOnMainThread:@selector(setData) withObject:nil waitUntilDone:NO];
- [tableView reloadData];
- }else {
- [self fetchLikes];
- }
- } else {
- [self fetchComments];
- [self fetchLikes];
- }
- // [self setData];
- }
- #pragma mark --
- #pragma mark setData & requestCompleted
- -(void)fetchLikes {
- NSMutableDictionary *postVariables = [[NSMutableDictionary alloc]init];
- if (selectedWall.likes > 0) {
- [postVariables setObject:[NSString stringWithFormat:@"%d",selectedWall.wallId] forKey:@"wallID"];
- NSString *jsonString = [Jomsocial CreateDictionary_joomsocial:@"wall" ExtTask:@"getLikes" TaskdataDictionary:postVariables Imagedata:nil];
- NSDictionary *dict = [JoomlaRegistration JoomSocialDictionary:jsonString Imagedata:nil];
- // newWall = [GlobalObjects Share:dict];
- if ([dict objectForKey:TAG_CODE]) {
- likeArray = [GlobalObjects Like:dict];
- //DLog(@"arr:%@",likeArray);
- selectedWall.likeList = [likeArray retain];
- [ApplicationData sharedInstance].errorCode = [[dict objectForKey:TAG_CODE] intValue];
- currentRequestType = jlikeUnlikeQuery;
- [self requestCompleted];
- }
- } else {
- [spinner stopAnimating];
- tableView.hidden = NO;
- [self setData];
- [self stopLoading];
- }
- }
- -(void)fetchComments {
- NSMutableDictionary *postVariables = [[NSMutableDictionary alloc]init];
- if (selectedWall.comments > 0) {
- [postVariables setObject:[NSString stringWithFormat:@"%d",selectedWall.wallId] forKey:@"wallID"];
- [postVariables setObject:[NSString stringWithFormat:@"%d",self.pageNo] forKey:@"pageNo"];
- NSString *jsonString = [Jomsocial CreateDictionary_joomsocial:@"wall" ExtTask:@"getComments" TaskdataDictionary:postVariables Imagedata:nil];
- NSDictionary *dict = [JoomlaRegistration JoomSocialDictionary:jsonString Imagedata:nil];
- DLog(@"response : %@",dict);
- [ApplicationData sharedInstance].errorCode = [[dict objectForKey:TAG_CODE] intValue];
- if ([ApplicationData sharedInstance].errorCode == 204) {
- [selectedWall.commentList removeAllObjects];
- [commentArray removeAllObjects];
- selectedWall.comments = 0;
- }
- if ([ApplicationData sharedInstance].errorCode != 200) {
- [self fetchLikes];
- } else {
- commentArray = [GlobalObjects Comments:dict];
- [selectedWall.commentList addObjectsFromArray: commentArray];
- selectedWall.comments = selectedWall.comments + [commentArray count];
- currentRequestType = jGeneralQuery;
- [self requestCompleted];
- }
- }
- else {
- [spinner stopAnimating];
- tableView.hidden = NO;
- [self setData];
- [self stopLoading];
- }
- }
- - (void)setData {
- lblHeader.textColor = [ApplicationData sharedInstance].textcolorhead;
- lblContent.textColor = [ApplicationData sharedInstance].textcolorhead;
- txtContent.textColor = [ApplicationData sharedInstance].textcolorhead;
- lblTime.textColor = [ApplicationData sharedInstance].textcolortime;
- lblLikes.textColor= [ApplicationData sharedInstance].textcolor;
- float height = 0;
- float y = 10;
- if (event) {
- // self.title = event.title;
- }
- else {
- // self.title = selectedWall.title;
- }
- lblContent.text = selectedWall.content;
- lblContent.text = [NSString emoticonizedString: selectedWall.content];
- NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData:[lblContent.text dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil ];
- lblContent.attributedText = attributedString;
- txtContent.text = selectedWall.content;
- lblHeader.font = [ApplicationData sharedInstance].header7;
- lblContent.font= [ApplicationData sharedInstance].header5;
- //lblLikes.font= [ApplicationData sharedInstance].header7;
- lblTime.font= [ApplicationData sharedInstance].header6;
- lblHeader.text = selectedWall.title;
- lblHeader.text = [NSString emoticonizedString: selectedWall.title];
- lblHeader.text = [lblHeader.text stringByAppendingString:[NSString stringWithFormat:@"<style>body{font-family: 'Helvetica'; font-size:13.0px;}</style>"]];
- NSAttributedString *attributedString1 = [[NSAttributedString alloc] initWithData:[lblHeader.text dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil ];
- lblHeader.attributedText = attributedString1;
- NSLog(@"selectedWall.title %@",selectedWall.title);
- NSLog(@"selectedWall.content %@",selectedWall.content);
- lblTime.text = [NSString stringWithFormat:@"%@", selectedWall.date];
- lblLikes.text = @"";
- NSString *likeString = @"";
- for (Like *record in selectedWall.likeList) {
- if (likeString == @"") {
- likeString = record.name;
- } else {
- likeString = [NSString stringWithFormat:@"%@, %@", likeString, record.name];
- }
- }
- if (likeString != @"") {
- lblLikes.text = [NSString stringWithFormat:@"%@ %@-", likeString, NSLocalizedString(@"like_this_comment", @"xyz Person like this comment")];
- }
- if ([selectedWall.title rangeOfString:@"{voice}"].location != NSNotFound) {
- Voiceview.hidden = NO;
- NSString *strTitle = selectedWall.title;
- strTitle = [strTitle stringByReplacingOccurrencesOfString: @"{voice}" withString:@""];
- strTitle = [strTitle stringByReplacingOccurrencesOfString: @"{/voice}" withString:@""];
- NSArray *arr = [strTitle componentsSeparatedByString:@"&"];
- selectedWall.playVoice = [arr objectAtIndex:0];
- lblSecond.text = [NSString stringWithFormat:@"%@ s",[arr objectAtIndex:1]];
- lblHeader.hidden = YES;
- }else{
- Voiceview.hidden = YES;
- lblHeader.hidden = NO;
- }
- if ([selectedWall.content rangeOfString:@"{voice}"].location != NSNotFound) {
- VoiceviewContent.hidden = NO;
- NSString *strTitle = selectedWall.content;
- strTitle = [strTitle stringByReplacingOccurrencesOfString: @"{voice}" withString:@""];
- strTitle = [strTitle stringByReplacingOccurrencesOfString: @"{/voice}" withString:@""];
- NSArray *arr = [strTitle componentsSeparatedByString:@"&"];
- selectedWall.playVoiceContent = [arr objectAtIndex:0];
- lblSecondContent.text = [NSString stringWithFormat:@"%@ s",[arr objectAtIndex:1]];
- lblContent.hidden = YES;
- txtContent.hidden = YES;
- VoiceviewContent.hidden = NO;
- }else{
- VoiceviewContent.hidden = YES;
- lblContent.hidden = NO;
- txtContent.hidden = NO;
- }
- height = [self getTextSize:lblHeader.text Font:lblHeader.font MaxWidth:280];
- lblHeader.frame = CGRectMake(posx, y, width, height);
- y += height+2;
- if ([selectedWall.imageList count] > 0) {
- yPos = y;
- [self setImages];
- y = yPos;
- }
- height = [self getTextSize:lblContent.text Font:lblContent.font MaxWidth:255];
- if ([selectedWall.content rangeOfString:@"{voice}"].location != NSNotFound) {
- VoiceviewContent.frame = CGRectMake(posx, y, 45, 25);
- }else{
- if (height <= 90) {
- lblContent.frame = CGRectMake(posx, y, width, height+2);
- lblContent.hidden = NO;
- txtContent.hidden = YES;
- } else {
- height = MIN(90, height);
- //txtContent.font = [UIFont fontWithName:[ApplicationData sharedInstance].fontname size:13];
- txtContent.frame = CGRectMake(posx, y, width, height+2);
- lblContent.hidden = YES;
- txtContent.hidden = NO;
- }}
- y += height+4;
- height = [self getTextSize:lblTime.text Font:lblTime.font MaxWidth:255];
- lblTime.frame = CGRectMake(posx, y, width, height);
- y += height+4;
- if (lblLikes.text.length > 0) {
- height = [self getTextSize:lblLikes.text Font:lblLikes.font MaxWidth:280];
- lblLikes.frame = CGRectMake(posx, y, width, height);
- y += height+4;
- }
- if (selectedWall.thumbImg) {
- thumbImg.image = selectedWall.thumbImg;
- }
- //tableView.hidden = YES;
- headerView.frame = CGRectMake(5, 0, 310, y);
- tableView.tableHeaderView = headerView;
- [tableView reloadData];
- [spinner stopAnimating];
- }
- - (IBAction) movieFinished: (id) sender {
- [mp stop];
- }
- - (IBAction)PlayButtonPressed:(id)sender {
- // Make sure the audio is at the start of the stream.
- if(![sender isSelected]) {
- NSString *strTitle = selectedWall.title;
- strTitle = [self stringBetweenString:@"{voice}" andString:@"{/voice}"];
- NSArray *arr = [strTitle componentsSeparatedByString:@"&"];
- selectedWall.playVoice = [arr objectAtIndex:0];
- [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
- [[AVAudioSession sharedInstance] setActive: YES error: nil];
- NSURL *url;
- url = [NSURL URLWithString:selectedWall.playVoice];
- DLog(@"url : %@",url);
- mp = [[MPMoviePlayerController alloc] initWithContentURL:url];
- [mp prepareToPlay];
- [mp play];
- DLog(@"Play...");
- }else{
- [mp stop];
- DLog(@"Stop...");
- }
- [sender setSelected:![sender isSelected]];
- }
- - (IBAction)PlayButtonPressed1:(id)sender {
- // Make sure the audio is at the start of the stream.
- if(![sender isSelected]) {
- NSString *strTitle = selectedWall.content;
- strTitle = [self stringBetweenString1:@"{voice}" andString:@"{/voice}"];
- NSArray *arr = [strTitle componentsSeparatedByString:@"&"];
- selectedWall.playVoiceContent = [arr objectAtIndex:0];
- [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
- [[AVAudioSession sharedInstance] setActive: YES error: nil];
- NSURL *url;
- url = [NSURL URLWithString:selectedWall.playVoiceContent];
- DLog(@"url : %@",url);
- mp = [[MPMoviePlayerController alloc] initWithContentURL:url];
- [mp prepareToPlay];
- [mp play];
- DLog(@"Play1...");
- }else{
- [mp stop];
- DLog(@"Stop1...");
- }
- [sender setSelected:![sender isSelected]];
- }
- -(NSString*)stringBetweenString:(NSString*)start andString:(NSString*)end {
- NSRange startRange = [selectedWall.title rangeOfString:start];
- if (startRange.location != NSNotFound) {
- NSRange targetRange;
- targetRange.location = startRange.location + startRange.length;
- targetRange.length = [selectedWall.title length] - targetRange.location;
- NSRange endRange = [selectedWall.title rangeOfString:end options:0 range:targetRange];
- if (endRange.location != NSNotFound) {
- targetRange.length = endRange.location - targetRange.location;
- DLog(@"title : %@",selectedWall.title);
- return [selectedWall.title substringWithRange:targetRange];
- }
- }
- return nil;
- }
- -(NSString*)stringBetweenString1:(NSString*)start andString:(NSString*)end1 {
- NSRange startRange = [selectedWall.content rangeOfString:start];
- if (startRange.location != NSNotFound) {
- NSRange targetRange;
- targetRange.location = startRange.location + startRange.length;
- targetRange.length = [selectedWall.content length] - targetRange.location;
- NSRange endRange = [selectedWall.content rangeOfString:end1 options:0 range:targetRange];
- if (endRange.location != NSNotFound) {
- targetRange.length = endRange.location - targetRange.location;
- DLog(@"title : %@",selectedWall.content);
- return [selectedWall.content substringWithRange:targetRange];
- }
- }
- return nil;
- }
- - (IBAction)PlayCommentcontentButtonPressed:(id)sender {
- // Make sure the audio is at the start of the stream.
- if(![sender isSelected]) {
- Comment *record = [commentArray objectAtIndex:[sender tag]];
- newAddedComment = record;
- NSString *strTitle = record.commentText;
- strTitle = [self stringBetweenStringComment:@"{voice}" andString:@"{/voice}"];
- NSArray *arr = [strTitle componentsSeparatedByString:@"&"];
- record.playVoice = [arr objectAtIndex:0];
- [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
- [[AVAudioSession sharedInstance] setActive: YES error: nil];
- NSURL *url;
- url = [NSURL URLWithString:record.playVoice];
- DLog(@"url : %@",url);
- mp = [[MPMoviePlayerController alloc] initWithContentURL:url];
- [mp prepareToPlay];
- [mp play];
- DLog(@"Play...");
- }else{
- [mp stop];
- DLog(@"Stop...");
- }
- [sender setSelected:![sender isSelected]];
- }
- -(NSString*)stringBetweenStringComment:(NSString*)start andString:(NSString*)end {
- NSRange startRange = [newAddedComment.commentText rangeOfString:start];
- if (startRange.location != NSNotFound) {
- NSRange targetRange;
- targetRange.location = startRange.location + startRange.length;
- targetRange.length = [newAddedComment.commentText length] - targetRange.location;
- NSRange endRange = [newAddedComment.commentText rangeOfString:end options:0 range:targetRange];
- if (endRange.location != NSNotFound) {
- targetRange.length = endRange.location - targetRange.location;
- DLog(@"title : %@",newAddedComment.commentText);
- return [newAddedComment.commentText substringWithRange:targetRange];
- }
- }
- return nil;
- }
- -(void)approvalmsg{
- [self showAlert:NSLocalizedString(@"Success",@"") Content:NSLocalizedString(@"approval_msg", @"")];
- }
- -(void)jBadRequest{
- [self showAlert:NSLocalizedString(@"alert_error",@"Error title") Content:NSLocalizedString(@"Wrong Data.", @"")];
- }
- -(void)jErroronServer{
- [self showAlert:NSLocalizedString(@"alert_error",@"Error title") Content:NSLocalizedString(@"Server Error.", @"")];
- }
- -(void)jErrorMessage{
- [self showAlert:NSLocalizedString(@"alert_error",@"Error title") Content:@"No Such Request Found."];
- }
- -(void)jNoContent{
- [self showAlert:NSLocalizedString(@"alert_error",@"Error title") Content:NSLocalizedString(@"No Content Found.", @"")];
- }
- -(void)jUnsupportedFile {
- [self showAlert:NSLocalizedString(@"alert_error",@"Error title") Content:NSLocalizedString(@"Unsupported File Type.", @"")];
- }
- -(void)jInvalidData {
- [self showAlert:NSLocalizedString(@"alert_error",@"Error title") Content:NSLocalizedString(@"Upload Limit Exceeded.", @"")];
- }
- -(void)jUserNameError {
- [self showAlert:NSLocalizedString(@"alert_error",@"Error title") Content:NSLocalizedString(@"Username Already Exists.", @"")];
- }
- -(void)jEmailError {
- [self showAlert:NSLocalizedString(@"alert_error",@"Error title") Content:NSLocalizedString(@"Email Already Exists.", @"")];
- }
- -(void)jFBOption {
- [self showAlert:NSLocalizedString(@"alert_error",@"Error title") Content:NSLocalizedString(@"Facebook User Not Found.", @"")];
- }
- -(void)jReportedContent {
- [self showAlert:NSLocalizedString(@"alert_error",@"Error title") Content:NSLocalizedString(@"Permission Denied.", @"")];
- }
- -(void)JPermissionError {
- txtComment.text = @"";
- [self showAlert:NSLocalizedString(@"alert_error",@"Error title") Content:NSLocalizedString(@"Restricted Access.", @"")];
- }
- -(void)jDuplicateData {
- [self showAlert:NSLocalizedString(@"alert_error",@"Error title") Content:NSLocalizedString(@"Request already exists.", @"")];
- }
- -(void)jWaitingForPermission {
- [self showAlert:NSLocalizedString(@"alert_error",@"Error title") Content:NSLocalizedString(@"Awaiting approval.", @"")];
- }
- - (void)requestCompleted {
- [spinner stopAnimating];
- self.view.userInteractionEnabled = YES;
- [self stopLoading];
- switch ([ApplicationData sharedInstance].errorCode) {
- case jBadRequest:
- [self performSelectorOnMainThread:@selector(jBadRequest) withObject:nil waitUntilDone:NO];
- break;
- case jLoginRequired:
- [[ApplicationData sharedInstance] logout:self];
- [self performSelectorOnMainThread:@selector(openLoginView) withObject:nil waitUntilDone:YES];
- break;
- case jErroronServer:
- [self performSelectorOnMainThread:@selector(jErrorMessage) withObject:nil waitUntilDone:NO];
- break;
- case jNoContent:
- [self performSelectorOnMainThread:@selector(jNoContent) withObject:nil waitUntilDone:NO];
- break;
- case jErrorMessage:
- [self performSelectorOnMainThread:@selector(jErrorMessage) withObject:nil waitUntilDone:NO];
- break;
- case jUnsupportedFile:
- [self performSelectorOnMainThread:@selector(jUnsupportedFile) withObject:nil waitUntilDone:NO];
- break;
- case jInvalidData:
- [self performSelectorOnMainThread:@selector(jInvalidData) withObject:nil waitUntilDone:NO];
- break;
- case jUserNameError:
- [self performSelectorOnMainThread:@selector(jUserNameError) withObject:nil waitUntilDone:NO];
- break;
- case jEmailError:
- [self performSelectorOnMainThread:@selector(jEmailError) withObject:nil waitUntilDone:NO];
- break;
- case jFBOption:
- [self performSelectorOnMainThread:@selector(jFBOption) withObject:nil waitUntilDone:NO];
- break;
- case jSessionExpire:
- DLog(@"Session Expired Logging in Again");
- [[ApplicationData sharedInstance] LoginCheck:self];
- break;
- break;
- case jReportedContent:
- [self performSelectorOnMainThread:@selector(jReportedContent) withObject:nil waitUntilDone:NO];
- break;
- case JPermissionError:
- [self performSelectorOnMainThread:@selector(JPermissionError) withObject:nil waitUntilDone:NO];
- break;
- case jDuplicateData:
- [self performSelectorOnMainThread:@selector(jDuplicateData) withObject:nil waitUntilDone:NO];
- break;
- case jWaitingForPermission:
- [self performSelectorOnMainThread:@selector(jWaitingForPermission) withObject:nil waitUntilDone:NO];
- break;
- case jSuccess:
- switch (currentRequestType) {
- case jGeneralQuery:
- if ([selectedWall.likeList count] > 0) {
- [self performSelectorOnMainThread:@selector(setData) withObject:nil waitUntilDone:NO];
- [tableView reloadData];
- }else {
- [self fetchLikes];
- }
- break;
- case jlikeUnlikeQuery:
- [self performSelectorOnMainThread:@selector(setData) withObject:nil waitUntilDone:NO];
- [tableView reloadData];
- break;
- case jPostQuery:
- {
- txtComment.text = @"";
- btnWriteComment.hidden = NO;
- selectedWall.comments++;
- [self performSelectorOnMainThread:@selector(fetchComments) withObject:nil waitUntilDone:NO];
- [self performSelectorOnMainThread:@selector(setData) withObject:nil waitUntilDone:NO];
- [tableView reloadData];
- }
- break;
- case jDeleteWallQuery:
- [self performSelectorOnMainThread:@selector(fetchComments) withObject:nil waitUntilDone:NO];
- [self performSelectorOnMainThread:@selector(setData) withObject:nil waitUntilDone:NO];
- [tableView reloadData];
- break;
- case jLikeQuery:
- self.navigationItem.rightBarButtonItem.title = NSLocalizedString(@"unlike_btn",@"");
- likeRecord.userId = [ApplicationData sharedInstance].loggedUser;
- likeRecord.name = [ApplicationData sharedInstance].userDetail.userName;
- [selectedWall.likeList addObject:likeRecord];
- [self performSelectorOnMainThread:@selector(setData2) withObject:nil waitUntilDone:NO];
- break;
- case jUnlikeQuery:
- self.navigationItem.rightBarButtonItem.title = NSLocalizedString(@"like_btn",@"");
- for (Like *record in selectedWall.likeList) {
- if ([ApplicationData sharedInstance].loggedUser == record.userId) {
- [selectedWall.likeList removeObject:record];
- break;
- }
- }
- [self performSelectorOnMainThread:@selector(setData2) withObject:nil waitUntilDone:NO];
- break;
- case jAddFriendQuery:
- [self performSelectorOnMainThread:@selector(approvalmsg) withObject:nil waitUntilDone:NO];
- break;
- default:
- break;
- }
- break;
- default:
- break;
- }
- }
- - (void)refresh {
- if (![spinner isAnimating]) {
- [spinner startAnimating];
- tableView.hidden = YES;
- // commentArray = [[NSMutableArray alloc] init];
- // likeArray = [[NSMutableArray alloc] init];
- [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(fetchComments) userInfo:nil repeats:NO];
- self.pageNo = 1;
- self.hasPrev = 0;
- }
- }
- - (void)openLoginView {
- LoginViewController *controller = [[LoginViewController alloc] init];
- [ApplicationData sharedInstance].userDetail.avatarImg = nil;
- int k = [controller LogincheckDict];
- if (k == 1) {
- [controller LoginDone];
- [self viewWillAppear:NO];
- }
- else if (k==2)
- {
- [controller FBLoginDone];
- [self viewWillAppear:NO];
- }
- else
- {
- [self presentModalViewController:controller animated:YES];
- }
- [controller release];
- }
- #pragma mark --
- #pragma mark setImages
- - (void)setImages {
- // set images in a row of custom table view
- int x = 42;
- int y = yPos;
- float width = 60;
- float height = 60;
- int i = 0;
- int row = 1;
- BOOL isGetNew = YES;
- for (Photo *record in selectedWall.imageList) {
- isGetNew = YES;
- UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
- btn.frame = CGRectMake(x, y, width, height);
- btn.tag = (NSInteger)i;
- if (record.thumbImg) {
- [btn setImage:record.thumbImg forState:UIControlStateNormal];
- [headerView insertSubview:btn atIndex:1];
- x += 62;
- if ((i+1) % 4 == 0) {
- row++;
- x = 42;
- y += 62;
- isGetNew = NO;
- }
- i++;
- }
- }
- if (isGetNew) {
- yPos = y + 62;
- } else {
- yPos = y;
- }
- [textView bringSubviewToFront:self.view];
- }
- - (float)getTextSize:(NSString *)text Font:(UIFont *)font MaxWidth:(float)width {
- // get the value of text fot the text height
- CGSize maximumLabelSize = CGSizeMake(width,9999);
- CGSize expectedLabelSize = [text sizeWithFont:font
- constrainedToSize:maximumLabelSize
- lineBreakMode:UILineBreakModeWordWrap];
- return expectedLabelSize.height;
- }
- #pragma mark --
- #pragma mark ButtonPressed
- - (void)setData2 {
- [textView resignFirstResponder];
- [textView setHidden:YES];
- [self setData];
- }
- #pragma mark --
- #pragma mark TableView
- - (NSInteger)tableView:(UITableView *)tableView1 numberOfRowsInSection:(NSInteger)section {
- if ([selectedWall.commentList count] > 0) {
- tableView.hidden = NO;
- return [commentArray count] + 1;
- }
- return 0;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- if(indexPath.row < [commentArray count])
- {
- Comment *record = [commentArray objectAtIndex:indexPath.row];
- CGSize size = [record.creatorname sizeWithFont:[UIFont boldSystemFontOfSize:11] constrainedToSize:CGSizeMake(240, 9999) lineBreakMode:UILineBreakModeWordWrap];
- CGFloat height = size.height;
- size = [record.commentText sizeWithFont:[UIFont systemFontOfSize:11] constrainedToSize:CGSizeMake(240, 9999) lineBreakMode:UILineBreakModeWordWrap];
- height += size.height;
- size = [record.dateTime sizeWithFont:[UIFont systemFontOfSize:11] constrainedToSize:CGSizeMake(240, 9999) lineBreakMode:UILineBreakModeWordWrap];
- height += size.height +14;
- if([record.commentLink isEqual: @""]){
- return MAX(height, 72);
- }else{
- return MAX(height+115, 72);
- }
- }else{
- return 44;
- }
- }
- - (UITableViewCell *)tableView:(UITableView *)tableViewController cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- if(indexPath.row < [commentArray count])
- {
- if (event) {
- JomCommentCell *cell = (JomCommentCell *)[tableView dequeueReusableCellWithIdentifier:kCellIdentifier1];
- cell.backgroundColor = [UIColor clearColor];
- Comment *record = [commentArray objectAtIndex:indexPath.row];
- if (cell == nil) {
- //kCellIdentifier will call the wallCell
- [cellOwner loadMyNibFile:kCellIdentifier1];
- cell = (JomCommentCell *)cellOwner.cell;
- }
- [cell.btnDelete addTarget:self action:@selector(deleteButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
- [cell.btnPlay addTarget:self action:@selector(PlayCommentcontentButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
- if (record.thumbURL > 0 && !record.thumbImg) {
- [self performSelectorOnMainThread:@selector(startIconDownload:) withObject:record waitUntilDone:NO];
- }
- cell.btnPlay.tag = (NSInteger)indexPath.row;
- cell.btnDelete.tag = (NSInteger)indexPath.row;
- cell.commentRecord = record;
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- [cell reloadCell];
- return cell;
- }
- else {
- commentListCell *cell = (commentListCell *)[tableView dequeueReusableCellWithIdentifier:kCellIdentifiercommentListCell];
- cell.backgroundColor = [UIColor clearColor];
- Comment *record = [commentArray objectAtIndex:indexPath.row];
- if (cell == nil) {
- //kCellIdentifier will call the wallCell
- [cellOwner loadMyNibFile:kCellIdentifiercommentListCell];
- cell = (commentListCell *)cellOwner.cell;
- }
- [cell.btnUser addTarget:self action:@selector(userButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
- [cell.btnDelete addTarget:self action:@selector(deleteButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
- [cell.btnPlay addTarget:self action:@selector(PlayCommentcontentButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
- cell.btnUser.tag = (NSInteger)indexPath.row;
- cell.btnDelete.tag = (NSInteger)indexPath.row;
- cell.btnPlay.tag = (NSInteger)indexPath.row;
- if (record.thumbURL > 0 && !record.thumbImg) {
- [self performSelectorOnMainThread:@selector(startIconDownload:) withObject:record waitUntilDone:NO];
- }
- cell.commentRecord = record;
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- [cell reloadCell];
- return cell;
- }
- }else{
- static NSString *CellIdentifier = @"Cell";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
- cell.backgroundColor = [ApplicationData sharedInstance].tintColor;
- if (cell == nil)
- {
- cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil]autorelease];
- // cell.backgroundColor = [ApplicationData sharedInstance].themeColor;
- cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:13];
- //cell.textLabel.textColor = [ApplicationData sharedInstance].textcolor;
- }
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- cell.textLabel.text = NSLocalizedString(@"moreresult_title", @"Get more results...");
- cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:13];
- cell.textLabel.textColor = [UIColor blackColor];
- return cell;
- }
- }
- - (void)tableView:(UITableView *)tableViewController didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
- if(indexPath.row < [commentArray count]){
- NSLog(@"tipota");
- }else{
- ++self.pageNo;
- NSLog([NSString stringWithFormat:@"Auto : %d", self.pageNo]);
- [spinner startAnimating];
- [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(fetchComments) userInfo:nil repeats:NO];
- [tableView setContentOffset:CGPointZero animated:NO];
- }
- }
- - (IBAction)userButtonPressed:(id)sender {
- /*
- Comment *record = [commentArray objectAtIndex:[sender tag]];
- MainPageViewController *controller = [[MainPageViewController alloc] init];
- controller.userDetail.userId = record.userId;
- controller.userDetail.userName = record.creatorname;
- [self.navigationController pushViewController:controller animated:YES];
- [controller release];
- */
- Comment *recorda = [commentArray objectAtIndex:[sender tag]];
- Wall *record = [[ApplicationData sharedInstance].updatesList objectAtIndex:[sender tag]];
- MainPageViewController *controller = [[MainPageViewController alloc] init];
- controller.userDetail = record.userdetail;
- controller.userDetail.userId = recorda.userId;
- [self.navigationController pushViewController:controller animated:YES];
- [controller release];
- }
- -(IBAction)deleteButtonPressed:(id)sender {
- Comment *record = [commentArray objectAtIndex:[sender tag]];
- NSMutableDictionary *postVariables = [[NSMutableDictionary alloc]init];
- NSDictionary *dict;
- [postVariables setObject:[NSString stringWithFormat:@"%d",record.commentId] forKey:@"uniqueID"];
- [postVariables setObject:@"1" forKey:@"comment"];
- NSString *jsonString = [Jomsocial CreateDictionary_joomsocial:@"wall" ExtTask:@"remove" TaskdataDictionary:postVariables Imagedata:nil];
- dict = [JoomlaRegistration JoomSocialDictionary:jsonString Imagedata:nil];
- // newWall = [GlobalObjects Share:dict];
- currentRequestType = jDeleteWallQuery;
- [ApplicationData sharedInstance].errorCode = [[dict objectForKey:@"code"] intValue];
- [self requestCompleted];
- }
- -(IBAction)Send1ButtonPressed:(id)sender{
- if (txtComment.text.length == 0) {
- [self showAlert:NSLocalizedString(@"no_text",@"") Content:NSLocalizedString(@"Please_enter_text", @"")];
- return;
- }
- [[self.view findFirstResponder] resignFirstResponder];
- NSMutableDictionary *postVariables = [[NSMutableDictionary alloc]init];
- [postVariables setObject:txtComment.text forKey:@"message"];
- [postVariables setObject:[NSString stringWithFormat:@"%d",selectedWall.wallId] forKey:@"uniqueID"];
- [postVariables setObject:[NSString stringWithFormat:@"%d",1] forKey:@"comment"];
- // [postVariables setObject:[NSString stringWithFormat:@"%d",permissionValue] forKey:@"permissions"];
- NSString *jsonString = [Jomsocial CreateDictionary_joomsocial:@"wall" ExtTask:@"add" TaskdataDictionary:postVariables Imagedata:nil];
- NSDictionary *dict = [JoomlaRegistration JoomSocialDictionary:jsonString Imagedata:nil];
- [ApplicationData sharedInstance].errorCode = [[dict objectForKey:TAG_CODE] intValue];
- currentRequestType = jPostQuery;
- [self requestCompleted];
- }
- -(IBAction)SendButtonPressed:(id)sender {
- [spinner startAnimating];
- [self voiceoverHide];
- [txtComment resignFirstResponder];
- [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(Send1ButtonPressed:) userInfo:nil repeats:NO];
- }
- -(IBAction)voiceSendButtonPressed:(id)sender {
- [Voiceover HoldAndSpeakButtonPressed:nil];
- if ([[ApplicationData sharedInstance].VoiceCurrentTime isEqualToString:@"00:00"]) {
- [spinner stopAnimating];
- DLog(@"return update...");
- return;
- }
- NSMutableDictionary *postVariables = [[NSMutableDictionary alloc]init];
- if (group) {
- [postVariables setObject:txtComment.text forKey:@"message"];
- [postVariables setObject:[NSString stringWithFormat:@"%d",selectedWall.wallId] forKey:@"uniqueID"];
- [postVariables setObject:[NSString stringWithFormat:@"%d",1] forKey:@"comment"];
- NSDictionary *dict = [Jomsocial JomsocialCommonDictfunctionVoice:@"group" ExtTask:@"addWall" TaskdataDictionary:postVariables Voicedata:[ApplicationData sharedInstance].Voicedata voicename:@"voice"];
- [ApplicationData sharedInstance].errorCode = [[dict objectForKey:TAG_CODE] intValue];
- }else if (event) {
- [postVariables setObject:txtComment.text forKey:@"message"];
- [postVariables setObject:[NSString stringWithFormat:@"%d",selectedWall.wallId] forKey:@"uniqueID"];
- [postVariables setObject:[NSString stringWithFormat:@"%d",1] forKey:@"comment"];
- NSDictionary *dict = [Jomsocial JomsocialCommonDictfunctionVoice:@"event" ExtTask:@"addWall" TaskdataDictionary:postVariables Voicedata:[ApplicationData sharedInstance].Voicedata voicename:@"voice"];
- [ApplicationData sharedInstance].errorCode = [[dict objectForKey:TAG_CODE] intValue];
- }else {
- [self voiceoverHide];
- [postVariables setObject:txtComment.text forKey:@"message"];
- [postVariables setObject:[NSString stringWithFormat:@"%d",selectedWall.wallId] forKey:@"uniqueID"];
- [postVariables setObject:[NSString stringWithFormat:@"%d",1] forKey:@"comment"];
- [postVariables setObject:@"0" forKey:@"privacy"];
- NSDictionary *dict = [Jomsocial JomsocialCommonDictfunctionVoice:@"wall" ExtTask:@"add" TaskdataDictionary:postVariables Voicedata:[ApplicationData sharedInstance].Voicedata voicename:@"voice"];
- [ApplicationData sharedInstance].errorCode = [[dict objectForKey:TAG_CODE] intValue];
- }
- currentRequestType = jPostQuery;
- [self requestCompleted];
- }
- -(IBAction)VoiceButtonPressed:(id)sender {
- // self.view.userInteractionEnabled = NO;
- [spinner startAnimating];
- Voiceover.SpeakerView.hidden = YES;
- [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(voiceSendButtonPressed:) userInfo:nil repeats:NO];
- }
- #pragma mark --
- #pragma mark AlertView
- - (void)showAlert:(NSString *)title Content:(NSString *)bodyText {
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:bodyText
- delegate:self cancelButtonTitle:NSLocalizedString(@"alert_cancel_btn_title",@"") otherButtonTitles: nil];
- [alert setContentMode:UIViewContentModeScaleAspectFit];
- [alert show];
- [alert release];
- }
- - (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex {
- if ((buttonIndex == 0) && (alertView.tag == 1)) {
- [textView resignFirstResponder];
- [textView setHidden:YES];
- self.navigationItem.leftBarButtonItem = nil;
- if (group) {
- self.navigationItem.rightBarButtonItem = nil;
- } else {
- self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"like_btn",@"")
- style:UIBarButtonItemStyleBordered target:self action:@selector(likeButtonPressed:)];
- for (Like *record in selectedWall.likeList) {
- if ([ApplicationData sharedInstance].loggedUser == record.userId) {
- self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"unlike_btn",@"")
- style:UIBarButtonItemStyleBordered target:self action:@selector(likeButtonPressed:)];
- break;
- }
- }
- }
- }
- }
- - (void)viewWillDisappear:(BOOL)animated {
- [mp stop];
- [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
- [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
- [NSObject cancelPreviousPerformRequestsWithTarget:self];
- if([spinner isAnimating]) {
- RequestResponseManager *requestManager = [RequestResponseManager sharedInstance];
- [requestManager cancleRequest];
- }
- if([imageDownloadsInProgress count] > 0) {
- IconDownloader *downloader;
- for(downloader in [imageDownloadsInProgress objectEnumerator]) {
- [downloader cancelDownload];
- }
- [imageDownloadsInProgress removeAllObjects];
- }
- [spinner stopAnimating];
- [super viewDidDisappear:animated];
- }
- - (void)dealloc {
- [NSObject cancelPreviousPerformRequestsWithTarget:self];
- [txtContent release];
- [textView release];
- [thumbImg release];
- [txtStatusMessage release];
- [btnStatusMessage release];
- [spinner release];
- [backImg release];
- [headerView release];
- [super dealloc];
- }
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////// IconDownloaderDelegate ////////////////////////////////////////////////
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////
- #pragma mark --
- #pragma mark IconDownloader
- - (void)startIconDownload:(Comment *)appRecord {
- IconDownloader *iconDownloader = [imageDownloadsInProgress objectForKey:appRecord.thumbURL];;
- if (iconDownloader == nil && [appRecord.thumbURL length] > 0) {
- [spinner startAnimating];
- iconDownloader = [[IconDownloader alloc] init];
- iconDownloader.appRecord = appRecord;
- iconDownloader.delegate = self;
- iconDownloader.imageKey = appRecord.thumbURL;
- [imageDownloadsInProgress setObject:iconDownloader forKey:appRecord.thumbURL];
- [iconDownloader startDownload];
- [iconDownloader release];
- [multipleDownloadRecord setObject:[[NSMutableArray alloc] initWithObjects:appRecord, nil] forKey:appRecord.thumbURL];
- } else {
- NSMutableArray *downloadingRecords = [multipleDownloadRecord objectForKey:appRecord.thumbURL];
- [downloadingRecords addObject:appRecord];
- }
- }
- - (void)appImageDidLoad:(NSObject *)imageKey {
- [imageDownloadsInProgress removeObjectForKey:imageKey];
- // for same url of multiple records
- NSMutableArray *downloadingRecords = [multipleDownloadRecord objectForKey:imageKey];
- if([downloadingRecords count] > 1) {
- if([[downloadingRecords objectAtIndex:0] isKindOfClass:[Comment class]]) {
- Comment *record = [downloadingRecords objectAtIndex:0];
- for(id<IconRecord> otherRecord in downloadingRecords) {
- [otherRecord setImage:record.thumbImg ImageKey:imageKey];
- }
- }
- }
- [downloadingRecords removeAllObjects];
- [multipleDownloadRecord removeObjectForKey:imageKey];
- if([imageDownloadsInProgress count] == 0) {
- [spinner stopAnimating];
- [[ApplicationData sharedInstance] stopImage];
- [tableView reloadData];
- }
- }
- - (void)keyboardWillShow:(NSNotification *)notification {
- if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
- {
- CGSize result = [[UIScreen mainScreen] bounds].size;
- if(result.height == 480)
- {
- tableView.frame = CGRectMake(5, 0, 310, 170);
- viewComment.frame = CGRectMake(0, 170, 320, 30);
- // iPhone Classic
- }
- if(result.height == 568)
- {
- tableView.frame = CGRectMake(5, 0, 310, 250);
- viewComment.frame = CGRectMake(0, 250, 320, 30);
- // iPhone 5
- }
- }
- }
- - (void)keyboardDidHide:(NSNotification *)notification {
- [self voiceoverHide];
- }
- -(BOOL)textFieldShouldReturn:(UITextField *)textField {
- [textField resignFirstResponder];
- return YES;
- }
- - (void)textViewDidBeginEditing:(UITextView *)textView {
- if ([[[UIDevice currentDevice]systemVersion]floatValue] >= 8.0) {
- if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
- {
- CGSize result = [[UIScreen mainScreen] bounds].size;
- if(result.height == 480)
- {
- Voiceover.frame = CGRectMake(5, 110, Voiceover.frame.size.width
- , Voiceover.frame.size.height);
- }
- if(result.height == 568)
- {
- Voiceover.frame = CGRectMake(5,200, Voiceover.frame.size.width
- , Voiceover.frame.size.height);
- }
- }
- }
- else{
- if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
- {
- CGSize result = [[UIScreen mainScreen] bounds].size;
- if(result.height == 480)
- {
- Voiceover.frame = CGRectMake(5, 150, Voiceover.frame.size.width
- , Voiceover.frame.size.height);
- }
- if(result.height == 568)
- {
- Voiceover.frame = CGRectMake(5,240, Voiceover.frame.size.width
- , Voiceover.frame.size.height);
- }
- }
- }
- }
- - (void)viewDidUnload {
- [NSObject cancelPreviousPerformRequestsWithTarget:self];
- [headerView release];
- headerView = nil;
- [super viewDidUnload];
- }
- ///------------------------------- Pull down to Refresh start ---------------------------------///
- - (void)addPullToRefreshHeader {
- textPull = [[NSString alloc] initWithString:@"Pull down to refresh..."];
- textRelease = [[NSString alloc] initWithString:@"Release to refresh..."];
- textLoading = [[NSString alloc] initWithString:@"Loading..."];
- refreshHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0 - REFRESH_HEADER_HEIGHT, 320, REFRESH_HEADER_HEIGHT)];
- refreshHeaderView.backgroundColor = [UIColor clearColor];
- refreshLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, pullTable.frame.size.width, REFRESH_HEADER_HEIGHT)];
- refreshLabel.backgroundColor = [UIColor clearColor];
- refreshLabel.font = [UIFont boldSystemFontOfSize:12.0];
- refreshLabel.textColor = [ApplicationData sharedInstance].textcolor;//[UIColor whiteColor];
- refreshLabel.textAlignment = UITextAlignmentCenter;
- refreshArrow = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrowpull.png"]];
- [refreshArrow setContentMode:UIViewContentModeCenter];
- refreshArrow.frame = CGRectMake((REFRESH_HEADER_HEIGHT - 27) / 2,
- (REFRESH_HEADER_HEIGHT - 44) / 2,
- 27, 44);
- [refreshHeaderView addSubview:refreshLabel];
- [refreshHeaderView addSubview:refreshArrow];
- [self->pullTable addSubview:refreshHeaderView];
- }
- - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView1 {
- tablescroll_Y = [scrollView1 contentOffset].y;
- if (txtComment.text.length == 0)
- {
- btnWriteComment.hidden = NO;
- }else{
- btnWriteComment.hidden = YES;
- }
- if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
- CGSize result = [[UIScreen mainScreen] bounds].size;
- if(result.height == 480) {
- if (isTabbarHidden == YES) {
- Voiceover.frame = CGRectMake(5, 360, Voiceover.frame.size.width, Voiceover.frame.size.height);
- }
- else {
- Voiceover.frame = CGRectMake(5, 310, Voiceover.frame.size.width, Voiceover.frame.size.height);
- }
- }
- else if(result.height == 568) {
- if (isTabbarHidden == YES) {
- Voiceover.frame = CGRectMake(5, 445, Voiceover.frame.size.width
- , Voiceover.frame.size.height);
- }
- else {
- Voiceover.frame = CGRectMake(5, 400, Voiceover.frame.size.width
- , Voiceover.frame.size.height);
- } // iPhone 5
- }
- }
- if (isLoading) return;
- isDragging = YES;
- }
- - (void)scrollViewDidScroll:(UIScrollView *)scrollView1 {
- if (isLoading) {
- // Update the content inset, good for section headers
- if (scrollView1.contentOffset.y > 0)
- self->pullTable.contentInset = UIEdgeInsetsZero;
- else if (scrollView1.contentOffset.y >= -REFRESH_HEADER_HEIGHT)
- self->pullTable.contentInset = UIEdgeInsetsMake(-scrollView1.contentOffset.y, 0, 0, 0);
- } else if (isDragging && scrollView1.contentOffset.y < 0) {
- // Update the arrow direction and label
- [UIView beginAnimations:nil context:NULL];
- if (scrollView1.contentOffset.y < -REFRESH_HEADER_HEIGHT) {
- // User is scrolling above the header
- refreshLabel.text = self->textRelease;
- [refreshArrow layer].transform = CATransform3DMakeRotation(M_PI, 0, 0, 1);
- } else { // User is scrolling somewhere within the header
- refreshLabel.text = self->textPull;
- [refreshArrow layer].transform = CATransform3DMakeRotation(M_PI * 2, 0, 0, 1);
- }
- [UIView commitAnimations];
- }
- }
- - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView1 willDecelerate:(BOOL)decelerate {
- [txtComment resignFirstResponder];
- [Voiceover.txtStaus resignFirstResponder];
- if (isLoading) return;
- isDragging = NO;
- if (scrollView1.contentOffset.y <= -REFRESH_HEADER_HEIGHT) {
- // Released above the header
- [self startLoading];
- }
- }
- - (void)startLoading {
- isLoading = YES;
- // Show the header
- [UIView beginAnimations:nil context:NULL];
- [UIView setAnimationDuration:0.3];
- self->pullTable.contentInset = UIEdgeInsetsMake(REFRESH_HEADER_HEIGHT, 0, 0, 0);
- refreshLabel.text = self->textLoading;
- refreshArrow.hidden = YES;
- [refreshSpinner startAnimating];
- [UIView commitAnimations];
- // Refresh action!
- [self refresh];
- }
- - (void)stopLoading {
- isLoading = NO;
- // Hide the header
- [UIView beginAnimations:nil context:NULL];
- [UIView setAnimationDelegate:self];
- [UIView setAnimationDuration:0.3];
- [UIView setAnimationDidStopSelector:@selector(stopLoadingComplete:finished:context:)];
- self->pullTable.contentInset = UIEdgeInsetsZero;
- [refreshArrow layer].transform = CATransform3DMakeRotation(M_PI * 2, 0, 0, 1);
- [UIView commitAnimations];
- }
- - (void)stopLoadingComplete:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
- // Reset the header
- refreshLabel.text = self->textPull;
- refreshArrow.hidden = NO;
- [refreshSpinner stopAnimating];
- }
- ///------------------------------- Pull down to Refresh end ---------------------------------///
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement