diff --git a/.DS_Store b/.DS_Store index d91b338..f99dd33 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/iFlyChatGlobalListView.xcodeproj/project.pbxproj b/iFlyChatGlobalListView.xcodeproj/project.pbxproj index 6edabad..95ac800 100644 --- a/iFlyChatGlobalListView.xcodeproj/project.pbxproj +++ b/iFlyChatGlobalListView.xcodeproj/project.pbxproj @@ -21,6 +21,12 @@ 6ECB81401B68FA0C009E78EA /* iFlyChatGlobalListViewTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6ECB813F1B68FA0C009E78EA /* iFlyChatGlobalListViewTests.m */; }; 6ECB81511B68FF99009E78EA /* UsersTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6ECB81501B68FF99009E78EA /* UsersTableViewController.m */; }; 6ECB81531B6902DE009E78EA /* GlobalListTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6ECB81521B6902DE009E78EA /* GlobalListTableViewCell.xib */; }; + 6ED0C65B1BF5E8B5005336B1 /* Utility.m in Sources */ = {isa = PBXBuildFile; fileRef = 6ED0C65A1BF5E8B5005336B1 /* Utility.m */; }; + 6ED0C6611BF5ED5F005336B1 /* ChatRoom.png in Resources */ = {isa = PBXBuildFile; fileRef = 6ED0C65C1BF5ED5F005336B1 /* ChatRoom.png */; }; + 6ED0C6621BF5ED5F005336B1 /* FemaleUser.png in Resources */ = {isa = PBXBuildFile; fileRef = 6ED0C65D1BF5ED5F005336B1 /* FemaleUser.png */; }; + 6ED0C6631BF5ED5F005336B1 /* MaleUser.png in Resources */ = {isa = PBXBuildFile; fileRef = 6ED0C65E1BF5ED5F005336B1 /* MaleUser.png */; }; + 6ED0C6641BF5ED5F005336B1 /* GeneralUser.png in Resources */ = {isa = PBXBuildFile; fileRef = 6ED0C65F1BF5ED5F005336B1 /* GeneralUser.png */; }; + 6ED0C6651BF5ED5F005336B1 /* iflychat_full.png in Resources */ = {isa = PBXBuildFile; fileRef = 6ED0C6601BF5ED5F005336B1 /* iflychat_full.png */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -59,6 +65,13 @@ 6ECB814F1B68FF99009E78EA /* UsersTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UsersTableViewController.h; sourceTree = ""; }; 6ECB81501B68FF99009E78EA /* UsersTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UsersTableViewController.m; sourceTree = ""; }; 6ECB81521B6902DE009E78EA /* GlobalListTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = GlobalListTableViewCell.xib; sourceTree = ""; }; + 6ED0C6591BF5E8B5005336B1 /* Utility.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Utility.h; sourceTree = ""; }; + 6ED0C65A1BF5E8B5005336B1 /* Utility.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Utility.m; sourceTree = ""; }; + 6ED0C65C1BF5ED5F005336B1 /* ChatRoom.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = ChatRoom.png; sourceTree = ""; }; + 6ED0C65D1BF5ED5F005336B1 /* FemaleUser.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = FemaleUser.png; sourceTree = ""; }; + 6ED0C65E1BF5ED5F005336B1 /* MaleUser.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = MaleUser.png; sourceTree = ""; }; + 6ED0C65F1BF5ED5F005336B1 /* GeneralUser.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = GeneralUser.png; sourceTree = ""; }; + 6ED0C6601BF5ED5F005336B1 /* iflychat_full.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = iflychat_full.png; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -167,8 +180,11 @@ 6EAEA1FE1B69F7790042A11D /* GlobalListTableViewCell */, 6ECB812D1B68FA0C009E78EA /* Main.storyboard */, 6ECB81301B68FA0C009E78EA /* Images.xcassets */, + 6ED0C6661BF5ED64005336B1 /* Resources */, 6ECB81321B68FA0C009E78EA /* LaunchScreen.xib */, 6ECB81231B68FA0C009E78EA /* Supporting Files */, + 6ED0C6591BF5E8B5005336B1 /* Utility.h */, + 6ED0C65A1BF5E8B5005336B1 /* Utility.m */, ); path = iFlyChatGlobalListView; sourceTree = ""; @@ -199,6 +215,18 @@ name = "Supporting Files"; sourceTree = ""; }; + 6ED0C6661BF5ED64005336B1 /* Resources */ = { + isa = PBXGroup; + children = ( + 6ED0C65C1BF5ED5F005336B1 /* ChatRoom.png */, + 6ED0C65D1BF5ED5F005336B1 /* FemaleUser.png */, + 6ED0C65E1BF5ED5F005336B1 /* MaleUser.png */, + 6ED0C65F1BF5ED5F005336B1 /* GeneralUser.png */, + 6ED0C6601BF5ED5F005336B1 /* iflychat_full.png */, + ); + name = Resources; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -248,6 +276,7 @@ TargetAttributes = { 6ECB811F1B68FA0C009E78EA = { CreatedOnToolsVersion = 6.4; + DevelopmentTeam = ET385UDM96; }; 6ECB81381B68FA0C009E78EA = { CreatedOnToolsVersion = 6.4; @@ -279,10 +308,15 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 6ED0C6621BF5ED5F005336B1 /* FemaleUser.png in Resources */, + 6ED0C6631BF5ED5F005336B1 /* MaleUser.png in Resources */, 6ECB81531B6902DE009E78EA /* GlobalListTableViewCell.xib in Resources */, + 6ED0C6651BF5ED5F005336B1 /* iflychat_full.png in Resources */, 6ECB812F1B68FA0C009E78EA /* Main.storyboard in Resources */, 6ECB81341B68FA0C009E78EA /* LaunchScreen.xib in Resources */, 6ECB81311B68FA0C009E78EA /* Images.xcassets in Resources */, + 6ED0C6611BF5ED5F005336B1 /* ChatRoom.png in Resources */, + 6ED0C6641BF5ED5F005336B1 /* GeneralUser.png in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -304,6 +338,7 @@ 6EAEA2011B69F7970042A11D /* GlobalListTableViewCell.m in Sources */, 6E6743101BA9910B00B03D5E /* ApplicationData.m in Sources */, 6EAEA2061B6A1ACF0042A11D /* RoomsTableViewController.m in Sources */, + 6ED0C65B1BF5E8B5005336B1 /* Utility.m in Sources */, 6ECB81291B68FA0C009E78EA /* AppDelegate.m in Sources */, 6ECB81511B68FF99009E78EA /* UsersTableViewController.m in Sources */, 6ECB81261B68FA0C009E78EA /* main.m in Sources */, @@ -369,6 +404,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_BITCODE = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; @@ -414,6 +450,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_BITCODE = NO; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; @@ -435,30 +472,40 @@ 6ECB81441B68FA0C009E78EA /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + ARCHS = "$(ARCHS_STANDARD)"; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_IDENTITY = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; ENABLE_BITCODE = NO; - FRAMEWORK_SEARCH_PATHS = "$(PROJECT_DIR)"; + FRAMEWORK_SEARCH_PATHS = ""; INFOPLIST_FILE = iFlyChatGlobalListView/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 7.1; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = "iFlyLabs.$(PRODUCT_NAME:rfc1034identifier)"; + PRODUCT_BUNDLE_IDENTIFIER = iFlyLabs.iFlyChatGlobalListView; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE = ""; TARGETED_DEVICE_FAMILY = "1,2"; + VALID_ARCHS = "arm64 armv7 armv7s"; }; name = Debug; }; 6ECB81451B68FA0C009E78EA /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + ARCHS = "$(ARCHS_STANDARD)"; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_IDENTITY = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; ENABLE_BITCODE = NO; - FRAMEWORK_SEARCH_PATHS = "$(PROJECT_DIR)"; + FRAMEWORK_SEARCH_PATHS = ""; INFOPLIST_FILE = iFlyChatGlobalListView/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 7.1; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = "iFlyLabs.$(PRODUCT_NAME:rfc1034identifier)"; + PRODUCT_BUNDLE_IDENTIFIER = iFlyLabs.iFlyChatGlobalListView; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE = ""; TARGETED_DEVICE_FAMILY = "1,2"; + VALID_ARCHS = "arm64 armv7 armv7s"; }; name = Release; }; diff --git a/iFlyChatGlobalListView.xcodeproj/project.xcworkspace/xcuserdata/prateek.xcuserdatad/UserInterfaceState.xcuserstate b/iFlyChatGlobalListView.xcodeproj/project.xcworkspace/xcuserdata/prateek.xcuserdatad/UserInterfaceState.xcuserstate index 3ff2ea6..c68d6ae 100644 Binary files a/iFlyChatGlobalListView.xcodeproj/project.xcworkspace/xcuserdata/prateek.xcuserdatad/UserInterfaceState.xcuserstate and b/iFlyChatGlobalListView.xcodeproj/project.xcworkspace/xcuserdata/prateek.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/iFlyChatGlobalListView.xcodeproj/xcuserdata/prateek.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/iFlyChatGlobalListView.xcodeproj/xcuserdata/prateek.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 8f94031..8f6a351 100644 --- a/iFlyChatGlobalListView.xcodeproj/xcuserdata/prateek.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/iFlyChatGlobalListView.xcodeproj/xcuserdata/prateek.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -13,5 +13,21 @@ stopOnStyle = "0"> + + + + diff --git a/iFlyChatGlobalListView/.DS_Store b/iFlyChatGlobalListView/.DS_Store index 249f08f..85aef73 100644 Binary files a/iFlyChatGlobalListView/.DS_Store and b/iFlyChatGlobalListView/.DS_Store differ diff --git a/iFlyChatGlobalListView/Base.lproj/LaunchScreen.xib b/iFlyChatGlobalListView/Base.lproj/LaunchScreen.xib index ad2c149..7ebb019 100644 --- a/iFlyChatGlobalListView/Base.lproj/LaunchScreen.xib +++ b/iFlyChatGlobalListView/Base.lproj/LaunchScreen.xib @@ -1,7 +1,7 @@ - + - + @@ -11,19 +11,22 @@ - + diff --git a/iFlyChatGlobalListView/ChatRoom.png b/iFlyChatGlobalListView/ChatRoom.png new file mode 100644 index 0000000..1aebfd3 Binary files /dev/null and b/iFlyChatGlobalListView/ChatRoom.png differ diff --git a/iFlyChatGlobalListView/DataClass.m b/iFlyChatGlobalListView/DataClass.m index 9ad54b6..7980a05 100644 --- a/iFlyChatGlobalListView/DataClass.m +++ b/iFlyChatGlobalListView/DataClass.m @@ -37,13 +37,16 @@ +(DataClass *)getInstance //Intialisation of chat -(void) initiFlyChatLibrary { + [Utilities setIsDebug:YES]; + //iFlyChatUserSession object with username, password and session key (if available) - appData.session = [[iFlyChatUserSession alloc] initIFlyChatUserSessionwithUserName:@"userName" userPassword:@"userPassword" userSessionKey:@""]; + + appData.session = [[iFlyChatUserSession alloc] initIFlyChatUserSessionwithUserName:@"username" userPassword:@"userPassword" userSessionKey:@""]; //iFlyChatConfig object with server host, auth URL, SSL connection boolean and iFlyChatUserSession object. These are the basic configuration parameters used to connect to iFlyChat's servers - appData.config = [[iFlyChatConfig alloc] initIFlyChatConfigwithServerHost:@"serverhost.com" authUrl:@"http://example.com/auth/url" isHttps:NO userSession:appData.session]; + appData.config = [[iFlyChatConfig alloc] initIFlyChatConfigwithServerHost:@"serverhost.com" authUrl:@"http://example.com/auth/url" isHttps:NO]; //If auto reconnection is required, set it to "YES" diff --git a/iFlyChatGlobalListView/FemaleUser.png b/iFlyChatGlobalListView/FemaleUser.png new file mode 100644 index 0000000..f0500ed Binary files /dev/null and b/iFlyChatGlobalListView/FemaleUser.png differ diff --git a/iFlyChatGlobalListView/GeneralUser.png b/iFlyChatGlobalListView/GeneralUser.png new file mode 100644 index 0000000..39cc3a6 Binary files /dev/null and b/iFlyChatGlobalListView/GeneralUser.png differ diff --git a/iFlyChatGlobalListView/GlobalListTableViewCell.h b/iFlyChatGlobalListView/GlobalListTableViewCell.h index e95e966..a2a1de8 100644 --- a/iFlyChatGlobalListView/GlobalListTableViewCell.h +++ b/iFlyChatGlobalListView/GlobalListTableViewCell.h @@ -11,6 +11,7 @@ @interface GlobalListTableViewCell : UITableViewCell @property (weak, nonatomic) IBOutlet UIImageView *avatarImage; +@property (weak, nonatomic) IBOutlet UILabel *userLetterLabel; @property (weak, nonatomic) IBOutlet UILabel *nameLabel; diff --git a/iFlyChatGlobalListView/GlobalListTableViewCell.m b/iFlyChatGlobalListView/GlobalListTableViewCell.m index 4c5205d..f7cc051 100644 --- a/iFlyChatGlobalListView/GlobalListTableViewCell.m +++ b/iFlyChatGlobalListView/GlobalListTableViewCell.m @@ -11,10 +11,25 @@ @implementation GlobalListTableViewCell @synthesize avatarImage; +@synthesize userLetterLabel; @synthesize nameLabel; @synthesize messageLabel; @synthesize timeLabel; +- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated +{ + UIColor *backgroundColor = self.avatarImage.backgroundColor; + [super setHighlighted:highlighted animated:animated]; + self.avatarImage.backgroundColor = backgroundColor; +} + +- (void)setSelected:(BOOL)selected animated:(BOOL)animated +{ + UIColor *backgroundColor = self.avatarImage.backgroundColor; + [super setSelected:selected animated:animated]; + self.avatarImage.backgroundColor = backgroundColor; +} + @end diff --git a/iFlyChatGlobalListView/GlobalListTableViewCell.xib b/iFlyChatGlobalListView/GlobalListTableViewCell.xib index a9660fa..03d47ba 100644 --- a/iFlyChatGlobalListView/GlobalListTableViewCell.xib +++ b/iFlyChatGlobalListView/GlobalListTableViewCell.xib @@ -1,8 +1,8 @@ - + - + @@ -13,10 +13,12 @@ + + @@ -33,6 +35,7 @@ + @@ -73,21 +79,46 @@ + + + + + + + + + + + + + + + diff --git a/iFlyChatGlobalListView/Info.plist b/iFlyChatGlobalListView/Info.plist index 028efc3..742c765 100644 --- a/iFlyChatGlobalListView/Info.plist +++ b/iFlyChatGlobalListView/Info.plist @@ -22,11 +22,11 @@ 1 LSRequiresIPhoneOS - NSAppTransportSecurity - - NSAllowsArbitraryLoads - - + NSAppTransportSecurity + + NSAllowsArbitraryLoads + + UILaunchStoryboardName LaunchScreen UIMainStoryboardFile diff --git a/iFlyChatGlobalListView/MaleUser.png b/iFlyChatGlobalListView/MaleUser.png new file mode 100644 index 0000000..aed2d44 Binary files /dev/null and b/iFlyChatGlobalListView/MaleUser.png differ diff --git a/iFlyChatGlobalListView/RoomsTableViewController.m b/iFlyChatGlobalListView/RoomsTableViewController.m index 81af9d1..c9186e3 100644 --- a/iFlyChatGlobalListView/RoomsTableViewController.m +++ b/iFlyChatGlobalListView/RoomsTableViewController.m @@ -9,12 +9,14 @@ #import "RoomsTableViewController.h" #import "GlobalListTableViewCell.h" #import "DataClass.h" +#import "Utility.h" #import "ApplicationSettings.h" @implementation RoomsTableViewController { DataClass *dtclass; ApplicationSettings *appSettings; + ApplicationData *appData; dispatch_queue_t fetchImage; NSCache *roomImageCache; } @@ -124,30 +126,13 @@ -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NS cell.nameLabel.text = currentRoom.getName; cell.timeLabel.text = @"5 pm"; - //Checking if the image is already downloaded for the room id - if([roomImageCache objectForKey:currentRoom.getId] == nil) - { - if([[currentRoom getAvatarUrl] length]!=0) - { - - dispatch_async(fetchImage, ^{ - - //Downloading images asynchronously - [self loadImagesWithURL:[NSString stringWithFormat:@"%@%@",@"http:",[currentRoom getAvatarUrl]] IndexPath:indexPath activeTableView:tableView roomId:currentRoom.getId]; - - - }); - } + [cell.userLetterLabel setHidden:YES]; - //If avatar url is empty, set the default image - cell.avatarImage.image = [UIImage imageNamed:@"defaultRoom.png"]; - - } - else - { - //If the image is already downloaded, get it from cache and set it - cell.avatarImage.image = [roomImageCache objectForKey:currentRoom.getId]; - } + //If avatar url is empty, set the default image + + [cell.avatarImage setBackgroundColor:[Utility getColorFromNameWithoutPrefix:currentRoom.getName]]; + + cell.avatarImage.image = [UIImage imageNamed:@"ChatRoom.png"]; cell.messageLabel.text = @"No message"; @@ -168,7 +153,10 @@ -(void) loadImagesWithURL:(NSString *)imageURL IndexPath:(NSIndexPath *)indexPat UIImage *img = [UIImage imageWithData:data]; //Inserting downloaded image in cache - [roomImageCache setObject:img forKey:roomId]; + if(img != nil) + { + [roomImageCache setObject:img forKey:roomId]; + } dispatch_async(dispatch_get_main_queue(), ^{ diff --git a/iFlyChatGlobalListView/UsersTableViewController.m b/iFlyChatGlobalListView/UsersTableViewController.m index 13d12e1..634c7f9 100644 --- a/iFlyChatGlobalListView/UsersTableViewController.m +++ b/iFlyChatGlobalListView/UsersTableViewController.m @@ -10,13 +10,19 @@ #import "GlobalListTableViewCell.h" #import "DataClass.h" #import "ApplicationSettings.h" +#import "Utility.h" +@import MobileCoreServices; +#import @implementation UsersTableViewController { DataClass *dtclass; ApplicationSettings *appSettings; + ApplicationData *appData; dispatch_queue_t fetchImage; NSCache *userImageCache; + + BOOL use_default_avatar; } @synthesize userArray; @@ -29,11 +35,15 @@ -(void) viewDidLoad //Getting singleton instances of DataClass and ApplicationSettings dtclass = [DataClass getInstance]; appSettings = [ApplicationSettings getInstance]; + appData = [ApplicationData getInstance]; //Setting the Top bar title for Users Tab [appSettings setUsersTabTopBarTitle:@"Chats"]; + use_default_avatar = NO; + + self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; //Adding search bar to the top of table view @@ -65,10 +75,18 @@ - (void)viewWillAppear:(BOOL)animated //Putting the data inside the table view [self refreshUserList]; + [self.tabBarController.tabBar setHidden:NO]; + //Registering for the notification that will come from DataClass after library sends the updated Global List [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshUserList) name:@"onUpdatedGlobalList" object:nil]; + + //Adding observers for required notifications. + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(chatConnect:) name:@"iFlyChat.onChatConnect" object:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(gotSessionKey:) name:@"iFlyChat.onGetSessionKey" object:nil]; } + - (void)viewDidDisappear: (BOOL)animated{ //Removing the observer @@ -88,6 +106,20 @@ - (void)refreshUserList } } +-(void) chatConnect:(NSNotification *)notification +{ + //Assigning the loggedUser data to the loggedUser variable in application data + NSDictionary *dict = [notification object]; + appData.loggedUser = [dict objectForKey:@"iFlyChatCurrentUser"]; +} + +-(void) gotSessionKey:(NSNotification *)notification +{ + //Assigning session key + appData.sessionKey = [notification object]; +} + + - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { @@ -131,23 +163,14 @@ -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NS //Checking if the image is already downloaded for the user id if([userImageCache objectForKey:currentUser.getId] == nil) { - if([[currentUser getAvatarUrl] length]!=0) - { - dispatch_async(fetchImage, ^{ - - //Downloading images asynchronously - [self loadImagesWithURL:[NSString stringWithFormat:@"%@%@",@"http:",[currentUser getAvatarUrl]] IndexPath:indexPath activeTableView:tableView userId:currentUser.getId]; - - }); - } - - //If avatar url is empty, set the default image - cell.avatarImage.image = [UIImage imageNamed:@"defaultUser.png"]; + [self setChatImage:cell.avatarImage userLetterLabel:cell.userLetterLabel userId:currentUser.getId userName:currentUser.getName userAvatarUrl:currentUser.getAvatarUrl]; } else { //If the image is already downloaded, get it from cache and set it cell.avatarImage.image = [userImageCache objectForKey:currentUser.getId]; + cell.avatarImage.backgroundColor = [UIColor whiteColor]; + [cell.userLetterLabel setHidden:YES]; } cell.messageLabel.text = @"No message"; @@ -155,7 +178,90 @@ -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NS return cell; } --(void) loadImagesWithURL:(NSString *)imageURL IndexPath:(NSIndexPath *)indexPath activeTableView:(UITableView *)tableView userId:(NSString *)userId +-(void) setChatImage:(UIImageView *)userImageView userLetterLabel:(UILabel *)userLetterLabel userId:(NSString *)userId userName:(NSString *)userName userAvatarUrl:(NSString *)userAvatarUrl +{ + if([self checkRegisteredUser:userId]) + { + if(userAvatarUrl.length != 0) + { + if([userAvatarUrl rangeOfString:@"default_avatar"].location != NSNotFound || [userAvatarUrl rangeOfString:@"gravatar"].location != NSNotFound ) + { + if(use_default_avatar) + { + //A registered user with no image set and we have to use only default image, no letter image + [self setDefaultAvatarWithBackgroundColor:userName userImageView: userImageView]; + [userLetterLabel setHidden:YES]; + } + else + { + //A registered user with no image set and we are allowed to use letter image + [self setLetterAvatarWithBackgroundColor:userName userImageView: userImageView userLetterLabel: userLetterLabel]; + } + } + else + { + //A registered user with image set so use URL image + dispatch_async(fetchImage, ^{ + //Downloading images asynchronously + [self loadImagesWithURL:[NSString stringWithFormat:@"%@%@",@"http:",userAvatarUrl] userImageView:userImageView userId:userId]; + }); + + [userLetterLabel setHidden:YES]; + userImageView.backgroundColor = [UIColor whiteColor]; + } + } + else if(use_default_avatar) + { + //A registered user with no URL for avatar and we have to use default image, no letter image + [self setDefaultAvatarWithBackgroundColor:userName userImageView: userImageView]; + [userLetterLabel setHidden:YES]; + } + else + { + //A registered user with no URL for avatar and we are allowed to use letter image + [self setLetterAvatarWithBackgroundColor:userName userImageView: userImageView userLetterLabel: userLetterLabel]; + } + } + else + { + if(use_default_avatar) + { + //A guest user and we have to use default image, no letter image + [self setDefaultAvatarWithBackgroundColor:[Utility getNameWithoutPrefix:userName] userImageView: userImageView]; + [userLetterLabel setHidden:YES]; + } + else + { + //A guest user and we are allowed to use letter image + [self setLetterAvatarWithBackgroundColor:[Utility getNameWithoutPrefix:userName] userImageView: userImageView userLetterLabel: userLetterLabel]; + } + } +} + + +-(void) setDefaultAvatarWithBackgroundColor:(NSString *)userNameWithoutPrefix userImageView:(UIImageView *)userImageView +{ + userImageView.backgroundColor = [Utility getColorFromNameWithoutPrefix:userNameWithoutPrefix]; + userImageView.image = [UIImage imageNamed:@"MaleUser"]; +} + +-(void) setLetterAvatarWithBackgroundColor:(NSString *)userNameWithoutPrefix userImageView:(UIImageView *)userImageView userLetterLabel:(UILabel *)userLetterLabel +{ + if([[Utility getLetterFromNameWithoutPrefix:userNameWithoutPrefix] rangeOfCharacterFromSet:[NSCharacterSet decimalDigitCharacterSet]].location != NSNotFound) + { + [userLetterLabel setHidden:YES]; + [self setDefaultAvatarWithBackgroundColor:userNameWithoutPrefix userImageView:userImageView]; + } + else + { + userImageView.backgroundColor = [Utility getColorFromNameWithoutPrefix:userNameWithoutPrefix]; + userLetterLabel.text = [Utility getLetterFromNameWithoutPrefix:userNameWithoutPrefix]; + [userLetterLabel setHidden:NO]; + userImageView.image = nil; + } +} + +-(void) loadImagesWithURL:(NSString *)imageURL userImageView:(UIImageView *)userImageView userId:(NSString *)userId { NSURL *url = [NSURL URLWithString:imageURL]; NSData *data = [[NSData alloc ] initWithContentsOfURL:url]; @@ -163,17 +269,30 @@ -(void) loadImagesWithURL:(NSString *)imageURL IndexPath:(NSIndexPath *)indexPat UIImage *img = [UIImage imageWithData:data]; //Inserting downloaded image in cache - [userImageCache setObject:img forKey:userId]; + if(img != nil) + { + [userImageCache setObject:img forKey:userId]; + } dispatch_async(dispatch_get_main_queue(), ^{ //Setting the image in the correct tableview and in the correct row - GlobalListTableViewCell *cell = (GlobalListTableViewCell *)[tableView cellForRowAtIndexPath:indexPath]; - cell.avatarImage.image = img; - + userImageView.image = img; }); } +-(BOOL) checkRegisteredUser:(NSString *)userId +{ + if([userId rangeOfString:@"0-"].location != NSNotFound) + { + return NO; + } + else + { + return YES; + } +} + - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 60; diff --git a/iFlyChatGlobalListView/Utility.h b/iFlyChatGlobalListView/Utility.h new file mode 100644 index 0000000..6776401 --- /dev/null +++ b/iFlyChatGlobalListView/Utility.h @@ -0,0 +1,21 @@ +// +// ColorPicker.h +// iFlyChatGlobalListView +// +// Created by iFlyLabs on 01/10/15. +// Copyright © 2015 iFlyLabs. All rights reserved. +// + +#import +#import +#import "ApplicationData.h" + +@interface Utility : NSObject + ++(NSString *) getNameWithoutPrefix:(NSString *)userName; + ++(UIColor *) getColorFromNameWithoutPrefix:(NSString *)userName; + ++(NSString *) getLetterFromNameWithoutPrefix:(NSString *)userName; + +@end diff --git a/iFlyChatGlobalListView/Utility.m b/iFlyChatGlobalListView/Utility.m new file mode 100644 index 0000000..a2748bf --- /dev/null +++ b/iFlyChatGlobalListView/Utility.m @@ -0,0 +1,85 @@ +// +// ColorPicker.m +// iFlyChatGlobalListView +// +// Created by iFlyLabs on 01/10/15. +// Copyright © 2015 iFlyLabs. All rights reserved. +// + +#import "Utility.h" + +@implementation Utility + ++(NSString *) getNameWithoutPrefix:(NSString *)userName +{ + NSString *guestPrefix = [[[ApplicationData getInstance].config getChatSettings] objectForKey:@"guestPrefix"]; + + userName = [userName substringFromIndex:guestPrefix.length]; + + if([userName length] == 0) + { + return guestPrefix; + } + + return userName; +} + ++(UIColor *) getColorFromNameWithoutPrefix:(NSString *)userName +{ + UIColor *bgColor; + char cString; + int sumOfCString=0; + int i=0; + + for(i=0;i<[userName length];i++) + { + cString = [userName characterAtIndex:i]; + sumOfCString += (int)cString; + } + + int modOfSum = sumOfCString%6; + + switch (modOfSum) { + case 0: + bgColor = [UIColor colorWithRed:(84.0f/255.0f) green:(171.0f/255.0f) blue:(214.0f/255.0f) alpha:1.0f]; + break; + + case 1: + bgColor = [UIColor colorWithRed:(209.0f/255.0f) green:(172.0f/255.0f) blue:(146.0f/255.0f) alpha:1.0f]; + break; + + case 2: + bgColor = [UIColor colorWithRed:(98.0f/255.0f) green:(197.0f/255.0f) blue:(168.0f/255.0f) alpha:1.0f]; + break; + + case 3: + bgColor = [UIColor colorWithRed:(249.0f/255.0f) green:(188.0f/255.0f) blue:(95.0f/255.0f) alpha:1.0f]; + break; + + case 4: + bgColor = [UIColor colorWithRed:(224.0f/255.0f) green:(105.0f/255.0f) blue:(99.0f/255.0f) alpha:1.0f]; + break; + + case 5: + bgColor = [UIColor colorWithRed:(199.0f/255.0f) green:(168.0f/255.0f) blue:(225.0f/255.0f) alpha:1.0f]; + break; + + default: + bgColor = [UIColor colorWithRed:(84.0f/255.0f) green:(171.0f/255.0f) blue:(214.0f/255.0f) alpha:1.0f]; + break; + } + + return bgColor; +} + ++(NSString *) getLetterFromNameWithoutPrefix:(NSString *)userName +{ + NSString *userLetter; + + userLetter = [userName substringToIndex:1]; + userLetter = [userLetter uppercaseString]; + + return userLetter; +} + +@end diff --git a/iFlyChatGlobalListView/iflychat_full.png b/iFlyChatGlobalListView/iflychat_full.png new file mode 100644 index 0000000..08e679a Binary files /dev/null and b/iFlyChatGlobalListView/iflychat_full.png differ