|
@@ -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;
|