Skip to content

Commit

Permalink
好友圈
Browse files Browse the repository at this point in the history
  • Loading branch information
tbl00c committed Mar 5, 2018
1 parent 3cce25b commit 5d6bddd
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ - (void)loadMenus
// 好友圈
self.addSection(TLDiscoverSectionTagMoments).sectionInsets(UIEdgeInsetsMake(15, 0, 0, 0));
TLMenuItem *moments = createMenuItem(@"discover_album", LOCSTR(@"朋友圈"));
[moments setRightIconURL:@"http://img4.duitang.com/uploads/item/201510/16/20151016113134_TZye4.thumb.224_0.jpeg" withRightIconBadge:YES];
[moments setRightIconURL:@"http://i01.pic.sogou.com/23112449ac395e72" withRightIconBadge:YES];
self.addCell(NAME_DISCOVER_MENU_CELL).toSection(TLDiscoverSectionTagMoments).withDataModel(moments).viewTag(TLDiscoverCellTagMoments);

// 功能
Expand Down
34 changes: 34 additions & 0 deletions TLChat/Modules/Moments/Resources/TestData/Moments.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
"momentID" : "m1002",
"user" : { "userID" : "1001", "nikeName" : "曾小贤", "avatarURL" : "http://i01.pic.sogou.com/23112449ac395e72"},
"date" : "1520244408",
"detail" : {
"text" : "Hello world!",
"images" : [
Expand All @@ -28,9 +29,24 @@
],
}
},
{
"momentID" : "m2001",
"user" : { "userID" : "1000", "nikeName" : "李伯坤", "avatarURL" : "http://p1.qq181.com/cms/120506/2012050623111097826.jpg"},
"source" : "作者",
"date" : "1520244008",
"detail" : {
"text" : "TLChat持续优化中,感谢大家的关注~~",
},
"link" : {
"title" : "Github·TLChat",
"jumpUrl" : "https://github.com/tbl00c/TLChat",
},
},
{
"momentID" : "m1008",
"user" : { "userID" : "1006", "nikeName" : "陆展博", "avatarURL" : "http://i01.pic.sogou.com/ce745becc4aa8316"},
"source" : "QQ",
"date" : "1520243008",
"detail" : {
"text" : "畅销书《C语言,从入门到放弃》即将上市,不要998,不要88,只要8块8。现在开始接受预定,机不可失,时不再来,欲购从速!!",
"images" : [
Expand Down Expand Up @@ -67,13 +83,15 @@
{
"momentID" : "m1005",
"user" : { "userID" : "1003", "nikeName" : "关谷神奇", "avatarURL" : "http://i04.pic.sogou.com/8c4442016e69ca3b"},
"date" : "1520242008",
"detail" : {
"text" : "分分钟切腹自尽",
},
},
{
"momentID" : "m1006",
"user" : { "userID" : "1011", "nikeName" : "张伟", "avatarURL" : "http://i02.pic.sogou.com/628f3f0836407f9e"},
"date" : "1520201008",
"detail" : {
"text" : "人要保持一定的饥饿感,不然就会变胖!",
},
Expand All @@ -89,6 +107,7 @@
{
"momentID" : "m1024",
"user" : { "userID" : "1002", "nikeName" : "陈美嘉", "avatarURL" : "http://i04.pic.sogou.com/d44a3766422d4930"},
"date" : "1520168008",
"detail" : {
"images" : ["http://p2.gexing.com/G1/M00/0C/3A/rBACE1MBs8_QSeZpAAChVX3kQcI875.jpg"],
},
Expand All @@ -107,9 +126,24 @@
{
"momentID" : "m1025",
"user" : { "userID" : "1001", "nikeName" : "曾小贤", "avatarURL" : "http://i01.pic.sogou.com/23112449ac395e72"},
"source" : "美拍",
"date" : "1520135508",
"detail" : {
"text" : "24k,纯帅",
"images" : ["http://images.enet.com.cn/egames/articleimage/201209/20120903050346235.jpg"],
},
},
{
"momentID" : "m2001",
"user" : { "userID" : "1000", "nikeName" : "李伯坤", "avatarURL" : "http://p1.qq181.com/cms/120506/2012050623111097826.jpg"},
"date" : "1520035508",
"source" : "作者",
"detail" : {
"text" : "ZZFLEX已开源,一种全新的界面构建方式。",
},
"link" : {
"title" : "Github·ZZFLEX",
"jumpUrl" : "https://github.com/tbl00c/ZZFLEX",
},
},
]
44 changes: 31 additions & 13 deletions TLChat/Modules/Moments/TLMomentsViewController/Models/TLMoment.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,24 @@
#import "TLMomentDetail.h"
#import "TLMomentExtension.h"


@interface TLMomentFrame : NSObject

@property (nonatomic, assign) CGFloat height;

@property (nonatomic, assign) CGFloat heightDetail;

@property (nonatomic, assign) CGFloat heightExtension;

@end


@class TLMomentLinkModel;
@class TLMomentFrame;

@interface TLMoment : NSObject

@property (nonatomic, strong) NSString *momentID;

@property (nonatomic, strong) TLUser *user;

@property (nonatomic, strong) NSDate *date;
/// 发布时间
@property (nonatomic, strong) NSString *date;
@property (nonatomic, strong, readonly) NSString *showDate;

/// 来源
@property (nonatomic, strong) NSString *source;

/// 跳转链接(位置、app url等)
@property (nonatomic, strong) TLMomentLinkModel *link;

/// 详细内容
@property (nonatomic, strong) TLMomentDetail *detail;
Expand All @@ -43,3 +41,23 @@

@end


@interface TLMomentLinkModel : NSObject

@property (nonatomic, strong) NSString *title;

@property (nonatomic, strong) NSString *jumpUrl;

@end


@interface TLMomentFrame : NSObject

@property (nonatomic, assign) CGFloat height;

@property (nonatomic, assign) CGFloat heightDetail;

@property (nonatomic, assign) CGFloat heightExtension;

@end

43 changes: 43 additions & 0 deletions TLChat/Modules/Moments/TLMomentsViewController/Models/TLMoment.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,42 @@

@implementation TLMoment

- (void)setDate:(NSString *)date
{
_date = date;
_showDate = [self momBabayMomentPublishTimeFromInterval:date];
}

- (NSString *)momBabayMomentPublishTimeFromInterval:(NSString *)timeInterval
{
NSTimeInterval late = [timeInterval longLongValue];
NSTimeInterval now = [[NSDate date] timeIntervalSince1970];
NSString *timeString = @"";

NSTimeInterval cha = now - late; //
if (cha < 60) {
timeString = @"刚刚";
}
else if (cha / 3600 < 1 && cha > 60) {
int mm = cha / 60;
timeString = [NSString stringWithFormat:@"%d分钟前", mm];
}
else if (cha / 3600 >= 1 && cha/86400 < 1) {
int hh = cha / 3600;
timeString = [NSString stringWithFormat:@"%d小时前", hh];
}
else if (cha / 86400 >= 1 && cha/31536000 < 1) {
int dd = cha / 86400;
timeString = [NSString stringWithFormat:@"%d天前", dd];
}
else if (cha / 31536000 >= 1) {
int yy = cha / 31536000;
timeString = [NSString stringWithFormat:@"%d年前", yy];
}

return timeString;
}

#pragma mark - # Getter
- (TLMomentFrame *)momentFrame
{
Expand All @@ -23,6 +59,9 @@ - (TLMomentFrame *)momentFrame
_momentFrame.height += 10;
_momentFrame.height += _momentFrame.heightExtension = self.extension.extensionFrame.height; // 拓展高度
}
if (self.link) {
_momentFrame.height += 25;
}
}
return _momentFrame;
}
Expand All @@ -39,3 +78,7 @@ - (BOOL)hasExtension
@implementation TLMomentFrame

@end

@implementation TLMomentLinkModel

@end
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ @interface TLMomentBaseCell ()
/// 点赞&评论
@property (nonatomic, strong) TLMomentExtensionView *extensionView;

/// 链接
@property (nonatomic, strong) UIButton *linkButton;
/// 时间
@property (nonatomic, strong) UILabel *dateLabel;
/// 来源
Expand Down Expand Up @@ -89,9 +91,11 @@ - (void)setMoment:(TLMoment *)moment
}];

// 时间
[self.dateLabel setText:@"1小时前"];
[self.dateLabel setText:moment.showDate];
// 来源
[self.originLabel setText:@"微博"];
[self.originLabel setText:moment.source];
// 链接
self.linkButton.zz_make.title(moment.link.title).hidden(moment.link.title.length == 0);
}

#pragma mark - # UI
Expand Down Expand Up @@ -183,6 +187,24 @@ - (void)p_initSubviews
make.centerY.mas_equalTo(self.dateLabel);
})
.view;

// 链接
self.linkButton = self.contentView.addButton(3010)
.backgroundColor([UIColor clearColor]).backgroundColorHL([UIColor lightGrayColor])
.titleFont([UIFont systemFontOfSize:13.0f]).titleColor([UIColor colorBlueMoment])
.eventBlock(UIControlEventTouchUpInside, ^(UIButton *sender) {
@strongify(self);
if (self.delegate && [self.delegate respondsToSelector:@selector(momentViewWithModel:jumpToUrl:)]) {
[self.delegate momentViewWithModel:self.moment jumpToUrl:self.moment.link.jumpUrl];
}
})
.masonry(^ (MASConstraintMaker *make) {
make.left.mas_equalTo(self.nameView);
make.right.mas_lessThanOrEqualTo(-10);
make.bottom.mas_equalTo(self.dateLabel.mas_top).mas_offset(-6);
make.height.mas_equalTo(20);
})
.view;
}

- (void)layoutSubviews
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,12 @@

@class TLMoment;
@class TLUser;
@protocol TLMomentMultiImageViewDelegate <NSObject>
@protocol TLMomentViewDelegate <NSObject>

- (void)momentViewClickImage:(NSArray *)images atIndex:(NSInteger)index;

@end


@protocol TLMomentDetailViewDelegate <TLMomentMultiImageViewDelegate>

@end


@protocol TLMomentViewDelegate <TLMomentDetailViewDelegate>

- (void)momentViewWithModel:(TLMoment *)moment didClickUser:(TLUser *)user;

- (void)momentViewWithModel:(TLMoment *)moment jumpToUrl:(NSString *)url;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import "TLMomentsViewController.h"
#import "TLUserDetailViewController.h"
#import <MWPhotoBrowser/MWPhotoBrowser.h>
#import "TLWebViewController.h"

#import "TLMomentHeaderCell.h"
#import "TLMomentImagesCell.h"
Expand Down Expand Up @@ -112,4 +113,10 @@ - (void)momentViewClickImage:(NSArray *)images atIndex:(NSInteger)index
[self presentViewController:broserNavC animated:NO completion:nil];
}

- (void)momentViewWithModel:(TLMoment *)moment jumpToUrl:(NSString *)url
{
TLWebViewController *webVC = [[TLWebViewController alloc] initWithUrl:url];
PushVC(webVC);
}

@end

0 comments on commit 5d6bddd

Please sign in to comment.