Aucune description

FLViewController.m 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. //
  2. // ViewController.m
  3. // FirstLink
  4. //
  5. // Created by mac on 14-8-25.
  6. // Copyright (c) 2014年 FirstLink. All rights reserved.
  7. //
  8. #import "FLViewController.h"
  9. #import "SchemaManager.h"
  10. #import <UMMobClick/MobClick.h>
  11. #import "FirstLinkAppDelegate.h"
  12. #import "FLControllerHelper.h"
  13. #import "FKLoadingView.h"
  14. @interface FLViewController ()
  15. <RefreshControlDelegate, UIGestureRecognizerDelegate>
  16. @property (nonatomic, weak) id originalDelgate;
  17. @property (nonatomic, strong) UITableViewCell *noContentTipCell;
  18. @property (nonatomic, strong) FKLoadingView *loadingView;
  19. @end
  20. @implementation FLViewController
  21. @synthesize refreshControl = _refreshControl;
  22. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  23. {
  24. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  25. if (self) {
  26. // Custom initialization
  27. self.edgesForExtendedLayout = NO;
  28. self.convertPopDelegate = YES;
  29. if([UIDevice currentDevice].systemVersion.floatValue >= 8.0) {
  30. self.navigationController.navigationBar.translucent = NO;
  31. }
  32. }
  33. return self;
  34. }
  35. - (void)viewDidLoad
  36. {
  37. [super viewDidLoad];
  38. // Do any additional setup after loading the view from its nib.
  39. [self configLeftNaviItem];
  40. }
  41. - (void)viewWillAppear:(BOOL)animated {
  42. [super viewWillAppear:animated];
  43. [MobClick beginLogPageView:NSStringFromClass([self class])];
  44. if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)] && self.convertPopDelegate) {
  45. self.originalDelgate = self.navigationController.interactivePopGestureRecognizer.delegate;
  46. self.navigationController.interactivePopGestureRecognizer.delegate = self;
  47. }
  48. }
  49. - (void)viewDidAppear:(BOOL)animated {
  50. [super viewDidAppear:animated];
  51. [MobClick endLogPageView:NSStringFromClass([self class])];
  52. }
  53. - (void)viewWillDisappear:(BOOL)animated {
  54. [super viewWillDisappear:animated];
  55. [MobClick endLogPageView:NSStringFromClass([self class])];
  56. if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)] && self.convertPopDelegate) {
  57. if (self.originalDelgate) {
  58. self.navigationController.interactivePopGestureRecognizer.delegate = self.originalDelgate;
  59. self.originalDelgate = nil;
  60. }
  61. }
  62. self.openURLPara = nil;
  63. }
  64. - (void)viewDidDisappear:(BOOL)animated {
  65. [super viewDidDisappear:animated];
  66. NSArray *viewControllers = [FLControllerHelper currentControllers];
  67. if (viewControllers.count <= 1) {
  68. [[FKPageRouterUtil sharedInstance] removePageRefers];
  69. }
  70. }
  71. - (void)didReceiveMemoryWarning
  72. {
  73. [super didReceiveMemoryWarning];
  74. // Dispose of any resources that can be recreated.
  75. }
  76. #pragma mark - Refresh
  77. - (void)forceRefresh {
  78. }
  79. #pragma mark - RefreshControl
  80. - (void)initRefreshControlWithTableView:(UITableView *)tableView {
  81. self.refreshControl = [[FKRefreshControl alloc] initWithScrollView:tableView delegate:self];
  82. self.refreshControl.autoRefreshBottom = YES;
  83. self.refreshControl.enableInsetBottom = 0;
  84. self.refreshControl.topEnabled = YES;
  85. self.refreshControl.bottomEnabled = YES;
  86. }
  87. - (void)finishLoadingData {
  88. if (self.refreshControl.refreshingDirection==RefreshingDirectionTop) {
  89. [self.refreshControl finishRefreshingDirection:RefreshDirectionTop];
  90. } else if (self.refreshControl.refreshingDirection==RefreshingDirectionBottom) {
  91. [self.refreshControl finishRefreshingDirection:RefreshDirectionBottom];
  92. }
  93. }
  94. #pragma mark - HUD
  95. - (MBProgressHUD*)hudView {
  96. if (!_hudView) {
  97. _hudView = [[MBProgressHUD alloc] initWithView:self.view];
  98. _hudView.color = [UIColor clearColor];
  99. _hudView.mode = MBProgressHUDModeCustomView;
  100. _hudView.customView = self.loadingView;
  101. [self.view addSubview:_hudView];
  102. }
  103. [self.loadingView startAnimation];
  104. [self.view bringSubviewToFront:_hudView];
  105. return _hudView;
  106. }
  107. - (FKLoadingView *)loadingView {
  108. if (!_loadingView) {
  109. _loadingView = [FKLoadingView new];
  110. _loadingView.frame = CGRectMake(0, 0, 80, 80);
  111. }
  112. return _loadingView;
  113. }
  114. #pragma mark - Status View
  115. - (FKStatusTipView*)statusView {
  116. if (!_statusView) {
  117. _statusView = [[FKStatusTipView alloc] init];
  118. }
  119. return _statusView;
  120. }
  121. - (FLEmptyFooter*)emptyFooterView {
  122. if (!_emptyFooterView) {
  123. _emptyFooterView = [[FLEmptyFooter alloc] initWithFrame:CGRectMake(0, 0, UISCREENWIDTH, [FLEmptyFooter height])];
  124. _emptyFooterView.textLabel.text = @"休息一下吧,所有商品已看完了";
  125. }
  126. return _emptyFooterView;
  127. }
  128. - (void)showSystemErrorTipInView:(UIView*)view {
  129. self.statusView.statusImageView.image = [UIImage imageNamed:@"StatusSystemError"];
  130. self.statusView.statusLabel.text = SystemErrorTip;
  131. self.statusView.actionButton.hidden = NO;
  132. self.statusView.actionButton.layer.borderWidth = 0;
  133. self.statusView.actionButton.layer.cornerRadius = 0;
  134. [self.statusView.actionButton setBackgroundImage:[UIImage imageNamed:@"StatusSystemButtonIcon"] forState:UIControlStateNormal];
  135. self.statusView.backgroundColor = UIColorFromRGB(0xf4f4f4);
  136. self.statusView.frame = view.bounds;
  137. [view addSubview:self.statusView];
  138. }
  139. - (void)showStatusTipInView:(UIView *)view image:(UIImage *)image title:(NSString *)title {
  140. self.statusView.statusImageView.image = image;
  141. self.statusView.statusLabel.text = title;
  142. self.statusView.backgroundColor = UIColorFromRGB(0xf4f4f4);
  143. self.statusView.frame = CGRectMake(0, 0, CGRectGetWidth(view.frame), CGRectGetHeight(view.frame));
  144. [view addSubview:self.statusView];
  145. }
  146. #pragma mark - NaviBar
  147. - (void)configLeftNaviItem {
  148. self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"fk_common_back"] style:UIBarButtonItemStylePlain target:self action:@selector(clickLeftNaviItem)];
  149. }
  150. - (void)clickLeftNaviItem {
  151. if (self.navigationController){
  152. [self.navigationController popViewControllerAnimated:YES];
  153. }
  154. }
  155. - (void)hideDefaultLeftNaviItem {
  156. self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage new]
  157. style:UIBarButtonItemStylePlain
  158. target:nil
  159. action:nil];
  160. }
  161. - (void)hideHud:(BOOL)animated {
  162. [self.hudView hide:animated];
  163. [self.hudView removeFromSuperview];
  164. self.hudView = nil;
  165. }
  166. #pragma mark - Login Action
  167. - (void)showLoginActionMenu {
  168. JGActionSheetSection *section = [JGActionSheetSection sectionWithTitle:nil
  169. message:@"是否登录?"
  170. buttonTitles:@[@"登录", @"取消"]
  171. buttonStyle:JGActionSheetButtonStyleDefault];
  172. section.tintColor = UIColorFromRGB(0x999999);
  173. JGActionSheet *actionSheet = [JGActionSheet actionSheetWithSections:@[section]];
  174. UIButton *button = section.buttons.firstObject;
  175. [button setTitleColor:UIColorFromRGB(0xff624a) forState:UIControlStateNormal];
  176. button.layer.borderWidth = 0;
  177. button = section.buttons[1];
  178. [button setTitleColor:UIColorFromRGB(0x666666) forState:UIControlStateNormal];
  179. button.layer.borderWidth = 0;
  180. actionSheet.delegate = self;
  181. actionSheet.insets = UIEdgeInsetsMake(20.0f, 0.0f, IS_IPHONE_X ? 34.0f : 0.0f, 0.0f);
  182. if (IS_IPHONE_X) {
  183. UIView *view = [UIView new];
  184. view.backgroundColor = [UIColor whiteColor];
  185. [actionSheet addSubview:view];
  186. [view mas_makeConstraints:^(MASConstraintMaker *make) {
  187. make.left.bottom.right.equalTo(actionSheet);
  188. make.height.mas_equalTo(34);
  189. }];
  190. }
  191. WeakSelf(weakSelf);
  192. actionSheet.outsidePressBlock = ^(JGActionSheet *sheet) {
  193. [sheet dismissAnimated:YES];
  194. [weakSelf dismissMenuWithNotLogin];
  195. };
  196. [actionSheet setButtonPressedBlock:^(JGActionSheet *sheet, NSIndexPath *indexPath) {
  197. [sheet dismissAnimated:YES];
  198. if (indexPath.row == 1) {
  199. [weakSelf dismissMenuWithNotLogin];
  200. }
  201. }];
  202. FirstLinkAppDelegate *delegate = (FirstLinkAppDelegate *)[[UIApplication sharedApplication] delegate];
  203. [actionSheet showInView:delegate.window animated:YES];
  204. }
  205. - (void)actionSheet:(JGActionSheet *)actionSheet pressedButtonAtIndexPath:(NSIndexPath *)indexPath {
  206. if (indexPath.row == 0) {
  207. [FLControllerHelper presentLoginViewController];
  208. }
  209. }
  210. - (void)dismissMenuWithNotLogin {
  211. }
  212. @end