Skip to content

Commit 1f23bc0

Browse files
committed
add unread red dot for voice
1 parent 0f51c7e commit 1f23bc0

10 files changed

Lines changed: 100 additions & 1 deletion

File tree

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,6 @@ DerivedData
3030
# you should judge for yourself, the pros and cons are mentioned at:
3131
# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
3232
#
33-
# Pods/
33+
# Pods/
34+
35+
.DS_Store

Example/MessageDisplayExample/MessageDisplayExample.xcodeproj/project.pbxproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
1FE768581A1627F200732D37 /* msg_chat_voice_unread.png in Resources */ = {isa = PBXBuildFile; fileRef = 1FE768561A1627F200732D37 /* msg_chat_voice_unread.png */; };
11+
1FE768591A1627F200732D37 /* msg_chat_voice_unread@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 1FE768571A1627F200732D37 /* msg_chat_voice_unread@2x.png */; };
1012
74065FB919123E1C00E1CE95 /* XHShareMenuItem.h in Headers */ = {isa = PBXBuildFile; fileRef = 74065FB719123E1C00E1CE95 /* XHShareMenuItem.h */; settings = {ATTRIBUTES = (Public, ); }; };
1113
74065FBA19123E1C00E1CE95 /* XHShareMenuItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 74065FB819123E1C00E1CE95 /* XHShareMenuItem.m */; };
1214
74065FBB19123E1C00E1CE95 /* XHShareMenuItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 74065FB819123E1C00E1CE95 /* XHShareMenuItem.m */; };
@@ -744,6 +746,8 @@
744746
/* End PBXContainerItemProxy section */
745747

746748
/* Begin PBXFileReference section */
749+
1FE768561A1627F200732D37 /* msg_chat_voice_unread.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = msg_chat_voice_unread.png; sourceTree = "<group>"; };
750+
1FE768571A1627F200732D37 /* msg_chat_voice_unread@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "msg_chat_voice_unread@2x.png"; sourceTree = "<group>"; };
747751
74065FB719123E1C00E1CE95 /* XHShareMenuItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XHShareMenuItem.h; sourceTree = "<group>"; };
748752
74065FB819123E1C00E1CE95 /* XHShareMenuItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XHShareMenuItem.m; sourceTree = "<group>"; };
749753
740660B21914CA0000E1CE95 /* XHPhotographyHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XHPhotographyHelper.h; sourceTree = "<group>"; };
@@ -1384,6 +1388,15 @@
13841388
/* End PBXFrameworksBuildPhase section */
13851389

13861390
/* Begin PBXGroup section */
1391+
1FE768551A1627E100732D37 /* ExtendImages */ = {
1392+
isa = PBXGroup;
1393+
children = (
1394+
1FE768561A1627F200732D37 /* msg_chat_voice_unread.png */,
1395+
1FE768571A1627F200732D37 /* msg_chat_voice_unread@2x.png */,
1396+
);
1397+
name = ExtendImages;
1398+
sourceTree = "<group>";
1399+
};
13871400
74180BD7190F447100A35C82 /* MessageDisplayFramework */ = {
13881401
isa = PBXGroup;
13891402
children = (
@@ -2093,6 +2106,7 @@
20932106
74FAB0BA190A92CC005623D0 /* Resources */ = {
20942107
isa = PBXGroup;
20952108
children = (
2109+
1FE768551A1627E100732D37 /* ExtendImages */,
20962110
7DA2EC7B19455F4100B009FC /* MultiSelectImages */,
20972111
7D0AAFF3194322FE00988FC3 /* PopMenuImages */,
20982112
74E5E99E1921F7580084BCFA /* VoiceRecordHUDImages */,
@@ -3288,6 +3302,7 @@
32883302
7DA2ECBF19457A2D00B009FC /* emotion9.gif in Resources */,
32893303
ABE83CCE1937E00E00BBF653 /* EmotionListNewTips@2x.png in Resources */,
32903304
74BBB020190B8EAB00093577 /* MessageDisplayKitString.strings in Resources */,
3305+
1FE768581A1627F200732D37 /* msg_chat_voice_unread.png in Resources */,
32913306
ABB7771D1932A7D700F4ACAF /* Contact_Male@2x.png in Resources */,
32923307
AB0C4AD81943B6BB00D346FF /* contacts_add_scan@2x.png in Resources */,
32933308
AB0C4AD51943B6BB00D346FF /* contacts_add_friend@2x.png in Resources */,
@@ -3323,6 +3338,7 @@
33233338
746C885F1916B612007F9A5E /* sharemore_wxtalk@2x.png in Resources */,
33243339
74E5E9AF1921F7710084BCFA /* RecordingSignal007@2x.png in Resources */,
33253340
ABCB35B819342DFA002F9938 /* VoiceSearchFeedback007_ios7@2x.png in Resources */,
3341+
1FE768591A1627F200732D37 /* msg_chat_voice_unread@2x.png in Resources */,
33263342
74E900691927940000D37C81 /* Contact@2x.png in Resources */,
33273343
746C88201916B5D6007F9A5E /* multiMedia_HL@2x.png in Resources */,
33283344
74E9006E1927940000D37C81 /* TableViewBackgroundImage@2x.png in Resources */,

Example/MessageDisplayExample/MessageDisplayExample/XHDemoWeChatMessageTableViewController.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,11 @@ - (void)multiMediaMessageDidSelectedOnMessage:(id<XHMessageModel>)message atInde
211211
break;
212212
case XHBubbleMessageMediaTypeVoice: {
213213
DLog(@"message : %@", message.voicePath);
214+
215+
// Mark the voice as read and hide the red dot.
216+
message.isRead = YES;
217+
messageTableViewCell.messageBubbleView.voiceUnreadDotImageView.hidden = YES;
218+
214219
[[XHAudioPlayerHelper shareInstance] setDelegate:self];
215220
if (_currentSelectedCell) {
216221
[_currentSelectedCell.messageBubbleView.animationVoiceImageView stopAnimating];

MessageDisplayKit/Classes/Models/XHMessage.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545

4646
@property (nonatomic, assign) XHBubbleMessageType bubbleMessageType;
4747

48+
@property (nonatomic) BOOL isRead;
49+
4850

4951
/**
5052
* 初始化文本消息
@@ -110,6 +112,25 @@
110112
sender:(NSString *)sender
111113
timestamp:(NSDate *)timestamp;
112114

115+
/**
116+
* 初始化语音类型的消息。增加已读未读标记
117+
*
118+
* @param voicePath 目标语音的本地路径
119+
* @param voiceUrl 目标语音在服务器的地址
120+
* @param voiceDuration 目标语音的时长
121+
* @param sender 发送者
122+
* @param date 发送时间
123+
* @param isRead 已读未读标记
124+
*
125+
* @return 返回Message model 对象
126+
*/
127+
- (instancetype)initWithVoicePath:(NSString *)voicePath
128+
voiceUrl:(NSString *)voiceUrl
129+
voiceDuration:(NSString *)voiceDuration
130+
sender:(NSString *)sender
131+
timestamp:(NSDate *)timestamp
132+
isRead:(BOOL)isRead;
133+
113134
/**
114135
* 初始化gif表情类型的消息
115136
*

MessageDisplayKit/Classes/Models/XHMessage.m

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,28 @@ - (instancetype)initWithVoicePath:(NSString *)voicePath
101101
voiceDuration:(NSString *)voiceDuration
102102
sender:(NSString *)sender
103103
timestamp:(NSDate *)timestamp {
104+
105+
return [self initWithVoicePath:voicePath voiceUrl:voiceUrl voiceDuration:voiceDuration sender:sender timestamp:timestamp isRead:YES];
106+
}
107+
108+
/**
109+
* 初始化语音类型的消息。增加已读未读标记
110+
*
111+
* @param voicePath 目标语音的本地路径
112+
* @param voiceUrl 目标语音在服务器的地址
113+
* @param voiceDuration 目标语音的时长
114+
* @param sender 发送者
115+
* @param date 发送时间
116+
* @param isRead 已读未读标记
117+
*
118+
* @return 返回Message model 对象
119+
*/
120+
- (instancetype)initWithVoicePath:(NSString *)voicePath
121+
voiceUrl:(NSString *)voiceUrl
122+
voiceDuration:(NSString *)voiceDuration
123+
sender:(NSString *)sender
124+
timestamp:(NSDate *)timestamp
125+
isRead:(BOOL)isRead {
104126
self = [super init];
105127
if (self) {
106128
self.voicePath = voicePath;
@@ -109,6 +131,7 @@ - (instancetype)initWithVoicePath:(NSString *)voicePath
109131

110132
self.sender = sender;
111133
self.timestamp = timestamp;
134+
self.isRead = isRead;
112135

113136
self.messageMediaType = XHBubbleMessageMediaTypeVoice;
114137
}

MessageDisplayKit/Classes/Models/XHMessageModel.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,8 @@
4848

4949
- (NSDate *)timestamp;
5050

51+
- (BOOL)isRead;
52+
- (void)setIsRead:(BOOL)isRead;
53+
5154
@end
5255

MessageDisplayKit/Classes/Views/MessageContentViews/XHMessageBubbleView.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@
6262
*/
6363
@property (nonatomic, weak, readonly) UIImageView *animationVoiceImageView;
6464

65+
/**
66+
* 用于显示语音未读的控件,小圆点
67+
*/
68+
@property (nonatomic, weak, readonly) UIImageView *voiceUnreadDotImageView;
69+
6570
/**
6671
* 用于显示语音时长的label
6772
*/

MessageDisplayKit/Classes/Views/MessageContentViews/XHMessageBubbleView.m

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ @interface XHMessageBubbleView ()
2929

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

32+
@property (nonatomic, weak, readwrite) UIImageView *voiceUnreadDotImageView;
33+
3234
@property (nonatomic, weak, readwrite) XHBubblePhotoImageView *bubblePhotoImageView;
3335

3436
@property (nonatomic, weak, readwrite) UIImageView *videoPlayImageView;
@@ -154,6 +156,9 @@ - (void)configureBubbleImageView:(id <XHMessageModel>)message {
154156
switch (currentType) {
155157
case XHBubbleMessageMediaTypeVoice: {
156158
_voiceDurationLabel.hidden = NO;
159+
if (message.isRead == NO) {
160+
_voiceUnreadDotImageView.hidden = NO;
161+
}
157162
}
158163
case XHBubbleMessageMediaTypeText:
159164
case XHBubbleMessageMediaTypeEmotion: {
@@ -320,6 +325,15 @@ - (instancetype)initWithFrame:(CGRect)frame
320325
[self addSubview:emotionImageView];
321326
_emotionImageView = emotionImageView;
322327
}
328+
329+
// 6. 初始化显示语音未读标记的imageview
330+
if (!_voiceUnreadDotImageView) {
331+
UIImageView *voiceUnreadDotImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
332+
voiceUnreadDotImageView.image = [UIImage imageNamed:@"msg_chat_voice_unread"];
333+
voiceUnreadDotImageView.hidden = YES;
334+
[self addSubview:voiceUnreadDotImageView];
335+
_voiceUnreadDotImageView = voiceUnreadDotImageView;
336+
}
323337
}
324338
return self;
325339
}
@@ -335,6 +349,8 @@ - (void)dealloc {
335349

336350
_animationVoiceImageView = nil;
337351

352+
_voiceUnreadDotImageView = nil;
353+
338354
_voiceDurationLabel = nil;
339355

340356
_emotionImageView = nil;
@@ -377,6 +393,7 @@ - (void)layoutSubviews {
377393
self.animationVoiceImageView.frame = animationVoiceImageViewFrame;
378394

379395
[self resetVoiceDurationLabelFrameWithBubbleFrame:bubbleFrame];
396+
[self resetVoiceUnreadDotImageViewFrameWithBubbleFrame:bubbleFrame];
380397

381398
self.emotionImageView.frame = bubbleFrame;
382399

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

428+
- (void)resetVoiceUnreadDotImageViewFrameWithBubbleFrame:(CGRect)bubbleFrame {
429+
CGRect voiceUnreadDotFrame = _voiceUnreadDotImageView.frame;
430+
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);
431+
voiceUnreadDotFrame.origin.y = bubbleFrame.size.height/2 + _voiceUnreadDotImageView.frame.size.height/2 - 2;
432+
_voiceUnreadDotImageView.frame = voiceUnreadDotFrame;
433+
}
434+
411435
@end
286 Bytes
Loading
525 Bytes
Loading

0 commit comments

Comments
 (0)