Fix chat progress bar for iOS4

Fix chat scroll
Fix status bar with image picker
This commit is contained in:
Yann Diorcet 2012-09-24 15:28:25 +02:00
parent 995857ba92
commit ca1f634bdb
16 changed files with 115 additions and 41 deletions

View file

@ -37,6 +37,8 @@
@property (nonatomic, retain) id<ChatRoomDelegate> chatRoomDelegate;
- (void)addChatEntry:(ChatModel*)chat;
- (void)scrollToBottom:(BOOL)animated;
- (void)scrollToLastUnread:(BOOL)animated;
- (void)updateChatEntry:(ChatModel*)chat;
@end

View file

@ -76,7 +76,6 @@
[data insertObject:chat atIndex:pos];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:pos inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
[self.tableView endUpdates];
[self scrollToLastUnread:true];
}
- (void)updateChatEntry:(ChatModel*)chat {
@ -93,6 +92,13 @@
return;
}
- (void)scrollToBottom:(BOOL)animated {
CGSize size = [self.tableView contentSize];
CGRect bounds = [self.tableView bounds];
bounds.origin.y = size.height - bounds.size.height;
[self.tableView scrollRectToVisible:bounds animated:animated];
}
- (void)scrollToLastUnread:(BOOL)animated {
if(data == nil) {
[LinphoneLogger logc:LinphoneLoggerWarning format:"Cannot add entry: null data"];
@ -116,7 +122,7 @@
// Scroll to unread
if(index >= 0) {
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:index inSection:0]
atScrollPosition:UITableViewScrollPositionMiddle
atScrollPosition:UITableViewScrollPositionTop
animated:animated];
}
}

View file

@ -34,6 +34,7 @@
LinphoneChatRoom *chatRoom;
ImageSharing *imageSharing;
OrderedDictionary *imageQualities;
BOOL scrollOnGrowingEnabled;
}
@property (nonatomic, retain) IBOutlet ChatRoomTableViewController* tableController;

View file

@ -52,6 +52,7 @@
- (id)init {
self = [super initWithNibName:@"ChatRoomViewController" bundle:[NSBundle mainBundle]];
if (self != nil) {
self->scrollOnGrowingEnabled = TRUE;
self->chatRoom = NULL;
self->imageSharing = NULL;
self->listTapGestureRecognizer = [[UITapGestureRecognizer alloc] init];
@ -314,6 +315,7 @@ static void message_status(LinphoneChatMessage* msg,LinphoneChatMessageState sta
[chat setState:[NSNumber numberWithInt:1]]; //INPROGRESS
[chat create];
[tableController addChatEntry:chat];
[tableController scrollToBottom:TRUE];
[chat release];
LinphoneChatMessage* msg = linphone_chat_room_create_message(chatRoom, [message UTF8String]);
@ -362,6 +364,7 @@ static void message_status(LinphoneChatMessage* msg,LinphoneChatMessageState sta
[chat update];
[[NSNotificationCenter defaultCenter] postNotificationName:kLinphoneTextReceived object:self];
[tableController addChatEntry:chat];
[tableController scrollToLastUnread:TRUE];
}
ms_free(fromStr);
}
@ -390,22 +393,29 @@ static void message_status(LinphoneChatMessage* msg,LinphoneChatMessageState sta
- (void)growingTextView:(HPGrowingTextView *)growingTextView willChangeHeight:(float)height {
int diff = height - growingTextView.bounds.size.height;
CGRect messageRect = [messageView frame];
messageRect.origin.y -= diff;
messageRect.size.height += diff;
[messageView setFrame:messageRect];
// Always stay at bottom
CGPoint contentPt = [tableController.tableView contentOffset];
contentPt.y += diff;
[tableController.tableView setContentOffset:contentPt animated:FALSE];
CGRect tableRect = [tableController.view frame];
tableRect.size.height -= diff;
[tableController.view setFrame:tableRect];
[messageBackgroundImage setImage:[TUNinePatchCache imageOfSize:[messageBackgroundImage bounds].size
forNinePatchNamed:@"chat_message_background"]];
if(diff != 0) {
CGRect messageRect = [messageView frame];
messageRect.origin.y -= diff;
messageRect.size.height += diff;
[messageView setFrame:messageRect];
// Always stay at bottom
if(scrollOnGrowingEnabled) {
CGRect tableFrame = [tableController.view frame];
CGPoint contentPt = [tableController.tableView contentOffset];
contentPt.y += diff;
if(contentPt.y + tableFrame.size.height > tableController.tableView.contentSize.height)
contentPt.y += diff;
[tableController.tableView setContentOffset:contentPt animated:FALSE];
}
CGRect tableRect = [tableController.view frame];
tableRect.size.height -= diff;
[tableController.view setFrame:tableRect];
[messageBackgroundImage setImage:[TUNinePatchCache imageOfSize:[messageBackgroundImage bounds].size
forNinePatchNamed:@"chat_message_background"]];
}
}
@ -422,7 +432,9 @@ static void message_status(LinphoneChatMessage* msg,LinphoneChatMessageState sta
- (IBAction)onSendClick:(id)event {
if([self sendMessage:[messageField text] withExterlBodyUrl:nil withInternalUrl:nil]) {
scrollOnGrowingEnabled = FALSE;
[messageField setText:@""];
scrollOnGrowingEnabled = TRUE;
[self onMessageChange:nil];
}
}
@ -496,7 +508,7 @@ static void message_status(LinphoneChatMessage* msg,LinphoneChatMessageState sta
#pragma mark ImageSharingDelegate
- (void)imageSharingProgress:(ImageSharing*)aimageSharing progress:(float)progress {
[imageTransferProgressBar setProgress:progress animated:FALSE];
[imageTransferProgressBar setProgress:progress];
}
- (void)imageSharingAborted:(ImageSharing*)aimageSharing {

View file

@ -60,10 +60,10 @@ static UICompositeViewDescription *compositeDescription = nil;
content:@"ImagePickerViewController"
stateBar:nil
stateBarEnabled:false
tabBar:@"UIMainBar"
tabBarEnabled:true
tabBar:nil
tabBarEnabled:false
fullscreen:false
landscapeMode:false
landscapeMode:[LinphoneManager runningOnIpad]
portraitMode:true];
}
return compositeDescription;
@ -85,10 +85,26 @@ static UICompositeViewDescription *compositeDescription = nil;
[pickerController setDelegate:self];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if ([[UIDevice currentDevice].systemVersion doubleValue] < 5.0) {
[pickerController viewWillAppear:animated];
}
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
if(popoverController != nil) {
[popoverController presentPopoverFromRect:CGRectZero inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:FALSE];
} else if ([[UIDevice currentDevice].systemVersion doubleValue] < 5.0) {
[pickerController viewDidAppear:animated];
}
}
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
if ([[UIDevice currentDevice].systemVersion doubleValue] < 5.0) {
[pickerController viewDidDisappear:animated];
}
}
@ -96,6 +112,8 @@ static UICompositeViewDescription *compositeDescription = nil;
[super viewWillDisappear:animated];
if(popoverController != nil) {
[popoverController dismissPopoverAnimated: NO];
} else if ([[UIDevice currentDevice].systemVersion doubleValue] < 5.0) {
[pickerController viewWillDisappear:animated];
}
}
@ -174,4 +192,13 @@ static UICompositeViewDescription *compositeDescription = nil;
return TRUE;
}
- (void)navigationController:(UINavigationController *)navigationController
willShowViewController:(UIViewController *)viewController
animated:(BOOL)animated {
if ([navigationController isKindOfClass:[UIImagePickerController class]]) {
[[UIApplication sharedApplication] setStatusBarHidden:NO];
}
}
@end

View file

@ -42,7 +42,7 @@
@synthesize chatRoomDelegate;
@synthesize imageTapGestureRecognizer;
static const CGFloat CELL_MIN_HEIGHT = 40.0f;
static const CGFloat CELL_MIN_HEIGHT = 50.0f;
static const CGFloat CELL_MIN_WIDTH = 150.0f;
static const CGFloat CELL_MAX_WIDTH = 320.0f;
static const CGFloat CELL_MESSAGE_X_MARGIN = 26.0f;

View file

@ -24,6 +24,8 @@
#import "UILinphone.h"
#import "PhoneMainView.h"
#import <MobileCoreServices/UTCoreTypes.h>
@implementation UIContactDetailsHeader
@synthesize avatarImage;
@ -251,7 +253,7 @@
// Displays a control that allows the user to choose picture or
// movie capture, if both are available:
controller.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:type];
controller.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeImage];
// Hides the controls for moving & scaling pictures, or for
// trimming movies. To instead show the controls, use YES.
@ -268,9 +270,9 @@
- (void)imagePickerDelegateImage:(UIImage*)image info:(NSDictionary *)info{
NSError* error = NULL;
if(!ABPersonRemoveImageData(contact, (CFErrorRef*)error)) {
[LinphoneLogger log:LinphoneLoggerLog format:@"Can't add entry: %@", [error localizedDescription]];
[LinphoneLogger log:LinphoneLoggerLog format:@"Can't remove entry: %@", [error localizedDescription]];
}
NSData *dataRef = UIImagePNGRepresentation(image);
NSData *dataRef = UIImagePNGRepresentation([image normalizedImage]);
CFDataRef cfdata = CFDataCreate(NULL,[dataRef bytes], [dataRef length]);
if(!ABPersonSetImageData(contact, cfdata, (CFErrorRef*)error)) {

View file

@ -190,7 +190,8 @@ static PhoneMainView* phoneMainViewInstance=nil;
+ (void)setOrientation:(UIInterfaceOrientation)orientation animated:(BOOL)animated {
UIView *firstResponder = nil;
for(UIWindow *window in [[UIApplication sharedApplication] windows]) {
if([NSStringFromClass(window.class) isEqualToString:@"UITextEffectsWindow"]) {
if([NSStringFromClass(window.class) isEqualToString:@"UITextEffectsWindow"] ||
[NSStringFromClass(window.class) isEqualToString:@"_UIAlertOverlayWindow"] ) {
continue;
}
UIView *view = window;

View file

@ -194,7 +194,7 @@
//size of content, so we can set the frame of self
NSInteger newSizeH = internalTextView.contentSize.height;
if(newSizeH < minHeight || !internalTextView.hasText) newSizeH = minHeight; //not smalles than minHeight
if (internalTextView.frame.size.height > maxHeight) newSizeH = maxHeight; // not taller than maxHeight
if(newSizeH > maxHeight) newSizeH = maxHeight; // not taller than maxHeight
if (internalTextView.frame.size.height != newSizeH)
{

View file

@ -267,7 +267,6 @@
<string key="NSFrame">{{262, 0}, {58, 57}}</string>
<reference key="NSSuperview" ref="833509359"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="IBUIOpaque">NO</bool>
<object class="IBUIAccessibilityConfiguration" key="IBUIAccessibilityConfiguration">
@ -290,7 +289,7 @@
</object>
<object class="NSColor" key="IBUIDisabledTitleColor">
<int key="NSColorSpace">2</int>
<bytes key="NSRGB">MC43MjU0OTAyMTI0IDAuNzY4NjI3NDY0OCAwLjc5NjA3ODQ0MzUAA</bytes>
<bytes key="NSRGB">MC44MDc4NDMxMzczIDAuODE1Njg2Mjc0NSAwLjgyMzUyOTQxMTgAA</bytes>
</object>
<object class="NSColor" key="IBUINormalTitleColor">
<int key="NSColorSpace">2</int>

View file

@ -278,7 +278,7 @@
</object>
<object class="NSColor" key="IBUIDisabledTitleColor">
<int key="NSColorSpace">2</int>
<bytes key="NSRGB">MC43MjU0OTAyMTI0IDAuNzY4NjI3NDY0OCAwLjc5NjA3ODQ0MzUAA</bytes>
<bytes key="NSRGB">MC44MDc4NDMxMzczIDAuODE1Njg2Mjc0NSAwLjgyMzUyOTQxMTgAA</bytes>
</object>
<object class="NSColor" key="IBUINormalTitleColor">
<int key="NSColorSpace">2</int>

View file

@ -337,17 +337,17 @@
<dict>
<key>backup</key>
<dict>
<key>33</key>
<key>34</key>
<dict>
<key>class</key>
<string>BLWrapperHandle</string>
<key>name</key>
<string>Classes/ChatRoomViewController/33/ChatRoomViewController.xib</string>
<string>Classes/ChatRoomViewController/34/ChatRoomViewController.xib</string>
</dict>
</dict>
</dict>
<key>change date</key>
<date>2012-09-24T07:54:14Z</date>
<date>2012-09-24T12:35:35Z</date>
<key>changed values</key>
<array/>
<key>class</key>
@ -357,7 +357,7 @@
<key>flags</key>
<integer>0</integer>
<key>hash</key>
<string>9cea2c5bb3cda145b0c819b0f48baf7c
<string>721bad8bcdaf6bd6dabf3d41eaf915d4
</string>
<key>name</key>
<string>ChatRoomViewController.xib</string>
@ -793,9 +793,9 @@
<key>versions</key>
<dict>
<key>en</key>
<string>33</string>
<string>34</string>
<key>fr</key>
<string>33</string>
<string>34</string>
</dict>
</dict>
<dict>
@ -10870,7 +10870,7 @@
</dict>
</dict>
<key>change date</key>
<date>2012-09-24T08:35:08Z</date>
<date>2012-09-24T09:53:58Z</date>
<key>changed values</key>
<array/>
<key>class</key>
@ -10880,7 +10880,7 @@
<key>flags</key>
<integer>0</integer>
<key>hash</key>
<string>aaac1683c5a04165fb53e6ece2921dbe
<string>660159e85a578aec4e5cdc047a29f686
</string>
<key>name</key>
<string>Localizable.strings</string>
@ -12312,6 +12312,31 @@ La cause était: %2$@</string>
<key>snapshots</key>
<dict/>
</dict>
<dict>
<key>change date</key>
<date>2001-01-01T00:00:00Z</date>
<key>changed values</key>
<array/>
<key>class</key>
<string>BLStringKeyObject</string>
<key>comment</key>
<string>No comment provided by engineer.</string>
<key>errors</key>
<array/>
<key>flags</key>
<integer>0</integer>
<key>key</key>
<string>Photo library</string>
<key>localizations</key>
<dict>
<key>en</key>
<string>Photo library</string>
<key>fr</key>
<string>Album photos</string>
</dict>
<key>snapshots</key>
<dict/>
</dict>
<dict>
<key>change date</key>
<date>2001-01-01T00:00:00Z</date>

View file

@ -267,7 +267,6 @@
<string key="NSFrame">{{262, 0}, {58, 57}}</string>
<reference key="NSSuperview" ref="833509359"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="IBUIOpaque">NO</bool>
<object class="IBUIAccessibilityConfiguration" key="IBUIAccessibilityConfiguration">
@ -290,7 +289,7 @@
</object>
<object class="NSColor" key="IBUIDisabledTitleColor">
<int key="NSColorSpace">2</int>
<bytes key="NSRGB">MC43MjU0OTAyMTI0IDAuNzY4NjI3NDY0OCAwLjc5NjA3ODQ0MzUAA</bytes>
<bytes key="NSRGB">MC44MDc4NDMxMzczIDAuODE1Njg2Mjc0NSAwLjgyMzUyOTQxMTgAA</bytes>
</object>
<object class="NSColor" key="IBUINormalTitleColor">
<int key="NSColorSpace">2</int>