Skip to content

Commit

Permalink
add unread red dot for voice
Browse files Browse the repository at this point in the history
  • Loading branch information
chenweiyj committed Nov 14, 2014
1 parent 0f51c7e commit 1f23bc0
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ DerivedData
# you should judge for yourself, the pros and cons are mentioned at:
# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
#
# Pods/
# Pods/

.DS_Store
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
1FE768581A1627F200732D37 /* msg_chat_voice_unread.png in Resources */ = {isa = PBXBuildFile; fileRef = 1FE768561A1627F200732D37 /* msg_chat_voice_unread.png */; };
1FE768591A1627F200732D37 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 1FE768571A1627F200732D37 /* [email protected] */; };
74065FB919123E1C00E1CE95 /* XHShareMenuItem.h in Headers */ = {isa = PBXBuildFile; fileRef = 74065FB719123E1C00E1CE95 /* XHShareMenuItem.h */; settings = {ATTRIBUTES = (Public, ); }; };
74065FBA19123E1C00E1CE95 /* XHShareMenuItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 74065FB819123E1C00E1CE95 /* XHShareMenuItem.m */; };
74065FBB19123E1C00E1CE95 /* XHShareMenuItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 74065FB819123E1C00E1CE95 /* XHShareMenuItem.m */; };
Expand Down Expand Up @@ -744,6 +746,8 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
1FE768561A1627F200732D37 /* msg_chat_voice_unread.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = msg_chat_voice_unread.png; sourceTree = "<group>"; };
1FE768571A1627F200732D37 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
74065FB719123E1C00E1CE95 /* XHShareMenuItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XHShareMenuItem.h; sourceTree = "<group>"; };
74065FB819123E1C00E1CE95 /* XHShareMenuItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XHShareMenuItem.m; sourceTree = "<group>"; };
740660B21914CA0000E1CE95 /* XHPhotographyHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XHPhotographyHelper.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1384,6 +1388,15 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
1FE768551A1627E100732D37 /* ExtendImages */ = {
isa = PBXGroup;
children = (
1FE768561A1627F200732D37 /* msg_chat_voice_unread.png */,
1FE768571A1627F200732D37 /* [email protected] */,
);
name = ExtendImages;
sourceTree = "<group>";
};
74180BD7190F447100A35C82 /* MessageDisplayFramework */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -2093,6 +2106,7 @@
74FAB0BA190A92CC005623D0 /* Resources */ = {
isa = PBXGroup;
children = (
1FE768551A1627E100732D37 /* ExtendImages */,
7DA2EC7B19455F4100B009FC /* MultiSelectImages */,
7D0AAFF3194322FE00988FC3 /* PopMenuImages */,
74E5E99E1921F7580084BCFA /* VoiceRecordHUDImages */,
Expand Down Expand Up @@ -3288,6 +3302,7 @@
7DA2ECBF19457A2D00B009FC /* emotion9.gif in Resources */,
ABE83CCE1937E00E00BBF653 /* [email protected] in Resources */,
74BBB020190B8EAB00093577 /* MessageDisplayKitString.strings in Resources */,
1FE768581A1627F200732D37 /* msg_chat_voice_unread.png in Resources */,
ABB7771D1932A7D700F4ACAF /* [email protected] in Resources */,
AB0C4AD81943B6BB00D346FF /* [email protected] in Resources */,
AB0C4AD51943B6BB00D346FF /* [email protected] in Resources */,
Expand Down Expand Up @@ -3323,6 +3338,7 @@
746C885F1916B612007F9A5E /* [email protected] in Resources */,
74E5E9AF1921F7710084BCFA /* [email protected] in Resources */,
ABCB35B819342DFA002F9938 /* [email protected] in Resources */,
1FE768591A1627F200732D37 /* [email protected] in Resources */,
74E900691927940000D37C81 /* [email protected] in Resources */,
746C88201916B5D6007F9A5E /* [email protected] in Resources */,
74E9006E1927940000D37C81 /* [email protected] in Resources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@ - (void)multiMediaMessageDidSelectedOnMessage:(id<XHMessageModel>)message atInde
break;
case XHBubbleMessageMediaTypeVoice: {
DLog(@"message : %@", message.voicePath);

// Mark the voice as read and hide the red dot.
message.isRead = YES;
messageTableViewCell.messageBubbleView.voiceUnreadDotImageView.hidden = YES;

[[XHAudioPlayerHelper shareInstance] setDelegate:self];
if (_currentSelectedCell) {
[_currentSelectedCell.messageBubbleView.animationVoiceImageView stopAnimating];
Expand Down
21 changes: 21 additions & 0 deletions MessageDisplayKit/Classes/Models/XHMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@

@property (nonatomic, assign) XHBubbleMessageType bubbleMessageType;

@property (nonatomic) BOOL isRead;


/**
* 初始化文本消息
Expand Down Expand Up @@ -110,6 +112,25 @@
sender:(NSString *)sender
timestamp:(NSDate *)timestamp;

/**
* 初始化语音类型的消息。增加已读未读标记
*
* @param voicePath 目标语音的本地路径
* @param voiceUrl 目标语音在服务器的地址
* @param voiceDuration 目标语音的时长
* @param sender 发送者
* @param date 发送时间
* @param isRead 已读未读标记
*
* @return 返回Message model 对象
*/
- (instancetype)initWithVoicePath:(NSString *)voicePath
voiceUrl:(NSString *)voiceUrl
voiceDuration:(NSString *)voiceDuration
sender:(NSString *)sender
timestamp:(NSDate *)timestamp
isRead:(BOOL)isRead;

/**
* 初始化gif表情类型的消息
*
Expand Down
23 changes: 23 additions & 0 deletions MessageDisplayKit/Classes/Models/XHMessage.m
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,28 @@ - (instancetype)initWithVoicePath:(NSString *)voicePath
voiceDuration:(NSString *)voiceDuration
sender:(NSString *)sender
timestamp:(NSDate *)timestamp {

return [self initWithVoicePath:voicePath voiceUrl:voiceUrl voiceDuration:voiceDuration sender:sender timestamp:timestamp isRead:YES];
}

/**
* 初始化语音类型的消息。增加已读未读标记
*
* @param voicePath 目标语音的本地路径
* @param voiceUrl 目标语音在服务器的地址
* @param voiceDuration 目标语音的时长
* @param sender 发送者
* @param date 发送时间
* @param isRead 已读未读标记
*
* @return 返回Message model 对象
*/
- (instancetype)initWithVoicePath:(NSString *)voicePath
voiceUrl:(NSString *)voiceUrl
voiceDuration:(NSString *)voiceDuration
sender:(NSString *)sender
timestamp:(NSDate *)timestamp
isRead:(BOOL)isRead {
self = [super init];
if (self) {
self.voicePath = voicePath;
Expand All @@ -109,6 +131,7 @@ - (instancetype)initWithVoicePath:(NSString *)voicePath

self.sender = sender;
self.timestamp = timestamp;
self.isRead = isRead;

self.messageMediaType = XHBubbleMessageMediaTypeVoice;
}
Expand Down
3 changes: 3 additions & 0 deletions MessageDisplayKit/Classes/Models/XHMessageModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,8 @@

- (NSDate *)timestamp;

- (BOOL)isRead;
- (void)setIsRead:(BOOL)isRead;

@end

Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@
*/
@property (nonatomic, weak, readonly) UIImageView *animationVoiceImageView;

/**
* 用于显示语音未读的控件,小圆点
*/
@property (nonatomic, weak, readonly) UIImageView *voiceUnreadDotImageView;

/**
* 用于显示语音时长的label
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ @interface XHMessageBubbleView ()

@property (nonatomic, weak, readwrite) UIImageView *animationVoiceImageView;

@property (nonatomic, weak, readwrite) UIImageView *voiceUnreadDotImageView;

@property (nonatomic, weak, readwrite) XHBubblePhotoImageView *bubblePhotoImageView;

@property (nonatomic, weak, readwrite) UIImageView *videoPlayImageView;
Expand Down Expand Up @@ -154,6 +156,9 @@ - (void)configureBubbleImageView:(id <XHMessageModel>)message {
switch (currentType) {
case XHBubbleMessageMediaTypeVoice: {
_voiceDurationLabel.hidden = NO;
if (message.isRead == NO) {
_voiceUnreadDotImageView.hidden = NO;
}
}
case XHBubbleMessageMediaTypeText:
case XHBubbleMessageMediaTypeEmotion: {
Expand Down Expand Up @@ -320,6 +325,15 @@ - (instancetype)initWithFrame:(CGRect)frame
[self addSubview:emotionImageView];
_emotionImageView = emotionImageView;
}

// 6. 初始化显示语音未读标记的imageview
if (!_voiceUnreadDotImageView) {
UIImageView *voiceUnreadDotImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
voiceUnreadDotImageView.image = [UIImage imageNamed:@"msg_chat_voice_unread"];
voiceUnreadDotImageView.hidden = YES;
[self addSubview:voiceUnreadDotImageView];
_voiceUnreadDotImageView = voiceUnreadDotImageView;
}
}
return self;
}
Expand All @@ -335,6 +349,8 @@ - (void)dealloc {

_animationVoiceImageView = nil;

_voiceUnreadDotImageView = nil;

_voiceDurationLabel = nil;

_emotionImageView = nil;
Expand Down Expand Up @@ -377,6 +393,7 @@ - (void)layoutSubviews {
self.animationVoiceImageView.frame = animationVoiceImageViewFrame;

[self resetVoiceDurationLabelFrameWithBubbleFrame:bubbleFrame];
[self resetVoiceUnreadDotImageViewFrameWithBubbleFrame:bubbleFrame];

self.emotionImageView.frame = bubbleFrame;

Expand Down Expand Up @@ -408,4 +425,11 @@ - (void)resetVoiceDurationLabelFrameWithBubbleFrame:(CGRect)bubbleFrame {
_voiceDurationLabel.textAlignment = (self.message.bubbleMessageType == XHBubbleMessageTypeSending ? NSTextAlignmentRight : NSTextAlignmentLeft);
}

- (void)resetVoiceUnreadDotImageViewFrameWithBubbleFrame:(CGRect)bubbleFrame {
CGRect voiceUnreadDotFrame = _voiceUnreadDotImageView.frame;
voiceUnreadDotFrame.origin.x = (self.message.bubbleMessageType == XHBubbleMessageTypeSending ? bubbleFrame.origin.x + _voiceUnreadDotImageView.frame.size.width : bubbleFrame.origin.x + bubbleFrame.size.width - _voiceUnreadDotImageView.frame.size.width * 2);
voiceUnreadDotFrame.origin.y = bubbleFrame.size.height/2 + _voiceUnreadDotImageView.frame.size.height/2 - 2;
_voiceUnreadDotImageView.frame = voiceUnreadDotFrame;
}

@end
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MessageDisplayKit/Resources/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1f23bc0

Please sign in to comment.