123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
- //
- // ViewController.m
- // FirstLink
- //
- // Created by mac on 14-8-25.
- // Copyright (c) 2014年 FirstLink. All rights reserved.
- //
- #import "FLViewController.h"
- #import "SchemaManager.h"
- #import <UMMobClick/MobClick.h>
- #import "FirstLinkAppDelegate.h"
- #import "FLControllerHelper.h"
- #import "FKLoadingView.h"
- @interface FLViewController ()
- <RefreshControlDelegate, UIGestureRecognizerDelegate>
- @property (nonatomic, weak) id originalDelgate;
- @property (nonatomic, strong) UITableViewCell *noContentTipCell;
- @property (nonatomic, strong) FKLoadingView *loadingView;
- @end
- @implementation FLViewController
- @synthesize refreshControl = _refreshControl;
- - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
- {
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if (self) {
- // Custom initialization
- self.edgesForExtendedLayout = NO;
- self.convertPopDelegate = YES;
- if([UIDevice currentDevice].systemVersion.floatValue >= 8.0) {
- self.navigationController.navigationBar.translucent = NO;
- }
- }
- return self;
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- // Do any additional setup after loading the view from its nib.
-
- [self configLeftNaviItem];
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- [MobClick beginLogPageView:NSStringFromClass([self class])];
-
- if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)] && self.convertPopDelegate) {
- self.originalDelgate = self.navigationController.interactivePopGestureRecognizer.delegate;
- self.navigationController.interactivePopGestureRecognizer.delegate = self;
- }
- }
- - (void)viewDidAppear:(BOOL)animated {
- [super viewDidAppear:animated];
-
- [MobClick endLogPageView:NSStringFromClass([self class])];
- }
- - (void)viewWillDisappear:(BOOL)animated {
- [super viewWillDisappear:animated];
- [MobClick endLogPageView:NSStringFromClass([self class])];
-
- if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)] && self.convertPopDelegate) {
- if (self.originalDelgate) {
- self.navigationController.interactivePopGestureRecognizer.delegate = self.originalDelgate;
- self.originalDelgate = nil;
- }
- }
-
- self.openURLPara = nil;
- }
- - (void)viewDidDisappear:(BOOL)animated {
- [super viewDidDisappear:animated];
-
- NSArray *viewControllers = [FLControllerHelper currentControllers];
- if (viewControllers.count <= 1) {
- [[FKPageRouterUtil sharedInstance] removePageRefers];
- }
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- #pragma mark - Refresh
- - (void)forceRefresh {
-
- }
- #pragma mark - RefreshControl
- - (void)initRefreshControlWithTableView:(UITableView *)tableView {
- self.refreshControl = [[FKRefreshControl alloc] initWithScrollView:tableView delegate:self];
- self.refreshControl.autoRefreshBottom = YES;
- self.refreshControl.enableInsetBottom = 0;
- self.refreshControl.topEnabled = YES;
- self.refreshControl.bottomEnabled = YES;
- }
- - (void)finishLoadingData {
- if (self.refreshControl.refreshingDirection==RefreshingDirectionTop) {
- [self.refreshControl finishRefreshingDirection:RefreshDirectionTop];
- } else if (self.refreshControl.refreshingDirection==RefreshingDirectionBottom) {
- [self.refreshControl finishRefreshingDirection:RefreshDirectionBottom];
- }
- }
- #pragma mark - HUD
- - (MBProgressHUD*)hudView {
- if (!_hudView) {
- _hudView = [[MBProgressHUD alloc] initWithView:self.view];
- _hudView.color = [UIColor clearColor];
- _hudView.mode = MBProgressHUDModeCustomView;
- _hudView.customView = self.loadingView;
- [self.view addSubview:_hudView];
- }
- [self.loadingView startAnimation];
- [self.view bringSubviewToFront:_hudView];
- return _hudView;
- }
- - (FKLoadingView *)loadingView {
- if (!_loadingView) {
- _loadingView = [FKLoadingView new];
- _loadingView.frame = CGRectMake(0, 0, 80, 80);
- }
- return _loadingView;
- }
- #pragma mark - Status View
- - (FKStatusTipView*)statusView {
- if (!_statusView) {
- _statusView = [[FKStatusTipView alloc] init];
- }
- return _statusView;
- }
- - (FLEmptyFooter*)emptyFooterView {
- if (!_emptyFooterView) {
- _emptyFooterView = [[FLEmptyFooter alloc] initWithFrame:CGRectMake(0, 0, UISCREENWIDTH, [FLEmptyFooter height])];
- _emptyFooterView.textLabel.text = @"休息一下吧,所有商品已看完了";
- }
- return _emptyFooterView;
- }
- - (void)showSystemErrorTipInView:(UIView*)view {
- self.statusView.statusImageView.image = [UIImage imageNamed:@"StatusSystemError"];
- self.statusView.statusLabel.text = SystemErrorTip;
- self.statusView.actionButton.hidden = NO;
- self.statusView.actionButton.layer.borderWidth = 0;
- self.statusView.actionButton.layer.cornerRadius = 0;
- [self.statusView.actionButton setBackgroundImage:[UIImage imageNamed:@"StatusSystemButtonIcon"] forState:UIControlStateNormal];
- self.statusView.backgroundColor = UIColorFromRGB(0xf4f4f4);
-
- self.statusView.frame = view.bounds;
- [view addSubview:self.statusView];
- }
- - (void)showStatusTipInView:(UIView *)view image:(UIImage *)image title:(NSString *)title {
- self.statusView.statusImageView.image = image;
- self.statusView.statusLabel.text = title;
- self.statusView.backgroundColor = UIColorFromRGB(0xf4f4f4);
-
- self.statusView.frame = CGRectMake(0, 0, CGRectGetWidth(view.frame), CGRectGetHeight(view.frame));
- [view addSubview:self.statusView];
- }
- #pragma mark - NaviBar
- - (void)configLeftNaviItem {
- self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"fk_common_back"] style:UIBarButtonItemStylePlain target:self action:@selector(clickLeftNaviItem)];
-
- }
- - (void)clickLeftNaviItem {
- if (self.navigationController){
- [self.navigationController popViewControllerAnimated:YES];
- }
- }
- - (void)hideDefaultLeftNaviItem {
- self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage new]
- style:UIBarButtonItemStylePlain
- target:nil
- action:nil];
- }
- - (void)hideHud:(BOOL)animated {
- [self.hudView hide:animated];
- [self.hudView removeFromSuperview];
- self.hudView = nil;
- }
- #pragma mark - Login Action
- - (void)showLoginActionMenu {
- JGActionSheetSection *section = [JGActionSheetSection sectionWithTitle:nil
- message:@"是否登录?"
- buttonTitles:@[@"登录", @"取消"]
- buttonStyle:JGActionSheetButtonStyleDefault];
- section.tintColor = UIColorFromRGB(0x999999);
- JGActionSheet *actionSheet = [JGActionSheet actionSheetWithSections:@[section]];
-
- UIButton *button = section.buttons.firstObject;
- [button setTitleColor:UIColorFromRGB(0xff624a) forState:UIControlStateNormal];
- button.layer.borderWidth = 0;
-
- button = section.buttons[1];
- [button setTitleColor:UIColorFromRGB(0x666666) forState:UIControlStateNormal];
- button.layer.borderWidth = 0;
-
- actionSheet.delegate = self;
- actionSheet.insets = UIEdgeInsetsMake(20.0f, 0.0f, IS_IPHONE_X ? 34.0f : 0.0f, 0.0f);
- if (IS_IPHONE_X) {
- UIView *view = [UIView new];
- view.backgroundColor = [UIColor whiteColor];
- [actionSheet addSubview:view];
- [view mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.bottom.right.equalTo(actionSheet);
- make.height.mas_equalTo(34);
- }];
- }
-
- WeakSelf(weakSelf);
- actionSheet.outsidePressBlock = ^(JGActionSheet *sheet) {
- [sheet dismissAnimated:YES];
- [weakSelf dismissMenuWithNotLogin];
- };
- [actionSheet setButtonPressedBlock:^(JGActionSheet *sheet, NSIndexPath *indexPath) {
- [sheet dismissAnimated:YES];
- if (indexPath.row == 1) {
- [weakSelf dismissMenuWithNotLogin];
- }
- }];
-
- FirstLinkAppDelegate *delegate = (FirstLinkAppDelegate *)[[UIApplication sharedApplication] delegate];
- [actionSheet showInView:delegate.window animated:YES];
- }
- - (void)actionSheet:(JGActionSheet *)actionSheet pressedButtonAtIndexPath:(NSIndexPath *)indexPath {
- if (indexPath.row == 0) {
- [FLControllerHelper presentLoginViewController];
- }
- }
- - (void)dismissMenuWithNotLogin {
-
- }
- @end
|