説明なし

FKCirclePublicController.m 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. //
  2. // FKPublicProductController.m
  3. // FirstLink
  4. //
  5. // Created by ascii on 16/6/8.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKCirclePublicController.h"
  9. #import "FKCirclePublicViewModel.h"
  10. #import "FKCircleAddView.h"
  11. #import "FKButtonChoiceMenu.h"
  12. #import "FKCirclePublicUserCell.h"
  13. #import "FKCirclePublicTextCell.h"
  14. #import "FKCirclePublicImageCell.h"
  15. #import "FKCirclePublicProcuctCell.h"
  16. #import "FLControllerHelper.h"
  17. #import "FLImageHelper.h"
  18. #import "FKCirDetailRequest.h"
  19. #import "FKCirDetailReform.h"
  20. #import "FKCircleDetailViewModel.h"
  21. #import "FKCirclePhotoClipController.h"
  22. #import "FKCircleProductSegmentController.h"
  23. #import "FKCircleTagsController.h"
  24. #import "FKWeakTimerTarget.h"
  25. @interface FKCirclePublicController ()
  26. <UITextViewDelegate, UITableViewDataSource, UITableViewDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate, FKCirclePhotoClipDelegate, FLNetworkDelegate>
  27. @property (nonatomic, strong) UITableView *tableView;
  28. @property (nonatomic, strong) FKCircleAddView *circleAddView;
  29. @property (nonatomic, strong) FKButtonChoiceMenu *buttonChoiceMenu;
  30. @property (nonatomic, strong) FKCirclePublicViewModel *viewModel;
  31. @property (nonatomic, assign) BOOL viewDidAppear;
  32. @property (nonatomic, strong) UITextView *responderTextView;
  33. @property (nonatomic, strong) UITextView *reframeTextView;
  34. @property (nonatomic, assign) CGFloat keyboardHeight;
  35. @end
  36. static NSInteger const FKCircleDetailRequest = 1;
  37. @implementation FKCirclePublicController
  38. - (instancetype)initWithItemID:(NSString *)itemID {
  39. self = [super init];
  40. if (self) {
  41. self.viewModel.itemID = itemID;
  42. }
  43. return self;
  44. }
  45. - (void)viewDidLoad {
  46. [super viewDidLoad];
  47. // Do any additional setup after loading the view.
  48. [self configKeyboardNotifications];
  49. self.view.backgroundColor = [UIColor whiteColor];
  50. self.navigationItem.title = @"晒单发布";
  51. [self configRightNaviItem];
  52. [self prepareInitData];
  53. [self addAllSubviews];
  54. }
  55. - (void)viewWillDisappear:(BOOL)animated {
  56. [super viewWillDisappear:animated];
  57. [self.view endEditing:NO];
  58. }
  59. - (void)viewDidAppear:(BOOL)animated {
  60. [super viewDidAppear:animated];
  61. [self delayBecomeFirstResponder];
  62. self.viewDidAppear = YES;
  63. }
  64. - (void)dealloc {
  65. [[NSNotificationCenter defaultCenter] removeObserver:self];
  66. }
  67. - (void)didReceiveMemoryWarning {
  68. [super didReceiveMemoryWarning];
  69. // Dispose of any resources that can be recreated.
  70. }
  71. #pragma mark - Request
  72. - (void)prepareInitData {
  73. if (self.viewModel.itemID.length > 0) {
  74. [FKCirDetailRequest reqCirDetailWithID:self.viewModel.itemID
  75. identify:FKCircleDetailRequest
  76. delegate:self];
  77. } else {
  78. [self.viewModel prepareInitData];
  79. }
  80. }
  81. /*
  82. #pragma mark - Navigation
  83. // In a storyboard-based application, you will often want to do a little preparation before navigation
  84. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  85. // Get the new view controller using [segue destinationViewController].
  86. // Pass the selected object to the new view controller.
  87. }
  88. */
  89. #pragma mark - response
  90. - (void)networkDidSuccessResponse:(NSDictionary*)response identify:(int)identify header:(MSGHeader*)header {
  91. [self.hudView hide:NO];
  92. if (header.code.integerValue == RESPONSE_MSG_NORMAL){
  93. if (identify == FKCircleDetailRequest){
  94. FKCircleDetailItem *dataItem = [FKCirDetailReform parserDetailItemWithDict:response];
  95. [self.viewModel loadDataFrom:dataItem];
  96. [self.tableView reloadData];
  97. }
  98. } else {
  99. [FLProgressHUDHelper showText:header.msg inView:self.view];
  100. }
  101. }
  102. - (void)networkDidReceiveError:(NSError*)error identify:(int)identify header:(MSGHeader*)header{
  103. [self.hudView hide:NO];
  104. [FLProgressHUDHelper showText:header.msg inView:self.view];
  105. }
  106. #pragma mark - UITableViewDataSource, UITableViewDelegate
  107. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  108. return self.viewModel.modelMutArray.count;
  109. }
  110. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  111. return 1;
  112. }
  113. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  114. if (section == 0) {
  115. return 6;
  116. }
  117. return CGFLOAT_MIN;
  118. }
  119. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  120. return 15;
  121. }
  122. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  123. id item = [self.viewModel modelItemAtIndexPath:indexPath];
  124. kCirclePublicType cellType = [self.viewModel cellTypeAtIndexPath:indexPath];
  125. switch (cellType) {
  126. case kCirclePublicUser:
  127. return [FKCirclePublicUserCell height];
  128. case kCirclePublicProductDesc:
  129. return [FKCirclePublicTextCell heightWith:item];
  130. case kCirclePublicImage:
  131. return [FKCirclePublicImageCell heightWith:item];
  132. case kCirclePublicProduct:
  133. return [FKCirclePublicProcuctCell height];
  134. default:
  135. break;
  136. }
  137. return 44;
  138. }
  139. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  140. id item = [self.viewModel modelItemAtIndexPath:indexPath];
  141. kCirclePublicType cellType = [self.viewModel cellTypeAtIndexPath:indexPath];
  142. NSString *identify = [self.viewModel orderCellIdentifyWith:cellType];
  143. id cell = [self.tableView dequeueReusableCellWithIdentifier:identify];
  144. switch (cellType) {
  145. case kCirclePublicUser:
  146. if ([cell isKindOfClass:[FKCirclePublicUserCell class]]) {
  147. FKCirclePublicUserCell *userCell = (FKCirclePublicUserCell *)cell;
  148. [userCell configWith:item];
  149. }
  150. break;
  151. case kCirclePublicProductDesc: {
  152. if ([cell isKindOfClass:[FKCirclePublicTextCell class]]) {
  153. FKCirclePublicTextCell *textCell = (FKCirclePublicTextCell *)cell;
  154. textCell.textView.delegate = self;
  155. textCell.textView.tag = indexPath.section;
  156. [textCell configWith:item];
  157. if (!self.viewDidAppear) {
  158. self.responderTextView = textCell.textView;
  159. }
  160. }
  161. break;
  162. }
  163. case kCirclePublicImage:
  164. if ([cell isKindOfClass:[FKCirclePublicImageCell class]]) {
  165. FKCirclePublicImageCell *imageCell = (FKCirclePublicImageCell *)cell;
  166. imageCell.textView.delegate = self;
  167. imageCell.tag = indexPath.section;
  168. imageCell.clickCallback = [self clickButtonOnImageCell];
  169. [imageCell configWith:item];
  170. }
  171. break;
  172. case kCirclePublicProduct:
  173. if ([cell isKindOfClass:[FKCirclePublicProcuctCell class]]) {
  174. FKCirclePublicProcuctCell *procuctCell = (FKCirclePublicProcuctCell *)cell;
  175. [procuctCell configWith:item];
  176. procuctCell.deleteButton.tag = indexPath.section;
  177. [procuctCell.deleteButton addTarget:self action:@selector(clickDeleteButtonOnProductCell:) forControlEvents:UIControlEventTouchUpInside];
  178. }
  179. break;
  180. default:
  181. break;
  182. }
  183. if (!cell) {
  184. cell = [[UITableViewCell alloc] init];
  185. }
  186. return (UITableViewCell*)cell;
  187. }
  188. #pragma mark - UITextViewDelegate
  189. - (void)textViewDidBeginEditing:(UITextView *)textView {
  190. self.reframeTextView = textView;
  191. [self replaceInputTextviewUponAddView:textView];
  192. }
  193. - (void) textViewDidChange:(UITextView *)textView {
  194. id item = [self.viewModel modelItemAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:textView.tag]];
  195. if ([item isKindOfClass:[FKCirclePublicTextItem class]]) {
  196. FKCirclePublicTextItem *textItem = (FKCirclePublicTextItem*)item;
  197. textItem.text = textView.text;
  198. } else if ([item isKindOfClass:[FKCirclePublicImageItem class]]) {
  199. FKCirclePublicImageItem *imageItem = (FKCirclePublicImageItem*)item;
  200. imageItem.imageDesc = textView.text;
  201. }
  202. [self.tableView beginUpdates];
  203. [self.tableView endUpdates];
  204. [self replaceInputTextviewUponAddView:textView];
  205. }
  206. - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
  207. if ([text isEqualToString:@"\n"]) {
  208. [textView resignFirstResponder];
  209. return NO;
  210. }
  211. return YES;
  212. }
  213. #pragma mark - KeyboardNotification
  214. - (void)keyboardWillChange:(NSNotification *)notification {
  215. if ([notification.name isEqualToString:UIKeyboardWillShowNotification]) {
  216. [self showBoardViewWithNotification:notification];
  217. } else if ([notification.name isEqualToString:UIKeyboardWillHideNotification]){
  218. [self dismissBoardViewWithNotification:notification];
  219. }
  220. }
  221. - (void)showBoardViewWithNotification:(NSNotification *)notification {
  222. CGFloat duration = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue];
  223. CGRect endRect = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
  224. UIViewAnimationOptions curve = (UIViewAnimationOptions)[notification.userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue];
  225. self.keyboardHeight = CGRectGetHeight(endRect);
  226. if (!IS_IPHONE_4) {
  227. WeakSelf(weakSelf);
  228. [UIView animateWithDuration:duration delay:0 options:curve animations:^{
  229. weakSelf.circleAddView.frame = CGRectMake(0
  230. , CGRectGetHeight(weakSelf.view.frame) - CGRectGetHeight(endRect) - [FKCircleAddView height]
  231. , CGRectGetWidth(weakSelf.circleAddView.bounds)
  232. , [FKCircleAddView height]);
  233. } completion:^(BOOL finished) {
  234. [weakSelf replaceInputTextviewUponAddView:self.reframeTextView];
  235. }];
  236. } else {
  237. [self replaceInputTextviewUponAddView:self.reframeTextView];
  238. }
  239. }
  240. - (void)dismissBoardViewWithNotification:(NSNotification *)notification {
  241. CGFloat duration = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue];
  242. UIViewAnimationOptions curve = (UIViewAnimationOptions)[notification.userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue];
  243. self.keyboardHeight = 0;
  244. WeakSelf(weakSelf);
  245. [UIView animateWithDuration:duration delay:0 options:curve animations:^
  246. {
  247. if (!IS_IPHONE_4) {
  248. weakSelf.circleAddView.frame = CGRectMake(0
  249. , CGRectGetHeight(weakSelf.view.frame) - [FKCircleAddView height]
  250. , CGRectGetWidth(weakSelf.circleAddView.frame)
  251. , [FKCircleAddView height]);
  252. }
  253. weakSelf.tableView.frame = CGRectMake(0, 0, CGRectGetWidth(weakSelf.tableView.frame), CGRectGetHeight(weakSelf.tableView.frame));
  254. } completion:^(BOOL finished) {
  255. }];
  256. }
  257. #pragma mark - UIImagePickerControllerDelegate
  258. - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
  259. NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
  260. if ([mediaType isEqualToString:(NSString *)kUTTypeImage]){
  261. UIImage *sourceImage = [info objectForKey:([picker allowsEditing] ? UIImagePickerControllerEditedImage : UIImagePickerControllerOriginalImage)];
  262. FKCirclePublicImageItem *item = [[FKCirclePublicImageItem alloc] init];
  263. item.sourceImage = sourceImage;
  264. if (sourceImage.size.width > FKCIRCLE_PUBLIC_IMAGE_LENGTH) {
  265. CGSize size = CGSizeMake(FKCIRCLE_PUBLIC_IMAGE_LENGTH, (FKCIRCLE_PUBLIC_IMAGE_LENGTH/sourceImage.size.width)*sourceImage.size.height);
  266. UIImage *scaleImage = [FLImageHelper imageWithImage:sourceImage scaledToSize:size];
  267. item.displayImage = scaleImage;
  268. } else {
  269. item.displayImage = sourceImage;
  270. }
  271. [self.viewModel.modelMutArray addObject:item];
  272. [self.tableView reloadData];
  273. [self scrollTableViewToBottom];
  274. }
  275. [picker dismissViewControllerAnimated:YES
  276. completion:^{
  277. }];
  278. }
  279. - (void)imageWasSavedSuccessfully:(UIImage *)paramImage didFinishSavingWithError:(NSError *)paramError contextInfo:(void *)paramContextInfo{
  280. if (paramError) {
  281. [FLProgressHUDHelper showText:paramError.localizedDescription inView:self.view];
  282. }
  283. }
  284. #pragma mark - FKCirclePhotoClipDelegate
  285. - (void)controller:(FKCirclePhotoClipController *)controller didFinishClipImage:(UIImage *)image {
  286. NSInteger tag = controller.view.tag;
  287. id item = [self.viewModel modelItemAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:tag]];
  288. if ([item isKindOfClass:[FKCirclePublicImageItem class]]) {
  289. FKCirclePublicImageItem *imageItem = (FKCirclePublicImageItem*)item;
  290. imageItem.displayImage = image;
  291. imageItem.photoURL = nil;
  292. [self.tableView reloadData];
  293. }
  294. }
  295. #pragma mark - Action
  296. - (FKCirclePublicImageCellClickCallback)clickButtonOnImageCell {
  297. WeakSelf(weakSelf);
  298. return ^(FKCirclePublicImageCellButton btnType, NSIndexPath *indexPath){
  299. id item = [weakSelf.viewModel modelItemAtIndexPath:indexPath];
  300. if (![item isKindOfClass:[FKCirclePublicImageItem class]]) {
  301. return ;
  302. }
  303. FKCirclePublicImageItem *imageItem = (FKCirclePublicImageItem*)item;
  304. switch (btnType) {
  305. case FKCirclePublicImageCellButtonDelete: {
  306. [weakSelf.viewModel removeModelItemAtIndexPath:indexPath];
  307. [weakSelf.tableView reloadData];
  308. break;
  309. }
  310. case FKCirclePublicImageCellButtonText: {
  311. imageItem.palceholder = CIRCLE_PUBLIC_IMAGETEXTVIEW_PALCEHOLDER;
  312. [weakSelf.tableView reloadData];
  313. [weakSelf.tableView scrollToRowAtIndexPath:indexPath
  314. atScrollPosition:UITableViewScrollPositionBottom animated:NO];
  315. FKCirclePublicImageCell *imageCell = [weakSelf.tableView cellForRowAtIndexPath:indexPath];
  316. if ([imageCell isKindOfClass:[FKCirclePublicImageCell class]] && imageItem.imageDesc.length == 0) {
  317. weakSelf.responderTextView = imageCell.textView;
  318. [weakSelf delayBecomeFirstResponder];
  319. }
  320. break;
  321. }
  322. case FKCirclePublicImageCellButtonClip: {
  323. [weakSelf pushPhotoClipController:imageItem.sourceImage indexPath:indexPath];
  324. break;
  325. }
  326. default:
  327. break;
  328. }
  329. };
  330. }
  331. - (IBAction)clickDeleteButtonOnProductCell:(UIButton *)sender {
  332. [self.viewModel removeModelItemAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:sender.tag]];
  333. [self.tableView reloadData];
  334. }
  335. - (void)pushPhotoClipController:(UIImage *)sourceImg indexPath:(NSIndexPath *)indexPath {
  336. FKCirclePhotoClipController *controller = [[FKCirclePhotoClipController alloc] initWithImage:sourceImg
  337. delegate:self];
  338. controller.view.tag = indexPath.section;
  339. controller.hidesBottomBarWhenPushed = YES;
  340. [self.navigationController pushViewController:controller animated:YES];
  341. }
  342. - (void)pushCircleProductController {
  343. FKCircleProductSegmentController *controller = [[FKCircleProductSegmentController alloc] init];
  344. controller.hidesBottomBarWhenPushed = YES;
  345. WeakSelf(weakSelf);
  346. controller.callback = ^(NSArray<FKCircleChoiceProductItem*> *items) {
  347. for (FKCircleChoiceProductItem *product in items) {
  348. [weakSelf.viewModel.modelMutArray addObject:product];
  349. }
  350. [weakSelf.tableView reloadData];
  351. [weakSelf scrollTableViewToBottom];
  352. };
  353. [self.navigationController pushViewController:controller animated:YES];
  354. }
  355. - (IBAction)clickRightNavItemAction:(id)sender {
  356. NSString *errMSG = [self.viewModel validDataMessage];
  357. if (!errMSG) {
  358. FKCircleTagsController *controller = [[FKCircleTagsController alloc] initWithViewModel:self.viewModel];
  359. controller.hidesBottomBarWhenPushed = YES;
  360. [self.navigationController pushViewController:controller animated:YES];
  361. } else {
  362. [FLProgressHUDHelper showText:errMSG inView:self.view];
  363. }
  364. }
  365. #pragma mark - Method
  366. - (void)showImageChoiceMenu {
  367. [self.view.window addSubview:self.buttonChoiceMenu];
  368. WeakSelf(weakSelf);
  369. // [UIView animateWithDuration:0.3
  370. // animations:^
  371. // {
  372. weakSelf.buttonChoiceMenu.alpha = 1.0;
  373. weakSelf.buttonChoiceMenu.frame = weakSelf.view.window.bounds;
  374. // }];
  375. }
  376. - (void)hideImageChoiceMenu {
  377. WeakSelf(weakSelf);
  378. [UIView animateWithDuration:0.3
  379. animations:^
  380. {
  381. weakSelf.buttonChoiceMenu.alpha = 0;
  382. // weakSelf.buttonChoiceMenu.frame = CGRectMake(0,
  383. // CGRectGetMaxY(weakSelf.view.window.bounds),
  384. // CGRectGetWidth(weakSelf.view.window.bounds),
  385. // CGRectGetHeight(weakSelf.view.window.bounds));
  386. }];
  387. [self.buttonChoiceMenu removeFromSuperview];
  388. }
  389. - (void)configKeyboardNotifications {
  390. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChange:) name:UIKeyboardWillShowNotification object:nil];
  391. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChange:) name:UIKeyboardDidShowNotification object:nil];
  392. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChange:) name:UIKeyboardWillHideNotification object:nil];
  393. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChange:) name:UIKeyboardDidHideNotification object:nil];
  394. }
  395. - (void)replaceInputTextviewUponAddView:(UIView *)view {
  396. if (view && self.keyboardHeight > 0) {
  397. CGRect rect = [view.superview convertRect:view.frame toView:self.view];
  398. CGFloat offset;
  399. if (IS_IPHONE_4) {
  400. offset = (CGRectGetMaxY(rect) - (CGRectGetHeight(self.view.frame) - self.keyboardHeight));
  401. } else {
  402. offset = (CGRectGetMaxY(rect) - CGRectGetMinY(self.circleAddView.frame));
  403. }
  404. if (offset > 0) {
  405. [self replaceViewOffsetY:-offset];
  406. }
  407. }
  408. }
  409. - (void)replaceViewOffsetY:(CGFloat)offset {
  410. WeakSelf(weakSelf);
  411. [UIView animateWithDuration:0.3
  412. animations:^
  413. {
  414. CGRect frame = weakSelf.tableView.frame;
  415. weakSelf.tableView.frame = CGRectMake(0, CGRectGetMinY(frame) + offset, CGRectGetWidth(frame), CGRectGetHeight(frame));
  416. }];
  417. }
  418. - (void)scrollTableViewToBottom {
  419. [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:self.viewModel.modelMutArray.count-1] atScrollPosition:UITableViewScrollPositionBottom animated:YES];
  420. }
  421. - (void)configRightNaviItem {
  422. UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithTitle:@"下一步"
  423. style:UIBarButtonItemStylePlain
  424. target:self
  425. action:@selector(clickRightNavItemAction:)];
  426. [rightItem setTitleTextAttributes:@{NSForegroundColorAttributeName : UIColorFromRGB(0xff6362),
  427. NSFontAttributeName : [UIFont systemFontOfSize:16]}
  428. forState:UIControlStateNormal];
  429. self.navigationItem.rightBarButtonItem = rightItem;
  430. }
  431. - (void)delayBecomeFirstResponder {
  432. [FKWeakTimerTarget scheduledTimerWithTimeInterval:0.5
  433. target:self
  434. selector:@selector(becomeFirstResponder:)
  435. userInfo:nil
  436. repeats:NO];
  437. }
  438. - (IBAction)becomeFirstResponder:(id)sender {
  439. if (self.responderTextView) {
  440. [self.responderTextView becomeFirstResponder];
  441. self.responderTextView = nil;
  442. }
  443. }
  444. #pragma mark - Layout
  445. - (void)addAllSubviews {
  446. [self.view addSubview:self.tableView];
  447. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  448. make.left.top.right.equalTo(self.view);
  449. make.bottom.equalTo(self.view).offset(-[FKCircleAddView height]);
  450. }];
  451. [self.view addSubview:self.circleAddView];
  452. [self.circleAddView mas_makeConstraints:^(MASConstraintMaker *make) {
  453. make.left.bottom.right.equalTo(self.view);
  454. make.height.mas_equalTo([FKCircleAddView height]);
  455. }];
  456. }
  457. #pragma mark - Property
  458. - (UITableView *)tableView {
  459. if (_tableView == nil) {
  460. _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
  461. _tableView.dataSource = self;
  462. _tableView.delegate = self;
  463. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  464. _tableView.sectionFooterHeight = 0;
  465. _tableView.showsVerticalScrollIndicator = NO;
  466. _tableView.backgroundColor = [UIColor whiteColor];
  467. [_tableView registerClass:[FKCirclePublicUserCell class] forCellReuseIdentifier:FKCirclePublicUserCellIdentify];
  468. [_tableView registerClass:[FKCirclePublicTextCell class] forCellReuseIdentifier:FKCirclePublicProductDescCellIdentify];
  469. [_tableView registerClass:[FKCirclePublicImageCell class] forCellReuseIdentifier:FKCirclePublicImageCellIdentify];
  470. [_tableView registerClass:[FKCirclePublicProcuctCell class] forCellReuseIdentifier:FKCirclePublicProductCellIdentify];
  471. }
  472. return _tableView;
  473. }
  474. - (FKCircleAddView *)circleAddView {
  475. if (!_circleAddView) {
  476. _circleAddView = [FKCircleAddView new];
  477. _circleAddView.backgroundColor = UIColorFromRGB(0xeeeeee);
  478. WeakSelf(weakSelf);
  479. _circleAddView.clickCallback = ^(NSInteger idx) {
  480. [weakSelf.view endEditing:NO];
  481. if (idx == 0) {
  482. [weakSelf showImageChoiceMenu];
  483. } else if (idx == 1) {
  484. [weakSelf pushCircleProductController];
  485. }
  486. };
  487. }
  488. return _circleAddView;
  489. }
  490. - (FKButtonChoiceMenu *)buttonChoiceMenu {
  491. if (!_buttonChoiceMenu) {
  492. _buttonChoiceMenu = [[FKButtonChoiceMenu alloc] initWithSectionTitles:@[@"拍照", @"从手机相册选择"]
  493. cancelTitle:@"取消"];
  494. _buttonChoiceMenu.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
  495. _buttonChoiceMenu.alpha = 0;
  496. _buttonChoiceMenu.frame = CGRectMake(0,
  497. CGRectGetMinY(self.view.window.bounds),
  498. CGRectGetWidth(self.view.window.bounds),
  499. CGRectGetHeight(self.view.window.bounds));
  500. WeakSelf(weakSelf);
  501. _buttonChoiceMenu.clickCallback = ^(NSInteger idx) {
  502. switch (idx) {
  503. case 0: {
  504. [weakSelf hideImageChoiceMenu];
  505. break;
  506. }
  507. case 1: {
  508. [weakSelf hideImageChoiceMenu];
  509. [FLControllerHelper launchAppCamera:weakSelf type:UIImagePickerControllerSourceTypePhotoLibrary];
  510. break;
  511. }
  512. case 2: {
  513. [weakSelf hideImageChoiceMenu];
  514. [FLControllerHelper launchAppCamera:weakSelf type:UIImagePickerControllerSourceTypeCamera];
  515. break;
  516. }
  517. default:
  518. break;
  519. }
  520. };
  521. }
  522. return _buttonChoiceMenu;
  523. }
  524. - (FKCirclePublicViewModel *)viewModel {
  525. if (!_viewModel) {
  526. _viewModel = [FKCirclePublicViewModel new];
  527. }
  528. return _viewModel;
  529. }
  530. @end