This repository has been archived by the owner on Apr 18, 2018. It is now read-only.
/
KBStatusViewController.m
157 lines (133 loc) · 5.38 KB
/
KBStatusViewController.m
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
//
// KBStatusViewController.m
// KegPad
//
// Created by Gabriel Handford on 7/30/10.
// Copyright 2010 Yelp. All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
#import "KBStatusViewController.h"
#import "KBNotifications.h"
#import "KBDataStore.h"
#import "KBApplication.h"
#import "KBApplicationDelegate.h"
@implementation KBStatusViewController
@synthesize nameLabel=nameLabel_, lastPourTimeLabel=lastPourTimeLabel_, lastPourTimeUnitsLabel=lastPourTimeUnitsLabel_,
lastPourAmountLabel=lastPourAmountLabel_, lastPourAmountUnitsLabel=lastPourAmountUnitsLabel_,
percentRemaingLabel=percentRemaingLabel_, totalPouredAmountLabel=totalPouredAmountLabel_,
temperatureLabel=temperatureLabel_, temperatureDescriptionLabel=temperatureDescriptionLabel_,
chartView=chartView_, leaderboardView=leaderboardView_, delegate=delegate_, flowIndicator=flowIndicator_;
- (id)init {
if ((self = [super initWithNibName:nil bundle:nil])) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"KBFlowIndicator" owner:nil options:nil];
for (id currentObject in topLevelObjects) {
if ([currentObject isKindOfClass:[KBFlowIndicator class]]) {
self.flowIndicator = currentObject;
break;
}
}
self.flowIndicator.frame = CGRectMake(20, 331, 402, 350);
[self.view addSubview:self.flowIndicator];
}
return self;
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[nameLabel_ release];
[lastPourTimeLabel_ release];
[lastPourTimeUnitsLabel_ release];
[lastPourAmountLabel_ release];
[lastPourAmountUnitsLabel_ release];
[percentRemaingLabel_ release];
[totalPouredAmountLabel_ release];
[temperatureLabel_ release];
[temperatureDescriptionLabel_ release];
[chartView_ release];
[leaderboardView_ release];
[flowIndicator_ release];
[super dealloc];
}
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] removeObserver:self];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_kegTemperatureDidChange:) name:KBKegTemperatureDidChangeNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_kegVolumeDidChange:) name:KBKegVolumeDidChangeNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_kegDidStartPour:) name:KBKegDidStartPourNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_kegDidEndPour:) name:KBKegDidEndPourNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_kegDidSavePour:) name:KBKegDidSavePourNotification object:nil];
}
- (void)updateLeaderboard {
[leaderboardView_ setUsers:[[KBApplication dataStore] topUsersByPourWithOffset:0 limit:6 error:nil]];
}
- (void)updateChart {
[chartView_ recompute];
}
- (void)updateKeg:(KBKeg *)keg {
self.view;
if (keg) {
nameLabel_.text = keg.beer.name;
percentRemaingLabel_.text = [NSString stringWithFormat:@"%0.0f", [keg volumeRemaingPercentage]];
totalPouredAmountLabel_.text = [NSString stringWithFormat:@"%0.1f liters", [keg volumeTotalPouredAdjustedValue]];
} else {
nameLabel_.text = @"";
percentRemaingLabel_.text = @"";
totalPouredAmountLabel_.text = @"-";
}
}
- (void)setLastKegPour:(KBKegPour *)kegPour {
self.view;
if (kegPour) {
NSDate *date = [kegPour date];
lastPourTimeLabel_.text = [NSString stringWithFormat:@"%d", [kegPour timeAgoInteger:date]];
lastPourTimeUnitsLabel_.text = [kegPour timeAgoUnitsDescription:date];
lastPourAmountLabel_.text = [kegPour amountValueDescriptionInOunces];
lastPourAmountUnitsLabel_.text = @"OUNCES";
} else {
lastPourTimeLabel_.text = @"-";
lastPourTimeUnitsLabel_.text = @"-";
lastPourAmountLabel_.text = @"-";
lastPourAmountUnitsLabel_.text = @"-";
}
}
- (void)setKegTemperature:(KBKegTemperature *)kegTemperature {
self.view;
if (kegTemperature) {
temperatureLabel_.text = [NSString stringWithFormat:@"%0.1f°C", [kegTemperature temperatureValue]];
temperatureDescriptionLabel_.text = [kegTemperature statusDescription];
} else {
temperatureLabel_.text = @"-";
temperatureDescriptionLabel_.text = @"TEMP.";
}
}
- (IBAction)flip:(id)sender {
[delegate_ flip];
}
#pragma mark -
- (void)_kegTemperatureDidChange:(NSNotification *)notification {
[self setKegTemperature:[notification object]];
}
- (void)_kegVolumeDidChange:(NSNotification *)notification {
[self updateKeg:[notification object]];
}
- (void)_kegDidStartPour:(NSNotification *)notification {
}
- (void)_kegDidEndPour:(NSNotification *)notification {
}
- (void)_kegDidSavePour:(NSNotification *)notification {
[self setLastKegPour:[notification object]];
[self updateLeaderboard];
[self updateChart];
}
@end