Browse Source

朋友圈添加缓存

桂欢 2 years ago
parent
commit
64e8ab1da2

+ 1 - 1
SLAiELTS/SLAiELTS/Tool/CYLTableViewPlaceHolder/UITableView+Refresh.h

@@ -9,7 +9,7 @@
 #import <UIKit/UIKit.h>
 #import "MJRefresh.h"
 
-#define SLPageSize 3
+#define SLPageSize 10
 
 typedef void(^TableListCount)(NSInteger listCount);
 

+ 1 - 0
SLAiELTS/SLAiELTS/ViewControllers/Home/Views/SLHomeView.m

@@ -67,6 +67,7 @@
     SLFriendsModel *model = [[SLFriendsModel alloc] init];
     model.userId = viewModel.pageModel.chatListModel.userId;
     model.contactsId = viewModel.pageModel.chatListModel.friendId;
+    model.name = viewModel.pageModel.chatListModel.dataName;
     model.head = viewModel.pageModel.chatListModel.dataHead;
     vc.friendModel = model;
     [self.viewController navPushViewController:vc animated:YES];

+ 1 - 1
SLAiELTS/SLAiELTS/ViewControllers/MessageVC/SLMessageViewController.m

@@ -23,7 +23,7 @@
 - (void)viewDidLoad {
     [super viewDidLoad];
     // Do any additional setup after loading the view from its nib.
-    self.title = @"自由畅聊";
+    self.title = self.friendModel.name;
     NSString *key = [NSString stringWithFormat:@"%@--to--%@",self.friendModel.userId, self.friendModel.contactsId];
     NSArray *arr = [[NSUserDefaults standardUserDefaults] objectForKey:key];
     if (arr) {

+ 1 - 0
SLAiELTS/SLAiELTS/ViewControllers/MyVC/Views/SLMySpeedView.m

@@ -55,6 +55,7 @@
     [self.segmentBgView addSubview:self.segment];
     
     self.segment1 = [self creatSegmentViewWith:@[@"简单", @"中等", @"困难"]];
+    self.segment1.userInteractionEnabled = NO;
     [self.segment1 updateWithSpacing:2 topHeight:3];
     [self.segment1BgView addSubview:self.segment1];
     

+ 1 - 0
SLAiELTS/SLAiELTS/ViewControllers/TimeLine/Model/SDTimeLineCellModel.h

@@ -33,6 +33,7 @@
 @interface SDTimeLineCellModel : NSObject
 
 @property (nonatomic, copy) NSString *userImg;
+@property (nonatomic, copy) NSString *userId;
 @property (nonatomic, copy) NSString *userName;
 @property (nonatomic, copy) NSString *friendId;
 @property (nonatomic, copy) NSString *friendContent;

+ 23 - 8
SLAiELTS/SLAiELTS/ViewControllers/TimeLine/TimeLineController/SDTimeLineTableViewController.m

@@ -58,6 +58,7 @@ static CGFloat textFieldH = 56;
 
 @property (nonatomic, strong) SDTimeLineCellCommentItemModel *currentCommentItemModel;
 
+@property (nonatomic, strong) NSString *currentCacheFriendId;
 @end
 
 @implementation SDTimeLineTableViewController
@@ -95,7 +96,14 @@ static CGFloat textFieldH = 56;
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(momentsDetail:) name:@"SLMomentsDetail" object:nil];
 
     [self creatModelsWithCount:0];
-    
+    NSString *cacheKey = [NSString stringWithFormat:@"SLMomentsCache--%@", self.userModel.userId];
+    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];
+    }
 }
 
 - (void)viewDidAppear:(BOOL)animated
@@ -231,7 +239,9 @@ static CGFloat textFieldH = 56;
 
 - (void)creatModelsWithCount:(NSInteger)count
 {
-    WEAKSELF;
+    
+    
+    WS(weakSelf);
     [self.tableView tableviewRefresh:self.dataArray TableViewRefresh:^(NSInteger pageNo, TableListCount listCount) {
         
         NSDictionary *parameter = @{@"PageIndex": @(pageNo),
@@ -239,7 +249,7 @@ static CGFloat textFieldH = 56;
                                     @"type" : @"0",
                                     @"userId" : self.userModel.userId,
         };
-        WS(weakSelf);
+        
         [[SLHttpCenter SharedInstance] getWithUrl:@"/api/Friend/GetFriendList" parameter:parameter success:^(id responseObject) {
             NSDictionary *data = [responseObject objectForKey:@"data"];
             NSArray *items = [data objectForKey:@"items"];
@@ -255,12 +265,18 @@ static CGFloat textFieldH = 56;
                         [obj.likeItemsArray addObject:model];
                     }];
                 }];
-                [self.dataArray addObjectsFromArray:marr];
-                
+                [weakSelf.dataArray addObjectsFromArray:marr];
                 dispatch_async(dispatch_get_main_queue(), ^{
-                    [self.tableView reloadData];
+                    [weakSelf.tableView reloadData];
+                    SDTimeLineCellModel *firstObj = self.dataArray.firstObject;
+                    if (pageNo == 1 && ![firstObj.friendId isEqualToString:weakSelf.currentCacheFriendId]) {
+                        weakSelf.currentCacheFriendId = firstObj.friendId;
+                        NSString *cacheKey = [NSString stringWithFormat:@"SLMomentsCache--%@", self.userModel.userId];
+                        [[NSUserDefaults standardUserDefaults] setObject:[data mj_JSONString] forKey:cacheKey];
+                        [[NSUserDefaults standardUserDefaults] synchronize];
+                    }
                 });
-                [self.dataArray enumerateObjectsUsingBlock:^(SDTimeLineCellModel * obj, NSUInteger idx, BOOL * _Nonnull stop) {
+                [weakSelf.dataArray enumerateObjectsUsingBlock:^(SDTimeLineCellModel * obj, NSUInteger idx, BOOL * _Nonnull stop) {
                     if ([obj.friendImgUrl componentsSeparatedByString:@","].count == 1) {
 
                         [weakSelf.KVOController observe:obj keyPath:@"imageSize" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld block:^(id  _Nullable observer, id  _Nonnull object, NSDictionary<NSKeyValueChangeKey,id> * _Nonnull change) {
@@ -287,7 +303,6 @@ static CGFloat textFieldH = 56;
 {
     SDTimeLineCell *cell = [tableView dequeueReusableCellWithIdentifier:kTimeLineTableViewCellId];
     cell.indexPath = indexPath;
-    NSLog(@"----%ld",indexPath.row);
     SDTimeLineCellModel *model = self.dataArray[indexPath.row];
     cell.model = model;
     __weak typeof(self) weakSelf = self;

+ 1 - 1
SLAiELTS/SLAiELTS/ViewControllers/TimeLine/TimeLineController/SLFriensInfoVc.m

@@ -31,7 +31,7 @@
     [self.fpyqBgView addTapWithBlock:^{
         SDTimeLineTableViewController *vc = [[SDTimeLineTableViewController alloc] init];
         SLUserModel *userModel = [[SLUserModel alloc] init];
-        userModel.userId = weakSelf.friendModel.userId;
+        userModel.userId = weakSelf.friendModel.contactsId;
         vc.userModel = userModel;
         [weakSelf navPushViewController:vc animated:YES];
     }];

+ 2 - 1
SLAiELTS/SLAiELTS/ViewControllers/TimeLine/Views/Cell/SDTimeLineCell.m

@@ -91,7 +91,8 @@ NSString *const kSDTimeLineCellOperationButtonClickedNotification = @"SDTimeLine
     [_nameLable addTapWithBlock:^{
         SLFriensInfoVc *vc = [[SLFriensInfoVc alloc] init];
         SLFriendsModel *model = [[SLFriendsModel alloc] init];
-        model.userId = weakSelf.model.userName;
+        model.userId = [SLGlobalInfo SharedInstance].loginInfo.user.userId;
+        model.contactsId = weakSelf.model.userId;
         model.name = weakSelf.model.userName;
         model.head = weakSelf.model.userImg;
         vc.friendModel = model;