Initial commit

This commit is contained in:
ifish
2017-08-15 16:59:01 +08:00
commit bdc83e07ef
5766 changed files with 423223 additions and 0 deletions
@@ -0,0 +1,13 @@
//
// UMComSimplicityDiscoverViewController.h
// UMCommunity
//
// Created by umeng on 15/11/17.
// Copyright © 2015年 Umeng. All rights reserved.
//
#import "UMComViewController.h"
@interface UMComSimplicityDiscoverViewController : UMComViewController
@end
@@ -0,0 +1,443 @@
//
// UMComForumFindViewController.m
// UMCommunity
//
// Created by umeng on 15/11/17.
// Copyright © 2015年 Umeng. All rights reserved.
//
#import "UMComSimplicityDiscoverViewController.h"
#import "UMComSimplicityFindTableViewCell.h"
#import "UMComSimpleProfileSettingController.h"
#import "UIViewController+UMComAddition.h"
#import <UMCommunitySDK/UMComSession.h>
#import "UMComSimplicityUserInfoBar.h"
#import "UMComLoginManager.h"
#import "UMComResouceDefines.h"
#import "UMComSimpleNoticeTableViewController.h"
#import "UMComSimpleFeedTableViewController.h"
#import "UMComSimpleCommentViewController.h"
#import "UMComSimpleLikeMyFeedViewController.h"
#import "UMComFeedListDataController.h"
#import "UMComLoginManager.h"
#import <UMCommunitySDK/UMComSession.h>
#import <UMComDataStorage/UMComUnReadNoticeModel.h>
#import "UMComNotificationMacro.h"
@interface UMComSimplicityDiscoverViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UIView *systemNotificationView;
@property (nonatomic, strong) UIView *userMessageView;
@property (nonatomic, strong) UIView *userMessageViewComment;//评论的小红点
@property (nonatomic, strong) UIView *userMessageViewLike;//赞的小红点
@property (nonatomic, strong) UIView *userMessageViewNotice;//通知的小红点
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UMComSimplicityUserInfoBar *userInfoBar;
@end
@implementation UMComSimplicityDiscoverViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self setForumUIBackButtonWithImage:UMComSimpleImageWithImageName(@"um_forum_back_gray@2x.png")];
[self setForumUITitle:UMComLocalizedString(@"um_com_find", @"我的")];
self.tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
self.tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin;
self.tableView.delegate = self;
self.tableView.dataSource = self;
if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[self.tableView setSeparatorInset:UIEdgeInsetsZero];
}
if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)])
{
[self.tableView setLayoutMargins:UIEdgeInsetsZero];
}
[self.tableView registerNib:[UINib nibWithNibName:@"UMComSimplicityFindTableViewCell" bundle:nil] forCellReuseIdentifier:@"FindTableViewCell"];
self.tableView.rowHeight = 55.0f;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.tableFooterView = [[UIView alloc] init];
self.tableView.scrollEnabled = NO;
[self.view addSubview:self.tableView];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshNoticeItemViews) name:kUMComUnreadNotificationRefreshNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshMessageData:) name:UIApplicationWillEnterForegroundNotification object:nil];
[self refreshNoticeItemViews];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)refreshMessageData:(id)sender
{
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
}
- (void)refreshNoticeItemViews
{
[self.tableView reloadData];
}
- (UIView *)creatNoticeViewWithOriginX:(CGFloat)originX
{
CGFloat noticeViewWidth = 7;
UIView *itemNoticeView = [[UIView alloc]initWithFrame:CGRectMake(originX,0, noticeViewWidth, noticeViewWidth)];
itemNoticeView.backgroundColor = [UIColor redColor];
itemNoticeView.layer.cornerRadius = noticeViewWidth/2;
itemNoticeView.clipsToBounds = YES;
itemNoticeView.hidden = YES;
return itemNoticeView;
}
#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 4;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section == 0) {
return 0;
} else if (section == 1) {
return 0;
} else if (section == 2) {
return 5;
} else {
return 1;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellID = @"FindTableViewCell";
UMComSimplicityFindTableViewCell *cell = (UMComSimplicityFindTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
if (indexPath.section == 0 || indexPath.section == 1) {
} else if (indexPath.section == 2) {
switch (indexPath.row) {
case 0: {
cell.titleImageView.image = UMComSimpleImageWithImageName(@"wodedongtai");
cell.titleNameLabel.text = UMComLocalizedString(@"um_news_notice", @"我的动态");
}
break;
case 1: {
cell.titleImageView.image = UMComSimpleImageWithImageName(@"um_favorite");
cell.titleNameLabel.text = UMComLocalizedString(@"um_com_user_collection", @"我的收藏");
}
break;
case 2: {
cell.titleImageView.image = UMComSimpleImageWithImageName(@"pinglun");
cell.titleNameLabel.text = UMComLocalizedString(@"um_com_comment", @"评论");
if (!self.userMessageViewComment) {
CGFloat padding = 2;
CGFloat defaultNoticeViewOriginX = 115;
CGSize nameSize = [cell.titleNameLabel.text sizeWithFont:cell.titleNameLabel.font];
CGFloat noticeViewOriginX = cell.titleNameLabel.frame.origin.x + nameSize.width + padding;
if (noticeViewOriginX >= cell.contentView.bounds.size.width) {
//大于cell的宽度就减去padding
noticeViewOriginX = cell.contentView.bounds.size.width - padding;
}
else if (noticeViewOriginX <= 0)
{
//小于0就用默认
noticeViewOriginX = defaultNoticeViewOriginX;
}
else{}
self.userMessageViewComment = [self creatNoticeViewWithOriginX:noticeViewOriginX];
self.userMessageViewComment.center = CGPointMake(self.userMessageViewComment.center.x, cell.titleNameLabel.frame.origin.y+11);
[cell.contentView addSubview:self.userMessageViewComment];
} else {
if (self.userMessageViewComment.superview != cell.contentView) {
[self.userMessageViewComment removeFromSuperview];
[cell.contentView addSubview:self.userMessageViewComment];
}
}
UMComUnReadNoticeModel *unReadNotice = [UMComSession sharedInstance].unReadNoticeModel;
if (unReadNotice.notiByCommentCount <= 0) {
self.userMessageViewComment.hidden = YES;
}else{
self.userMessageViewComment.hidden = NO;
}
}
break;
case 3: {
cell.titleImageView.image = UMComSimpleImageWithImageName(@"thumb-blue");
cell.titleNameLabel.text = UMComLocalizedString(@"um_com_be_liked", @"赞我的");
if (!self.userMessageViewLike) {
CGFloat padding = 2;
CGFloat defaultNoticeViewOriginX = 115;
CGSize nameSize = [cell.titleNameLabel.text sizeWithFont:cell.titleNameLabel.font];
CGFloat noticeViewOriginX = cell.titleNameLabel.frame.origin.x + nameSize.width + padding;
if (noticeViewOriginX >= cell.contentView.bounds.size.width) {
//大于cell的宽度就减去padding
noticeViewOriginX = cell.contentView.bounds.size.width - padding;
}
else if (noticeViewOriginX <= 0)
{
//小于0就用默认
noticeViewOriginX = defaultNoticeViewOriginX;
}
else{}
self.userMessageViewLike = [self creatNoticeViewWithOriginX:noticeViewOriginX];
self.userMessageViewLike.center = CGPointMake(self.userMessageViewLike.center.x, cell.titleNameLabel.frame.origin.y+11);
[cell.contentView addSubview:self.userMessageViewLike];
} else {
if (self.userMessageViewLike.superview != cell.contentView) {
[self.userMessageViewLike removeFromSuperview];
[cell.contentView addSubview:self.userMessageViewLike];
}
}
UMComUnReadNoticeModel *unReadNotice = [UMComSession sharedInstance].unReadNoticeModel;
if (unReadNotice.notiByLikeCount <= 0) {
self.userMessageViewLike.hidden = YES;
}else{
self.userMessageViewLike.hidden = NO;
}
}
break;
case 4: {
cell.titleImageView.image = UMComSimpleImageWithImageName(@"tongzhi");
cell.titleNameLabel.text = UMComLocalizedString(@"um_com_notification", @"通知");
if (!self.userMessageViewNotice) {
CGFloat padding = 2;
CGFloat defaultNoticeViewOriginX = 115;
CGSize nameSize = [cell.titleNameLabel.text sizeWithFont:cell.titleNameLabel.font];
CGFloat noticeViewOriginX = cell.titleNameLabel.frame.origin.x + nameSize.width + padding;
if (noticeViewOriginX >= cell.contentView.bounds.size.width) {
//大于cell的宽度就减去padding
noticeViewOriginX = cell.contentView.bounds.size.width - padding;
}
else if (noticeViewOriginX <= 0)
{
//小于0就用默认
noticeViewOriginX = defaultNoticeViewOriginX;
}
else{}
self.userMessageViewNotice = [self creatNoticeViewWithOriginX:noticeViewOriginX];
self.userMessageViewNotice.center = CGPointMake(self.userMessageViewNotice.center.x, cell.titleNameLabel.frame.origin.y+11);
[cell.contentView addSubview:self.userMessageViewNotice];
} else {
if (self.userMessageViewNotice.superview != cell.contentView) {
[self.userMessageViewNotice removeFromSuperview];
[cell.contentView addSubview:self.userMessageViewNotice];
}
}
UMComUnReadNoticeModel *unReadNotice = [UMComSession sharedInstance].unReadNoticeModel;
if (unReadNotice.notiByAdministratorCount <= 0) {
self.userMessageViewNotice.hidden = YES;
}else{
self.userMessageViewNotice.hidden = NO;
}
}
break;
default:
break;
}
if (indexPath.row == 0) {
[cell setCellStyleForLine:UMComSimplicityCellLineStyleTop | UMComSimplicityCellLineStyleMiddle];
} else if (indexPath.row == 4) {
[cell setCellStyleForLine:UMComSimplicityCellLineStyleBottom];
} else {
[cell setCellStyleForLine:UMComSimplicityCellLineStyleMiddle];
}
} else {
switch (indexPath.row) {
case 0: {
cell.titleImageView.image = UMComSimpleImageWithImageName(@"shezhi");
cell.titleNameLabel.text = UMComLocalizedString(@"um_com_setting", @"设置");
[cell setCellStyleForLine:UMComSimplicityCellLineStyleTop | UMComSimplicityCellLineStyleBottom];
}
break;
default:
break;
}
}
return cell;
}
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
UIEdgeInsets edge = UIEdgeInsetsMake(tableView.rowHeight - 1, 15, 0, 0);
if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[self.tableView setSeparatorInset:edge];
}
if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)])
{
[self.tableView setLayoutMargins:edge];
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if (section == 0) {
return 15.f;
}else if (section == 1) {
return 110.f;
} else if (section == 2) {
return 15.0f;
}else {
return 15.0f;
}
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
if (section == 1) {
NSArray *xibs = [[NSBundle mainBundle] loadNibNamed:@"UMComSimplicityUserInfoBar" owner:self options:nil];
self.userInfoBar = xibs[0];
[_userInfoBar refresh];
[_userInfoBar addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(prepareToUserCenter)]];
return _userInfoBar;
} else {
}
return nil;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
__weak typeof(self) ws = self;
[UMComLoginManager performLogin:self completion:^(id responseObject, NSError *error) {
if (!error) {
[ws.userInfoBar refresh];
if (indexPath.section == 0) {
} else if (indexPath.section == 1) {
} else if (indexPath.section == 2) {
switch (indexPath.row) {
case 0:
{
[ws tranToUserFeedFlow];
}
break;
case 1:
[ws tranToUsersFavourites];
break;
case 2:
[ws tranToComment];
break;
case 3:
[ws tranToBeLiked];
break;
case 4:
[ws tranToNotification];
break;
default:
break;
}
}else if(indexPath.section == 3){
switch (indexPath.row) {
case 0:
{
[ws tranToSetting];
}
break;
default:
break;
}
}
}
}];
}
- (void)prepareToUserCenter
{
if ([[UMComSession sharedInstance] isLogin]) {
} else {
__weak typeof(self) ws = self;
[UMComLoginManager performLogin:self completion:^(id responseObject, NSError *error) {
if (!error) {
[ws.userInfoBar refresh];
}
}];
}
}
- (void)tranToUserFeedFlow
{
UMComSimpleFeedTableViewController *VC = [[UMComSimpleFeedTableViewController alloc] init];
VC.dataController = [[UMComFeedTimeLineDataController alloc] initWithCount:UMCom_Limit_Page_Count userID:[UMComSession sharedInstance].loginUser.uid timeLineFeedListType:UMComUserTimeLineFeedType_Default];
VC.titleName = UMComLocalizedString(@"um_com_user_feed_flow", @"我的动态");
[self.navigationController pushViewController:VC animated:YES];
}
- (void)tranToUsersFavourites
{
UMComSimpleFeedTableViewController *VC = [[UMComSimpleFeedTableViewController alloc] init];
VC.dataController = [[UMComFeedFavoriteDataController alloc] initWithCount:UMCom_Limit_Page_Count];
VC.feedType = UMComFeedType_Favorite;
VC.titleName = UMComLocalizedString(@"um_com_fav_feed", @"我的收藏");
[self.navigationController pushViewController:VC animated:YES];
}
- (void)tranToComment
{
UMComSimpleCommentViewController *VC = [[UMComSimpleCommentViewController alloc] init];
[self.navigationController pushViewController:VC animated:YES];
}
- (void)tranToBeLiked
{
UMComSimpleLikeMyFeedViewController *VC = [[UMComSimpleLikeMyFeedViewController alloc] init];
[self.navigationController pushViewController:VC animated:YES];
}
- (void)tranToNotification
{
UMComSimpleNoticeTableViewController *noticeVc = [[UMComSimpleNoticeTableViewController alloc] init];
[self.navigationController pushViewController:noticeVc animated:YES];
}
- (void)tranToSetting
{
UMComSimpleProfileSettingController *settingVc = [[UMComSimpleProfileSettingController alloc] init];
[self.navigationController pushViewController:settingVc animated:YES];
}
- (void)tranToUserCenter
{
}
@end
@@ -0,0 +1,27 @@
//
// UMComSimplicityFindTableViewCell.h
// UMCommunity
//
// Created by umeng on 15-3-31.
// Copyright (c) 2015年 Umeng. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "UMComTableViewCell.h"
typedef NS_ENUM(NSUInteger, UMComSimplicityCellLineStyle) {
UMComSimplicityCellLineStyleTop = 1,
UMComSimplicityCellLineStyleMiddle = 1 << 1L,
UMComSimplicityCellLineStyleBottom = 1 << 2L,
};
@interface UMComSimplicityFindTableViewCell : UMComTableViewCell
@property (weak, nonatomic) IBOutlet UIImageView *titleImageView;
@property (weak, nonatomic) IBOutlet UILabel *titleNameLabel;
@property (weak, nonatomic) IBOutlet UIView *topLine;
@property (weak, nonatomic) IBOutlet UIView *bottomLine;
- (void)setCellStyleForLine:(UMComSimplicityCellLineStyle)style;
@end
@@ -0,0 +1,69 @@
//
// UMComFindTableViewCell.m
// UMCommunity
//
// Created by umeng on 15-3-31.
// Copyright (c) 2015年 Umeng. All rights reserved.
//
#import "UMComSimplicityFindTableViewCell.h"
#import "UMComResouceDefines.h"
@implementation UMComSimplicityFindTableViewCell
- (void)awakeFromNib {
// Initialization code
self.titleNameLabel.font = UMComFontNotoSansLightWithSafeSize(17);
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (void)setCellStyleForLine:(UMComSimplicityCellLineStyle)style
{
CGRect frame;
if (style & UMComSimplicityCellLineStyleTop) {
frame = _topLine.frame;
frame.origin = CGPointMake(0.f, 0.f);
frame.size.width = self.frame.size.width;
_topLine.frame = frame;
_topLine.hidden = NO;
} else {
_topLine.hidden = YES;
}
if (style & UMComSimplicityCellLineStyleMiddle) {
frame = _bottomLine.frame;
frame.origin = CGPointMake(_titleNameLabel.frame.origin.x, self.frame.size.height);
frame.size.width = self.frame.size.width - frame.origin.x;
_bottomLine.frame = frame;
}
if (style & UMComSimplicityCellLineStyleBottom) {
frame = _bottomLine.frame;
frame.origin = CGPointMake(0.f, self.frame.size.height - 1);
frame.size.width = self.frame.size.width;
_bottomLine.frame = frame;
}
// _topLine.hidden = YES;
// _bottomLine.hidden = YES;
}
- (void)drawRect:(CGRect)rect
{
// UIColor *color = UMComColorWithHexString(UMCom_Feed_BgColor);
// CGContextRef context = UIGraphicsGetCurrentContext();
// CGFloat height = 2;
// CGRect drawFrame = CGRectMake(15, rect.size.height - height, rect.size.width-15, height);
// CGContextSetFillColorWithColor(context, color.CGColor);
// CGContextFillRect(context, drawFrame);
}
@end
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9532" systemVersion="14F27" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9530"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="FindTableViewCell" id="KGk-i7-Jjw" customClass="UMComSimplicityFindTableViewCell">
<rect key="frame" x="0.0" y="0.0" width="320" height="60"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
<rect key="frame" x="0.0" y="0.0" width="320" height="59.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" id="26Z-cq-Jxv">
<rect key="frame" x="15" y="16" width="25" height="26"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES"/>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="jmT-sd-hqO">
<rect key="frame" x="55" y="10" width="250" height="40"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<view contentMode="scaleToFill" id="gza-Nk-b0v" userLabel="top_line">
<rect key="frame" x="0.0" y="0.0" width="240" height="1"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" red="0.81568627450980391" green="0.82352941176470584" blue="0.82745098039215681" alpha="1" colorSpace="calibratedRGB"/>
</view>
<view contentMode="scaleToFill" id="UFI-Au-Qab" userLabel="bottom_line">
<rect key="frame" x="40" y="61" width="240" height="1"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" red="0.81568627450980391" green="0.82352941176470584" blue="0.82745098039215681" alpha="1" colorSpace="calibratedRGB"/>
</view>
</subviews>
</tableViewCellContentView>
<connections>
<outlet property="bottomLine" destination="UFI-Au-Qab" id="0dA-5Y-lwi"/>
<outlet property="titleImageView" destination="26Z-cq-Jxv" id="0uX-KH-F1O"/>
<outlet property="titleNameLabel" destination="jmT-sd-hqO" id="11G-NX-9Hb"/>
<outlet property="topLine" destination="gza-Nk-b0v" id="8VF-IE-RB2"/>
</connections>
<point key="canvasLocation" x="56" y="146"/>
</tableViewCell>
</objects>
</document>
@@ -0,0 +1,23 @@
//
// UMComUserInfoBar.h
// UMCommunity
//
// Created by umeng on 1/21/16.
// Copyright © 2016 Umeng. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "UMComImageView.h"
@interface UMComSimplicityUserInfoBar : UIView
@property (weak, nonatomic) IBOutlet UMComImageView *avatar;
@property (weak, nonatomic) IBOutlet UIView *userInfoBar;
@property (weak, nonatomic) IBOutlet UILabel *name;
@property (weak, nonatomic) IBOutlet UMComImageView *medalView;
@property (weak, nonatomic) IBOutlet UILabel *loginTip;
@property (weak, nonatomic) IBOutlet UIImageView *genderIcon;
- (void)refresh;
@end
@@ -0,0 +1,292 @@
//
// UMComUserInfoBar.m
// UMCommunity
//
// Created by umeng on 1/21/16.
// Copyright © 2016 Umeng. All rights reserved.
//
#import "UMComSimplicityUserInfoBar.h"
#import "UMComResouceDefines.h"
#import <UMCommunitySDK/UMComSession.h>
#import <UMComDataStorage/UMComUser.h>
#import <UMComDataStorage/UMComImageUrl.h>
#import "UMComMedalImageView.h"
#import <UMComDataStorage/UMComMedal.h>
#import "UMComLoginManager.h"
#import <UMComFoundation/UMComKit+Autolayout.h>
#import <UMComFoundation/UMComKit+Color.h>
#import "UMComNotificationMacro.h"
@interface UMComSimplicityUserInfoBar ()<UMComImageViewDelegate, UMImageViewDelegate>
//单个勋章显示
//@property(nonatomic,strong)UMComMedalImageView* medalView;
////多勋章布局
//@property(nonatomic,assign)NSInteger curMedalCount;//勋章的数量(最大5个)
//@property(nonatomic,strong)NSMutableArray* medalViewArray;//包含勋章控件
//-(void) createMedalViews;
//-(void) requestIMGForMedalViews:(UMComUser*)user;
//-(void) clearRequestForMedalViews;
//-(CGSize)computeMedalViewSize:(UMComMedalImageView*)medalView;
//-(void) layoutMedalViews;
@end
@implementation UMComSimplicityUserInfoBar
- (void)awakeFromNib
{
[super awakeFromNib];
// [self createMedalViews];
self.layer.borderColor = UMComColorWithHexString(@"#dfdfdf").CGColor;
self.layer.borderWidth = 1.f;
self.name.textColor = UMComColorWithHexString(@"#666666");
self.name.font = UMComFontNotoSansLightWithSafeSize(15);
__weak typeof(self) ws = self;
[[NSNotificationCenter defaultCenter] addObserverForName:kUserLoginSucceedNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
[ws refresh];
}];
[[NSNotificationCenter defaultCenter] addObserverForName:kUserUpdateAvatarSucceedNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
[ws refresh];
}];
}
- (void)refresh
{
UMComUser *user = [UMComSession sharedInstance].loginUser;
if (user) {
_name.text = user.name;
if (user.gender.integerValue == 0) {
_genderIcon.image = UMComSimpleImageWithImageName(@"um_com_female");
}
else{
_genderIcon.image = UMComSimpleImageWithImageName(@"um_com_male");
}
if (user.medal_list.count > 0) {
UMComMedal* medal = user.medal_list.firstObject;
if (medal && [medal isKindOfClass:[UMComMedal class]]) {
self.medalView.delegate = self;
self.medalView.isAutoStart = YES;
[self.medalView setImageURL:medal.icon_url placeHolderImage:UMComSimpleImageWithImageName(@"um_com_authorized_smal")];
}
else{
[self.medalView setImageURL:nil placeHolderImage:UMComSimpleImageWithImageName(@"um_com_authorized_smal")];
}
}
else
{
[self.medalView removeFromSuperview];
}
UMComColorWithHexString(@"34C035").CGColor;
[_avatar setImageURL:[user.icon_url small_url_string] placeHolderImage:UMComSimpleImageWithImageName(@"um_default_avatar")];
_loginTip.hidden = YES;
_userInfoBar.hidden = NO;
} else {
_loginTip.hidden = NO;
_userInfoBar.hidden = YES;
[_avatar setImage:UMComSimpleImageWithImageName(@"um_default_avatar")];
}
}
//- (void)hideInfoSubviews:(BOOL)hide
//{
// _name.hidden = hide;
// if (hide) {
// [self clearRequestForMedalViews];
// }
//}
-(void) updateMedalWithImageView:(UMImageView *)imageView;
{
CGFloat width = imageView.bounds.size.width;
CGFloat height = imageView.bounds.size.height;
CGSize imageSize = imageView.image.size;
width = imageSize.width * height/ imageSize.height;
[UMComKit ALView:imageView setConstraintConstant:width forAttribute:NSLayoutAttributeWidth];
}
- (void)imageViewLoadedImage:(UMImageView*)imageView
{
[self updateMedalWithImageView:imageView];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
//#pragma mark - 勋章相关
//-(void) createMedalViews
//{
// //创建默认的medalViewArray队列
// self.medalViewArray = [NSMutableArray arrayWithCapacity:[UMComMedalImageView maxMedalCount]];
//
// //创建勋章
// for(NSInteger i = 0; i < [UMComMedalImageView maxMedalCount]; i++)
// {
// UMComMedalImageView* medalView = [[UMComMedalImageView alloc] initWithFrame:CGRectMake(0, 0, [UMComMedalImageView defaultWidth], [UMComMedalImageView defaultHeight])];
// medalView.tag = i;
// medalView.contentMode = UIViewContentModeScaleAspectFit;
// [self.medalViewArray addObject:medalView];
// [self addSubview:medalView];
// }
//}
//
//-(void) requestIMGForMedalViews:(UMComUser*)user
//{
// if (user.medal_list.count > 0) {
// //确认当前勋章不能超过[UMComMedalImageView maxMedalCount]
// self.curMedalCount = user.medal_list.count;
// if (self.curMedalCount > [UMComMedalImageView maxMedalCount]) {
// self.curMedalCount = [UMComMedalImageView maxMedalCount];
// }
//
// for(int i = 0;i < self.curMedalCount; i++)
// {
// UMComMedalImageView* medalView = self.medalViewArray[i];
// if (medalView) {
// medalView.hidden = NO;
// UMComMedal* umcomMedal = (UMComMedal*)user.medal_list[i];
// if (umcomMedal && umcomMedal.icon_url) {
// medalView.imageLoaderDelegate = nil;
// medalView.isAutoStart = YES;
// [medalView setImageURL:[NSURL URLWithString:umcomMedal.icon_url] placeholderImage:nil];
// medalView.imageLoaderDelegate = self;
// }
// else{
// medalView.hidden = YES;
// }
//
// }
// }
//
// [self layoutMedalViews];
// }
//}
//
//-(void) clearRequestForMedalViews
//{
// for(int i = 0;i < self.medalViewArray.count; i++)
// {
// UMComMedalImageView* medalView = self.medalViewArray[i];
// if (medalView) {
// medalView.hidden = YES;
// medalView.imageLoaderDelegate = nil;
// }
// }
//}
//
//-(CGSize)computeMedalViewSize:(UMComMedalImageView*)medalView
//{
// if (!medalView) {
// return CGSizeMake(0, 0);
// }
//
// //先确定勋章图片的宽度和高度;
// CGFloat medalWidth = [UMComMedalImageView defaultWidth];
// CGFloat medalHeight = [UMComMedalImageView defaultHeight];
//
// CGSize cellSize = self.bounds.size;
//
// if (medalView.image) {
//
// CGSize tempSize = medalView.image.size;
//
// if (tempSize.height <= medalHeight) {
// medalHeight = tempSize.height;
// }
// else{
// //目前只是简单的判断图片的高度是否超过self.nameLabel.frame的高度
// if (tempSize.height < self.name.frame.size.height) {
// medalHeight = tempSize.height;
// }
// else
// {
// medalHeight = self.name.frame.size.height;
// }
// }
//
// if (tempSize.width <= medalWidth) {
// medalWidth = tempSize.width;
// }
// else{
// //根据图片的宽高比,算勋章的宽度
// medalWidth = medalHeight * tempSize.width / tempSize.height;
// if (medalWidth >= cellSize.width) {
// //如果宽度大于cell的宽度就设置为默认值(此处只是简单判断)
// medalWidth = [UMComMedalImageView defaultWidth];
// }
// }
// }
//
// medalView.bounds = CGRectMake(0, 0, medalWidth, medalHeight);
// return medalView.bounds.size;
//}
//
//-(void) layoutMedalViews
//{
// //先确定勋章图片的宽度和高度
// CGFloat totalMedalWidth = 0;
// for (int i = 0; i < self.curMedalCount; i++) {
//
// //先计算图片的宽高
// UMComMedalImageView* medalView = self.medalViewArray[i];
// if (medalView) {
// CGSize medalViewSize = [self computeMedalViewSize:medalView];
// totalMedalWidth += medalViewSize.width + [UMComMedalImageView spaceBetweenMedalViews];
// }
// }
//
// //计算nameLabel的宽度
// CGFloat nameLabelWidth = 0;
// CGFloat nameLabelMaxWidth = self.bounds.size.width - self.name.frame.origin.x - totalMedalWidth - 10;
// CGSize nameLabelSize = [self.name.text sizeWithFont:self.name.font];
// if (nameLabelSize.width > nameLabelMaxWidth) {
// nameLabelWidth = nameLabelMaxWidth;
// }
// else{
// nameLabelWidth = nameLabelSize.width;
// }
//
// //确定nameLabel的范围
// CGRect nameLabelFrame = self.name.frame;
// nameLabelFrame.size.width = nameLabelWidth;
// self.name.frame = nameLabelFrame;
//
// //确定medalViews的范围
// CGFloat offsetX = self.name.frame.origin.x + self.name.frame.size.width + 5;
// CGFloat offsetY = self.name.frame.origin.y;
// for (int i = 0; i < self.curMedalCount; i++) {
//
// UMComMedalImageView* medalView = self.medalViewArray[i];
// if (medalView) {
// CGRect medalViewFrame = medalView.frame;
// medalViewFrame.origin.x = offsetX;
// medalViewFrame.origin.y = offsetY;
// medalView.frame = medalViewFrame;
// offsetX += medalViewFrame.size.width + [UMComMedalImageView spaceBetweenMedalViews];
// }
// }
//}
//
//- (void)umcomImageViewLoadedImage:(UMComImageView *)imageView
//{
// [self layoutMedalViews];
//}
@end
@@ -0,0 +1,95 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9531" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="iN0-l3-epB" customClass="UMComSimplicityUserInfoBar">
<rect key="frame" x="0.0" y="0.0" width="510" height="91"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="IW5-50-zb3" customClass="UMComImageView">
<rect key="frame" x="15" y="5.5" width="80" height="80"/>
<constraints>
<constraint firstAttribute="height" constant="80" id="bHG-Qi-Kjn"/>
<constraint firstAttribute="width" constant="80" id="fTn-xP-h0c"/>
</constraints>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius">
<integer key="value" value="40"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</imageView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="I7o-mT-8xm" userLabel="user_info_bar">
<rect key="frame" x="105" y="21.5" width="405" height="49"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="name" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="mcd-Jr-OHp">
<rect key="frame" x="0.0" y="0.0" width="35.5" height="17"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" red="0.20000000000000001" green="0.20000000000000001" blue="0.20000000000000001" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="Jzu-pT-dae" userLabel="medal" customClass="UMComImageView">
<rect key="frame" x="0.0" y="27" width="22" height="22"/>
<constraints>
<constraint firstAttribute="width" constant="22" id="02v-Kj-t8X"/>
<constraint firstAttribute="height" constant="22" id="e3v-Dt-LgB"/>
</constraints>
</imageView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="Jzu-pT-dae" firstAttribute="leading" secondItem="mcd-Jr-OHp" secondAttribute="leading" id="8MI-pH-IPY"/>
<constraint firstItem="mcd-Jr-OHp" firstAttribute="top" secondItem="I7o-mT-8xm" secondAttribute="top" id="NAj-kg-BGK"/>
<constraint firstAttribute="bottom" secondItem="Jzu-pT-dae" secondAttribute="bottom" id="lWz-dF-Pru"/>
<constraint firstItem="mcd-Jr-OHp" firstAttribute="bottom" secondItem="Jzu-pT-dae" secondAttribute="top" constant="-10" id="nj3-vx-kg7"/>
<constraint firstItem="mcd-Jr-OHp" firstAttribute="leading" secondItem="I7o-mT-8xm" secondAttribute="leading" id="wJD-w7-LJR"/>
<constraint firstAttribute="bottom" secondItem="mcd-Jr-OHp" secondAttribute="bottom" priority="750" id="yyo-Sp-Euz"/>
</constraints>
</view>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="立即登录" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="o8g-O3-l18" userLabel="loginTip">
<rect key="frame" x="106" y="36" width="64" height="19.5"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="2DZ-Gh-dDT" userLabel="gender_icon">
<rect key="frame" x="76" y="66.5" width="16" height="16"/>
<constraints>
<constraint firstAttribute="width" constant="16" id="UCu-rD-1fF"/>
<constraint firstAttribute="height" constant="16" id="cEb-54-HzH"/>
</constraints>
</imageView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="2DZ-Gh-dDT" firstAttribute="bottom" secondItem="IW5-50-zb3" secondAttribute="bottom" constant="-3" id="AaT-dd-DbV"/>
<constraint firstItem="o8g-O3-l18" firstAttribute="leading" secondItem="IW5-50-zb3" secondAttribute="trailing" constant="11" id="Brm-Pc-1lg"/>
<constraint firstItem="2DZ-Gh-dDT" firstAttribute="trailing" secondItem="IW5-50-zb3" secondAttribute="trailing" constant="-3" id="F03-Va-nKB"/>
<constraint firstItem="I7o-mT-8xm" firstAttribute="leading" secondItem="IW5-50-zb3" secondAttribute="trailing" constant="10" id="OXW-qE-KsS"/>
<constraint firstItem="o8g-O3-l18" firstAttribute="centerY" secondItem="IW5-50-zb3" secondAttribute="centerY" id="OcU-Sm-vZz"/>
<constraint firstItem="IW5-50-zb3" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="15" id="RK8-4l-fOF"/>
<constraint firstAttribute="trailing" secondItem="I7o-mT-8xm" secondAttribute="trailing" id="cQQ-K1-M1E"/>
<constraint firstItem="I7o-mT-8xm" firstAttribute="centerY" secondItem="IW5-50-zb3" secondAttribute="centerY" id="tdc-Wn-caG"/>
<constraint firstItem="IW5-50-zb3" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="centerY" id="tk8-DP-crZ"/>
</constraints>
<nil key="simulatedStatusBarMetrics"/>
<nil key="simulatedTopBarMetrics"/>
<nil key="simulatedBottomBarMetrics"/>
<simulatedOrientationMetrics key="simulatedOrientationMetrics"/>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<connections>
<outlet property="avatar" destination="IW5-50-zb3" id="Rya-Wl-W9f"/>
<outlet property="genderIcon" destination="2DZ-Gh-dDT" id="YFf-Fv-dcx"/>
<outlet property="loginTip" destination="o8g-O3-l18" id="9h7-au-byY"/>
<outlet property="medalView" destination="Jzu-pT-dae" id="rhp-jk-aet"/>
<outlet property="name" destination="mcd-Jr-OHp" id="R3Y-Gg-CkW"/>
<outlet property="userInfoBar" destination="I7o-mT-8xm" id="dKO-Y2-zGE"/>
</connections>
<point key="canvasLocation" x="302" y="289.5"/>
</view>
</objects>
</document>