| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- //
- // DeviceConditionPopupView.m
- // kneet2
- //
- // Created by Jason Lee on 11/26/15.
- // Copyright (c) 2015 ntels. All rights reserved.
- //
- #import "JDObject.h"
- #import "RequestHandler.h"
- #import "JDJSONModel.h"
- #import "CustomLabel.h"
- #import "CustomTextField.h"
- #import "CustomTableView.h"
- #import "CustomImageView.h"
- #import "CustomButton.h"
- #import "CustomCheckBox.h"
- #import "CustomRadioGroup.h"
- #import "ValidateUtil.h"
- #import "ImageUtil.h"
- #import "UIImageView+WebCache.h"
- #import "DeviceConditionPopupView.h"
- @implementation DeviceConditionPopupTableViewCell
- @end
- @interface DeviceConditionPopupView () <UITableViewDataSource, UITableViewDelegate, CustomCheckBoxDelegate> {
-
- CustomRadioReusableGroup *_rgroup;
- BOOL _isNotFirstLoading;
- UIImage *_bgCellImage1, *_bgCellImage2;
-
- NSMutableArray<ItemModel> *_checkedDevices;
- }
- @end
- @implementation DeviceSelectPopupView
- - (id)initFromNib {
- for (UIView *view in [CommonUtil nibViews:@"DeviceSelectPopupView"]) {
- if ([view isKindOfClass:[DeviceSelectPopupView class]]) {
- self = (DeviceSelectPopupView *)view;
- //XIB의 경우, 현재 화면 사이즈로 맞춰줘야 함.
- self.frame = [UIScreen mainScreen].bounds;
- self.lblTitle.text = NSLocalizedString(@"장치 선택", @"장치 선택");
-
- [self initTableViewAsDefaultStyle:_tableView];
-
- UINib *nib = [UINib nibWithNibName:@"DeviceSelectPopupTableViewCell" bundle:nil];
- [_tableView registerNib:nib forCellReuseIdentifier:@"DeviceCellIdentifier"];
-
- //set radio group
- _rgroup = [[CustomRadioReusableGroup alloc] init];
- _rgroup.tableView = _tableView;
-
- //Localization
- [self.btnConfirm setTitle:NSLocalizedString(@"확인", @"확인") forState:UIControlStateNormal];
- [self.btnCancel setTitle:NSLocalizedString(@"취소", @"취소") forState:UIControlStateNormal];
-
- UIEdgeInsets insets = UIEdgeInsetsMake(4, 4, 4, 4);
- _bgCellImage1 = [ImageUtil resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch img:[UIImage imageNamed:@"tp_01_img_list_bg_01"]];
- _bgCellImage2 = [ImageUtil resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch img:[UIImage imageNamed:@"tp_01_img_list_bg_02"]];
- }
- }
- return self;
- }
- - (void)initTableViewAsDefaultStyle:(CustomTableView *)tableView {
- tableView.dataSource = self;
- tableView.delegate = self;
-
- tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- tableView.backgroundColor = [UIColor clearColor];
-
- tableView.tableFooterView = [[UIView alloc] init]; //this call table events;
- }
- - (void)didMoveToSuperview {
- }
- - (void)setRefDevices:(NSMutableArray<ItemModel> *)refDevices {
- _refDevices = refDevices;
-
- for (ItemSubModel *item in _refDevices) {
- [[JDFacade facade] setRadioButtonStatus:@NO object:item];
- }
-
- [_tableView reloadData];
- }
- - (NSArray<ItemModel> *)selectedDevices {
- NSArray<ItemModel> *devices = nil;
-
- if ([_typeCode isEqualToString:ksItemTypeCodeAction]) {
- devices = _checkedDevices;
- } else {
- devices = (NSArray<ItemModel> *)@[_rgroup.valueForChecked];
- }
- return devices;
- }
- #pragma mark - Main Logic
- #pragma mark - UITableView DataSource & Delegate
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return _refDevices ? _refDevices.count : 0;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- CGFloat height = 95.0f;
-
- return height;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
-
- ItemModel *item = _refDevices[indexPath.row];
-
- DeviceSelectPopupTableViewCell *tcell = (DeviceSelectPopupTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"DeviceCellIdentifier"];
- tcell.lblDeviceName.text = item.sourceName;
- [tcell.imgvDevice sd_setImageWithURL:[NSURL URLWithString:item.imageFileName] placeholderImage:nil options:SDWebImageRefreshCached];
-
-
- if ([_typeCode isEqualToString:ksItemTypeCodeTrigger] || [_typeCode isEqualToString:ksItemTypeCodeCondition]) {//트리거 또는 컨디션
- tcell.chkSelect.hidden = YES;
-
- tcell.rdoSelect.value = item;
- if (indexPath.row == 0 && !_isNotFirstLoading) {
- _isNotFirstLoading = YES;
- tcell.rdoSelect.checked = YES;
- } else {
- tcell.rdoSelect.checked = [tcell.rdoSelect getRadioStatusFromValue];
- }
-
- [_rgroup addRadioButton:tcell.rdoSelect];
-
- } else if ([_typeCode isEqualToString:ksItemTypeCodeAction]) {//액션
- tcell.rdoSelect.hidden = YES;
-
- tcell.chkSelect.delegate = self;
- tcell.chkSelect.value = item;
- tcell.chkSelect.checked = [tcell.chkSelect getCheckStatusFromValue];
- }
-
- return tcell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
-
- DeviceSelectPopupTableViewCell *tcell = (DeviceSelectPopupTableViewCell *)[self tableView:tableView cellForRowAtIndexPath:indexPath];
-
- if ([_typeCode isEqualToString:ksItemTypeCodeTrigger] || [_typeCode isEqualToString:ksItemTypeCodeCondition]) {
- [_rgroup someRadioButtonTouched:tcell.rdoSelect];
-
- } else if ([_typeCode isEqualToString:ksItemTypeCodeAction]) {
- [tcell.chkSelect checkBoxClicked];
-
- }
- [_tableView reloadData];
- }
- - (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 - CustomCheckBox Delegate
- - (void)didCheckBoxClicked:(id)sender {
- }
- #pragma mark - UI Events
- - (IBAction)btnConfirmTouched:(id)sender {
- //validate
-
- if ([_typeCode isEqualToString:ksItemTypeCodeAction]) {//디바이스 멀티 BOOL isSelected = NO;
-
- _checkedDevices = (NSMutableArray<ItemModel> *)[_refDevices matchedArrayByObjectName:ksCustomCheckBoxStatus condition:YES];
- if (!_checkedDevices || !_checkedDevices.count) {
- [[JDFacade facade] alert:NSLocalizedString(@"선택된 항목이 없습니다", @"선택된 항목이 없습니다")];
- return;
- }
- }
-
- [super btnConfirmTouched:sender];
- }
- @end
|