Bläddra i källkod

朋友圈优化

桂欢 1 år sedan
förälder
incheckning
f6da3ef523

+ 2 - 0
SLAiELTS/SLAiELTS/ViewControllers/Moments/Model/SLMomentsNewsModel.h

@@ -15,6 +15,8 @@ NS_ASSUME_NONNULL_BEGIN
  
 @property (nonatomic, copy) NSString *userId;
 
+@property (nonatomic, copy) NSString *head;
+
 @property (nonatomic, copy) NSString *friendId;
 
 @property (nonatomic, copy) NSString *image;

+ 11 - 9
SLAiELTS/SLAiELTS/ViewControllers/Moments/MomentsVc/SLMomentsVc.m

@@ -73,20 +73,22 @@ static CGFloat textFieldH = 56;
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(momentsUpdateType:) name:@"SLMomentsUpdateType" object:nil];
 
     [self creatModelsWithCount:0];
-    if (!self.isDetail) {
+    if (!self.isDetail && !self.dataArray.count) {
         NSString *cacheKey = [NSString stringWithFormat:@"SLMomentsCache--%@--%@", self.userModel.userId,@(self.isFriendList)];
         NSString *cacheStr = [[NSUserDefaults standardUserDefaults] objectForKey:cacheKey];
         NSArray *items = [[cacheStr mj_JSONObject] objectForKey:@"items"];
         if (items.count) {
             NSArray<SDTimeLineCellModel *> *models = [SDTimeLineCellModel mj_objectArrayWithKeyValuesArray:items];
             self.currentCacheFriendId = models.firstObject.friendId;
-            [self.dataArray addObjectsFromArray:models];
+            if (!self.dataArray.count) {
+                [self.dataArray addObjectsFromArray:models];
+            }
         }
     }
     if ([self.userModel.userId isEqualToString:[SLGlobalInfo SharedInstance].loginInfo.user.userId] && !self.isFriendList) {
         WS(weakSelf);
         [self.KVOController observe:[SLGlobalInfo SharedInstance] keyPath:@"loginInfo" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld block:^(id  _Nullable observer, id  _Nonnull object, NSDictionary<NSKeyValueChangeKey,id> * _Nonnull change) {
-            [weakSelf updateTableViewHeaderView];
+            [weakSelf updateTableViewHeaderView:YES];
         }];
     }
 }
@@ -109,7 +111,7 @@ static CGFloat textFieldH = 56;
     }
 }
 
-- (void)updateTableViewHeaderView {
+- (void)updateTableViewHeaderView:(BOOL)needReload {
     [self.headerView confignHeaderWith:self.userModel];
     SLUserModel *userModel = [SLGlobalInfo SharedInstance].loginInfo.user;
     if ([self.userModel.userId isEqualToString:userModel.userId]) {
@@ -127,6 +129,9 @@ static CGFloat textFieldH = 56;
             self.rdv_tabBarItem.badgeValue = unReadCount < 99 ? [NSString stringWithFormat:@"%ld",unReadCount] : @"99+";
             self.rdv_tabBarItem.badgePositionAdjustment = UIOffsetMake(-10, 0);
             self.rdv_tabBarItem.badgeTextFont = [UIFont systemFontOfSize:10];
+            if (needReload) {
+                [self.tableView reloadData];
+            }
         }
     }
 }
@@ -137,7 +142,7 @@ static CGFloat textFieldH = 56;
         self.userModel = [SLGlobalInfo SharedInstance].loginInfo.user;
     }
     if ([self.tableView.tableHeaderView isKindOfClass:SDTimeLineTableHeaderView.class]) {
-        [self updateTableViewHeaderView];
+        [self updateTableViewHeaderView:NO];
     }
     if (self.tableView.contentOffset.y < 300 && !self.tableView.mj_header.refreshing) {
         [self.tableView.mj_header beginRefreshing];
@@ -305,7 +310,7 @@ static CGFloat textFieldH = 56;
         [[SLHttpCenter SharedInstance] getWithUrl:url parameter:parameter success:^(id responseObject) {
             NSDictionary *data = [responseObject objectForKey:@"data"];
             [SLGlobalInfo SharedInstance].loginInfo.user.momentsMsgNotice = [[data objectForKey:@"unread"] stringValue];
-            [self updateTableViewHeaderView];
+            [self updateTableViewHeaderView:NO];
             NSArray *items = [data objectForKey:@"items"];
             if (items.count) {
                 NSMutableArray *marr = [SDTimeLineCellModel mj_objectArrayWithKeyValuesArray:items];
@@ -361,9 +366,6 @@ static CGFloat textFieldH = 56;
         self.navigationBar.rightBarButtonItemView.itemImageView.image = ImageName(@"icon_pyq_more_back");
         self.navigationBar.titleItemView.alpha = alpha;
         self.navigationBar.leftBarButtonItemView.itemImageView.image = ImageName(@"icon_back_b");
-
-        if (self.isFriendList) {
-        }
     } else {
         self.navigationBar.titleItemView.alpha = 0;
         self.navigationBar.backgroundColor = [color colorWithAlphaComponent:0];

+ 12 - 12
SLAiELTS/SLAiELTS/ViewControllers/Moments/Views/CommentView/SDTimeLineCellCommentView.m

@@ -119,18 +119,6 @@
         label.font = [UIFont systemFontOfSize:14];
         label.textColor = SLColor(@"#48484A");
         label.delegate = self;
-        WS(weakSelf);
-        __block UILabel *blockLabel = label;
-        label.labelLongTouchBlock = ^{
-            [weakSelf showMsgSegmentWith:blockLabel model:self->_commentItemsArray[i]];
-            NSLog(@"didLongTouchCommentLabelBlock--%d---------commentItemsArray",i);
-        };
-        label.labelClickedBlock = ^{
-            NSLog(@"%d---------commentItemsArray",i);
-            if (weakSelf.didClickCommentLabelBlock) {
-                weakSelf.didClickCommentLabelBlock(@"123", CGRectZero, [NSIndexPath indexPathForRow:self.indexPath.row inSection:i]);
-            }
-        };
         [self addSubview:label];
         [self.commentLabelsArray addObject:label];
     }
@@ -142,6 +130,18 @@
             model.attributedContent = [self generateAttributedStringWithCommentItemModel:model];
         }
         label.attributedText = model.attributedContent;
+        WS(weakSelf);
+        __block UILabel *blockLabel = label;
+        label.labelLongTouchBlock = ^{
+            [weakSelf showMsgSegmentWith:blockLabel model:self->_commentItemsArray[i]];
+            NSLog(@"didLongLabelBlock--%d---------commentItemsArray",i);
+        };
+        label.labelClickedBlock = ^{
+            NSLog(@"%d----commentItemsArray",i);
+            if (weakSelf.didClickCommentLabelBlock) {
+                weakSelf.didClickCommentLabelBlock(@"123", CGRectZero, [NSIndexPath indexPathForRow:self.indexPath.row inSection:i]);
+            }
+        };
     }
 }
 

+ 2 - 0
SLAiELTS/SLAiELTS/ViewControllers/Moments/Views/MomentsNewsCell/SLMomentsNewsCell.m

@@ -26,6 +26,8 @@
         NSString *momentImage = [NSString stringWithFormat:@"%@%@",[SLHttpCenter SharedInstance].serverUrl,[model.image componentsSeparatedByString:@","].firstObject];
         [self.momentImageView sd_setImageWithURL:[NSURL URLWithString:momentImage] placeholderImage:nil];
     }
+    NSString *headUrl = [NSString stringWithFormat:@"%@%@",[SLHttpCenter SharedInstance].serverUrl,model.head];
+    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:headUrl] placeholderImage:ImageName(@"icon_ellipse")];
     self.timeLabel.text = model.interDate;
     self.plLabel.text = model.commentContent;
     if ([model.interType isEqualToString:@"0"]) {

+ 1 - 1
SLAiELTS/SLAiELTS/ViewControllers/Moments/Views/MomentsNewsCell/SLMomentsNewsCell.xib

@@ -16,7 +16,7 @@
                 <rect key="frame" x="0.0" y="0.0" width="417" height="124"/>
                 <autoresizingMask key="autoresizingMask"/>
                 <subviews>
-                    <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="icon_ellipse" translatesAutoresizingMaskIntoConstraints="NO" id="NbU-5i-Wt7">
+                    <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="icon_ellipse" translatesAutoresizingMaskIntoConstraints="NO" id="NbU-5i-Wt7">
                         <rect key="frame" x="16" y="15" width="48" height="48"/>
                         <constraints>
                             <constraint firstAttribute="height" constant="48" id="PRw-nr-4qm"/>