| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- //
- // ScenesRegisterPredefineViewController.m
- // kneet
- //
- // Created by Jason Lee on 4/1/15.
- // Copyright (c) 2015 ntels. All rights reserved.
- //
- #import "RequestHandler.h"
- #import "SceneModel.h"
- #import "CustomLabel.h"
- #import "CustomImageView.h"
- #import "UIImageView+WebCache.h"
- #import "ScenesRegisterViewController.h"
- #import "ScenesRegisterPredefineViewController.h"
- #import "JYRefreshController.h"
- @implementation PredefinedSceneTitleViewCell
- - (void)awakeFromNib {
- _lblTitle.text = NSLocalizedString(@"샘플을 선택하세요", @"샘플을 선택하세요");
- self.backgroundColor = [UIColor clearColor];
- }
- @end
- @implementation PredefinedSceneTableViewCell
- - (void)awakeFromNib {
- self.backgroundColor = [UIColor clearColor];
- }
- @end
- @interface ScenesRegisterPredefineViewController () <UITableViewDataSource, UITableViewDelegate> {
- NSString *_pagingType, *_pagingId;
- NSMutableArray<SceneModel> *_predefinedSceneList;
- UIImage *_bgCellImage1, *_bgCellImage2;
- }
- @property (strong, nonatomic) JYPullToRefreshController *refreshController;
- @property (strong, nonatomic) JYPullToLoadMoreController *loadMoreController;
- @end
- #pragma mark - Class Definition
- @implementation ScenesRegisterPredefineViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- _predefinedSceneList = (NSMutableArray<SceneModel> *)[[NSMutableArray alloc] init];
- _pagingId = nil;
- _pagingType = nil;
- [self initUI];
- [self prepareViewDidLoad];
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- self.title = NSLocalizedString(@"멀티 제어 만들기",nil);
- }
- - (void)initUI {
- //initialize tableview
- _tableView.dataSource = self;
- _tableView.delegate = self;
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _tableView.backgroundColor = [UIColor clearColor];
- _tableView.tableFooterView = [[UIView alloc] init]; //this call table events;
- //set refresh controls
- __weak typeof(self) weakSelf = self;
- self.refreshController = [[JYPullToRefreshController alloc] initWithScrollView:self.tableView];
- self.refreshController.pullToRefreshHandleAction = ^{
- [weakSelf requestPredefinedRulesRecently];
- };
-
- self.loadMoreController = [[JYPullToLoadMoreController alloc] initWithScrollView:self.tableView];
- self.loadMoreController.pullToLoadMoreHandleAction = ^{
- [weakSelf requestPredefinedRulesOlder];
- };
- UIEdgeInsets insets = UIEdgeInsetsMake(4, 4, 4, 4);
- _bgCellImage1 = [CommonUtil resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch img:[UIImage imageNamed:@"tp_01_img_list_bg_01"]];
- _bgCellImage2 = [CommonUtil resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch img:[UIImage imageNamed:@"tp_01_img_list_bg_02"]];
- }
- - (void)prepareViewDidLoad {
- [self performSelector:@selector(requestPredefinedScenes) withObject:nil afterDelay:0.0f];
- }
- #pragma mark - Main Logic
- - (void)requestPredefinedRulesRecently {
- SceneModel *firstScene = [_predefinedSceneList firstObject];
- _pagingType = ksListPagingTypeUpward;
- _pagingId = firstScene.predSceneId;
- [self performSelector:@selector(requestPredefinedScenes) withObject:nil afterDelay:0.0f];
- }
- - (void)requestPredefinedRulesOlder {
- SceneModel *lastScene = [_predefinedSceneList lastObject];
- _pagingType = ksListPagingTypeDownward;
- _pagingId = lastScene.predSceneId;
- [self performSelector:@selector(requestPredefinedScenes) withObject:nil afterDelay:0.0f];
- }
- - (void)requestPredefinedScenes {
- NSDictionary *parameter = @{@"pred_scene_id": _pagingId ? _pagingId : ksEmptyString,
- @"paging_type": _pagingType ? _pagingType : ksEmptyString};
- NSString *path = [NSString stringWithFormat:API_GET_PRESCENE_LIST];
- [[RequestHandler handler] sendAsyncGetRequestAPIPath:path parameters:parameter modelClass:[SceneListModel class] completion:^(id responseObject) {
- if (!responseObject) {//응답결과가 잘못되었거나 없을 경우,
- return;
- }
- SceneListModel *fetchedPreRuleList = (SceneListModel *)responseObject;
- if (fetchedPreRuleList && fetchedPreRuleList.list && fetchedPreRuleList.list.count) {//API 성공,
- [_predefinedSceneList addObjectsFromArray:fetchedPreRuleList.list];
- } else {//실패 시,
- if (!_predefinedSceneList.count) {//이미 로드된 데이터가 있을 경우는 출력하지 않음.
- // NoContentView *noContentView = [NoContentView viewFromNib];
- // _tableView.tableFooterView = noContentView;
- }
- }
- [_tableView reloadData];
- } failure:^(id errorObject) {
- JDErrorModel *error = (JDErrorModel *)errorObject;
- [[JDFacade facade] alert:error.errorMessage];
- }];
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return _predefinedSceneList.count + 1;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- CGFloat height = 100.0f;
- if (indexPath.row == 0) {
- height = 40.0f;
- }
- return height;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- UITableViewCell *cell = nil;
- if (indexPath.row == 0) {//info cell
- cell = [tableView dequeueReusableCellWithIdentifier:@"InfoCellIdentifier"];
- } else {
- PredefinedSceneTableViewCell *pcell = [tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];
- if (pcell == nil) {
- pcell = [[PredefinedSceneTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CellIdentifier"];
- }
- SceneModel *predefinedScene = _predefinedSceneList[indexPath.row-1];
- pcell.lblSceneName.text = predefinedScene.sceneName;
- [pcell.imgvIcon sd_setImageWithURL:[NSURL URLWithString:predefinedScene.imageFileName] placeholderImage:nil];
- cell = pcell;
- }
- //set background image
- if (indexPath.row % 2 == 1) {
- cell.backgroundView = [[UIImageView alloc] initWithImage:_bgCellImage1];
- } else {
- cell.backgroundView = [[UIImageView alloc] initWithImage:_bgCellImage2];
- }
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
- if (indexPath.row == 0)
- return;
- //goto rule title register
- ScenesRegisterViewController *vc = (ScenesRegisterViewController *)[CommonUtil instantiateViewControllerWithIdentifier:@"ScenesRegisterViewController" storyboardName:@"Scenes"];
- SceneModel *predefinedScene = _predefinedSceneList[indexPath.row-1];
- vc.tmpPredScene = predefinedScene;
- [self.navigationController pushViewController:vc animated:YES];
- }
- - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
- // Remove seperator inset
- if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
- [cell setSeparatorInset:UIEdgeInsetsZero];
- }
- // Prevent the cell from inheriting the Table View's margin settings
- if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
- [cell setPreservesSuperviewLayoutMargins:NO];
- }
- // Explictly set your cell's layout margins
- if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
- [cell setLayoutMargins:UIEdgeInsetsZero];
- }
- }
- #pragma mark - UI Events
- #pragma mark - MemoryWarning
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- @end
|