ICRTaskItemView.m 5.38 KB
Newer Older
mei's avatar
mei committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
//
//  ICRTaskItemView.m
//  XFFruit
//
//  Created by Xummer on 4/11/15.
//  Copyright (c) 2015 Xummer. All rights reserved.
//

#import "ICRTaskItemView.h"

#define TASK_LABEL_VERTICAL_MARGIN  (10.0f)
#define TASK_LABEL_HORIZON_MARGIN   (15.0f)
#define TASK_LABEL_INNER_GAP        (5.0f)

@interface ICRTaskItemView ()
@property (strong, nonatomic) IBTUILabel *m_storeLabel;
@property (strong, nonatomic) IBTUILabel *m_storeValueLabel;
@property (strong, nonatomic) IBTUILabel *m_codeLabel;
@property (strong, nonatomic) IBTUILabel *m_codeValueLabel;
@property (strong, nonatomic) IBTUILabel *m_typeLabel;
@property (strong, nonatomic) IBTUILabel *m_typeValueLabel;
@property (strong, nonatomic) IBTUILabel *m_taskLabel;
@property (strong, nonatomic) IBTUILabel *m_taskValueLabel;
@property (strong, nonatomic) IBTUILabel *m_deadLineLabel;
@property (strong, nonatomic) IBTUILabel *m_deadLineValueLabel;

@end

@implementation ICRTaskItemView

#pragma mark - Life Cycle
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (!self) {
        return nil;
    }
    
    [self initSubviews];
    
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    CGFloat fMaxW = self.width - 2 * TASK_LABEL_HORIZON_MARGIN;
    
    [_m_storeLabel sizeToFit];
    _m_storeLabel.origin = (CGPoint){
        .x = TASK_LABEL_HORIZON_MARGIN,
        .y = TASK_LABEL_VERTICAL_MARGIN
    };
    
    _m_storeValueLabel.frame = (CGRect){
        .origin.x = _m_storeLabel.right,
        .origin.y = _m_storeLabel.y,
        .size.width = fMaxW - _m_storeLabel.width,
        .size.height = _m_storeLabel.height
    };
    
    [_m_codeLabel sizeToFit];
    _m_codeLabel.origin = (CGPoint){
        .x = _m_storeLabel.x,
        .y = _m_storeLabel.bottom + TASK_LABEL_INNER_GAP
    };
    
    _m_codeValueLabel.frame = (CGRect){
        .origin.x = _m_codeLabel.right,
        .origin.y = _m_codeLabel.y,
        .size.width = fMaxW - _m_codeLabel.width,
        .size.height = _m_codeLabel.height
    };
    
    [_m_typeLabel sizeToFit];
    _m_typeLabel.origin = (CGPoint){
        .x = _m_storeLabel.x,
        .y = _m_codeLabel.bottom + TASK_LABEL_INNER_GAP
    };
    
    _m_typeValueLabel.frame = (CGRect){
        .origin.x = _m_typeLabel.right,
        .origin.y = _m_typeLabel.y,
        .size.width = fMaxW - _m_typeLabel.width,
        .size.height = _m_typeLabel.height
    };
    
    
    [_m_taskLabel sizeToFit];
    _m_taskLabel.origin = (CGPoint){
        .x = _m_storeLabel.x,
        .y = _m_typeLabel.bottom + TASK_LABEL_INNER_GAP
    };
    
    _m_taskValueLabel.frame = (CGRect){
        .origin.x = _m_taskLabel.right,
        .origin.y = _m_taskLabel.y,
        .size.width = fMaxW - _m_taskLabel.width,
        .size.height = _m_taskLabel.height
    };

    [_m_deadLineLabel sizeToFit];
    _m_deadLineLabel.origin = (CGPoint){
        .x = _m_storeLabel.x,
        .y = _m_taskLabel.bottom + TASK_LABEL_INNER_GAP
    };
    
    _m_deadLineValueLabel.frame = (CGRect){
        .origin.x = _m_deadLineLabel.right,
        .origin.y = _m_deadLineLabel.y,
        .size.width = fMaxW - _m_deadLineLabel.width,
        .size.height = _m_deadLineLabel.height
    };
}

#pragma mark - Private Method
- (void)initSubviews {
    
    self.m_storeLabel =
    [[self class] titleLabelWithText:[IBTCommon localizableString:@"Store"]];
    
    self.m_codeLabel =
    [[self class] titleLabelWithText:[IBTCommon localizableString:@"Task Code"]];
    
    self.m_typeLabel =
    [[self class] titleLabelWithText:[IBTCommon localizableString:@"Task Type"]];
    
    self.m_taskLabel =
    [[self class] titleLabelWithText:[IBTCommon localizableString:@"Task Title"]];
    
    self.m_deadLineLabel =
    [[self class] titleLabelWithText:[IBTCommon localizableString:@"Task Deadline"]];
    
    self.m_storeValueLabel = [[self class] valueLabel];
    self.m_codeValueLabel = [[self class] valueLabel];
    self.m_typeValueLabel = [[self class] valueLabel];
    self.m_taskValueLabel = [[self class] valueLabel];
    self.m_deadLineValueLabel = [[self class] valueLabel];
    
    [self addSubview:_m_storeLabel];
    [self addSubview:_m_codeLabel];
    [self addSubview:_m_typeLabel];
    [self addSubview:_m_taskLabel];
    [self addSubview:_m_deadLineLabel];
    [self addSubview:_m_storeValueLabel];
    [self addSubview:_m_codeValueLabel];
    [self addSubview:_m_typeValueLabel];
    [self addSubview:_m_taskValueLabel];
    [self addSubview:_m_deadLineValueLabel];
}

+ (IBTUILabel *)titleLabelWithText:(NSString *)nsTitle {
    IBTUILabel *label = [[IBTUILabel alloc] init];
    label.textAlignment = NSTextAlignmentLeft;
    label.textColor = [UIColor blackColor];
    label.font = [UIFont systemFontOfSize:15.0f];
    label.text = [nsTitle stringByAppendingString:@":"];
    return label;
}

+ (IBTUILabel *)valueLabel {
    IBTUILabel *label = [[IBTUILabel alloc] init];
    label.textAlignment = NSTextAlignmentLeft;
    label.textColor = [UIColor blackColor];
    label.font = [UIFont systemFontOfSize:15.0f];
    return label;
}

@end

#import "ICRTask.h"
@implementation ICRTaskItemView (Configure)

- (void)updateWithTask:(ICRTask *)task {
    self.m_storeValueLabel.text = task.storeCode;
    self.m_codeValueLabel.text = task.billNumber;
    self.m_typeValueLabel.text = task.billNumber;
    self.m_taskValueLabel.text = task.title;
    self.m_deadLineValueLabel.text = task.requireDate;
    
    [self setNeedsLayout];
}

@end