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,56 @@
//
// UIViewController+UMComAddition.h
// UMCommunity
//
// Created by umeng on 15/5/8.
// Copyright (c) 2015年 Umeng. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIViewController (UMComAddition)
- (void)setBackButtonWithTitle:(NSString *)title;
- (void)setBackButtonWithImage;
- (void)setBackButtonWithImage:(UIImage*)image;
- (void)setLeftButtonWithTitle:(NSString *)title action:(SEL)action;
- (void)setLeftButtonWithImageName:(NSString *)imageName action:(SEL)action;
- (void)setBackButtonWithImageName:(NSString *)imageName buttonSize:(CGSize)size action:(SEL)action;
- (void)setLeftButtonWithImage:(UIImage*)image action:(SEL)action;
- (void)setBackButtonWithImage:(UIImage*)image buttonSize:(CGSize)size action:(SEL)action;
- (void)setRightButtonWithTitle:(NSString *)title action:(SEL)action;
- (void)setRightButtonWithImageName:(NSString *)imageName action:(SEL)action;
- (void)setRightButtonWithImage:(UIImage *)image action:(SEL)action;
- (void)setTitleViewWithTitle:(NSString *)title;
//论坛版UItitle设置方法
- (void)setForumUITitle:(NSString *)title;
//论坛版返回按钮设置方法
- (void)setForumUIBackButton;
- (void)setForumUIBackButtonWithImage:(UIImage*)image;
- (void)setTitle:(NSString *)title font:(UIFont *)font titleColor:(UIColor *)color;
- (void)showTipLableFromTopWithTitle:(NSString *)title;
- (void)transitionFromViewControllerAtIndex:(NSInteger)fromIndex
toViewControllerAtIndex:(NSInteger)toIndex
duration:(NSTimeInterval)duration
options:(UIViewAnimationOptions)options
animations:(void (^ __nullable)(void))animations
completion:(void (^ __nullable)(BOOL finished))completion;
- (void)transitionFromViewControllerAtIndex:(NSInteger)fromIndex
toViewControllerAtIndex:(NSInteger)toIndex
animations:(void (^ __nullable)(void))animations
completion:(void (^ __nullable)(BOOL finished))completion;
@end
@@ -0,0 +1,309 @@
//
// UIViewController+UMComAddition.m
// UMCommunity
//
// Created by umeng on 15/5/8.
// Copyright (c) 2015年 Umeng. All rights reserved.
//
#import "UIViewController+UMComAddition.h"
#import "UMComResouceDefines.h"
#import <objc/runtime.h>
#import "UMComBarButtonItem.h"
#import <UMComFoundation/UMComKit+Color.h>
const char kTopTipLabelKey;
const char kAnimating;
@implementation UIViewController (UMComAddition)
- (void)setBackButtonWithTitle:(NSString *)title
{
if ([[UIDevice currentDevice].systemVersion floatValue] < 7.0 || self.navigationController.viewControllers.count == 1) {
self.navigationController.navigationItem.leftBarButtonItem = nil;
UIBarButtonItem *backButtonItem = [[UMComBarButtonItem alloc] initWithTitle:title target:self action:@selector(goBack)];
backButtonItem.customView.frame = CGRectMake(0, 0, 40, 35);
self.navigationItem.leftBarButtonItem = backButtonItem;
}
}
- (void)setBackButtonWithImage
{
if ([[UIDevice currentDevice].systemVersion floatValue] < 7.0 || self.navigationController.viewControllers.count <= 1) {
self.navigationController.navigationItem.leftBarButtonItem = nil;
UMComBarButtonItem *backButtonItem = [[UMComBarButtonItem alloc] initWithNormalImageName:@"Backx" target:self action:@selector(goBack)];
backButtonItem.customView.frame = CGRectMake(0, 0, 40, 35);
backButtonItem.customButtonView.frame = CGRectMake(5, 0, 20, 20);
self.navigationItem.leftBarButtonItem = backButtonItem;
}
}
- (void)setBackButtonWithImage:(UIImage*)image
{
if ([[UIDevice currentDevice].systemVersion floatValue] < 7.0 || self.navigationController.viewControllers.count <= 1) {
self.navigationController.navigationItem.leftBarButtonItem = nil;
UMComBarButtonItem *backButtonItem = [[UMComBarButtonItem alloc] initWithNormalImage:image target:self action:@selector(goBack)];
backButtonItem.customView.frame = CGRectMake(0, 0, 40, 35);
backButtonItem.customButtonView.frame = CGRectMake(5, 0, 20, 20);
self.navigationItem.leftBarButtonItem = backButtonItem;
}
}
- (void)setLeftButtonWithTitle:(NSString *)title action:(SEL)action
{
UIBarButtonItem *backButtonItem = [[UMComBarButtonItem alloc] initWithTitle:title target:self action:@selector(action)];
backButtonItem.customView.frame = CGRectMake(0, 0, 40, 35);
self.navigationItem.leftBarButtonItem = backButtonItem;
}
- (void)setLeftButtonWithImageName:(NSString *)imageName action:(SEL)action
{
[self setBackButtonWithImageName:imageName buttonSize:CGSizeMake(20, 20) action:action];
}
- (void)setBackButtonWithImageName:(NSString *)imageName buttonSize:(CGSize)size action:(SEL)action
{
UMComBarButtonItem *backButtonItem = [[UMComBarButtonItem alloc] initWithNormalImageNameWithBackItem:imageName target:self action:@selector(goBack)];
if (!backButtonItem) {
NSLog(@"backButtonItem must not nil");
return;
}
backButtonItem.customView.frame = CGRectMake(0, 0, size.width + 10 , size.height);
backButtonItem.customButtonView.frame = CGRectMake(10, 0, size.width, size.height);
//self.navigationItem.leftBarButtonItem = backButtonItem;
//通过设置leftBarButtonItems中一个固定偏移来设置左边返回按钮的点击返回,让用户方便点击
if ([[[[UIDevice currentDevice] systemVersion] substringToIndex:1] intValue]< 8) {
UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
negativeSpacer.width = -10;
self.navigationItem.leftBarButtonItems = @[negativeSpacer, backButtonItem];
}else{
//在IOS8.0以上把返回按钮的坐标设置为0
CGRect backButtonRC = backButtonItem.customButtonView.frame;
backButtonRC.origin.x = 0;
backButtonItem.customButtonView.frame = backButtonRC;
self.navigationItem.leftBarButtonItem = backButtonItem;
}
}
- (void)setLeftButtonWithImage:(UIImage*)image action:(SEL)action
{
[self setBackButtonWithImage:image buttonSize:CGSizeMake(20, 20) action:action];
}
- (void)setBackButtonWithImage:(UIImage*)image buttonSize:(CGSize)size action:(SEL)action
{
UMComBarButtonItem *backButtonItem = [[UMComBarButtonItem alloc] initWithNormalImageWithBackItem:image target:self action:@selector(goBack)];
if (!backButtonItem) {
NSLog(@"backButtonItem must not nil");
return;
}
backButtonItem.customView.frame = CGRectMake(0, 0, size.width + 10 , size.height);
backButtonItem.customButtonView.frame = CGRectMake(10, 0, size.width, size.height);
//self.navigationItem.leftBarButtonItem = backButtonItem;
//通过设置leftBarButtonItems中一个固定偏移来设置左边返回按钮的点击返回,让用户方便点击
if ([[[[UIDevice currentDevice] systemVersion] substringToIndex:1] intValue]< 8) {
UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
negativeSpacer.width = -10;
self.navigationItem.leftBarButtonItems = @[negativeSpacer, backButtonItem];
}else{
//在IOS8.0以上把返回按钮的坐标设置为0
CGRect backButtonRC = backButtonItem.customButtonView.frame;
backButtonRC.origin.x = 0;
backButtonItem.customButtonView.frame = backButtonRC;
self.navigationItem.leftBarButtonItem = backButtonItem;
}
}
- (void)setRightButtonWithTitle:(NSString *)title action:(SEL)action
{
UIBarButtonItem *rightButtonItem = [[UMComBarButtonItem alloc] initWithTitle:title target:self action:action];
rightButtonItem.customView.frame = CGRectMake(0, 0, 40, 35);
self.navigationItem.rightBarButtonItem = rightButtonItem;
}
- (void)setRightButtonWithImageName:(NSString *)imageName action:(SEL)action
{
UMComBarButtonItem *rightButtonItem = [[UMComBarButtonItem alloc] initWithNormalImageName:imageName target:self action:action];
self.navigationItem.rightBarButtonItem = rightButtonItem;
}
- (void)setRightButtonWithImage:(UIImage *)image action:(SEL)action
{
UMComBarButtonItem *rightButtonItem = [[UMComBarButtonItem alloc] initWithNormalImage:image target:self action:action];
self.navigationItem.rightBarButtonItem = rightButtonItem;
}
- (void)setTitleViewWithTitle:(NSString *)title
{
[self setForumUITitle:title];
// [self setTitle:title font:UMComFontNotoSansLightWithSafeSize(18) titleColor:[UIColor blackColor]];
}
- (void)setForumUITitle:(NSString *)title
{
[self setTitle:title font:UMComFontNotoSansLightWithSafeSize(UMCom_ForumUI_Title_Font) titleColor:UMComColorWithHexString(UMCom_ForumUI_Title_Color)];
}
- (void)setTitle:(NSString *)title font:(UIFont *)font titleColor:(UIColor *)color
{
UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(100, 0, self.view.frame.size.width-200, 100)];
titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.font = font;
titleLabel.text= title;
titleLabel.textColor = color;
[self.navigationItem setTitleView:titleLabel];
}
- (void)setForumUIBackButton
{
[self setBackButtonWithImageName:@"um_forum_back_gray" buttonSize:CGSizeMake(10, 19) action:@selector(goBack)];
}
- (void)setForumUIBackButtonWithImage:(UIImage*)image
{
[self setBackButtonWithImage:image buttonSize:CGSizeMake(10, 19) action:@selector(goBack)];
}
- (void)goBack
{
if (self.navigationController.viewControllers.count > 1) {
[self.navigationController popViewControllerAnimated:YES];
}else{
[self dismissViewControllerAnimated:YES completion:^{
}];
}
}
- (void)showTipLableFromTopWithTitle:(NSString *)title
{
UILabel *tipLabel = objc_getAssociatedObject(self, &kTopTipLabelKey);//[self creatTipLabelWithTitle:title];
if (!tipLabel) {
tipLabel = [self creatTipLabel];
tipLabel.backgroundColor = UMComColorWithHexString(FontColorBlue);
tipLabel.textColor = [UIColor whiteColor];
objc_setAssociatedObject(self, &kTopTipLabelKey, tipLabel, OBJC_ASSOCIATION_ASSIGN);
}
tipLabel.text = title;
tipLabel.frame = CGRectMake(0, -40, tipLabel.frame.size.width, tipLabel.frame.size.height);
[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
tipLabel.frame = CGRectMake(0, 0, tipLabel.frame.size.width, tipLabel.frame.size.height);
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.5 delay:1 options:UIViewAnimationOptionCurveEaseOut animations:^{
tipLabel.frame = CGRectMake(0, -40, tipLabel.frame.size.width, tipLabel.frame.size.height);
} completion:^(BOOL finished) {
}];
}];
}
- (UILabel *)creatTipLabel
{
UILabel *tipLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, -40, self.view.frame.size.width, 40)];
tipLabel.backgroundColor = [UIColor clearColor];
tipLabel.textColor = [UIColor blackColor];
tipLabel.alpha = 0.8;
tipLabel.font = UMComFontNotoSansLightWithSafeSize(16);
tipLabel.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:tipLabel];
return tipLabel;
}
- (void)transitionFromViewControllerAtIndex:(NSInteger)fromIndex toViewControllerAtIndex:(NSInteger)toIndex duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^ __nullable)(void))animations completion:(void (^ __nullable)(BOOL finished))completion
{
if (fromIndex >= self.childViewControllers.count || toIndex >= self.childViewControllers.count) {
NSLog(@"index is beyond self.childViewControllers.count");
if (completion) {
completion(YES);
}
return;
}
if (fromIndex == toIndex) {
if (completion) {
completion(YES);
}
return;
}
// __block NSNumber *isAnimating = objc_getAssociatedObject(self, &kAnimating);//[self creatTipLabelWithTitle:title];
// if (isAnimating == nil) {
// isAnimating = [NSNumber numberWithBool:NO];
// objc_setAssociatedObject(self, &kAnimating, isAnimating, OBJC_ASSOCIATION_ASSIGN);
// }
// if ([isAnimating boolValue] == YES) {
// return;
// }
// isAnimating = [NSNumber numberWithBool:YES];
// objc_setAssociatedObject(self, &kAnimating, isAnimating, OBJC_ASSOCIATION_ASSIGN);
UIViewController *fromViewController = self.childViewControllers[fromIndex];
UIViewController *toViewController = self.childViewControllers[toIndex];
// __block CGPoint fromCenter = fromViewController.view.center;
// CGRect currentFrame = toViewController.view.frame;
// currentFrame.size.height = self.view.frame.size.height - currentFrame.origin.y;
// if (currentFrame.size.height != toViewController.view.frame.size.height) {
// toViewController.view.frame = currentFrame;
// }
// CGPoint toCenter = toViewController.view.center;
//// if (fromIndex == toIndex) {
// toCenter.x = self.view.frame.size.width/2;
// toViewController.view.center = toCenter;
// isAnimating = [NSNumber numberWithBool:NO];
// objc_setAssociatedObject(self, &kAnimating, isAnimating, OBJC_ASSOCIATION_ASSIGN);
// return;
// }
// if (toIndex > fromIndex) {
// if (toViewController.view.frame.origin.x <= 0) {
// toCenter.x = self.view.frame.size.width*3/2;
// toViewController.view.center = toCenter;
// }
// }else if(toIndex < fromIndex){
// if (toViewController.view.frame.origin.x >= 0) {
// toCenter.x = - self.view.frame.size.width*3/2;
// toViewController.view.center = toCenter;
// }
// }
// __weak typeof(self) weakSelf = self;
[self transitionFromViewController:fromViewController toViewController:toViewController duration:duration options:options animations:^{
// if (fromViewController == toViewController) {
// isAnimating = [NSNumber numberWithBool:YES];
// objc_setAssociatedObject(self, &kAnimating, isAnimating, OBJC_ASSOCIATION_ASSIGN);
// return ;
// }
// toViewController.view.center = CGPointMake(weakSelf.view.frame.size.width/2, toViewController.view.center.y);
// if (toIndex > fromIndex) {
// fromCenter.x = - weakSelf.view.frame.size.width*3/2;
// }else if(toIndex < fromIndex){
// fromCenter.x = weakSelf.view.frame.size.width*3/2;
// }
// fromViewController.view.center = fromCenter;
if (animations) {
animations();
}
} completion:^(BOOL finished) {
// isAnimating = [NSNumber numberWithBool:NO];
// objc_setAssociatedObject(self, &kAnimating, isAnimating, OBJC_ASSOCIATION_ASSIGN);
if (completion) {
completion(YES);
}
}];
}
- (void)transitionFromViewControllerAtIndex:(NSInteger)fromIndex
toViewControllerAtIndex:(NSInteger)toIndex
animations:(void (^ __nullable)(void))animations
completion:(void (^ __nullable)(BOOL finished))completion
{
[self transitionFromViewControllerAtIndex:fromIndex toViewControllerAtIndex:toIndex duration:0.1 options:UIViewAnimationOptionCurveEaseIn animations:animations completion:completion];
}
@end
@@ -0,0 +1,13 @@
//
// UMComNavigationController.h
// UMCommunity
//
// Created by Gavin Ye on 8/27/14.
// Copyright (c) 2014 Umeng. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UMComNavigationController : UINavigationController
@end
@@ -0,0 +1,46 @@
//
// UMComNavigationController.m
// UMCommunity
//
// Created by Gavin Ye on 8/27/14.
// Copyright (c) 2014 Umeng. All rights reserved.
//
#import "UMComNavigationController.h"
#import "UMComResouceDefines.h"
#import <UMComFoundation/UMComKit+Color.h>
@interface UMComNavigationController ()
@end
@implementation UMComNavigationController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
if ([[UIDevice currentDevice].systemVersion floatValue] < 7) {
[self.navigationBar setBackgroundColor:UMComColorWithHexString(@"#f7f7f8")];
[self.navigationBar setBackgroundImage:[[UIImage alloc]init] forBarMetrics:UIBarMetricsDefault];
}else{
[self.navigationBar setBarTintColor:UMComColorWithHexString(@"#f7f7f8")];
}
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
@@ -0,0 +1,117 @@
//
// UMComRequestTableViewController.h
// UMCommunity
//
// Created by umeng on 15/11/16.
// Copyright © 2015年 Umeng. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "UMComListDataController.h"
#import <UMComDataStorage/UMComDataBaseManager.h>
typedef void (^UMComLoadSeverDataCompletionHandler)(NSArray *data,NSError *error);
@protocol UMComScrollViewDelegate;
@class UMComHeadView,UMComFootView;
@interface UMComRequestTableViewController : UIViewController<UITableViewDelegate, UITableViewDataSource>
/**
*继承与UMComRequestTableViewController的TableViewController都带有一个dataController,负责处理为TableViewController处理数据和业务逻辑,并未tableView提供显示的model
*/
@property (nonatomic, strong) UMComListDataController *dataController;
/**
* tableView
*/
@property (nonatomic, strong) UITableView *tableView;
/**
*下拉刷新控件
*/
@property (nonatomic, strong) UMComHeadView *refreshHeadView;
/**
*上拉加载控件
*/
@property (nonatomic, strong) UMComFootView *refreshFootView;
///**
// *下拉刷新控件
// */
//@property (nonatomic, strong) UIRefreshControl *refreshControl;
/**
*显示数据为空或网络问题label
*/
@property (nonatomic, strong) UILabel *noDataTipLabel;
/**
*tableView上次滚动的位置
*/
@property (nonatomic, assign, readonly) CGPoint lastPosition;
/**
*是否自动加载数据
*/
@property (nonatomic, assign) BOOL isAutoStartLoadData;
/**
*网络数据是否加载完成
*/
@property (nonatomic, assign) BOOL isLoadFinish;
/**
*是否显示数据为空的提示
*/
@property (nonatomic, assign) BOOL doNotShowNodataNote;
/**
*tableView滚动delegate
*/
@property (nonatomic, weak) id<UMComScrollViewDelegate> scrollViewDelegate;
@property (nonatomic, copy) UMComLoadSeverDataCompletionHandler refreshSeverDataCompletionHandler;
@property (nonatomic, copy) UMComLoadSeverDataCompletionHandler loadMoreDataCompletionHandler;
- (BOOL)isBeginScrollBottom:(UIScrollView *)scrollView;
- (BOOL)isScrollToBottom:(UIScrollView *)scrollView;
#pragma mark - data request method
/**
* 请求本地数据(先请求本地数据在请求网络数据,适合没网的时候显示本地数据)
*/
- (void)fetchLocalData;
/**
*刷新数据(第一页数据)
*/
- (void)refreshData;
/**
* 加载更多(下一页数据)
*/
- (void)loadMoreData;
#pragma mark - data handle method
/**
*处理本地数据
*/
- (void)handleLocalData:(NSArray *)data error:(NSError *)error;
/**
*处理网络请求第一页数据
*/
- (void)handleFirstPageData:(NSArray *)data error:(NSError *)error;
/**
*处理网络请求下一页数据
*/
- (void)handleNextPageData:(NSArray *)data error:(NSError *)error;
@end
@@ -0,0 +1,424 @@
//
// UMComRequestTableViewController.m
// UMCommunity
//
// Created by umeng on 15/11/16.
// Copyright © 2015年 Umeng. All rights reserved.
//
#import "UMComRequestTableViewController.h"
#import "UMComScrollViewDelegate.h"
#import "UIViewController+UMComAddition.h"
#import <UMCommunitySDK/UMComSession.h>
#import "UMComShowToast.h"
#import "UMComRefreshView.h"
#import <UMComFoundation/UMComKit+Color.h>
typedef NS_ENUM(NSInteger, UMComVisitType){
UMComVisitType_None = -1, //< 初始化状态
UMComVisitType_VisitNeedLoginForMoreData = 0, //< 需要登录才能访问更多数据
UMComVisitType_VisitNeedLoginForNoMoreData = 1, //< 需要登录访问,但是没有下一页数据
UMComVisitType_Visit = 2, //< 可以访问(目前没有用到,UMComVisitType_VisitForMoreData和UMComVisitType_VisitForNoMoreData都可以表示可以访问)
UMComVisitType_VisitForMoreData = 3, //< 可以访问下一页数据
UMComVisitType_VisitForNoMoreData = 4 //< 可以访问没有下一页数据
};
@interface UMComRequestTableViewController ()<UITableViewDelegate, UITableViewDataSource, UMComScrollViewDelegate>
@property (nonatomic, assign) CGPoint lastPosition;
@property(nonatomic,assign)UMComVisitType visitMoreDataMode;
//检查是否访客模式
-(BOOL) canVisitNextPage;
-(void) refreshDataFromServer;
@end
@implementation UMComRequestTableViewController
- (instancetype)init
{
self = [super init];
if (self) {
[self initData];
}
return self;
}
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
[self initData];
}
return self;
}
- (void)initData
{
self.isLoadFinish = YES;
self.isAutoStartLoadData = YES;
self.visitMoreDataMode = UMComVisitType_None;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.isLoadFinish = YES;
self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:self.tableView];
if ([self respondsToSelector:@selector(edgesForExtendedLayout)]) {
[self setEdgesForExtendedLayout:UIRectEdgeNone];
}
__weak typeof(self) weakSelf = self;
self.refreshHeadView = (UMComHeadView *)[UMComHeadView refreshControllViewWithScrollView:self.tableView block:^{
[weakSelf refreshData];
}];
self.refreshFootView = (UMComFootView *)[UMComFootView refreshControllViewWithScrollView:self.tableView block:^{
[weakSelf loadMoreData];
}];
self.tableView.separatorColor = UMComColorWithHexString(UMCom_Feed_BgColor);
if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[self.tableView setSeparatorInset:UIEdgeInsetsZero];
}
if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)])
{
[self.tableView setLayoutMargins:UIEdgeInsetsZero];
}
self.scrollViewDelegate = self;
[self setForumUIBackButtonWithImage:UMComImageWithImageName(@"um_forum_back_gray")];
[self setForumUITitle:self.title];
[self updateTableviewConstraints];
}
- (void)updateTableviewConstraints
{
UITableView *tableView = self.tableView;
[tableView setTranslatesAutoresizingMaskIntoConstraints:NO];
NSDictionary *dict1 = NSDictionaryOfVariableBindings(tableView);
NSDictionary *metrics = @{@"hPadding":@0,@"topPadding":@0,@"vPadding":@0};
NSString *vfl = @"|-hPadding-[tableView]-hPadding-|";
NSString *vfl0 = @"V:|-topPadding-[tableView]-vPadding-|";
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:vfl options:0 metrics:metrics views:dict1]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:vfl0 options:0 metrics:metrics views:dict1]];
}
- (void)creatNoFeedTip
{
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height/2-40, self.view.frame.size.width,40)];
label.backgroundColor = [UIColor clearColor];
label.text = UMComLocalizedString(@"um_com_emptyData", @"暂时没有内容哦!");
label.font = UMComFontNotoSansLightWithSafeSize(17);
label.textColor = UMComColorWithHexString(FontColorGray);
label.textAlignment = NSTextAlignmentCenter;
label.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
label.hidden = YES;
[self.view addSubview:label];
self.noDataTipLabel = label;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
if (!self.noDataTipLabel && self.doNotShowNodataNote == NO) {
[self creatNoFeedTip];
}
// 未登录时发送请求可能会不断收到未登录错误码而不断弹出登录
// 修改为第一次加载后开始手动下拉刷新加载
if (self.isAutoStartLoadData && self.isLoadFinish) {
[self refreshData];
self.isAutoStartLoadData = NO;
}else{
[self.tableView reloadData];
}
// //首先判断非访客模式===begin
// if (self.visitMoreDataMode == UMComVisitType_None) {
// //第一次进入的时候初始化为UMComVisitType_None的时候,表示未知状态,不需要判断其是否为访客模式,需要等到第一次网络请求到了,包含的访客模式(即为visitMoreDataMode赋非UMComVisitType_None的值)
// return;
// }
//
// //如果当前是访客模式即登录了,但是visitMoreDataMode为非访客模式,就需要修改其提示加载更多
// if ([self canVisitNextPage]) {
// if (self.visitMoreDataMode == UMComVisitType_VisitNeedLoginForMoreData)
// {
// //非访客模式直接显示加载更多
// [self.loadMoreStatusView setLoadStatus:UMComNoLoad];
// }
// else if (self.visitMoreDataMode == UMComVisitType_VisitNeedLoginForNoMoreData)
// {
// //非访客模式直接显示加载完成
// [self.loadMoreStatusView setLoadStatus:UMComFinish];
// }
// else if (self.visitMoreDataMode == UMComVisitType_VisitForMoreData)
// {
// [self.loadMoreStatusView setLoadStatus:UMComNoLoad];
// }
// else if (self.visitMoreDataMode == UMComVisitType_VisitForNoMoreData)
// {
// [self.loadMoreStatusView setLoadStatus:UMComFinish];
// }
// else{}
// }
// //首先判断非访客模式===end
}
////
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (self.dataController.dataArray.count > 0)//有数据
{
self.noDataTipLabel.hidden = YES;
}
else//数据为空
{
self.noDataTipLabel.hidden = NO;
}
return self.dataController.dataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellId = @"cellId";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
}
return cell;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (self.isLoadFinish && self.scrollViewDelegate && [self.scrollViewDelegate respondsToSelector:@selector(customScrollViewDidScroll:lastPosition:)]) {
[self.scrollViewDelegate customScrollViewDidScroll:scrollView lastPosition:self.lastPosition];
}
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
self.lastPosition = scrollView.contentOffset;
if (self.scrollViewDelegate && [self.scrollViewDelegate respondsToSelector:@selector(customScrollViewDidEnd:lastPosition:)]) {
[self.scrollViewDelegate customScrollViewDidEnd:scrollView lastPosition:self.lastPosition];
}
self.lastPosition = scrollView.contentOffset;
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
// [self refreshScrollViewDidEndDragging:scrollView];
if (self.scrollViewDelegate && [self.scrollViewDelegate respondsToSelector:@selector(customScrollViewEndDrag:lastPosition:)]) {
[self.scrollViewDelegate customScrollViewEndDrag:scrollView lastPosition:self.lastPosition];
}
self.lastPosition = scrollView.contentOffset;
}
#pragma mark - refreshdelegate
- (void)refreshData:(UMComRefreshView *)refreshView
{
[self refreshData];
}
- (void)loadMoreData:(UMComRefreshView *)refreshView
{
[self loadMoreData];
}
#pragma mark - UMComRefreshTableViewDelegate
- (void) fetchLocalData
{
__weak typeof(self) weakSelf = self;
[self.dataController fetchLocalDataWithCompletion:^(NSArray *dataArray, NSError *error) {
if (dataArray && [dataArray isKindOfClass:[NSArray class]] && dataArray.count > 0) {
[weakSelf handleLocalData:dataArray error:error];
[weakSelf.tableView reloadData];
}
[weakSelf refreshDataFromServer];
}];
}
- (void)refreshData
{
if (self.dataController.isReadLoacalData) {
//设置NO只会第一次下拉刷新取本地数据
self.dataController.isReadLoacalData = NO;
//取本地数据的话,就不需要显示loadMoreStatusView的views
[self fetchLocalData];
}
else{
[self refreshDataFromServer];
}
}
-(void)refreshDataFromServer
{
if (!self.dataController) {
[self.refreshHeadView noMoreData];
return;
}
if (self.isLoadFinish == NO) {
return;
}
self.isLoadFinish = NO;
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
__weak typeof(self) weakSelf = self;
[self.dataController refreshNewDataCompletion:^(NSArray *responseData, NSError *error) {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
[UMComShowToast showFetchResultTipWithError:error];
if (!error) {
[weakSelf.refreshHeadView endLoading];
if (weakSelf.dataController.haveNextPage) {
[weakSelf.refreshFootView endLoading];
}else{
[weakSelf.refreshFootView noMoreData];
}
}else{
[weakSelf.refreshHeadView endLoading];
weakSelf.refreshHeadView.statusLable.text = UMComLocalizedString(@"server_error", @"网络请求失败");
}
weakSelf.isLoadFinish = YES;
if (weakSelf.refreshSeverDataCompletionHandler) {
weakSelf.refreshSeverDataCompletionHandler(responseData, error);
}
[weakSelf handleFirstPageData:responseData error:error];
[weakSelf.tableView reloadData];
}];
}
- (void)loadMoreData
{
//首先判断非访客模式===begin
if (![self canVisitNextPage]) {
[self.refreshFootView endLoading];
self.refreshFootView.statusLable.text = @"登录加载更多";
return;
}
// //非访客模式,并且请求了第一次的网络数据
// if(![self canVisitNextPage] && self.visitMoreDataMode != UMComVisitType_None)
// {
//
// return;
// }
if (self.isLoadFinish == NO) {
return;
}
if (!self.dataController) {
[self.refreshFootView noMoreData];
return;
}
self.isLoadFinish = NO;
__weak typeof(self) weakSelf = self;
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
[self.dataController loadNextPageDataWithCompletion:^(NSArray *responseData, NSError *error) {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
weakSelf.isLoadFinish = YES;
if (!error) {
if (weakSelf.dataController.haveNextPage) {
[weakSelf.refreshFootView endLoading];
}else{
[weakSelf.refreshFootView noMoreData];
}
}else{
[weakSelf.refreshFootView endLoading];
weakSelf.refreshFootView.statusLable.text = UMComLocalizedString(@"server_error", @"网络请求失败");
}
if (weakSelf.loadMoreDataCompletionHandler) {
weakSelf.loadMoreDataCompletionHandler(responseData, error);
}
[weakSelf handleNextPageData:responseData error:error];
if (responseData) {
[weakSelf.tableView reloadData];
}
}];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/**
* 登陆用户和访客模式都会返回true,因其拥有一样的权限
*
* @return true 表示有权限查看下一页 false 代表没有权限查看下一页
*/
-(BOOL) canVisitNextPage
{
//登陆用户
if ([UMComSession sharedInstance].isLogin) {
return YES;
}
return self.dataController.canVisitNextPage;
}
#pragma mark - data handle method
/**
*处理本地数据
*/
- (void)handleLocalData:(NSArray *)data error:(NSError *)error
{
if (error) {
[UMComShowToast showFetchResultTipWithError:error];
}else{
}
}
/**
*处理网络请求第一页数据
*/
- (void)handleFirstPageData:(NSArray *)data error:(NSError *)error
{
if (error) {
[UMComShowToast showFetchResultTipWithError:error];
}else{
}
}
/**
*处理网络请求下一页数据
*/
- (void)handleNextPageData:(NSArray *)data error:(NSError *)error
{
if (error) {
[UMComShowToast showFetchResultTipWithError:error];
}else{
}
}
@end
@@ -0,0 +1,20 @@
//
// UMComScrollViewDelegate.h
// UMCommunity
//
// Created by umeng on 15/7/27.
// Copyright (c) 2015年 Umeng. All rights reserved.
//
#import <Foundation/Foundation.h>
@protocol UMComScrollViewDelegate <NSObject>
@optional;
- (void)customScrollViewDidScroll:(UIScrollView *)scrollView lastPosition:(CGPoint)lastPosition;
- (void)customScrollViewDidEnd:(UIScrollView *)scrollView lastPosition:(CGPoint)lastPosition;
- (void)customScrollViewEndDrag:(UIScrollView *)scrollView lastPosition:(CGPoint)lastPosition;
@end
@@ -0,0 +1,15 @@
//
// UMComViewController.h
// UMCommunity
//
// Created by umeng on 15/9/14.
// Copyright (c) 2015年 Umeng. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UMComViewController : UIViewController
@property (nonatomic, assign) BOOL doNotShowBackButton;
@end
@@ -0,0 +1,69 @@
//
// UMComViewController.m
// UMCommunity
//
// Created by umeng on 15/9/14.
// Copyright (c) 2015年 Umeng. All rights reserved.
//
#import "UMComViewController.h"
#import "UMComResouceDefines.h"
#import <UMCommunitySDK/UMComSession.h>
#import "UMComLoginManager.h"
#import "UIViewController+UMComAddition.h"
#import <UMComNetwork/UMComHttpCode.h>
@interface UMComViewController ()
@end
@implementation UMComViewController
- (instancetype)init
{
self = [super init];
if (self) {
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
if (self.doNotShowBackButton == NO) {
[self setForumUIBackButton];
}
if ([self respondsToSelector:@selector(edgesForExtendedLayout)]) {
[self setEdgesForExtendedLayout:UIRectEdgeNone];
}
if (CGColorEqualToColor(self.view.backgroundColor.CGColor, [UIColor clearColor].CGColor)) {
self.view.backgroundColor = [UIColor whiteColor];
}
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(communityInvalidErrorNotitficationAlert) name:kUMComCommunityInvalidErrorNotification object:nil];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self name:kUMComCommunityInvalidErrorNotification object:nil];
}
- (void)communityInvalidErrorNotitficationAlert
{
[UMComLoginManager userLogout];
[self.navigationController popToRootViewControllerAnimated:YES];
[[[UIAlertView alloc]initWithTitle:nil message:UMComLocalizedString(ERR_MSG_INVALID_COMMUNITY,@"社区已经被强制关闭,暂时无法访问请见谅。") delegate:nil cancelButtonTitle:UMComLocalizedString(@"um_com_ok",@"") otherButtonTitles:nil, nil] show];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end