123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- //
- // EMMessageStatusView.m
- // ChatDemo-UI3.0
- //
- // Created by XieYajie on 2019/1/25.
- // Copyright © 2019 XieYajie. All rights reserved.
- //
- #import "EMMessageStatusView.h"
- @interface EMMessageStatusView()
- @property (nonatomic, strong) UILabel *label;
- @property (nonatomic, strong) UIButton *failButton;
- @property (nonatomic, strong) UIActivityIndicatorView *activityView;
- @property (nonatomic) EMMessageStatus status;
- @property (nonatomic) BOOL isReadAcked;
- @end
- @implementation EMMessageStatusView
- - (instancetype)init
- {
- self = [super init];
- if (self) {
- self.hidden = YES;
- self.backgroundColor = [UIColor clearColor];
- }
-
- return self;
- }
- #pragma mark - Subviews
- - (UILabel *)label
- {
- if (_label == nil) {
- _label = [[UILabel alloc] init];
- _label.textColor = UIColorHex(999999);
- _label.font = [UIFont systemFontOfSize:12];
- }
-
- return _label;
- }
- - (UIButton *)failButton
- {
- if (_failButton == nil) {
- _failButton = [[UIButton alloc] init];
- [_failButton setImage:[UIImage imageNamed:@"msg_fail"] forState:UIControlStateNormal];
- [_failButton addTarget:self action:@selector(failButtonAction) forControlEvents:UIControlEventTouchUpInside];
- }
-
- return _failButton;
- }
- - (UIActivityIndicatorView *)activityView
- {
- if (_activityView == nil) {
- _activityView = [[UIActivityIndicatorView alloc] init];
- _activityView.color = kColor_Blue;
- }
-
- return _activityView;
- }
- #pragma mark - Public
- - (void)setSenderStatus:(EMMessageStatus)aStatus
- isReadAcked:(BOOL)aIsReadAcked
- type:(EMChatType)chatType
- {
- if (_status != aStatus) {
- _status = aStatus;
-
- if (aStatus == EMMessageStatusDelivering) {
- self.hidden = NO;
- [_label removeFromSuperview];
- [_failButton removeFromSuperview];
-
- [self addSubview:self.activityView];
- [self.activityView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(self);
- make.width.equalTo(@20);
- }];
- [self.activityView startAnimating];
- } else if (aStatus == EMMessageStatusFailed) {
- self.hidden = NO;
- [_label removeFromSuperview];
-
- [_activityView stopAnimating];
- [_activityView removeFromSuperview];
-
- [self addSubview:self.failButton];
- [self.failButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(self);
- make.width.equalTo(@20);
- }];
- } else if (aStatus == EMMessageStatusSucceed) {
- self.hidden = NO;
- [_failButton removeFromSuperview];
- [_activityView stopAnimating];
- [_activityView removeFromSuperview];
- [self addSubview:self.label];
- [self.label mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(self);
- }];
- } else {
- self.hidden = YES;
- [_label removeFromSuperview];
- [_failButton removeFromSuperview];
-
- [_activityView stopAnimating];
- [_activityView removeFromSuperview];
- }
- self.label.text = aIsReadAcked ? @"已读" : @"未读";
- } else if (self.isReadAcked != aIsReadAcked && aStatus == EMMessageStatusSucceed) {
- // if (chatType == EMChatTypeGroupChat) {
- // self.label.text = @"";
- // }else{
- // self.label.text = aIsReadAcked ? @"已读" : @"未读";
- // }
- self.label.text = aIsReadAcked ? @"已读" : @"未读";
- }
- self.isReadAcked = aIsReadAcked;
- }
- #pragma mark - Action
- - (void)failButtonAction
- {
- if (self.resendCompletion) {
- self.resendCompletion();
- }
- }
- @end
|