Permalink
Browse files

Refs #264

 * Re-design direct message UI

git-svn-id: http://naan.net/svn/trunk/TwitterFon@1533 542e9493-1a22-0410-9183-c10453d2b9ee
  • Loading branch information...
1 parent bc86d4c commit f35719d59deb63f147d14159ab11c9d14d0ec703 kaz committed Dec 17, 2008
@@ -0,0 +1,22 @@
+//
+// ChatBubbleCell.h
+// TwitterFon
+//
+// Created by kaz on 12/17/08.
+// Copyright 2008 naan studio. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@class DirectMessage;
+@class ChatBubbleView;
+
+@interface ChatBubbleCell : UITableViewCell
+{
+ DirectMessage* message;
+ ChatBubbleView* cellView;
+}
+
+- (void)setMessage:(DirectMessage*)msg isOwn:(BOOL)isOwnMessage;
+
+@end
@@ -0,0 +1,50 @@
+//
+// ChatBubbleCell.m
+// TwitterFon
+//
+// Created by kaz on 12/17/08.
+// Copyright 2008 naan studio. All rights reserved.
+//
+
+#import "ChatBubbleCell.h"
+#import "DirectMessage.h"
+#import "ChatBubbleView.h"
+
+@implementation ChatBubbleCell
+
+- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier
+{
+ [super initWithFrame:frame reuseIdentifier:reuseIdentifier];
+
+ cellView = [[[ChatBubbleView alloc] initWithFrame:CGRectZero] autorelease];
+ [self.contentView addSubview:cellView];
+
+ return self;
+}
+
+- (void)setMessage:(DirectMessage*)aMessage isOwn:(BOOL)isOwn
+{
+ self.text = message.text;
+ message = aMessage;
+ cellView.type = isOwn;
+}
+
+- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
+
+ [super setSelected:selected animated:animated];
+
+ // Configure the view for the selected state
+}
+
+- (void)layoutSubviews
+{
+ [super layoutSubviews];
+ cellView.frame = self.bounds;
+ self.backgroundColor = [UIColor clearColor];
+}
+
+- (void)dealloc {
+ [super dealloc];
+}
+
+@end
@@ -0,0 +1,23 @@
+//
+// ChatBubbleView.h
+// TwitterFon
+//
+// Created by kaz on 12/17/08.
+// Copyright 2008 naan studio. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+typedef enum {
+ BUBBLE_TYPE_GRAY,
+ BUBBLE_TYPE_GREEN,
+} BubbleType;
+
+@interface ChatBubbleView : UIView
+{
+ BubbleType type;
+}
+
+@property(nonatomic, assign) BubbleType type;
+
+@end
@@ -0,0 +1,65 @@
+//
+// ChatBubbleView.m
+// TwitterFon
+//
+// Created by kaz on 12/17/08.
+// Copyright 2008 naan studio. All rights reserved.
+//
+
+#import "ChatBubbleView.h"
+static UIImage* sGreenBubble = nil;
+static UIImage* sGrayBubble = nil;
+
+@interface ChatBubbleView(Private)
++ (UIImage*)greenBubble;
++ (UIImage*)grayBubble;
+@end
+
+@implementation ChatBubbleView
+
+@synthesize type;
+
+- (id)initWithFrame:(CGRect)frame
+{
+ if (self = [super initWithFrame:frame]) {
+ self.backgroundColor = [UIColor clearColor];
+ }
+ return self;
+}
+
+- (void)drawRect:(CGRect)rect
+{
+ UIImage *background;
+ if (type == BUBBLE_TYPE_GRAY) {
+ background = [ChatBubbleView grayBubble];
+ }
+ else {
+ background = [ChatBubbleView greenBubble];
+ }
+ [background drawInRect:rect];
+}
+
+
+- (void)dealloc {
+ [super dealloc];
+}
+
++ (UIImage*)greenBubble
+{
+ if (sGreenBubble == nil) {
+ UIImage *i = [UIImage imageNamed:@"Balloon_1.png"];
+ sGreenBubble = [[i stretchableImageWithLeftCapWidth:15 topCapHeight:13] retain];
+ }
+ return sGreenBubble;
+}
+
++ (UIImage*)grayBubble
+{
+ if (sGrayBubble == nil) {
+ UIImage *i = [UIImage imageNamed:@"Balloon_2.png"];
+ sGrayBubble = [[i stretchableImageWithLeftCapWidth:21 topCapHeight:13] retain];
+ }
+ return sGrayBubble;
+}
+
+@end
@@ -0,0 +1,21 @@
+//
+// DMConversationController.h
+// TwitterFon
+//
+// Created by kaz on 12/17/08.
+// Copyright 2008 naan studio. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@class DirectMessage;
+
+@interface DMConversationController : UITableViewController
+{
+ NSMutableArray* messages;
+ DirectMessage* firstMessage;
+}
+
+- (id)initWithMessage:(DirectMessage*)message;
+
+@end
@@ -0,0 +1,134 @@
+//
+// DMConversationController.m
+// TwitterFon
+//
+// Created by kaz on 12/17/08.
+// Copyright 2008 naan studio. All rights reserved.
+//
+
+#import "TwitterFonAppDelegate.h"
+#import "DMConversationController.h"
+#import "DirectMessage.h"
+#import "ColorUtils.h"
+#import "ChatBubbleCell.h"
+
+@implementation DMConversationController
+
+- (id)initWithMessage:(DirectMessage*)msg
+{
+ self = [super initWithStyle:UITableViewStylePlain];
+ self.navigationItem.title = msg.senderScreenName;
+ self.tableView.separatorColor = [UIColor conversationBackground];
+ self.tableView.backgroundColor = [UIColor conversationBackground];
+
+ UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:self action:@selector(postTweet:)];
+ self.navigationItem.rightBarButtonItem = button;
+
+// self.navigationItem.rightBarButtonItem = self.editButtonItem;
+
+ messages = [[NSMutableArray alloc] init];
+ firstMessage = msg;
+ [DirectMessage getConversation:msg.senderId messages:messages all:false];
+
+ return self;
+}
+
+ - (void)viewWillAppear:(BOOL)animated
+{
+ [super viewWillAppear:animated];
+ self.navigationController.navigationBar.tintColor = nil;
+ }
+/*
+ - (void)viewDidAppear:(BOOL)animated {
+ [super viewDidAppear:animated];
+ }
+ */
+/*
+ - (void)viewWillDisappear:(BOOL)animated {
+ }
+ */
+/*
+ - (void)viewDidDisappear:(BOOL)animated {
+ }
+ */
+/*
+ - (void)didReceiveMemoryWarning {
+ [super didReceiveMemoryWarning];
+ }
+ */
+
+- (void)dealloc {
+ [messages release];
+ [super dealloc];
+}
+
+
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
+ return 1;
+}
+
+
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
+{
+ return [messages count];
+}
+
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ static NSString *CellIdentifier = @"ChatBubble";
+
+ ChatBubbleCell *cell = (ChatBubbleCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
+ if (cell == nil) {
+ cell = [[[ChatBubbleCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
+ }
+
+ DirectMessage *dm = [messages objectAtIndex:indexPath.row];
+
+ [cell setMessage:dm isOwn:dm.senderId != firstMessage.senderId];
+ cell.text = dm.text;
+ cell.font = [UIFont systemFontOfSize:16];
+// cell.image = [[TwitterFonAppDelegate getAppDelegate].imageStore getProfileImage:dm.profileImageUrl delegate:dm];
+ // Configure the cell
+ return cell;
+}
+
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
+{
+ [tableView deselectRowAtIndexPath:indexPath animated:YES];
+}
+
+/*
+- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
+
+ if (editingStyle == UITableViewCellEditingStyleDelete) {
+ }
+ if (editingStyle == UITableViewCellEditingStyleInsert) {
+ }
+}
+*/
+
+/*
+- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
+ return YES;
+}
+*/
+
+/*
+- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
+}
+*/
+
+/*
+- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
+ return YES;
+}
+*/
+
+- (void)postTweet:(id)sender
+{
+ PostViewController* postView = [TwitterFonAppDelegate getAppDelegate].postView;
+ [postView editDirectMessage:self.navigationItem.title];
+}
+
+@end
+
@@ -0,0 +1,35 @@
+//
+// FriendsTimelineController.h
+// TwitterFon
+//
+// Created by kaz on 10/29/08.
+// Copyright 2008 naan studio. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@class Tweet;
+@class TwitterClient;
+@class LoadCell;
+
+@interface DMTimelineController : UITableViewController
+{
+ NSMutableArray* timeline;
+ NSMutableDictionary* messages;
+ TwitterClient* twitterClient;
+ LoadCell* loadCell;
+ int unread;
+ BOOL isLoaded;
+ BOOL firstTimeToAppear;
+ BOOL isRestored;
+ BOOL needToGetSentMessage;
+ CGPoint contentOffset;
+}
+
+- (void)loadTimeline;
+- (void)restoreAndLoadTimeline:(BOOL)load;
+- (void)postTweetDidSucceed:(Tweet*)status;
+
+- (IBAction)reload:(id)sender;
+
+@end
Oops, something went wrong.

0 comments on commit f35719d

Please sign in to comment.