| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- //
- // MainViewController.m
- // kneet2
- //
- // StoryBoard - page 8.
- //
- // Created by Jason Lee on 10/2/15.
- // Copyright © 2015 ntels. All rights reserved.
- //
- #import "JDObject.h"
- #import "RequestHandler.h"
- #import "CustomButton.h"
- #import "UIButton+WebCache.h"
- #import "ImageUtil.h"
- #import "ThingsViewController.h"
- #import "RulesViewController.h"
- #import "HomeMemberViewController.h"
- #import "MainViewController.h"
- @interface MainViewController () <ImageUtilDelegate> {
- ThingsViewController *_tvc;
- RulesViewController *_rvc;
- HomeMemberViewController *_mvc;
-
- ImageUtil *_imageUtil;
- }
- @property (strong, nonatomic) UIView *thingsContainerView;
- @property (strong, nonatomic) UIView *rulesContainerView;
- @property (strong, nonatomic) UIView *membersContainerView;
- @end
- #pragma mark - Class Definition
- @implementation MainViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
-
- [self initUI];
- [self prepareViewDidLoad];
- }
- - (void)initUI {
- //1. init tabBar
- //1-1. scroll top bottom
-
- //2. init scrollView
- CGFloat height = IPHONE_HEIGHT - _tabBar.height;
- [_scrollView setContentSize:CGSizeMake(IPHONE_WIDTH * 3, height)];
- _scrollView.pagingEnabled = YES;
- _scrollView.scrollEnabled = NO;
-
-
- CGRect sr = CGRectMake(0, 0, IPHONE_WIDTH, height);
-
- //init child view for childViewController
- _thingsContainerView = [[UIView alloc] initWithFrame:sr];
- _rulesContainerView = [[UIView alloc] initWithFrame:sr];
- _membersContainerView = [[UIView alloc] initWithFrame:sr];
-
- [_scrollView addSubview:_thingsContainerView];
-
- _rulesContainerView.x = IPHONE_WIDTH;
- [_scrollView addSubview:_rulesContainerView];
-
- _membersContainerView.x = IPHONE_WIDTH * 2;
- [_scrollView addSubview:_membersContainerView];
-
- //when first loading this view.
- [self initThingsViewController];
- }
- - (void)initThingsViewController {
-
- if (!_tvc) {
- _tvc = (ThingsViewController *)[CommonUtil instantiateViewControllerWithIdentifier:@"ThingsViewController" storyboardName:@"Things"];
- }
-
- [self addChildViewController:_tvc];
- [_tvc didMoveToParentViewController:self];
-
- if ([self isViewLoaded]) {
- [_tvc beginAppearanceTransition:YES animated:NO];
- [_thingsContainerView addSubview:_tvc.view];
- [_tvc endAppearanceTransition];
- }
- }
- - (void)initRulesViewController {
-
- if (!_rvc) {
- _rvc = (RulesViewController *)[CommonUtil instantiateViewControllerWithIdentifier:@"RulesViewController" storyboardName:@"Rules"];
- }
-
- [self addChildViewController:_rvc];
- [_rvc didMoveToParentViewController:self];
-
- if ([self isViewLoaded]) {
- [_rvc beginAppearanceTransition:YES animated:NO];
- [_rulesContainerView addSubview:_rvc.view];
- [_rvc endAppearanceTransition];
- }
- }
- - (void)initMembersViewController {
- if (!_mvc) {
- _mvc = (HomeMemberViewController *)[CommonUtil instantiateViewControllerWithIdentifier:@"HomeMemberViewController" storyboardName:@"HomeMember"];
- }
-
- [self addChildViewController:_mvc];
- [_mvc didMoveToParentViewController:self];
-
- if ([self isViewLoaded]) {
- [_mvc beginAppearanceTransition:YES animated:NO];
- [_membersContainerView addSubview:_mvc.view];
- [_mvc endAppearanceTransition];
- }
- }
- - (void)prepareViewDidLoad {
-
- }
- #pragma mark - Main Logic
- - (void)requestUpdateHomeGroupImage:(UIImage *)profileImage {
-
- //parameters
- NSDictionary *parameter = @{@"image_file": profileImage};
-
- NSString *path = [NSString stringWithFormat:API_POST_HOMEGROUP_UPDATE_IMAGE];
-
- [[RequestHandler handler] sendAsyncPostRequestAPIPath:path parameters:parameter modelClass:[LoginModel class] completion:^(id responseObject) {
- if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
- return;
- }
-
- LoginModel *response = (LoginModel *)responseObject;
-
- if (response) {//API 성공 ,
- [_btnHomegrpImage sd_setImageWithURL:[NSURL URLWithString:response.imageFileName] forState:UIControlStateNormal placeholderImage:nil options:SDWebImageRefreshCached];
- [[JDFacade facade] toast:@"홈 이미지를 변경했습니다"];
- }
- } failure:^(id errorObject) {
- JDErrorModel *error = (JDErrorModel *)errorObject;
- [[JDFacade facade] alert:error.errorMessage];
- }];
- }
- #pragma mark - ImageUtil delegate
- - (void)didFinishPickingImage:(UIImage *)image {
- [self requestUpdateHomeGroupImage:image];
- }
- #pragma mark - UI Events
- - (IBAction)btnThingsTouched:(id)sender {
-
- [[JDFacade facade] showLoadingWhileExecutingBlock:^{
- if (!_tvc) {
- dispatch_async(dispatch_get_main_queue(), ^{
- [self initThingsViewController];
- });
- }
- } completionHandler:^{
- CGPoint cpoint = CGPointMake(0, 0);
- [_scrollView setContentOffset:cpoint animated:NO];
- }];
- }
- - (IBAction)btnRuleTouched:(id)sender {
-
- [[JDFacade facade] showLoadingWhileExecutingBlock:^{
- if (!_rvc) {
- dispatch_async(dispatch_get_main_queue(), ^{
- [self initRulesViewController];
- });
- }
- } completionHandler:^{
- CGPoint cpoint = CGPointMake(IPHONE_WIDTH, 0);
- [_scrollView setContentOffset:cpoint animated:NO];
- }];
- }
- - (IBAction)btnMemberTouched:(id)sender {
- [[JDFacade facade] showLoadingWhileExecutingBlock:^{
- if (!_mvc) {
- dispatch_async(dispatch_get_main_queue(), ^{
- [self initMembersViewController];
- });
- }
- } completionHandler:^{
- CGPoint cpoint = CGPointMake(IPHONE_WIDTH * 2, 0);
- [_scrollView setContentOffset:cpoint animated:NO];
- }];
- }
- - (IBAction)btnExtendTouched:(id)sender {
-
- _constraintExpandViewTop.constant = -IPHONE_HEIGHT;
-
- [UIView animateWithDuration:ANIMATION_DUR animations:^{
- [self.view layoutIfNeeded];
- }];
- }
- - (IBAction)btnCollapseTouched:(id)sender {
-
- _constraintExpandViewTop.constant = 0;
-
- [UIView animateWithDuration:ANIMATION_DUR animations:^{
- [self.view layoutIfNeeded];
- }];
- }
- - (IBAction)btnProfileTouched:(id)sender {
- if (!_imageUtil) {
- _imageUtil = [[ImageUtil alloc] init];
- _imageUtil.delegate = self;
- }
-
- [_imageUtil prepareImagePicker];
- }
- - (IBAction)btnNoticeTouched:(id)sender {
- UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"NoticeViewController" storyboardName:@"Main"];
- [self presentViewController:vc animated:YES completion:nil];
- }
- - (void)btnMessageBoxTouched:(id)sender {
- UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"MessageBoxViewController" storyboardName:@"Main"];
- [self presentViewController:vc animated:YES completion:nil];
- }
- - (void)btnHomeHubTouched:(id)sender {
-
- }
- - (IBAction)btnSettingsTouched:(id)sender {
-
- UIViewController *vc = [CommonUtil instantiateViewControllerWithIdentifier:@"SettingsViewController" storyboardName:@"Settings"];
- [self presentViewController:vc animated:YES completion:nil];
- }
- #pragma mark - MemoryWarning
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- @end
|