forked from mirrors/linphone-iphone
Chat: set self avatar if available
This commit is contained in:
parent
e3ce60f9f8
commit
9fdc8d6efa
6 changed files with 34 additions and 28 deletions
|
|
@ -34,8 +34,8 @@
|
|||
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxX="YES" heightSizable="YES" flexibleMaxY="YES"/>
|
||||
</imageView>
|
||||
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" image="avatar.png" id="hD2-19-7IH" userLabel="avatarImage" customClass="UIRoundedImageView">
|
||||
<rect key="frame" x="7" y="1" width="40" height="40"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
|
||||
<rect key="frame" x="7" y="7" width="40" height="40"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<accessibility key="accessibilityConfiguration" label="Contact avatar">
|
||||
<accessibilityTraits key="traits" none="YES" image="YES" notEnabled="YES"/>
|
||||
<bool key="isElement" value="YES"/>
|
||||
|
|
|
|||
|
|
@ -106,7 +106,14 @@
|
|||
LinphoneChatMessageState state = linphone_chat_message_get_state(_message);
|
||||
BOOL outgoing = linphone_chat_message_is_outgoing(_message);
|
||||
|
||||
if (outgoing) {
|
||||
[LinphoneUtils setSelfAvatar:_avatarImage];
|
||||
} else {
|
||||
ABRecordRef contact = [FastAddressBook getContactWithAddress:linphone_chat_message_get_peer_address(_message)];
|
||||
_avatarImage.image = [FastAddressBook getContactImage:contact thumbnail:YES];
|
||||
}
|
||||
_backgroundColorImage.image = _bottomBarColor.image = [UIImage imageNamed:(outgoing ? @"color_A" : @"color_D")];
|
||||
|
||||
if (!outgoing) {
|
||||
_statusImage.accessibilityValue = @"incoming";
|
||||
_statusImage.hidden = TRUE; // not useful for incoming chats..
|
||||
|
|
|
|||
|
|
@ -35,8 +35,8 @@
|
|||
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxX="YES" heightSizable="YES" flexibleMaxY="YES"/>
|
||||
</imageView>
|
||||
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" image="avatar.png" id="P1c-sD-eOv" userLabel="avatarImage" customClass="UIRoundedImageView">
|
||||
<rect key="frame" x="7" y="2" width="40" height="40"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
|
||||
<rect key="frame" x="7" y="7" width="40" height="40"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<accessibility key="accessibilityConfiguration" label="Contact avatar">
|
||||
<accessibilityTraits key="traits" none="YES" image="YES" notEnabled="YES"/>
|
||||
<bool key="isElement" value="YES"/>
|
||||
|
|
|
|||
|
|
@ -6,8 +6,6 @@
|
|||
//
|
||||
//
|
||||
|
||||
#import <AssetsLibrary/ALAsset.h>
|
||||
|
||||
#import "SideMenuView.h"
|
||||
#import "LinphoneManager.h"
|
||||
#import "PhoneMainView.h"
|
||||
|
|
@ -26,25 +24,7 @@
|
|||
_nameLabel.text = @"No account";
|
||||
_addressLabel.text = NSLocalizedString(@"No address", nil);
|
||||
}
|
||||
|
||||
// set avatar if available
|
||||
NSURL *url = [NSURL URLWithString:[LinphoneManager.instance lpConfigStringForKey:@"avatar"]];
|
||||
if (url) {
|
||||
[LinphoneManager.instance.photoLibrary assetForURL:url
|
||||
resultBlock:^(ALAsset *asset) {
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, (unsigned long)NULL), ^(void) {
|
||||
UIImage *decodedImage = [[UIImage alloc] initWithCGImage:[asset thumbnail]];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[_avatarImage setImage:decodedImage];
|
||||
});
|
||||
});
|
||||
}
|
||||
failureBlock:^(NSError *error) {
|
||||
LOGE(@"Can't read avatar");
|
||||
}];
|
||||
} else {
|
||||
[_avatarImage setImage:[UIImage imageNamed:@"avatar"]];
|
||||
}
|
||||
[LinphoneUtils setSelfAvatar:_avatarImage];
|
||||
}
|
||||
|
||||
- (void)viewWillAppear:(BOOL)animated {
|
||||
|
|
|
|||
|
|
@ -27,9 +27,7 @@
|
|||
void linphone_iphone_log_handler(int lev, const char *fmt, va_list args);
|
||||
@end
|
||||
|
||||
@interface LinphoneUtils : NSObject {
|
||||
|
||||
}
|
||||
@interface LinphoneUtils : NSObject
|
||||
|
||||
+ (BOOL)findAndResignFirstResponder:(UIView*)view;
|
||||
+ (void)adjustFontSize:(UIView*)view mult:(float)mult;
|
||||
|
|
@ -39,6 +37,7 @@ void linphone_iphone_log_handler(int lev, const char *fmt, va_list args);
|
|||
+ (NSString *)deviceName;
|
||||
|
||||
+ (NSString *)timeToString:(time_t)time withStyle:(NSDateFormatterStyle)style;
|
||||
+ (void)setSelfAvatar:(UIImageView *)avatar;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
#import <UIKit/UIView.h>
|
||||
#import <CommonCrypto/CommonDigest.h>
|
||||
#import <sys/utsname.h>
|
||||
#import <AssetsLibrary/ALAsset.h>
|
||||
|
||||
#import "Utils.h"
|
||||
#import "linphone/linphonecore.h"
|
||||
|
|
@ -81,6 +82,25 @@ void linphone_iphone_log_handler(int lev, const char *fmt, va_list args) {
|
|||
|
||||
@implementation LinphoneUtils
|
||||
|
||||
+ (void)setSelfAvatar:(UIImageView *)avatar {
|
||||
NSURL *url = [NSURL URLWithString:[LinphoneManager.instance lpConfigStringForKey:@"avatar"]];
|
||||
if (url) {
|
||||
[LinphoneManager.instance.photoLibrary assetForURL:url
|
||||
resultBlock:^(ALAsset *asset) {
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, (unsigned long)NULL), ^(void) {
|
||||
UIImage *decodedImage = [[UIImage alloc] initWithCGImage:[asset thumbnail]];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
avatar.image = decodedImage;
|
||||
});
|
||||
});
|
||||
}
|
||||
failureBlock:^(NSError *error) {
|
||||
LOGE(@"Can't read avatar");
|
||||
}];
|
||||
} else {
|
||||
avatar.image = [UIImage imageNamed:@"avatar"];
|
||||
}
|
||||
}
|
||||
+ (NSString *)timeToString:(time_t)time withStyle:(NSDateFormatterStyle)style {
|
||||
NSDate *todayDate = [[NSDate alloc] init];
|
||||
NSDate *messageDate = (time == 0) ? todayDate : [NSDate dateWithTimeIntervalSince1970:time];
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue