PageRenderTime 28ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/WHAMBUSH/wbSingleVideoView.m

https://gitlab.com/urbanjunglestudio/whambush-ios
Objective C | 1052 lines | 723 code | 156 blank | 173 comment | 124 complexity | f7d42e518d14bb1908e7470143a19c4f MD5 | raw file
  1. //
  2. // wbSingleVideoView.m
  3. // WHAMBUSH
  4. //
  5. // Created by Jari Kalinainen on 9/6/13.
  6. // Copyright (c) 2013 Jari Kalinainen. All rights reserved.
  7. //
  8. #import "wbSingleVideoView.h"
  9. @implementation wbSingleVideoView
  10. @synthesize videoPlayerController;
  11. #define kCOMMENTROW ([indexPath row]-4)
  12. - (id)initWithFrame:(CGRect)frame controller:(UIViewController*)_controller content:(NSMutableDictionary*) contentA
  13. {
  14. self = [super initWithFrame:frame];
  15. if (self) {
  16. controller = _controller;
  17. contentArray = contentA;
  18. [[wbData sharedData] saveWhambushUser:[contentArray objectForKey:@"added_by"]];
  19. if (![[contentArray objectForKey:@"mission_id"] isKindOfClass:[NSNull class]]) {
  20. mission = [[wbMission alloc] initWithId:[[contentArray objectForKey:@"mission_id"] integerValue]];
  21. }
  22. if ([[contentArray objectForKey:@"video_type"] integerValue] == 2) {
  23. [[wbHeader sharedHeader] setLogo:@"_tv_"];
  24. [(wbBaseViewController*)controller setHeaderLogo:@"_tv_"];
  25. }
  26. DCMSG(contentArray);
  27. charCount = 0;
  28. videoRowHeight = (self.bounds.size.width/16)*9;
  29. descriptionRowHeight = 50;
  30. moreRowHeight = 0;
  31. fclRowHeight = 40.0;
  32. videoWebLoaded = NO;
  33. commentCount = [[contentArray valueForKey:@"comment_count"] integerValue];
  34. likeCount = [[contentArray valueForKey:@"like_count"] integerValue];
  35. dislikeCount = [[contentArray valueForKey:@"dislike_count"] integerValue];
  36. has_liked = [[contentArray valueForKey:@"has_liked"] boolValue];
  37. has_disliked = [[contentArray valueForKey:@"has_disliked"] boolValue];
  38. content = [[UITableView alloc] initWithFrame:CGRectMake(0, 1, [self frame].size.width, [self frame].size.height)];
  39. [content setBackgroundColor:kTRANSPARENTUICOLOR];
  40. [content setDelegate:self];
  41. [content setDataSource:self];
  42. [content setSeparatorStyle:UITableViewCellSeparatorStyleNone];
  43. [content setCanCancelContentTouches:NO];
  44. UIView *tableFooter =[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, 50)];
  45. [tableFooter setBackgroundColor:kTRANSPARENTUICOLOR];
  46. UIActivityIndicatorView *commentai = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
  47. [commentai setCenter:CGPointMake(tableFooter.frame.size.width/2, tableFooter.frame.size.height/2)];
  48. [commentai startAnimating];
  49. [tableFooter addSubview:commentai];
  50. [content setTableFooterView:tableFooter];
  51. flagSelect = [[wbFlagSelectionView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
  52. insertTxtView = [[wbInsertTextView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
  53. [insertTxtView setDelegate:self];
  54. [insertTxtView setMaxCharCount:150];
  55. [insertTxtView setMaxLinesCount:6];
  56. [insertTxtView setHeaderText:NSLocalizedString(@"SINGLE_ADD_COMMENT", @"")];
  57. user = [[wbData sharedData] getWhambushUser:[[contentArray objectForKey:@"added_by"] objectForKey:@"url"]];
  58. //videoPlayerController = [[wbVideoPlayerViewController alloc] init];
  59. [self setGAIViewName];
  60. if (videoPlayerController == nil) {
  61. videoPlayerController = [[wbVideoPlayerViewController alloc] init];
  62. }
  63. [videoPlayerController setVideoURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://view.vzaar.com/%@/video",[contentArray valueForKey:@"external_id"]]]];
  64. [videoPlayerController setVideoThumbURL:[NSURL URLWithString:[contentArray valueForKey:@"thumbnail_url"]]];
  65. [videoPlayerController.view setHidden:NO];
  66. [(wbVideoPlayerView*)videoPlayerController.view setShowShare:YES];
  67. [videoPlayerController setDelegate:self];
  68. NSBlockOperation *op = [NSBlockOperation blockOperationWithBlock:^(void){
  69. [[wbWaitView sharedWait] performSelectorOnMainThread:@selector(show) withObject:NULL waitUntilDone:YES];
  70. }];
  71. [op setCompletionBlock:^(void){
  72. NSArray *excludedServices = [NSArray arrayWithObjects:
  73. //UIActivityTypePostToFacebook,
  74. //UIActivityTypePostToTwitter,
  75. //UIActivityTypePostToWeibo,
  76. //UIActivityTypeMessage,
  77. //UIActivityTypeMail,
  78. UIActivityTypePrint,
  79. //UIActivityTypeCopyToPasteboard,
  80. UIActivityTypeAssignToContact,
  81. UIActivityTypeSaveToCameraRoll,
  82. //UIActivityTypeAddToReadingList,
  83. UIActivityTypePostToFlickr,
  84. UIActivityTypePostToVimeo,
  85. //UIActivityTypePostToTencentWeibo,
  86. UIActivityTypeAirDrop,
  87. nil];
  88. NSString *shareString = [NSString stringWithFormat:NSLocalizedString(@"SINGLE_SHARE_MESSAGE", @""),[contentArray objectForKey:@"name"]];
  89. NSURL *shareURL = [NSURL URLWithString:[contentArray objectForKey:@"web_url"]];
  90. activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[shareString, shareURL] applicationActivities:nil];
  91. [activityViewController setExcludedActivityTypes:excludedServices];
  92. [activityViewController setValue:NSLocalizedString(@"SINGLE_SHARE_TITLE", @"") forKey:@"subject"];
  93. [self performSelectorOnMainThread:@selector(initialize) withObject:NULL waitUntilDone:YES];
  94. }];
  95. [op start];
  96. UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureAction:)];
  97. [self addGestureRecognizer:tapGesture];
  98. }
  99. DPRINTCLASS;
  100. return self;
  101. }
  102. -(void)setGAIViewName
  103. {
  104. NSString *gaString = [NSString stringWithFormat:@"Single:video=%ld",(long)[[contentArray objectForKey:@"id"] integerValue]];
  105. [[wbAPI sharedAPI] registerGoogleAnalytics:gaString];
  106. }
  107. // Only override drawRect: if you perform custom drawing.
  108. // An empty implementation adversely affects performance during animation.
  109. //- (void)drawRect:(CGRect)rect
  110. - (void)initialize
  111. {
  112. DMSG;
  113. // Drawing code
  114. // description start
  115. wbLabel *title = [[wbLabel alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
  116. [title setText:[NSString stringWithFormat:@"%@",[[contentArray objectForKey:@"name"] uppercaseString]]];
  117. [title setFont:kFONT(22)];
  118. [title setTextColor:kWHITEUICOLOR];
  119. [title setEdgeInsets:UIEdgeInsetsMake(6, 6, 0, 0)];
  120. [title sizeToFit];
  121. descriptionRowHeight = CGRectGetHeight(title.frame);
  122. wbButton *username = [wbButton buttonWithType:UIButtonTypeSystem];
  123. [user userButton:username controller:controller txt:YES];
  124. [username setFrame:CGRectMake(0,CGRectGetMaxY(title.frame), 0, 0)];
  125. [username setTitleEdgeInsets:UIEdgeInsetsMake(0, 6, 2, 0)];
  126. [username sizeToFit];
  127. descriptionRowHeight += CGRectGetHeight(username.frame);
  128. UITextView *description = [[UITextView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(username.frame), self.frame.size.width, 0)];
  129. [description setBackgroundColor:kTRANSPARENTUICOLOR];
  130. if ([[contentArray objectForKey:@"description"] length] > 0) {
  131. [description setText:[NSString stringWithFormat:@"%@",[contentArray objectForKey:@"description"]]];
  132. [description setFont:kFONTHelvetica(15)];
  133. [description setTextColor:kWHITEUICOLOR];
  134. [description setDataDetectorTypes:UIDataDetectorTypeLink];
  135. [description setTextContainerInset:UIEdgeInsetsMake(2, 2, 2, 0)];
  136. [description setScrollEnabled:NO];
  137. [description setEditable:NO];
  138. [description setUserInteractionEnabled:YES];
  139. [description setTintColor:kGREENUICOLOR];
  140. [description sizeToFit];
  141. }
  142. descriptionRowHeight += CGRectGetHeight(description.frame);
  143. //tags
  144. wbLabel *tags = [[wbLabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(description.frame), self.frame.size.width, 0)];
  145. if ([[contentArray objectForKey:@"tags"] length] > 0) {
  146. NSString *tagString = [[[contentArray objectForKey:@"tags"] uppercaseString] stringByReplacingOccurrencesOfString:@"," withString:@", "];
  147. [tags setText:[NSString stringWithFormat:@"%@ %@",NSLocalizedString(@"SINGLE_TAG_PREFIX", @""),tagString]];
  148. [tags setFont:kFONT(12)];
  149. [tags setEdgeInsets:UIEdgeInsetsMake(8, 6, 2, 0)];
  150. [tags setTextColor:kWHITEUICOLOR];
  151. [tags setNumberOfLines:0];
  152. [tags sizeToFit];
  153. }
  154. descriptionRowHeight += CGRectGetHeight(tags.frame);
  155. wbLabel *posted = [[wbLabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(tags.frame), self.frame.size.width, 1)];
  156. [posted setText:[NSString stringWithFormat:@"%@",[[wbAPI sharedAPI] parsePostedTime:[contentArray objectForKey:@"published_at"]]]];
  157. [posted setFont:kFONTHelvetica(10)];
  158. [posted setTextColor:kWHITEUICOLOR];
  159. [posted setEdgeInsets:UIEdgeInsetsMake(2, 6, 6, 0)];
  160. [posted sizeToFit];
  161. descriptionRowHeight += CGRectGetHeight(posted.frame);
  162. if (postedButton == nil) {
  163. postedButton = [wbButton buttonWithType:UIButtonTypeSystem];
  164. }
  165. [postedButton.titleLabel setFont:kFONTHelvetica(10)];
  166. [postedButton setTitleColor:kWHITEUICOLOR forState:UIControlStateNormal];
  167. [postedButton setTitleColor:kWHITEUICOLOR forState:UIControlStateSelected];
  168. [postedButton setTitle:[NSString stringWithFormat:@"%@",[[wbAPI sharedAPI] parsePostedTime:[contentArray objectForKey:@"published_at"]]] forState:UIControlStateNormal];
  169. [postedButton setTitle:[[wbAPI sharedAPI] beautifyTime:[contentArray objectForKey:@"published_at"]] forState:UIControlStateSelected];
  170. [postedButton setSelected:NO];
  171. [postedButton setTintColor:kTRANSPARENTUICOLOR];
  172. [postedButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
  173. [postedButton sizeToFit];
  174. [postedButton setFrame:CGRectMake(6, CGRectGetMaxY(tags.frame), self.frame.size.width, postedButton.frame.size.height)];
  175. [postedButton addTarget:self action:@selector(togglePosted) forControlEvents:UIControlEventTouchUpInside];
  176. if (descriptionRow == nil) {
  177. descriptionRow = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, descriptionRowHeight)];
  178. }
  179. [descriptionRow setBackgroundColor:kTOPUICOLORAlpha];
  180. [descriptionRow addSubview:title];
  181. [descriptionRow addSubview:username];
  182. [descriptionRow addSubview:description];
  183. [descriptionRow addSubview:tags];
  184. [descriptionRow addSubview:postedButton];
  185. // desription end
  186. [self addSubview:content];
  187. // super.header = [GUI headerBarWithBack:controller];
  188. // super.footer = [GUI footerBar:controller];
  189. // [self addSubview:super.header];
  190. // [self addSubview:super.footer];
  191. [self addSubview:flagSelect];
  192. [flagSelect setVideoId:[[contentArray valueForKey:@"id"] integerValue]];
  193. [self addSubview:insertTxtView];
  194. UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
  195. [refreshControl addTarget:self action:@selector(refresh:) forControlEvents:UIControlEventValueChanged];
  196. [refreshControl setBackgroundColor:[UIColor colorWithPatternImage:[UIImage ch_imageNamed:@"refresh_bg_image"]]];
  197. [content addSubview:refreshControl];
  198. if (commentArray == nil) {
  199. if (commentCount > 0) {
  200. //[self performSelectorInBackground:@selector(getComments) withObject:NULL];
  201. [self performSelector:@selector(getComments) withObject:NULL];
  202. } else {
  203. [[[content tableFooterView] subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
  204. }
  205. }
  206. DMSG;
  207. kHIDEWAIT
  208. }
  209. -(void)togglePosted
  210. {
  211. [postedButton setSelected:![postedButton isSelected]];
  212. }
  213. - (void)refresh:(UIRefreshControl *)refreshControl
  214. {
  215. if (refreshControl != nil) {
  216. [refreshControl beginRefreshing];
  217. }
  218. if ([[wbAPI sharedAPI] checkIfNetworkAvailable]) {
  219. DNSLog(@"1---- rows %ld",(long)[content numberOfRowsInSection:0]);
  220. //NSInteger count = [commentArray count];
  221. NSMutableArray *commentRows = [[NSMutableArray alloc] init];
  222. for (int i = 0; i< commentCount; i++) {
  223. NSIndexPath *ip = [NSIndexPath indexPathForItem:i+4 inSection:0];
  224. [commentRows addObject:ip];
  225. }
  226. DNSLog(@"1---- rows %ld",(long)[content numberOfRowsInSection:0]);
  227. commentCount = 0;
  228. commentArray = nil;
  229. [content beginUpdates];
  230. [content deleteRowsAtIndexPaths:commentRows withRowAnimation:UITableViewRowAnimationAutomatic];
  231. [content endUpdates];
  232. DCMSG(commentRows);
  233. commentRows = nil;
  234. DNSLog(@"2---- rows %ld",(long)[content numberOfRowsInSection:0]);
  235. [self getComments];
  236. }
  237. if (refreshControl != nil) {
  238. [refreshControl endRefreshing];
  239. [self setNewContentSize];
  240. }
  241. }
  242. -(void)refreshVideoCell
  243. {
  244. [content beginUpdates];
  245. [content reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationAutomatic];
  246. [content endUpdates];
  247. }
  248. -(void)saveCommentUsers:(NSArray*)userArray
  249. {
  250. //DNSLog(@"%@",userArray);
  251. NSInteger count = [userArray count];
  252. for (int i = 0; i < count; i++) {
  253. [[wbData sharedData] saveWhambushUser:[[userArray objectAtIndex:i] objectForKey:@"user"]];
  254. }
  255. }
  256. -(void)dataReady:(id)data
  257. {
  258. if (commentArray == nil) {
  259. commentArray = [NSMutableArray arrayWithArray:[data objectForKey:@"results"]];
  260. [self performSelectorInBackground:@selector(saveCommentUsers:) withObject:commentArray];
  261. commentCount = [[data valueForKey:@"count"] integerValue];
  262. [contentArray setObject:[NSNumber numberWithLong:commentCount] forKey:@"comment_count"];
  263. nextUrl = [data objectForKey:@"next"];
  264. DCMSG(nextUrl);
  265. NSMutableArray *newRows = [[NSMutableArray alloc] init];
  266. for (int i = 0; i < commentCount ; i++) {
  267. NSIndexPath *ip = [NSIndexPath indexPathForRow:i+4 inSection:0];
  268. [newRows addObject:ip];
  269. }
  270. DCMSG(newRows);
  271. [content beginUpdates];
  272. if ([content numberOfRowsInSection:0] > 4) {
  273. [content reloadRowsAtIndexPaths:newRows withRowAnimation:UITableViewRowAnimationAutomatic];
  274. } else {
  275. DMSG;
  276. [content insertRowsAtIndexPaths:newRows withRowAnimation:UITableViewRowAnimationAutomatic];
  277. }
  278. [content endUpdates];
  279. [[[content tableFooterView] subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
  280. } else {
  281. NSArray *newResult = [data objectForKey:@"results"];
  282. NSInteger oldCount = [commentArray count];
  283. nextUrl = [data objectForKey:@"next"];
  284. NSMutableArray *newRows = [[NSMutableArray alloc] init];
  285. for (NSInteger i = (oldCount+4); i < (commentCount+4); i++) {
  286. NSIndexPath *newReloadRows = [NSIndexPath indexPathForRow:i inSection:0];
  287. [newRows addObject:newReloadRows];
  288. }
  289. DCMSG(newRows);
  290. [commentArray addObjectsFromArray:newResult];
  291. [content beginUpdates];
  292. [content deleteRowsAtIndexPaths:newRows withRowAnimation:UITableViewRowAnimationNone];
  293. [content insertRowsAtIndexPaths:newRows withRowAnimation:UITableViewRowAnimationAutomatic];
  294. [content endUpdates];
  295. [self setNewContentSize];
  296. gettingMoreResults = NO;
  297. }
  298. [self setNewContentSize];
  299. }
  300. -(void)getComments
  301. {
  302. if ([[wbAPI sharedAPI] checkIfNetworkAvailable]) {
  303. [[wbAPI sharedAPI] getDataWithEndpoint:[NSString stringWithFormat:@"%@video/%ld/",kCOMMENTAPI,(long)[[contentArray valueForKey:@"id"] integerValue]] delegate:self];
  304. }
  305. }
  306. -(void)setNewContentSize
  307. {
  308. float contentHeight = 100 + videoRowHeight + fclRowHeight + descriptionRowHeight + commentCount;
  309. for (int i = 0; i < [commentArray count] ; i++)
  310. {
  311. NSString *textString = [[commentArray objectAtIndex:i] objectForKey:@"comment"];
  312. contentHeight += [self commentHeight:textString];
  313. }
  314. CGSize newContentSize = CGSizeMake(content.contentSize.width, contentHeight);
  315. [content setContentSize:newContentSize];
  316. }
  317. -(float)commentHeight:(NSString*)textString
  318. {
  319. wbLabel *text = [[wbLabel alloc] initWithFrame:CGRectMake(0, 0, 255, 700)];
  320. [text setNumberOfLines:0];
  321. [text setEdgeInsets:UIEdgeInsetsMake(4, 6, 2, 16)];
  322. [text setFont:kFONTHelvetica(15)];
  323. [text setText:textString];
  324. [text setPreserveWidth:YES];
  325. [text sizeToFit];
  326. return text.frame.size.height + 30;
  327. }
  328. -(void)getMoreComments
  329. {
  330. if (!gettingMoreResults) {
  331. if ([[wbAPI sharedAPI] checkIfNetworkAvailable]) {
  332. gettingMoreResults = YES;
  333. [[wbAPI sharedAPI] getDataWithURL:nextUrl delegate:self];
  334. }
  335. }
  336. }
  337. -(void)addComment
  338. {
  339. if ([[wbAPI sharedAPI] is_guest]) {
  340. [[wbLoginRegisterViewController sharedLRVC] showAskToLoginRegisterOnView:self];
  341. } else {
  342. [insertTxtView showTextView];
  343. }
  344. }
  345. -(void)hideKB
  346. {
  347. [insertTxtView hideTextView];
  348. }
  349. -(void)newText:(NSString*)text //delegate method for insetTxtView
  350. {
  351. DMSG;
  352. if ([text length] > 0) {
  353. NSBlockOperation *op = [NSBlockOperation blockOperationWithBlock:^(void){
  354. [[wbWaitView sharedWait] performSelectorOnMainThread:@selector(show) withObject:NULL waitUntilDone:YES];
  355. }];
  356. [op setCompletionBlock:^(void){
  357. [[wbAPI sharedAPI] addComment:text videoid:[[contentArray valueForKey:@"id"] integerValue] delegate:self];
  358. }];
  359. [op start];
  360. }
  361. }
  362. //-(void)goBack
  363. //{
  364. // insertTxtView = nil;
  365. // [controller performSelector:@selector(goBack:)];
  366. //}
  367. -(void)scrollTableTop
  368. {
  369. [content setContentOffset:CGPointZero animated:YES];
  370. }
  371. //Tableview stuff
  372. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  373. {
  374. return 4+commentCount;
  375. }
  376. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  377. {
  378. if ([indexPath row] == 0) { //video
  379. return videoRowHeight;
  380. } else if ([indexPath row] == 1) { // like comment
  381. return fclRowHeight;
  382. } else if ([indexPath row] == 2) { // more
  383. return moreRowHeight;
  384. } else if ([indexPath row] == 3) { // description
  385. return descriptionRowHeight;
  386. // } else if ([indexPath row] == [self tableView:content numberOfRowsInSection:0] - 1) {
  387. // return 100;
  388. } else { //comments
  389. if ([commentArray count] > kCOMMENTROW) {
  390. NSString *textString = [[commentArray objectAtIndex:kCOMMENTROW] objectForKey:@"comment"];
  391. return [self commentHeight:textString];
  392. } else {
  393. return 0;
  394. }
  395. }
  396. }
  397. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  398. {
  399. //NSString *identifier = [NSString stringWithFormat:@"sv_%ld_%ld",(long)indexPath.section,(long)indexPath.row];
  400. //wbBaseCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  401. //if (cell == nil) {
  402. wbBaseCell *cell = [[wbBaseCell alloc] init];//WithStyle:UITableViewCellStyleDefault];// reuseIdentifier:identifier];
  403. //}
  404. if ([commentArray count]-5 == kCOMMENTROW) {
  405. if ([commentArray count] < commentCount) {
  406. //[self performSelectorInBackground:@selector(getMoreComments) withObject:NULL];
  407. [self performSelectorOnMainThread:@selector(getMoreComments) withObject:NULL waitUntilDone:NO];
  408. }
  409. }
  410. if ([indexPath row] == 0) { //video
  411. //[cell setClipsToBounds:NO];
  412. [cell addSubview:videoPlayerController.view];
  413. [cell bringSubviewToFront:videoPlayerController.view];
  414. [cell setClipsToBounds:YES];
  415. [cell setHidden:NO];
  416. DCMSG(cell);
  417. } else if ([indexPath row] == 1) { // flag like comment
  418. cell = nil;
  419. cell = [[wbBaseCell alloc] init];
  420. [self fclCell:cell];
  421. } else if ([indexPath row] == 2) { // more
  422. cell = nil;
  423. cell = [[wbBaseCell alloc] init];
  424. [self moreCell:cell];
  425. } else if ([indexPath row] == 3) { // description
  426. DCMSG(descriptionRow);
  427. [cell addSubview:descriptionRow];
  428. [cell bringSubviewToFront:descriptionRow];
  429. } else { //comments
  430. cell = nil;
  431. cell = [[wbBaseCell alloc] init];
  432. [cell setBackgroundColor:kTRANSPARENTUICOLOR];
  433. if ([commentArray count] > kCOMMENTROW) {
  434. wbCommentCell *ccell = [[wbCommentCell alloc] init];
  435. [ccell setParentView:self];
  436. [ccell setCellContent:[commentArray objectAtIndex:kCOMMENTROW]];
  437. [ccell setController:controller];
  438. [ccell setTotalNumberOfComments:commentCount];
  439. [ccell setCurrentCommentNumber:kCOMMENTROW+1];
  440. NSString *textString = [[commentArray objectAtIndex:kCOMMENTROW] objectForKey:@"comment"];
  441. float height = [self commentHeight:textString];
  442. [ccell setFrame:CGRectMake(0, 0, self.frame.size.width, height)];
  443. UILongPressGestureRecognizer *longTap = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longTapGesture:)];
  444. [ccell addGestureRecognizer:longTap];
  445. [cell addSubview:ccell];
  446. }
  447. }
  448. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  449. return cell;
  450. }
  451. // cells
  452. // like,comment
  453. //-(wbBaseCell*)fclCell:(wbBaseCell *)cell
  454. -(void)fclCell:(wbBaseCell *)cell
  455. {
  456. [cell setBackgroundColor:kBKGUICOLORAlpha];
  457. //[cell setSelected:NO];
  458. //[cell setClipsToBounds:NO];
  459. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  460. UIImage *moreImg = [UIImage ch_imageNamed:@"options.png"];
  461. if (moreButton == nil) {
  462. moreButton = [UIButton buttonWithType:UIButtonTypeSystem];
  463. }
  464. [moreButton setBackgroundImage:moreImg forState:UIControlStateNormal];
  465. [moreButton setBackgroundImage:[UIImage ch_imageNamed:@"options_active.png"] forState:UIControlStateSelected];
  466. [moreButton setBackgroundColor:kTRANSPARENTUICOLOR];
  467. [moreButton setFrame:CGRectMake(cell.frame.size.width-moreImg.size.width, 0, fclRowHeight, fclRowHeight)];
  468. [moreButton addTarget:self action:@selector(toggleMoreRow) forControlEvents:UIControlEventTouchUpInside];
  469. [moreButton setTintColor:kTRANSPARENTUICOLOR];
  470. UIImage *addCommentImg = [UIImage ch_imageNamed:@"comment.png"];
  471. if (addCommentButton == nil) {
  472. addCommentButton = [wbButton buttonWithType:UIButtonTypeSystem];
  473. }
  474. [addCommentButton setFrame:CGRectMake(6, 0, fclRowHeight, fclRowHeight)];
  475. //[addCommentButton setBackgroundImage:addCommentImg forState:UIControlStateNormal];
  476. [addCommentButton setCropButtonImage:YES];
  477. [addCommentButton setButtonImage:addCommentImg];
  478. [addCommentButton setBackgroundColor:kTRANSPARENTUICOLOR];
  479. [addCommentButton addTarget:self action:@selector(addComment) forControlEvents:UIControlEventTouchUpInside];
  480. [cell addSubview:addCommentButton];
  481. [cell addSubview:moreButton];
  482. if(!has_liked) {
  483. likeBtnImg = [UIImage ch_imageNamed:@"banana_inactive.png"];
  484. } else {
  485. likeBtnImg = [UIImage ch_imageNamed:@"banana_active.png"];
  486. }
  487. if (likeBtn == nil) {
  488. likeBtn = [UIButton buttonWithType:UIButtonTypeSystem];
  489. }
  490. [likeBtn setBackgroundImage:likeBtnImg forState:UIControlStateNormal];
  491. [likeBtn setFrame:CGRectMake(CGRectGetMaxX(addCommentButton.frame)+25, 0, fclRowHeight, fclRowHeight)];
  492. [likeBtn addTarget:self action:@selector(like) forControlEvents:UIControlEventTouchUpInside];
  493. if(!has_disliked) {
  494. dislikeBtnImg = [UIImage ch_imageNamed:@"shit_inactive.png"];
  495. } else {
  496. dislikeBtnImg = [UIImage ch_imageNamed:@"shit_active.png"];
  497. }
  498. if (dislikeBtn == nil) {
  499. dislikeBtn = [UIButton buttonWithType:UIButtonTypeSystem];
  500. }
  501. [dislikeBtn setBackgroundImage:dislikeBtnImg forState:UIControlStateNormal];
  502. [dislikeBtn setFrame:CGRectMake(CGRectGetMinX(moreButton.frame)-dislikeBtnImg.size.width-25, 0, fclRowHeight, fclRowHeight)];
  503. [dislikeBtn addTarget:self action:@selector(dislike) forControlEvents:UIControlEventTouchUpInside];
  504. NSInteger count = likeCount - dislikeCount;
  505. NSString *countStr;
  506. if (count > 999) {
  507. countStr = [NSString stringWithFormat:@"%ldk",(long)ABS(count)/1000];
  508. } else {
  509. countStr = [NSString stringWithFormat:@"%ld",(long)(ABS(count))];
  510. }
  511. UIImageView *likeDislikeCountBubble;
  512. if (likeDislikeCount == nil) {
  513. likeDislikeCount = [[wbLabel alloc] initWithFrame:CGRectMake(CGRectGetMinX(likeBtn.frame), 0, CGRectGetMaxX(dislikeBtn.frame)-CGRectGetMinX(likeBtn.frame), fclRowHeight)];
  514. }
  515. [likeDislikeCount setBackgroundColor:kTRANSPARENTUICOLOR];
  516. [likeDislikeCount setTextAlignment:NSTextAlignmentCenter];
  517. [likeDislikeCount setEdgeInsets:UIEdgeInsetsMake(5, 0, 0, 0)];
  518. [likeDislikeCount setFont:kFONT(24)];
  519. [likeDislikeCount setText:countStr];
  520. if (count < 0) {
  521. [likeDislikeCount setTextColor:kREDUICOLOR];
  522. likeDislikeCountBubble = [[wbAPI sharedAPI] giveBubleWithBanana:NO frame:likeDislikeCount.frame];
  523. } else {
  524. [likeDislikeCount setTextColor:kGREENUICOLOR];
  525. likeDislikeCountBubble = [[wbAPI sharedAPI] giveBubleWithBanana:YES frame:likeDislikeCount.frame];
  526. }
  527. [cell addSubview:likeDislikeCount];
  528. if (!(likeCount == 0 && dislikeCount == 0)) {
  529. [cell addSubview:likeDislikeCountBubble];
  530. } else {
  531. [likeDislikeCount setTextColor:UIColorFromHexRGB(0x8F8F8F)];
  532. }
  533. [cell addSubview:likeBtn];
  534. [cell addSubview:dislikeBtn];
  535. if (ai == nil) {
  536. ai = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
  537. }
  538. [ai setFrame:CGRectMake(0, 0, fclRowHeight, fclRowHeight)];
  539. [ai setHidden:YES];
  540. [cell addSubview:ai];
  541. //DCMSG(cell);
  542. //return cell;
  543. }
  544. -(void)moreCell:(wbBaseCell*)cell
  545. {
  546. [cell setBackgroundColor:kSEPRATORUICOLORAlpha];
  547. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  548. UIImage *shareImg = [UIImage ch_imageNamed:@"share_inactive.png"];
  549. shareButton = [UIButton buttonWithType:UIButtonTypeSystem];
  550. [shareButton setBackgroundImage:shareImg forState:UIControlStateNormal];
  551. [shareButton setBackgroundColor:kTRANSPARENTUICOLOR];
  552. //[shareButton setBackgroundColor:kYELLOWUICOLOR];
  553. [shareButton setFrame:CGRectMake((cell.frame.size.width)-(moreRowHeight), 0,moreRowHeight, moreRowHeight)];
  554. [shareButton addTarget:self action:@selector(showShareSelect) forControlEvents:UIControlEventTouchUpInside];
  555. UIImage *flagImg = [UIImage ch_imageNamed:@"flag_inactive.png"];
  556. flagButton = [UIButton buttonWithType:UIButtonTypeSystem];
  557. [flagButton setBackgroundImage:flagImg forState:UIControlStateNormal];
  558. [flagButton setBackgroundColor:kTRANSPARENTUICOLOR];
  559. //[flagButton setBackgroundColor:kREDUICOLOR];
  560. [flagButton setFrame:CGRectMake(CGRectGetMinX(shareButton.frame)-(moreRowHeight+1), 0,moreRowHeight, moreRowHeight)];
  561. [flagButton addTarget:flagSelect action:@selector(show) forControlEvents:UIControlEventTouchUpInside];
  562. UIImage *trashImg = [UIImage ch_imageNamed:@"remove_video.png"];
  563. deleteButton = [UIButton buttonWithType:UIButtonTypeSystem];
  564. [deleteButton setBackgroundImage:trashImg forState:UIControlStateNormal];
  565. [deleteButton setBackgroundColor:kTRANSPARENTUICOLOR];
  566. //[deleteButton setBackgroundColor:kYELLOWUICOLOR];
  567. [deleteButton setFrame:CGRectMake(CGRectGetMinX(flagButton.frame)-(moreRowHeight+1), 0,moreRowHeight, moreRowHeight)];
  568. [deleteButton addTarget:self action:@selector(deleteVideo) forControlEvents:UIControlEventTouchUpInside];
  569. if([[[wbUser sharedUser] userId] integerValue] == [[user userId] integerValue]){
  570. if ([self showDelete]) {
  571. [cell addSubview:deleteButton];
  572. }
  573. }
  574. [cell addSubview:shareButton];
  575. [cell addSubview:flagButton];
  576. }
  577. -(void)showShareSelect
  578. {
  579. if ([[contentArray valueForKey:@"is_processed"] boolValue]) {
  580. [controller presentViewController:activityViewController animated:YES completion:NULL/*^{ ...}*/];
  581. }
  582. }
  583. -(BOOL)showDelete
  584. {
  585. if (mission == nil) {
  586. return YES;
  587. } else if ([mission ready]) {
  588. if ([[mission status] isEqualToString:@"OLD"] && [[mission is_videos_ranked] boolValue]) {
  589. return YES;
  590. }
  591. }
  592. return NO;
  593. }
  594. -(void)deleteVideo
  595. {
  596. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"GENERAL_WARNING_TITLE", @"")
  597. message:NSLocalizedString(@"SINGLE_DELETE_VIDEO", @"")
  598. delegate:self
  599. cancelButtonTitle:NSLocalizedString(@"GENERAL_NO",@"")
  600. otherButtonTitles:NSLocalizedString(@"GENERAL_YES",@""),nil];
  601. [alert show];
  602. }
  603. -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  604. {
  605. if (buttonIndex == 1) {
  606. NSBlockOperation *op = [NSBlockOperation blockOperationWithBlock:^(void){
  607. [[wbWaitView sharedWait] performSelectorOnMainThread:@selector(show) withObject:NULL waitUntilDone:YES];
  608. }];
  609. [op setCompletionBlock:^(void){
  610. [[wbAPI sharedAPI] removeVideo:[[contentArray objectForKey:@"id"] integerValue] delegate:self];
  611. }];
  612. [op start];
  613. }
  614. }
  615. -(void)deleteDone
  616. {
  617. [[wbUser sharedUser] updateUserData];
  618. [contentArray setObject:[NSNumber numberWithBool:YES] forKey:@"deleted"];
  619. //[[[[wbData sharedData] videoCells] objectForKey:(NSNumber*)[contentArray objectForKey:@"id"]] setNeedsDisplay];
  620. //[[wbData sharedData] refreshFeedData:@"MAIN_FEED_MY_VIDEOS" delegate:nil];
  621. [[NSNotificationCenter defaultCenter] postNotificationName:@"deleteVideoDone" object:self];
  622. [kROOTVC performSelectorOnMainThread:@selector(goBack:) withObject:self waitUntilDone:NO];
  623. }
  624. -(void)likeDone:(NSNumber*)who count:(NSNumber*)count
  625. {
  626. switch ([who integerValue]) {
  627. case 1: //like
  628. likeCount = [count integerValue];
  629. has_liked = YES;
  630. [contentArray setObject:[NSNumber numberWithInt:1] forKey:@"has_liked"];
  631. [contentArray setObject:[NSNumber numberWithLong:likeCount] forKey:@"like_count"];
  632. if (has_disliked) {
  633. [self dislike];
  634. }
  635. break;
  636. case 2: //unlike
  637. likeCount = [count integerValue];
  638. has_liked = NO;
  639. [contentArray setObject:[NSNumber numberWithInt:0] forKey:@"has_liked"];
  640. [contentArray setObject:[NSNumber numberWithLong:likeCount] forKey:@"like_count"];
  641. break;
  642. case 3: //dislike
  643. dislikeCount = [count integerValue];
  644. has_disliked = YES;
  645. [contentArray setObject:[NSNumber numberWithInt:1] forKey:@"has_disliked"];
  646. [contentArray setObject:[NSNumber numberWithLong:dislikeCount] forKey:@"dislike_count"];
  647. if (has_liked) {
  648. [self like];
  649. }
  650. break;
  651. case 4: //undislike
  652. dislikeCount = [count integerValue];
  653. has_disliked = NO;
  654. [contentArray setObject:[NSNumber numberWithInt:0] forKey:@"has_disliked"];
  655. [contentArray setObject:[NSNumber numberWithLong:dislikeCount] forKey:@"dislike_count"];
  656. break;
  657. default:
  658. break;
  659. }
  660. [content reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:1 inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
  661. [likeBtn setEnabled:YES];
  662. [dislikeBtn setEnabled:YES];
  663. [ai stopAnimating];
  664. [ai setHidden:YES];
  665. }
  666. -(void)like
  667. {
  668. DCMSG(@"like");
  669. if (!has_liked) {
  670. // likeCount = [[wbAPI sharedAPI] like:YES videoid:[NSString stringWithFormat:@"%@",[contentArray valueForKey:@"id"]]];
  671. [[wbAPI sharedAPI] like:YES videoid:[[contentArray valueForKey:@"id"] stringValue] delegate:self];
  672. [likeBtn setEnabled:NO];
  673. [ai setHidden:NO];
  674. [ai startAnimating];
  675. [ai setCenter:likeBtn.center];
  676. } else {
  677. //likeCount = [[wbAPI sharedAPI] unlike:YES videoid:[NSString stringWithFormat:@"%@",[contentArray valueForKey:@"id"]]];
  678. [[wbAPI sharedAPI] unlike:YES videoid:[[contentArray valueForKey:@"id"] stringValue] delegate:self];
  679. [likeBtn setEnabled:NO];
  680. [ai setHidden:NO];
  681. [ai startAnimating];
  682. [ai setCenter:likeBtn.center];
  683. }
  684. // [content reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:1 inSection:0]] withRowAnimation:UITableViewRowAnimationAutomatic];
  685. }
  686. -(void)dislike
  687. {
  688. DCMSG(@"dislike");
  689. if (!has_disliked) {
  690. [dislikeBtn setEnabled:NO];
  691. [ai setHidden:NO];
  692. [ai startAnimating];
  693. [ai setCenter:dislikeBtn.center];
  694. // dislikeCount = [[wbAPI sharedAPI] like:NO videoid:[NSString stringWithFormat:@"%@",[contentArray valueForKey:@"id"]]];
  695. [[wbAPI sharedAPI] like:NO videoid:[[contentArray valueForKey:@"id"] stringValue] delegate:self];
  696. // has_disliked = YES;
  697. // [contentArray setObject:[NSNumber numberWithInt:1] forKey:@"has_disliked"];
  698. // [contentArray setObject:[NSNumber numberWithLong:dislikeCount] forKey:@"dislike_count"];
  699. // if (has_liked) {
  700. // [self like];
  701. // }
  702. } else {
  703. // dislikeCount = [[wbAPI sharedAPI] unlike:NO videoid:[NSString stringWithFormat:@"%@",[contentArray valueForKey:@"id"]]];
  704. [dislikeBtn setEnabled:NO];
  705. [ai setHidden:NO];
  706. [ai startAnimating];
  707. [ai setCenter:dislikeBtn.center];
  708. [[wbAPI sharedAPI] unlike:NO videoid:[[contentArray valueForKey:@"id"] stringValue] delegate:self];
  709. // has_disliked = NO;
  710. // [contentArray setObject:[NSNumber numberWithInt:0] forKey:@"has_disliked"];
  711. // [contentArray setObject:[NSNumber numberWithLong:dislikeCount] forKey:@"dislike_count"];
  712. }
  713. // [content reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:1 inSection:0]] withRowAnimation:UITableViewRowAnimationAutomatic];
  714. }
  715. -(void)toggleMoreRow
  716. {
  717. if (moreRowOpen) {
  718. moreRowHeight = 0;
  719. moreRowOpen = NO;
  720. [moreButton setSelected:NO];
  721. [moreButton setBackgroundColor:kTRANSPARENTUICOLOR];
  722. } else {
  723. moreRowHeight = fclRowHeight;
  724. moreRowOpen = YES;
  725. [moreButton setSelected:YES];
  726. [moreButton setBackgroundColor:kSEPRATORUICOLORAlpha];
  727. }
  728. [content reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:2 inSection:0]] withRowAnimation:UITableViewRowAnimationAutomatic];
  729. }
  730. /*-(UIImageView*)giveBubleWithBanana:(BOOL)banana frame:(CGRect)frame
  731. {
  732. // variables to make things happend
  733. float width = frame.size.width-25-frame.size.height;
  734. float height = frame.size.height-6;
  735. float xx = 25+frame.size.height;
  736. float yy = 6;
  737. float rr = height/3.0;
  738. //DNSLog(@"%f, %f, %f, %f, %f",width,height,xx,yy,rr);
  739. //start graphic context
  740. UIGraphicsBeginImageContextWithOptions(CGSizeMake(frame.size.width,frame.size.height),0.0,0.0);
  741. //this gets the graphic context
  742. CGContextRef context = UIGraphicsGetCurrentContext();
  743. //you can stroke and/or fill
  744. UIBezierPath *countBkg = [UIBezierPath bezierPath];
  745. //draw "buble"
  746. [countBkg moveToPoint:CGPointMake(xx+rr, yy)];
  747. [countBkg addLineToPoint:CGPointMake(width-rr, yy)];
  748. [countBkg addCurveToPoint:CGPointMake(width, yy+rr) controlPoint1:CGPointMake(width-rr/2,yy) controlPoint2:CGPointMake(width, yy+rr/2)];
  749. [countBkg addLineToPoint:CGPointMake(width, height-rr)];
  750. [countBkg addCurveToPoint:CGPointMake(width-rr, height) controlPoint1:CGPointMake(width,height-rr/2) controlPoint2:CGPointMake(width-rr/2, height)];
  751. [countBkg addLineToPoint:CGPointMake(xx+rr, height)];
  752. [countBkg addCurveToPoint:CGPointMake(xx, height-rr) controlPoint1:CGPointMake(xx+rr/2,height) controlPoint2:CGPointMake(xx, height-rr/2)];
  753. [countBkg addLineToPoint:CGPointMake(xx, yy/2+height/2)];
  754. [countBkg addLineToPoint:CGPointMake(xx-(25+yy), yy/2+height/2)]; // point
  755. [countBkg addLineToPoint:CGPointMake(xx, yy/2+height/2)];
  756. [countBkg addLineToPoint:CGPointMake(xx, yy+rr)];
  757. [countBkg addCurveToPoint:CGPointMake(xx+rr, yy) controlPoint1:CGPointMake(xx,yy+rr/2) controlPoint2:CGPointMake(xx+rr/2, yy)];
  758. [countBkg closePath];
  759. //draw circle
  760. UIBezierPath *circle = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(yy, yy, frame.size.height-yy*2, frame.size.height-yy*2)];
  761. UIBezierPath *circleEmpty = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(frame.size.width-(yy+(frame.size.height-yy*2)), yy, frame.size.height-yy*2, frame.size.height-yy*2)];
  762. //define color
  763. if (banana) {
  764. CGContextSetStrokeColorWithColor(context, kGREENUICOLOR.CGColor);
  765. } else {
  766. CGContextSetStrokeColorWithColor(context, kREDUICOLOR.CGColor);
  767. }
  768. [countBkg setLineWidth:1.0];
  769. [countBkg stroke];
  770. [circle setLineWidth:1.0];
  771. [circle stroke];
  772. CGContextSetStrokeColorWithColor(context, UIColorFromHexRGB(0x8F8F8F).CGColor);//kBOTTOMUICOLOR.CGColor);
  773. [circleEmpty setLineWidth:1.0];
  774. [circleEmpty stroke];
  775. //create image
  776. UIImage *bezierImage = UIGraphicsGetImageFromCurrentImageContext();
  777. UIGraphicsEndImageContext();
  778. //image to view
  779. UIImageView *bezierImageView = [[UIImageView alloc] initWithImage:bezierImage];
  780. // turn image view 180 decree if shit ;)
  781. if (!banana) [bezierImageView setTransform:CGAffineTransformRotate([bezierImageView transform],M_PI)];
  782. //set to frame
  783. [bezierImageView setFrame:frame];
  784. return bezierImageView;
  785. }*/
  786. //-(void)dealloc
  787. //{
  788. // [self clean];
  789. //}
  790. //
  791. //-(void)clean
  792. //{
  793. // videoWebLoaded = NO;
  794. // contentArray = nil;
  795. // commentArray = nil;
  796. // likeBtn = nil;
  797. // likeBtnImg = nil;
  798. // dislikeBtn = nil;
  799. // dislikeBtnImg = nil;
  800. // likeDislikeCount = nil;
  801. // controller = nil;
  802. // flagSelect = nil;
  803. // insertTxtView = nil;
  804. // descriptionRow = nil;
  805. // user = nil;
  806. // nextUrl = nil;
  807. // videoHtmlString = nil;
  808. // content = nil;
  809. // flagButton = nil;
  810. // addCommentButton = nil;
  811. // [videoPlayerController clean];
  812. // videoPlayerController = nil;
  813. //}
  814. -(void)tapGestureAction:(UITapGestureRecognizer*)gesture
  815. {
  816. if ([[UIMenuController sharedMenuController] isMenuVisible]) {
  817. [[UIMenuController sharedMenuController] setMenuVisible:NO];
  818. }
  819. }
  820. -(void)longTapGesture:(UILongPressGestureRecognizer*)gesture
  821. {
  822. if ([gesture state] == UIGestureRecognizerStateBegan) {
  823. commentDictionary = [(wbCommentCell*)[gesture view] cellContent];
  824. [self becomeFirstResponder];
  825. DNSLog(@"longTapGesture");
  826. DNSLog(@"%@",gesture);
  827. menu = [UIMenuController sharedMenuController];
  828. CGRect targetRectangle = CGRectMake([gesture locationInView:self].x-50, [gesture locationInView:self].y, 100, 100);
  829. [menu setTargetRect:targetRectangle inView:self];
  830. UIMenuItem *menuItem1 = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"SINGLE_FLAG_COMMENT_LABEL", @"") action:@selector(reportAction:)]; //TODO: Comment flagging
  831. DCMSG(menuItem1);
  832. UIMenuItem *menuItem2;
  833. if ([[[commentDictionary objectForKey:@"user"] objectForKey:@"id"] integerValue] == [[[wbUser sharedUser] userId] integerValue] ) {
  834. menuItem2 = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"SINGLE_DELETE_COMMENT_LABEL", @"") action:@selector(deleteAction:)];
  835. }
  836. [menu setMenuItems:[[NSArray alloc] initWithObjects:/*menuItem1,*/menuItem2, nil]];
  837. [menu update];
  838. // [menu setMenuVisible:YES animated:YES];
  839. [menu setMenuVisible:YES];
  840. DCMSG(menu);
  841. DNSLog(@"menuframe: %.f %.f %.f %.f",menu.menuFrame.origin.x,menu.menuFrame.origin.y,menu.menuFrame.size.width,menu.menuFrame.size.height);
  842. }
  843. }
  844. - (BOOL)canBecomeFirstResponder
  845. {
  846. return YES;
  847. }
  848. - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
  849. {
  850. BOOL result = NO;
  851. if(@selector(copy:) == action || @selector(deleteAction:) == action || @selector(reportAction:) == action) {
  852. result = YES;
  853. }
  854. return result;
  855. }
  856. // UIMenuController Methods
  857. // Default copy method
  858. - (void)copy:(id)sender
  859. {
  860. DCMSG(@"copy");
  861. [[UIPasteboard generalPasteboard] setString:[commentDictionary valueForKey:@"comment"] ];
  862. }
  863. // Our custom method
  864. - (void)deleteAction:(id)sender
  865. {
  866. DCMSG(@"deleteAction");
  867. DCMSG(commentDictionary);
  868. NSNumber *commentId = [NSNumber numberWithInteger:[[commentDictionary valueForKey:@"id"] integerValue]];
  869. [[wbAPI sharedAPI] removeComment:commentId delegate:self];
  870. }
  871. -(void)deleteCommentDone
  872. {
  873. [self refresh:nil];
  874. }
  875. - (void)reportAction:(id)sender
  876. {
  877. DCMSG(@"reportAction");
  878. DCMSG(commentDictionary);
  879. }
  880. // scroll
  881. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  882. [[UIMenuController sharedMenuController] setMenuVisible:NO];
  883. }
  884. @end