Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
陈高翔
/
DreamSleep-iOS
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit b8563e0e
由
cgx
编写于
2022-10-14 18:29:51 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
完成官方动态功能模块
1 个父辈
b17d74f8
隐藏空白字符变更
内嵌
并排
正在显示
12 个修改的文件
包含
513 行增加
和
77 行删除
DreamSleep/DreamSleep.xcodeproj/project.pbxproj
DreamSleep/DreamSleep/Class/CommunityModule/Controller/CommunityController.m
DreamSleep/DreamSleep/Class/CommunityModule/Controller/DynamicDetailController.m
DreamSleep/DreamSleep/Class/CommunityModule/Model/ComDynListResultModel.h
DreamSleep/DreamSleep/Class/CommunityModule/Model/ComDynListResultModel.m
DreamSleep/DreamSleep/Class/CommunityModule/Model/OfficialMessageModel.h
DreamSleep/DreamSleep/Class/CommunityModule/Model/OfficialMessageModel.m
DreamSleep/DreamSleep/Class/CommunityModule/View/CommunityView.m
DreamSleep/DreamSleep/Class/CommunityModule/View/OfficialMessageCell.h
DreamSleep/DreamSleep/Class/CommunityModule/View/OfficialMessageCell.m
DreamSleep/DreamSleep/Class/CommunityModule/ViewModel/ComListViewModel.h
DreamSleep/DreamSleep/Class/CommunityModule/ViewModel/ComListViewModel.m
DreamSleep/DreamSleep.xcodeproj/project.pbxproj
查看文件 @
b8563e0
...
@@ -214,6 +214,9 @@
...
@@ -214,6 +214,9 @@
D0B836F528F11CA0006E76C0 /* ReplyModel.m in Sources */ = {isa = PBXBuildFile; fileRef = D0B836F428F11CA0006E76C0 /* ReplyModel.m */; };
D0B836F528F11CA0006E76C0 /* ReplyModel.m in Sources */ = {isa = PBXBuildFile; fileRef = D0B836F428F11CA0006E76C0 /* ReplyModel.m */; };
D0B836F828F1232F006E76C0 /* ComReplyModel.m in Sources */ = {isa = PBXBuildFile; fileRef = D0B836F728F1232F006E76C0 /* ComReplyModel.m */; };
D0B836F828F1232F006E76C0 /* ComReplyModel.m in Sources */ = {isa = PBXBuildFile; fileRef = D0B836F728F1232F006E76C0 /* ComReplyModel.m */; };
D0B836FB28F1655E006E76C0 /* DynamicCommentCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D0B836FA28F1655E006E76C0 /* DynamicCommentCell.m */; };
D0B836FB28F1655E006E76C0 /* DynamicCommentCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D0B836FA28F1655E006E76C0 /* DynamicCommentCell.m */; };
D0B8C39B28F9115700279AA6 /* OfficialMessageModel.m in Sources */ = {isa = PBXBuildFile; fileRef = D0B8C39A28F9115700279AA6 /* OfficialMessageModel.m */; };
D0B8C39E28F935D000279AA6 /* ComDynListResultModel.m in Sources */ = {isa = PBXBuildFile; fileRef = D0B8C39D28F935D000279AA6 /* ComDynListResultModel.m */; };
D0B8C3A128F94E4D00279AA6 /* OfficialMessageCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D0B8C3A028F94E4D00279AA6 /* OfficialMessageCell.m */; };
D0BB9AA4281626F200DB209E /* ExceptionDefaultView.m in Sources */ = {isa = PBXBuildFile; fileRef = D0BB9AA3281626F200DB209E /* ExceptionDefaultView.m */; };
D0BB9AA4281626F200DB209E /* ExceptionDefaultView.m in Sources */ = {isa = PBXBuildFile; fileRef = D0BB9AA3281626F200DB209E /* ExceptionDefaultView.m */; };
D0BB9AA728164DFB00DB209E /* NickNameController.m in Sources */ = {isa = PBXBuildFile; fileRef = D0BB9AA628164DFB00DB209E /* NickNameController.m */; };
D0BB9AA728164DFB00DB209E /* NickNameController.m in Sources */ = {isa = PBXBuildFile; fileRef = D0BB9AA628164DFB00DB209E /* NickNameController.m */; };
D0BDDFFC28618123006558D4 /* DisableAllTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = D0BDDFFB28618123006558D4 /* DisableAllTextView.m */; };
D0BDDFFC28618123006558D4 /* DisableAllTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = D0BDDFFB28618123006558D4 /* DisableAllTextView.m */; };
...
@@ -717,6 +720,12 @@
...
@@ -717,6 +720,12 @@
D0B836F728F1232F006E76C0 /* ComReplyModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ComReplyModel.m; sourceTree = "<group>"; };
D0B836F728F1232F006E76C0 /* ComReplyModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ComReplyModel.m; sourceTree = "<group>"; };
D0B836F928F1655E006E76C0 /* DynamicCommentCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DynamicCommentCell.h; sourceTree = "<group>"; };
D0B836F928F1655E006E76C0 /* DynamicCommentCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DynamicCommentCell.h; sourceTree = "<group>"; };
D0B836FA28F1655E006E76C0 /* DynamicCommentCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DynamicCommentCell.m; sourceTree = "<group>"; };
D0B836FA28F1655E006E76C0 /* DynamicCommentCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DynamicCommentCell.m; sourceTree = "<group>"; };
D0B8C39928F9115700279AA6 /* OfficialMessageModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OfficialMessageModel.h; sourceTree = "<group>"; };
D0B8C39A28F9115700279AA6 /* OfficialMessageModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OfficialMessageModel.m; sourceTree = "<group>"; };
D0B8C39C28F935D000279AA6 /* ComDynListResultModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ComDynListResultModel.h; sourceTree = "<group>"; };
D0B8C39D28F935D000279AA6 /* ComDynListResultModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ComDynListResultModel.m; sourceTree = "<group>"; };
D0B8C39F28F94E4D00279AA6 /* OfficialMessageCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OfficialMessageCell.h; sourceTree = "<group>"; };
D0B8C3A028F94E4D00279AA6 /* OfficialMessageCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OfficialMessageCell.m; sourceTree = "<group>"; };
D0BB9AA2281626F200DB209E /* ExceptionDefaultView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ExceptionDefaultView.h; sourceTree = "<group>"; };
D0BB9AA2281626F200DB209E /* ExceptionDefaultView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ExceptionDefaultView.h; sourceTree = "<group>"; };
D0BB9AA3281626F200DB209E /* ExceptionDefaultView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ExceptionDefaultView.m; sourceTree = "<group>"; };
D0BB9AA3281626F200DB209E /* ExceptionDefaultView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ExceptionDefaultView.m; sourceTree = "<group>"; };
D0BB9AA528164DFB00DB209E /* NickNameController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NickNameController.h; sourceTree = "<group>"; };
D0BB9AA528164DFB00DB209E /* NickNameController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NickNameController.h; sourceTree = "<group>"; };
...
@@ -1543,6 +1552,8 @@
...
@@ -1543,6 +1552,8 @@
D030796628E3D92700ED96BF /* LikeButton */,
D030796628E3D92700ED96BF /* LikeButton */,
D02B7E5A28E2A28500218EF7 /* ComDynamicCell.h */,
D02B7E5A28E2A28500218EF7 /* ComDynamicCell.h */,
D02B7E5B28E2A28500218EF7 /* ComDynamicCell.m */,
D02B7E5B28E2A28500218EF7 /* ComDynamicCell.m */,
D0B8C39F28F94E4D00279AA6 /* OfficialMessageCell.h */,
D0B8C3A028F94E4D00279AA6 /* OfficialMessageCell.m */,
D0A3BB9028D95A2B00F58781 /* CommunityView.h */,
D0A3BB9028D95A2B00F58781 /* CommunityView.h */,
D0A3BB9128D95A2B00F58781 /* CommunityView.m */,
D0A3BB9128D95A2B00F58781 /* CommunityView.m */,
D070A78928DEF2D30039C5A7 /* DynamicView.h */,
D070A78928DEF2D30039C5A7 /* DynamicView.h */,
...
@@ -1615,6 +1626,10 @@
...
@@ -1615,6 +1626,10 @@
D0A3BB8F28D95A0C00F58781 /* Model */ = {
D0A3BB8F28D95A0C00F58781 /* Model */ = {
isa = PBXGroup;
isa = PBXGroup;
children = (
children = (
D0B8C39C28F935D000279AA6 /* ComDynListResultModel.h */,
D0B8C39D28F935D000279AA6 /* ComDynListResultModel.m */,
D0B8C39928F9115700279AA6 /* OfficialMessageModel.h */,
D0B8C39A28F9115700279AA6 /* OfficialMessageModel.m */,
D02B7E5D28E2C89600218EF7 /* ComDynModel.h */,
D02B7E5D28E2C89600218EF7 /* ComDynModel.h */,
D02B7E5E28E2C89600218EF7 /* ComDynModel.m */,
D02B7E5E28E2C89600218EF7 /* ComDynModel.m */,
D0B836F628F1232F006E76C0 /* ComReplyModel.h */,
D0B836F628F1232F006E76C0 /* ComReplyModel.h */,
...
@@ -2518,6 +2533,7 @@
...
@@ -2518,6 +2533,7 @@
D09D0E9D280D73B6008DEDAB /* InviteController.m in Sources */,
D09D0E9D280D73B6008DEDAB /* InviteController.m in Sources */,
D0FEE7D128854967006C2B67 /* SleepReadyDoneView.m in Sources */,
D0FEE7D128854967006C2B67 /* SleepReadyDoneView.m in Sources */,
D043DD58285B25EE0043A4CE /* VersionRequestModel.m in Sources */,
D043DD58285B25EE0043A4CE /* VersionRequestModel.m in Sources */,
D0B8C39B28F9115700279AA6 /* OfficialMessageModel.m in Sources */,
D07257F3286BF99F0080F458 /* DailyTaskView.m in Sources */,
D07257F3286BF99F0080F458 /* DailyTaskView.m in Sources */,
D0534F092835D90400F8892E /* DSNaviBarViewController.m in Sources */,
D0534F092835D90400F8892E /* DSNaviBarViewController.m in Sources */,
D04B3D9A27F6D4D90022F8DF /* LeadingController.m in Sources */,
D04B3D9A27F6D4D90022F8DF /* LeadingController.m in Sources */,
...
@@ -2664,6 +2680,7 @@
...
@@ -2664,6 +2680,7 @@
D053D0DF28F40C6A00BB2B84 /* MessageController.m in Sources */,
D053D0DF28F40C6A00BB2B84 /* MessageController.m in Sources */,
D043A8B6287EBA4000226176 /* ReadyItemView.m in Sources */,
D043A8B6287EBA4000226176 /* ReadyItemView.m in Sources */,
D09BF331280E570D00E5F06C /* UserModel.m in Sources */,
D09BF331280E570D00E5F06C /* UserModel.m in Sources */,
D0B8C39E28F935D000279AA6 /* ComDynListResultModel.m in Sources */,
D0C50B4F27FD832300DC68F0 /* LeadView.m in Sources */,
D0C50B4F27FD832300DC68F0 /* LeadView.m in Sources */,
D091E674283F5B4200D3279E /* ScoreDetailModel.m in Sources */,
D091E674283F5B4200D3279E /* ScoreDetailModel.m in Sources */,
D01BD425282BFFB400BA86B3 /* WhiteNoiseRequestModel.m in Sources */,
D01BD425282BFFB400BA86B3 /* WhiteNoiseRequestModel.m in Sources */,
...
@@ -2707,6 +2724,7 @@
...
@@ -2707,6 +2724,7 @@
D08EE4AF28F2CFC300B76FF9 /* MajorCommentCell.m in Sources */,
D08EE4AF28F2CFC300B76FF9 /* MajorCommentCell.m in Sources */,
D02B7E6428E2D76D00218EF7 /* ComListViewModel.m in Sources */,
D02B7E6428E2D76D00218EF7 /* ComListViewModel.m in Sources */,
D01814DC27FFD92200583D4E /* DSDataSource.m in Sources */,
D01814DC27FFD92200583D4E /* DSDataSource.m in Sources */,
D0B8C3A128F94E4D00279AA6 /* OfficialMessageCell.m in Sources */,
D0A1C48D28C1A42A000975DC /* TestFlutterController.m in Sources */,
D0A1C48D28C1A42A000975DC /* TestFlutterController.m in Sources */,
D07DACA92810557D0067A1BF /* UIImage+RSKImageCropper.m in Sources */,
D07DACA92810557D0067A1BF /* UIImage+RSKImageCropper.m in Sources */,
D053D0E828F41FB300BB2B84 /* CommentReplyCell.m in Sources */,
D053D0E828F41FB300BB2B84 /* CommentReplyCell.m in Sources */,
...
...
DreamSleep/DreamSleep/Class/CommunityModule/Controller/CommunityController.m
查看文件 @
b8563e0
...
@@ -58,20 +58,21 @@
...
@@ -58,20 +58,21 @@
[
LoginUtils
jumpToLoginControllerWithTarget
:
self
];
[
LoginUtils
jumpToLoginControllerWithTarget
:
self
];
return
;
return
;
}
}
// [self.navigationController pushViewController:[MessageController new] animated:YES];
[
self
.
navigationController
pushViewController
:[
MessageController
new
]
animated
:
YES
];
#warning - 测试删除接口
[
self
testDynDeleteAPI
];
}
}
-
(
void
)
testDynDeleteAPI
{
-
(
void
)
testDynDeleteAPI
{
#warning - 测试删除接口
self
.
personDynViewModel
=
[
PersonDynViewModel
new
];
self
.
personDynViewModel
=
[
PersonDynViewModel
new
];
self
.
personDynViewModel
.
oper_type
=
@"
dynamic
"
;
self
.
personDynViewModel
.
oper_type
=
@"
comment
"
;
self
.
personDynViewModel
.
delete_id
=
5
8
;
self
.
personDynViewModel
.
delete_id
=
1
8
;
[
self
.
personDynViewModel
communityDeleteOperationWithCompletion
:
^
(
PersonDynViewModel
*
_Nonnull
requestModel
)
{
[
self
.
personDynViewModel
communityDeleteOperationWithCompletion
:
^
(
PersonDynViewModel
*
_Nonnull
requestModel
)
{
if
(
requestModel
.
resCode
==
DSResCodeSuccess
)
{
if
(
requestModel
.
resCode
==
DSResCodeSuccess
)
{
[
self
.
comListViewModel
deleteComDynWithDynamicID
:
self
.
personDynViewModel
.
delete_id
];
[
self
.
comListViewModel
deleteComDynWithDynamicID
:
self
.
personDynViewModel
.
delete_id
];
[
self
.
communityView
updateListView
];
[
self
.
communityView
updateListView
];
}
else
{
[
DSProgressHUD
showToast
:
requestModel
.
errMessage
];
}
}
}];
}];
}
}
...
...
DreamSleep/DreamSleep/Class/CommunityModule/Controller/DynamicDetailController.m
查看文件 @
b8563e0
...
@@ -71,17 +71,12 @@
...
@@ -71,17 +71,12 @@
-
(
void
)
fireTapDetailLikeBtn
{
-
(
void
)
fireTapDetailLikeBtn
{
// 1、用户点赞或取消点赞直接响应UI变化
// 1、用户点赞或取消点赞直接响应UI变化
if
(
self
.
comDynModel
.
isLike
)
{
[
ComListViewModel
updateLikeData
:
self
.
comDynModel
];
self
.
comDynModel
.
likeCount
--
;
}
else
{
self
.
comDynModel
.
likeCount
++
;
}
self
.
comDynModel
.
isLike
=
!
self
.
comDynModel
.
isLike
;
[
self
.
detailView
updateLikeStateAndLikeCount
:
self
.
comDynModel
];
[
self
.
detailView
updateLikeStateAndLikeCount
:
self
.
comDynModel
];
// 2、更新点赞或取消点赞请求
// 2、更新点赞或取消点赞请求
if
(
self
.
likeDataTask
)
{
[
self
.
likeDataTask
cancel
];
}
if
(
self
.
likeDataTask
)
{
[
self
.
likeDataTask
cancel
];
}
self
.
likeDataTask
=
[
ComListViewModel
userDynamicPraiseWith
TalkID
:
self
.
comDynModel
.
dynamicID
completion
:
^
(
ComListViewModel
*
_Nonnull
requestModel
)
{
self
.
likeDataTask
=
[
ComListViewModel
userDynamicPraiseWith
ComDynModel
:
self
.
comDynModel
completion
:
^
(
ComListViewModel
*
_Nonnull
requestModel
)
{
if
(
requestModel
.
resCode
==
DSResCodeSuccess
)
{
if
(
requestModel
.
resCode
==
DSResCodeSuccess
)
{
// 3、更新成功回调刷新社区列表点赞数据
// 3、更新成功回调刷新社区列表点赞数据
if
(
self
.
delegate
&&
[
self
.
delegate
respondsToSelector
:
@selector
(
updateLikeOrRemark
)])
{
if
(
self
.
delegate
&&
[
self
.
delegate
respondsToSelector
:
@selector
(
updateLikeOrRemark
)])
{
...
@@ -90,13 +85,6 @@
...
@@ -90,13 +85,6 @@
}
else
{
}
else
{
// 4、如果请求失败,延迟执行回退
// 4、如果请求失败,延迟执行回退
dispatch_after
(
dispatch_time
(
DISPATCH_TIME_NOW
,
(
int64_t
)(
3
.
0
*
NSEC_PER_SEC
)),
dispatch_get_main_queue
(),
^
{
dispatch_after
(
dispatch_time
(
DISPATCH_TIME_NOW
,
(
int64_t
)(
3
.
0
*
NSEC_PER_SEC
)),
dispatch_get_main_queue
(),
^
{
// 修改数据model
if
(
self
.
comDynModel
.
isLike
)
{
self
.
comDynModel
.
likeCount
--
;
}
else
{
self
.
comDynModel
.
likeCount
++
;
}
self
.
comDynModel
.
isLike
=
!
self
.
comDynModel
.
isLike
;
[
self
.
detailView
updateLikeStateAndLikeCount
:
self
.
comDynModel
];
[
self
.
detailView
updateLikeStateAndLikeCount
:
self
.
comDynModel
];
[
DSProgressHUD
showToast
:
requestModel
.
errMessage
];
[
DSProgressHUD
showToast
:
requestModel
.
errMessage
];
});
});
...
...
DreamSleep/DreamSleep/Class/CommunityModule/Model/ComDynListResultModel.h
0 → 100644
查看文件 @
b8563e0
//
// ComDynListResultModel.h
// DreamSleep
//
// Created by peter on 2022/10/14.
//
#import <Foundation/Foundation.h>
#import "OfficialMessageModel.h"
#import "ComDynModel.h"
NS_ASSUME_NONNULL_BEGIN
@interface
ComDynListResultModel
:
NSObject
/// 官方动态消息
@property
(
nonatomic
,
strong
)
OfficialMessageModel
*
officialMessageModel
;
/// 总页数
@property
(
nonatomic
,
assign
)
int
count
;
/// 用户动态列表
@property
(
nonatomic
,
strong
)
NSArray
<
ComDynModel
*>
*
data_list
;
@end
NS_ASSUME_NONNULL_END
DreamSleep/DreamSleep/Class/CommunityModule/Model/ComDynListResultModel.m
0 → 100644
查看文件 @
b8563e0
//
// ComDynListResultModel.m
// DreamSleep
//
// Created by peter on 2022/10/14.
//
#import "ComDynListResultModel.h"
@implementation
ComDynListResultModel
+
(
nullable
NSDictionary
<
NSString
*
,
id
>
*
)
modelCustomPropertyMapper
{
return
@{
@"officialMessageModel"
:
@"message"
};
}
+
(
NSDictionary
*
)
modelContainerPropertyGenericClass
{
return
@{
@"data_list"
:
[
ComDynModel
class
]};
}
@end
DreamSleep/DreamSleep/Class/CommunityModule/Model/OfficialMessageModel.h
0 → 100644
查看文件 @
b8563e0
//
// OfficialMessageModel.h
// DreamSleep
//
// Created by peter on 2022/10/14.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/// 社区列表官方消息model
@interface
OfficialMessageModel
:
NSObject
@property
(
nonatomic
,
assign
)
int
message_id
;
@property
(
nonatomic
,
copy
)
NSString
*
user_profile
;
@property
(
nonatomic
,
copy
)
NSString
*
title
;
@property
(
nonatomic
,
copy
)
NSString
*
content
;
@property
(
nonatomic
,
copy
)
NSString
*
imgs
;
@property
(
nonatomic
,
copy
)
NSString
*
publish_time
;
@property
(
nonatomic
,
assign
)
BOOL
isShowAllContent
;
+
(
UIFont
*
)
contentFont
;
+
(
CGFloat
)
contentMargin
;
-
(
NSAttributedString
*
)
contentAttriStr
;
-
(
CGFloat
)
imgHeight
;
-
(
CGFloat
)
contentHeight
;
-
(
CGFloat
)
cellHeight
;
-
(
NSArray
*
)
getImgUrlsArr
:(
NSString
*
)
imgUrls
;
@end
NS_ASSUME_NONNULL_END
DreamSleep/DreamSleep/Class/CommunityModule/Model/OfficialMessageModel.m
0 → 100644
查看文件 @
b8563e0
//
// OfficialMessageModel.m
// DreamSleep
//
// Created by peter on 2022/10/14.
//
// 回复内容显示最大行数
#define kMaxOfficialContentLine 5
#import "OfficialMessageModel.h"
@implementation
OfficialMessageModel
#pragma mark - YYModel
+
(
nullable
NSDictionary
<
NSString
*
,
id
>
*
)
modelCustomPropertyMapper
{
return
@{
@"message_id"
:
@"id"
};
}
//- (BOOL)modelCustomTransformFromDictionary:(NSDictionary *)dic {
// // YYModel给自定义字段设置默认值
// // self.isOfficial = YES;
// return YES;
//}
#pragma mark - public
+
(
UIFont
*
)
contentFont
{
return
SysFont
(
14
);
}
+
(
CGFloat
)
contentMargin
{
return
15
;
}
-
(
NSAttributedString
*
)
contentAttriStr
{
NSString
*
contentStr
=
self
.
content
?:
@""
;
NSMutableAttributedString
*
attStr
=
[[
NSMutableAttributedString
alloc
]
initWithString
:
contentStr
attributes
:[
self
contentAttributes
:
NO
]];
if
(
self
.
isShowAllContent
)
{
return
attStr
.
copy
;
}
if
([
self
contentMaxLines
].
count
>
kMaxOfficialContentLine
)
{
// 1、获取显示最多行字符串
NSMutableString
*
mLineStr
=
[
NSMutableString
string
];
for
(
NSInteger
i
=
0
;
i
<
kMaxOfficialContentLine
;
i
++
)
{
[
mLineStr
appendString
:[
self
contentMaxLines
][
i
]];
}
// 2、截取字符串最后1个位置,用于填充自定义富文本
NSString
*
subLineStr
=
[
mLineStr
substringWithRange
:
NSMakeRange
(
0
,
mLineStr
.
length
-
1
)];
// 3、将subLineStr转换未富文本
attStr
=
[[
NSMutableAttributedString
alloc
]
initWithString
:
subLineStr
attributes
:[
self
contentAttributes
:
NO
]];
// 4、自定义结尾富文本
NSMutableAttributedString
*
dotAtrStr
=
[[
NSMutableAttributedString
alloc
]
initWithString
:
@"..."
attributes
:[
self
contentAttributes
:
YES
]];
[
attStr
appendAttributedString
:
dotAtrStr
.
copy
];
}
return
attStr
.
copy
;
}
-
(
CGFloat
)
imgHeight
{
if
(
self
.
imgs
)
{
if
(
iPhone5
)
{
return
100
;
}
else
{
NSArray
*
imgUrls
=
[
self
getImgUrlsArr
:
self
.
imgs
];
if
(
imgUrls
.
count
==
1
||
imgUrls
.
count
==
2
)
{
return
150
;
}
else
if
(
imgUrls
.
count
==
3
)
{
return
95
;
}
return
0
;
}
}
return
0
;
}
-
(
CGFloat
)
contentHeight
{
CGFloat
contentW
=
[
OfficialMessageModel
contentMaxW
];
return
[
UILabel
getHeightByWidth
:
contentW
attributedText
:[
self
contentAttriStr
]
font
:
[
OfficialMessageModel
contentFont
]];
}
-
(
CGFloat
)
cellHeight
{
NSArray
*
imgUrls
=
[
self
getImgUrlsArr
:
self
.
imgs
];
CGFloat
topH
=
67
;
CGFloat
bottomH
=
15
;
CGFloat
contentH
=
[
self
contentHeight
];
CGFloat
imgTextSpace
=
imgUrls
.
count
?
12
:
0
;
CGFloat
imgH
=
[
self
imgHeight
];
return
topH
+
bottomH
+
contentH
+
imgTextSpace
+
imgH
;
}
-
(
NSArray
*
)
getImgUrlsArr
:
(
NSString
*
)
imgUrls
{
if
(
imgUrls
&&
imgUrls
.
length
)
{
return
[
imgUrls
componentsSeparatedByString
:
@"|"
];
}
return
@[];
}
#pragma mark - private
+
(
CGFloat
)
contentMaxW
{
return
kScreenWidth
-
4
*
[
OfficialMessageModel
contentMargin
];
}
-
(
NSArray
*
)
contentMaxLines
{
return
[
self
.
content
getLinesArrayOfStringWidth
:[
OfficialMessageModel
contentMaxW
]
attributes
:@{
NSFontAttributeName
:
[
OfficialMessageModel
contentFont
]}];
}
-
(
NSDictionary
*
)
contentAttributes
:
(
BOOL
)
isTail
{
NSMutableParagraphStyle
*
paragraphStyle
=
[[
NSMutableParagraphStyle
alloc
]
init
];
paragraphStyle
.
minimumLineHeight
=
[
OfficialMessageModel
contentFont
].
lineHeight
;
paragraphStyle
.
maximumLineHeight
=
[
OfficialMessageModel
contentFont
].
lineHeight
;
paragraphStyle
.
alignment
=
NSTextAlignmentLeft
;
NSMutableDictionary
*
mAttributes
=
[
NSMutableDictionary
dictionaryWithDictionary
:
@{
NSFontAttributeName
:
[
OfficialMessageModel
contentFont
],
NSParagraphStyleAttributeName
:
paragraphStyle
}];
if
(
isTail
)
{
[
mAttributes
setObject
:
BrandColor
forKey
:
NSForegroundColorAttributeName
];
}
return
mAttributes
.
copy
;
}
@end
DreamSleep/DreamSleep/Class/CommunityModule/View/CommunityView.m
查看文件 @
b8563e0
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
//
//
#import "CommunityView.h"
#import "CommunityView.h"
#import "OfficialMessageCell.h"
#import "InformCancelAlertView.h"
#import "InformCancelAlertView.h"
@interface
CommunityView
()
<
UITableViewDelegate
,
UITableViewDataSource
,
InformCancelAlertViewDelegate
>
@interface
CommunityView
()
<
UITableViewDelegate
,
UITableViewDataSource
,
InformCancelAlertViewDelegate
>
...
@@ -88,8 +89,13 @@
...
@@ -88,8 +89,13 @@
}
}
-
(
CGFloat
)
tableView
:
(
UITableView
*
)
tableView
heightForRowAtIndexPath
:
(
NSIndexPath
*
)
indexPath
{
-
(
CGFloat
)
tableView
:
(
UITableView
*
)
tableView
heightForRowAtIndexPath
:
(
NSIndexPath
*
)
indexPath
{
ComDynModel
*
model
=
self
.
comListVM
.
listArr
[
indexPath
.
section
];
if
(
self
.
comListVM
.
isOfficial
&&
indexPath
.
section
==
0
)
{
return
[
model
cellHeight
:
DynModelTypeCom
];
OfficialMessageModel
*
model
=
self
.
comListVM
.
listArr
[
0
];
return
[
model
cellHeight
];
}
else
{
ComDynModel
*
model
=
self
.
comListVM
.
listArr
[
indexPath
.
section
];
return
[
model
cellHeight
:
DynModelTypeCom
];
}
}
}
-
(
CGFloat
)
tableView
:
(
UITableView
*
)
tableView
heightForHeaderInSection
:
(
NSInteger
)
section
{
-
(
CGFloat
)
tableView
:
(
UITableView
*
)
tableView
heightForHeaderInSection
:
(
NSInteger
)
section
{
...
@@ -109,31 +115,43 @@
...
@@ -109,31 +115,43 @@
}
}
-
(
UITableViewCell
*
)
tableView
:
(
UITableView
*
)
tableView
cellForRowAtIndexPath
:
(
NSIndexPath
*
)
indexPath
{
-
(
UITableViewCell
*
)
tableView
:
(
UITableView
*
)
tableView
cellForRowAtIndexPath
:
(
NSIndexPath
*
)
indexPath
{
ComDynamicCell
*
cell
=
[
tableView
dequeueReusableCellWithIdentifier
:
NSStringFromClass
([
ComDynamicCell
class
])];
if
(
!
cell
)
{
cell
=
[[
ComDynamicCell
alloc
]
initWithCellType
:
DynModelTypeCom
style
:
UITableViewCellStyleDefault
reuseIdentifier
:
NSStringFromClass
([
ComDynamicCell
class
])];
}
ComDynModel
*
model
=
self
.
comListVM
.
listArr
[
indexPath
.
section
];
cell
.
model
=
model
;
WS
(
weakSelf
);
WS
(
weakSelf
);
__weak
ComDynamicCell
*
weakCell
=
(
ComDynamicCell
*
)
cell
;
if
(
self
.
comListVM
.
isOfficial
&&
indexPath
.
section
==
0
)
{
cell
.
tapInformBlock
=
^
{
OfficialMessageCell
*
cell
=
[
tableView
dequeueReusableCellWithIdentifier
:
NSStringFromClass
([
OfficialMessageCell
class
])
forIndexPath
:
indexPath
];
if
(
weakSelf
.
delegate
&&
[
weakSelf
.
delegate
respondsToSelector
:
@selector
(
didTapInformItem
:)])
{
OfficialMessageModel
*
model
=
self
.
comListVM
.
listArr
[
0
];
[
weakSelf
.
delegate
didTapInformItem
:
model
.
dynamicID
];
cell
.
model
=
model
;
}
cell
.
showAllContentBlock
=
^
{
};
[
weakSelf
.
comListVM
showOfficialAllContent
];
cell
.
tapLikeBlock
=
^
{
[
weakSelf
.
listView
reloadSections
:[
NSIndexSet
indexSetWithIndex
:
0
]
withRowAnimation
:
UITableViewRowAnimationNone
];
if
(
weakSelf
.
delegate
&&
[
weakSelf
.
delegate
respondsToSelector
:
@selector
(
didTapLikeItem
:
cell
:
)])
{
};
[
weakSelf
.
delegate
didTapLikeItem
:
model
cell
:
weakCell
];
return
cell
;
}
else
{
ComDynamicCell
*
cell
=
[
tableView
dequeueReusableCellWithIdentifier
:
NSStringFromClass
([
ComDynamicCell
class
])];
if
(
!
cell
)
{
cell
=
[[
ComDynamicCell
alloc
]
initWithCellType
:
DynModelTypeCom
style
:
UITableViewCellStyleDefault
reuseIdentifier
:
NSStringFromClass
([
ComDynamicCell
class
])];
}
}
};
ComDynModel
*
model
=
self
.
comListVM
.
listArr
[
indexPath
.
section
];
cell
.
tapRemarkBlock
=
^
{
cell
.
model
=
model
;
[
weakSelf
tableView
:
tableView
didSelectRowAtIndexPath
:
indexPath
];
__weak
ComDynamicCell
*
weakCell
=
(
ComDynamicCell
*
)
cell
;
};
cell
.
tapInformBlock
=
^
{
return
cell
;
if
(
weakSelf
.
delegate
&&
[
weakSelf
.
delegate
respondsToSelector
:
@selector
(
didTapInformItem
:)])
{
[
weakSelf
.
delegate
didTapInformItem
:
model
.
dynamicID
];
}
};
cell
.
tapLikeBlock
=
^
{
if
(
weakSelf
.
delegate
&&
[
weakSelf
.
delegate
respondsToSelector
:
@selector
(
didTapLikeItem
:
cell
:
)])
{
[
weakSelf
.
delegate
didTapLikeItem
:
model
cell
:
weakCell
];
}
};
cell
.
tapRemarkBlock
=
^
{
[
weakSelf
tableView
:
tableView
didSelectRowAtIndexPath
:
indexPath
];
};
return
cell
;
}
}
}
-
(
void
)
tableView
:
(
UITableView
*
)
tableView
didSelectRowAtIndexPath
:
(
NSIndexPath
*
)
indexPath
{
-
(
void
)
tableView
:
(
UITableView
*
)
tableView
didSelectRowAtIndexPath
:
(
NSIndexPath
*
)
indexPath
{
if
(
self
.
comListVM
.
isOfficial
&&
indexPath
.
section
==
0
)
{
return
;
}
ComDynModel
*
model
=
self
.
comListVM
.
listArr
[
indexPath
.
section
];
ComDynModel
*
model
=
self
.
comListVM
.
listArr
[
indexPath
.
section
];
if
(
self
.
delegate
&&
[
self
.
delegate
respondsToSelector
:
@selector
(
didSelectItemWithModel
:)])
{
if
(
self
.
delegate
&&
[
self
.
delegate
respondsToSelector
:
@selector
(
didSelectItemWithModel
:)])
{
[
self
.
delegate
didSelectItemWithModel
:
model
];
[
self
.
delegate
didSelectItemWithModel
:
model
];
...
@@ -158,6 +176,7 @@
...
@@ -158,6 +176,7 @@
_listView
.
separatorStyle
=
UITableViewCellSeparatorStyleNone
;
_listView
.
separatorStyle
=
UITableViewCellSeparatorStyleNone
;
_listView
.
tableHeaderView
=
self
.
headView
;
_listView
.
tableHeaderView
=
self
.
headView
;
_listView
.
contentInsetAdjustmentBehavior
=
UIScrollViewContentInsetAdjustmentNever
;
_listView
.
contentInsetAdjustmentBehavior
=
UIScrollViewContentInsetAdjustmentNever
;
[
_listView
registerClass
:[
OfficialMessageCell
class
]
forCellReuseIdentifier
:
NSStringFromClass
([
OfficialMessageCell
class
])];
WS
(
weakSelf
);
WS
(
weakSelf
);
_listView
.
mj_header
=
[
DSGifHeader
headerWithRefreshingBlock
:
^
{
_listView
.
mj_header
=
[
DSGifHeader
headerWithRefreshingBlock
:
^
{
...
...
DreamSleep/DreamSleep/Class/CommunityModule/View/OfficialMessageCell.h
0 → 100644
查看文件 @
b8563e0
//
// OfficialMessageCell.h
// DreamSleep
//
// Created by peter on 2022/10/14.
//
#import "BaseTableViewCell.h"
#import "OfficialMessageModel.h"
NS_ASSUME_NONNULL_BEGIN
/// 查看所有内容
typedef
void
(
^
ShowAllContentBlock
)(
void
);
/// 社区列表官方消息cell
@interface
OfficialMessageCell
:
BaseTableViewCell
@property
(
nonatomic
,
strong
)
OfficialMessageModel
*
model
;
@property
(
nonatomic
,
copy
)
ShowAllContentBlock
showAllContentBlock
;
@end
NS_ASSUME_NONNULL_END
DreamSleep/DreamSleep/Class/CommunityModule/View/OfficialMessageCell.m
0 → 100644
查看文件 @
b8563e0
//
// OfficialMessageCell.m
// DreamSleep
//
// Created by peter on 2022/10/14.
//
#import "OfficialMessageCell.h"
#import "GKPhotoBrowser.h"
@interface
OfficialMessageCell
()
@property
(
nonatomic
,
assign
)
CGFloat
margin
;
@property
(
nonatomic
,
strong
)
UIImageView
*
userIcon
;
@property
(
nonatomic
,
strong
)
UILabel
*
userNameLab
;
@property
(
nonatomic
,
strong
)
UILabel
*
timeLab
;
@property
(
nonatomic
,
strong
)
UIView
*
imgContainerView
;
@property
(
nonatomic
,
strong
)
UILabel
*
contentLab
;
@property
(
nonatomic
,
strong
)
NSMutableArray
*
photos
;
@end
@implementation
OfficialMessageCell
-
(
instancetype
)
initWithStyle
:(
UITableViewCellStyle
)
style
reuseIdentifier
:(
NSString
*
)
reuseIdentifier
{
if
(
self
=
[
super
initWithStyle
:
style
reuseIdentifier
:
reuseIdentifier
])
{
self
.
photos
=
[
NSMutableArray
array
];
[
self
cornerRadius
:
24
.
0
];
self
.
margin
=
[
OfficialMessageModel
contentMargin
];
self
.
dk_backgroundColorPicker
=
DKColorPickerWithColors
(
DSWhite
,
CornerViewDarkColor
,
DSWhite
);
[
self
.
contentView
addSubview
:
self
.
userIcon
];
[
self
.
contentView
addSubview
:
self
.
userNameLab
];
[
self
.
contentView
addSubview
:
self
.
timeLab
];
[
self
.
contentView
addSubview
:
self
.
imgContainerView
];
[
self
.
contentView
addSubview
:
self
.
contentLab
];
[
self
.
userIcon
mas_makeConstraints
:
^
(
MASConstraintMaker
*
make
)
{
make
.
left
.
equalTo
(
self
.
contentView
).
offset
(
self
.
margin
);
make
.
top
.
equalTo
(
self
.
contentView
).
offset
(
15
);
make
.
size
.
mas_equalTo
(
CGSizeMake
(
40
,
40
));
}];
[
self
.
userNameLab
mas_makeConstraints
:
^
(
MASConstraintMaker
*
make
)
{
make
.
left
.
equalTo
(
self
.
userIcon
.
mas_right
).
offset
(
14
);
make
.
top
.
equalTo
(
self
.
userIcon
);
make
.
right
.
equalTo
(
self
.
contentView
).
offset
(
-
14
);
}];
[
self
.
timeLab
mas_makeConstraints
:
^
(
MASConstraintMaker
*
make
)
{
make
.
left
.
equalTo
(
self
.
userNameLab
);
make
.
top
.
equalTo
(
self
.
contentView
).
offset
(
38
);
}];
}
return
self
;
}
-
(
void
)
setModel
:(
OfficialMessageModel
*
)
model
{
_model
=
model
;
[
self
.
userIcon
yy_setImageWithURL
:[
NSURL
URLWithString
:
model
.
user_profile
]
placeholder
:[
UIImage
defaultPlaceholderWithSize
:
CGSizeMake
(
40
,
40
)]];
self
.
userNameLab
.
text
=
model
.
title
;
self
.
timeLab
.
text
=
model
.
publish_time
;
self
.
contentLab
.
attributedText
=
[
model
contentAttriStr
];
[
self
.
contentLab
mas_remakeConstraints
:
^
(
MASConstraintMaker
*
make
)
{
make
.
top
.
equalTo
(
self
.
userIcon
.
mas_bottom
).
offset
(
12
);
make
.
left
.
equalTo
(
self
.
contentView
).
offset
(
self
.
margin
);
make
.
right
.
equalTo
(
self
.
contentView
).
offset
(
-
self
.
margin
);
make
.
height
.
equalTo
(
@
([
model
contentHeight
]));
}];
// 先移除
[
self
.
imgContainerView
.
subviews
enumerateObjectsUsingBlock
:
^
(
__kindof
UIView
*
_Nonnull
obj
,
NSUInteger
idx
,
BOOL
*
_Nonnull
stop
)
{
[
obj
removeFromSuperview
];
}];
[
self
.
photos
removeAllObjects
];
// 再添加
CGFloat
imgContainerViewH
=
[
model
imgHeight
];
[
self
.
imgContainerView
mas_remakeConstraints
:
^
(
MASConstraintMaker
*
make
)
{
make
.
top
.
equalTo
(
self
.
contentLab
.
mas_bottom
).
offset
(
12
);
make
.
left
.
equalTo
(
self
.
contentView
).
offset
(
self
.
margin
);
make
.
right
.
equalTo
(
self
.
contentView
).
offset
(
-
self
.
margin
);
make
.
height
.
equalTo
(
@
(
imgContainerViewH
));
}];
if
(
imgContainerViewH
>
0
)
{
NSArray
*
imgUrlArr
=
[
model
getImgUrlsArr
:
model
.
imgs
];
CGFloat
itemCount
=
imgUrlArr
.
count
;
CGFloat
itemSpace
=
itemCount
>
1
?
(
kScreenWidth
-
60
-
imgContainerViewH
*
itemCount
)
/
(
itemCount
-
1
)
:
0
;
for
(
int
index
=
0
;
index
<
itemCount
;
index
++
)
{
UIImageView
*
imgView
=
[[
UIImageView
alloc
]
initWithFrame
:
CGRectMake
(
index
*
(
imgContainerViewH
+
itemSpace
),
0
,
imgContainerViewH
,
imgContainerViewH
)];
[
imgView
cornerRadius
:
12
];
imgView
.
tag
=
index
;
imgView
.
userInteractionEnabled
=
YES
;
[
imgView
yy_setImageWithURL
:[
NSURL
URLWithString
:
imgUrlArr
[
index
]]
placeholder
:[
UIImage
defaultPlaceholderWithSize
:
imgView
.
size
]];
imgView
.
dk_alphaPicker
=
DKAlphaPickerWithAlphas
(
1
.
f
,
0
.
5
f
,
0
.
1
f
);
[
self
.
imgContainerView
addSubview
:
imgView
];
UITapGestureRecognizer
*
tapGR
=
[[
UITapGestureRecognizer
alloc
]
initWithTarget
:
self
action
:
@selector
(
lookImg
:
)];
[
imgView
addGestureRecognizer
:
tapGR
];
GKPhoto
*
photo
=
[
GKPhoto
new
];
photo
.
url
=
[
NSURL
URLWithString
:
imgUrlArr
[
index
]];
photo
.
sourceImageView
=
imgView
;
[
self
.
photos
addObject
:
photo
];
}
}
}
#pragma mark - private
-
(
void
)
lookImg
:(
UITapGestureRecognizer
*
)
tapGR
{
UIImageView
*
showIV
=
(
UIImageView
*
)
tapGR
.
view
;
GKPhotoBrowser
*
browser
=
[
GKPhotoBrowser
photoBrowserWithPhotos
:[
_photos
copy
]
currentIndex
:
showIV
.
tag
];
browser
.
showStyle
=
GKPhotoBrowserShowStyleZoom
;
browser
.
loadStyle
=
GKPhotoBrowserLoadStyleDeterminate
;
[
browser
showFromVC
:
self
.
ds_viewController
];
}
-
(
void
)
showAllContent
{
if
(
self
.
model
.
isShowAllContent
)
{
return
;
}
if
(
self
.
showAllContentBlock
)
{
self
.
showAllContentBlock
();
}
}
#pragma mark - lazy
-
(
UIImageView
*
)
userIcon
{
if
(
!
_userIcon
)
{
_userIcon
=
[
UIImageView
new
];
[
_userIcon
cornerRadius
:
20
];
_userIcon
.
dk_alphaPicker
=
DKAlphaPickerWithAlphas
(
1
.
f
,
0
.
5
f
,
0
.
1
f
);
}
return
_userIcon
;
}
-
(
UILabel
*
)
userNameLab
{
if
(
!
_userNameLab
)
{
_userNameLab
=
[
UILabel
labWithFont
:
BoldFont
(
15
)];
_userNameLab
.
dk_textColorPicker
=
DKColorPickerWithColors
(
MainTextColor
,
DkTitleColor
,
DSWhite
);
}
return
_userNameLab
;
}
-
(
UILabel
*
)
timeLab
{
if
(
!
_timeLab
)
{
_timeLab
=
[
UILabel
labWithFont
:
SysFont
(
12
)];
_timeLab
.
dk_textColorPicker
=
DKColorPickerWithColors
(
SmallTextColor
,
ColorFromHexA
(
0xFFFFFF
,
.
3
),
DSWhite
);
}
return
_timeLab
;
}
-
(
UIView
*
)
imgContainerView
{
if
(
!
_imgContainerView
)
{
_imgContainerView
=
[
UIView
new
];
}
return
_imgContainerView
;
}
-
(
UILabel
*
)
contentLab
{
if
(
!
_contentLab
)
{
_contentLab
=
[
UILabel
labWithFont
:[
OfficialMessageModel
contentFont
]];
_contentLab
.
dk_textColorPicker
=
DKColorPickerWithColors
(
MainTextColor
,
ColorFromHexA
(
0xFFFFFF
,
.
5
),
DSWhite
);
_contentLab
.
numberOfLines
=
0
;
_contentLab
.
userInteractionEnabled
=
YES
;
UITapGestureRecognizer
*
tapGR
=
[[
UITapGestureRecognizer
alloc
]
initWithTarget
:
self
action
:
@selector
(
showAllContent
)];
[
_contentLab
addGestureRecognizer
:
tapGR
];
}
return
_contentLab
;
}
@end
DreamSleep/DreamSleep/Class/CommunityModule/ViewModel/ComListViewModel.h
查看文件 @
b8563e0
...
@@ -7,25 +7,29 @@
...
@@ -7,25 +7,29 @@
#import "DSNetworkTool.h"
#import "DSNetworkTool.h"
#import "ComDynModel.h"
#import "ComDynModel.h"
#import "OfficialMessageModel.h"
NS_ASSUME_NONNULL_BEGIN
NS_ASSUME_NONNULL_BEGIN
/// 社区动态列表、用户点赞
/// 社区动态列表、用户点赞
@interface
ComListViewModel
:
DSNetworkTool
@interface
ComListViewModel
:
DSNetworkTool
/// 总页数
///
对外提供
总页数
@property
(
nonatomic
,
assign
)
int
totalCount
;
@property
(
nonatomic
,
assign
)
int
totalCount
;
/// 社区动态列表数据
///
对外提供的
社区动态列表数据
@property
(
nonatomic
,
strong
)
NSArray
*
listArr
;
@property
(
nonatomic
,
strong
)
NSArray
*
listArr
;
/// 自定义字段,用于标识是否是官方发布的动态
-
(
void
)
getComListWithCompletion
:(
void
(
^
)(
ComListViewModel
*
requestModel
))
completion
;
@property
(
nonatomic
,
assign
)
BOOL
isOfficial
;
/// 社区动态查询列表接口
/// 社区动态查询列表接口
/// @param loadMore
loadMore
/// @param loadMore
上下拉标识
/// @param offset offset
/// @param offset offset
/// @param completion completion
/// @param completion completion
-
(
NSURLSessionDataTask
*
)
querySleepDynamicListWithLoadMore
:(
BOOL
)
loadMore
offset
:(
int
)
offset
completion
:(
void
(
^
)(
ComListViewModel
*
requestModel
))
completion
;
-
(
NSURLSessionDataTask
*
)
querySleepDynamicListWithLoadMore
:(
BOOL
)
loadMore
offset
:(
int
)
offset
completion
:(
void
(
^
)(
ComListViewModel
*
requestModel
))
completion
;
/// 显示全部官方动态内容
-
(
void
)
showOfficialAllContent
;
/// 删除个人社区动态
/// 删除个人社区动态
/// @param dynamicID 动态id
/// @param dynamicID 动态id
-
(
void
)
deleteComDynWithDynamicID
:(
int
)
dynamicID
;
-
(
void
)
deleteComDynWithDynamicID
:(
int
)
dynamicID
;
...
...
DreamSleep/DreamSleep/Class/CommunityModule/ViewModel/ComListViewModel.m
查看文件 @
b8563e0
...
@@ -6,9 +6,20 @@
...
@@ -6,9 +6,20 @@
//
//
#import "ComListViewModel.h"
#import "ComListViewModel.h"
#import "ComDynListResultModel.h"
@interface
ComListViewModel
()
/// 社区动态列表结果数据model
@property
(
nonatomic
,
strong
)
ComDynListResultModel
*
resultModel
;
@end
@implementation
ComListViewModel
@implementation
ComListViewModel
+
(
nullable
NSDictionary
<
NSString
*
,
id
>
*
)
modelCustomPropertyMapper
{
return
@{
@"resultModel"
:
@"result"
};
}
-
(
instancetype
)
init
{
-
(
instancetype
)
init
{
if
(
self
=
[
super
init
])
{
if
(
self
=
[
super
init
])
{
self
.
listArr
=
[
NSArray
array
];
self
.
listArr
=
[
NSArray
array
];
...
@@ -16,44 +27,38 @@
...
@@ -16,44 +27,38 @@
return
self
;
return
self
;
}
}
-
(
void
)
getComListWithCompletion
:
(
void
(
^
)(
ComListViewModel
*
requestModel
))
completion
{
ComListViewModel
*
requestModel
=
[[
ComListViewModel
alloc
]
init
];
NSDictionary
*
apiDic
=
[[
NSDictionary
alloc
]
initWithContentsOfFile
:[[
NSBundle
mainBundle
]
pathForResource
:
@"comList"
ofType
:
@"plist"
]];
NSArray
*
resultArr
=
apiDic
[
@"result"
];
requestModel
.
resCode
=
[
apiDic
[
@"res_code"
]
integerValue
];
requestModel
.
errMessage
=
apiDic
[
@"error"
];
NSMutableArray
*
tmpArr
=
[
NSMutableArray
array
];
for
(
int
i
=
0
;
i
<
resultArr
.
count
;
i
++
)
{
ComDynModel
*
model
=
[
ComDynModel
yy_modelWithDictionary
:
resultArr
[
i
]];
[
tmpArr
addObject
:
model
];
}
requestModel
.
listArr
=
[
tmpArr
copy
];
DSLog
(
@"apiDic:%@"
,
apiDic
);
completion
(
requestModel
);
}
-
(
NSURLSessionDataTask
*
)
querySleepDynamicListWithLoadMore
:
(
BOOL
)
loadMore
offset
:
(
int
)
offset
completion
:
(
void
(
^
)(
ComListViewModel
*
requestModel
))
completion
{
-
(
NSURLSessionDataTask
*
)
querySleepDynamicListWithLoadMore
:
(
BOOL
)
loadMore
offset
:
(
int
)
offset
completion
:
(
void
(
^
)(
ComListViewModel
*
requestModel
))
completion
{
NSString
*
api
=
@"query_sleep_dynamic_list"
;
NSString
*
api
=
@"query_sleep_dynamic_list"
;
NSString
*
argStr
=
[
NSString
stringWithFormat
:
@"query{%@(offset:%d)}"
,
api
,
offset
];
NSString
*
argStr
=
[
NSString
stringWithFormat
:
@"query{%@(offset:%d)}"
,
api
,
offset
];
return
[
ComListViewModel
httpPostBodyRequestWithAPI
:
api
params
:@{
@"query"
:
argStr
}
view
:
nil
hasNetActivity
:
YES
loadingInfo
:
nil
hasFailInfo
:
NO
success
:^
(
NSDictionary
*
_Nonnull
apiDic
)
{
return
[
ComListViewModel
httpPostBodyRequestWithAPI
:
api
params
:@{
@"query"
:
argStr
}
view
:
nil
hasNetActivity
:
YES
loadingInfo
:
nil
hasFailInfo
:
NO
success
:^
(
NSDictionary
*
_Nonnull
apiDic
)
{
DSLog
(
@"社区动态查询列表接口apiDic:%@"
,
apiDic
);
DSLog
(
@"社区动态查询列表接口apiDic:%@"
,
apiDic
);
// 1、解析数据
self
.
resCode
=
DSResCodeSuccess
;
self
.
resCode
=
DSResCodeSuccess
;
NSDictionary
*
resultDic
=
apiDic
[
@"result"
];
self
.
resultModel
=
[
ComDynListResultModel
yy_modelWithDictionary
:
apiDic
[
@"result"
]];
NSArray
*
data_list
=
resultDic
[
@"data_list"
];
// 2、根据业务需要的数据结构对数据进行加工
NSMutableArray
*
tmpArr
=
[
NSMutableArray
array
];
NSArray
*
lastes_data_list
=
self
.
resultModel
.
data_list
?:
@[];
for
(
int
i
=
0
;
i
<
data_list
.
count
;
i
++
)
{
ComDynModel
*
model
=
[
ComDynModel
yy_modelWithDictionary
:
data_list
[
i
]];
[
tmpArr
addObject
:
model
];
}
if
(
loadMore
)
{
if
(
loadMore
)
{
NSMutableArray
*
tmp
DyList
=
[
NSMutableArray
arrayWithArray
:
self
.
listArr
];
NSMutableArray
*
tmp
_list_arr
=
[
NSMutableArray
arrayWithArray
:
self
.
listArr
];
[
tmp
DyList
addObjectsFromArray
:
tmpArr
.
copy
];
[
tmp
_list_arr
addObjectsFromArray
:
lastes_data_list
.
copy
];
self
.
listArr
=
tmp
DyList
.
copy
;
self
.
listArr
=
tmp
_list_arr
.
copy
;
}
else
{
}
else
{
self
.
listArr
=
tmpArr
.
copy
;
self
.
listArr
=
lastes_data_list
.
copy
;
}
}
self
.
totalCount
=
self
.
resultModel
.
count
;
self
.
totalCount
=
[
resultDic
[
@"count"
]
intValue
];
// 3、如果是官方发布的动态,则放在第一位,并且只插入1次
NSMutableArray
*
newList
=
[
NSMutableArray
arrayWithArray
:
self
.
listArr
];
__block
BOOL
hasOfficialModel
=
NO
;
[
newList
enumerateObjectsUsingBlock
:
^
(
id
_Nonnull
obj
,
NSUInteger
idx
,
BOOL
*
_Nonnull
stop
)
{
if
([
obj
isKindOfClass
:[
OfficialMessageModel
class
]])
{
hasOfficialModel
=
YES
;
*
stop
=
YES
;
}
}];
if
(
hasOfficialModel
==
NO
)
{
[
newList
insertObject
:
self
.
resultModel
.
officialMessageModel
atIndex
:
0
];
}
self
.
isOfficial
=
self
.
resultModel
.
officialMessageModel
;
self
.
listArr
=
newList
.
copy
;
completion
(
self
);
completion
(
self
);
}
failure
:^
(
id
_Nonnull
failureInfo
)
{
}
failure
:^
(
id
_Nonnull
failureInfo
)
{
self
.
resCode
=
[
failureInfo
[
@"errorCode"
]
integerValue
];
self
.
resCode
=
[
failureInfo
[
@"errorCode"
]
integerValue
];
...
@@ -62,6 +67,10 @@
...
@@ -62,6 +67,10 @@
}];
}];
}
}
-
(
void
)
showOfficialAllContent
{
self
.
resultModel
.
officialMessageModel
.
isShowAllContent
=
YES
;
}
-
(
void
)
deleteComDynWithDynamicID
:
(
int
)
dynamicID
{
-
(
void
)
deleteComDynWithDynamicID
:
(
int
)
dynamicID
{
NSMutableArray
*
tmpListArr
=
[
NSMutableArray
arrayWithArray
:
self
.
listArr
];
NSMutableArray
*
tmpListArr
=
[
NSMutableArray
arrayWithArray
:
self
.
listArr
];
[
tmpListArr
enumerateObjectsUsingBlock
:
^
(
ComDynModel
*
obj
,
NSUInteger
idx
,
BOOL
*
_Nonnull
stop
)
{
[
tmpListArr
enumerateObjectsUsingBlock
:
^
(
ComDynModel
*
obj
,
NSUInteger
idx
,
BOOL
*
_Nonnull
stop
)
{
...
@@ -76,8 +85,13 @@
...
@@ -76,8 +85,13 @@
-
(
void
)
insertUserDyModel
:
(
ComDynModel
*
)
dyModel
{
-
(
void
)
insertUserDyModel
:
(
ComDynModel
*
)
dyModel
{
if
(
!
dyModel
)
{
return
;
}
if
(
!
dyModel
)
{
return
;
}
// 用户发的说说临时插入到动态列表第一条
// 用户发的说说临时插入到动态列表第一条
NSInteger
insertIndex
=
0
;
// 如果有官方动态,则插入到官方动态下面
if
(
self
.
resultModel
.
officialMessageModel
)
{
insertIndex
=
1
;
}
NSMutableArray
*
tmpListArr
=
[
NSMutableArray
arrayWithArray
:
self
.
listArr
];
NSMutableArray
*
tmpListArr
=
[
NSMutableArray
arrayWithArray
:
self
.
listArr
];
[
tmpListArr
insertObject
:
dyModel
atIndex
:
0
];
[
tmpListArr
insertObject
:
dyModel
atIndex
:
insertIndex
];
self
.
listArr
=
tmpListArr
.
copy
;
self
.
listArr
=
tmpListArr
.
copy
;
}
}
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论