-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathAppConfiguration.java
More file actions
316 lines (244 loc) · 8.21 KB
/
AppConfiguration.java
File metadata and controls
316 lines (244 loc) · 8.21 KB
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
/*
* Copyright 2003-2020 The Kegbot Project contributors <info@kegbot.org>
*
* This file is part of the Kegtab package from the Kegbot project. For
* more information on Kegtab or Kegbot, see <http://kegbot.org/>.
*
* Kegtab 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, version 2.
*
* Kegtab 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 Kegtab. If not, see <http://www.gnu.org/licenses/>.
*/
package org.kegbot.app.config;
import java.net.MalformedURLException;
import java.net.URL;
/**
* Helper methods for getting and setting preferences from a {@link ConfigurationStore}. This is the
* primary interface for app-local configuration settings.
*/
public class AppConfiguration {
public static final String TRUE = Boolean.TRUE.toString();
public static final String FALSE = Boolean.FALSE.toString();
private final ConfigurationStore mConfig;
public AppConfiguration(final ConfigurationStore config) {
mConfig = config;
}
private String get(ConfigKey key) {
return mConfig.getString(key.getName(), key.getDefault());
}
private void set(ConfigKey key, String value) {
mConfig.putString(key.getName(), value);
}
private boolean getBoolean(ConfigKey key) {
return mConfig.getBoolean(key.getName(), Boolean.valueOf(key.getDefault()).booleanValue());
}
private void setBoolean(ConfigKey key, boolean value) {
mConfig.putBoolean(key.getName(), value);
}
private int getInteger(ConfigKey key) {
return mConfig.getInteger(key.getName(), Integer.valueOf(key.getDefault()).intValue());
}
private void setInteger(ConfigKey key, int value) {
mConfig.putInteger(key.getName(), value);
}
private long getLong(ConfigKey key) {
return mConfig.getLong(key.getName(), Long.valueOf(key.getDefault()).longValue());
}
private void setLong(ConfigKey key, long value) {
mConfig.putLong(key.getName(), value);
}
public String getKegbotUrl() {
String uriString = get(ConfigKey.KEGBOT_URL);
uriString = uriString.replaceAll("/+$", "");
return uriString;
}
public String getApiUrl() {
return getKegbotUrl() + "/api";
}
public void setKegbotUrl(String url) {
url = url.replaceAll("/+$", "");
set(ConfigKey.KEGBOT_URL, url);
}
public boolean isKeghub() {
try {
return new URL(getKegbotUrl()).getHost().endsWith(".keghub.com");
} catch (MalformedURLException e) {
return false;
}
}
public void setApiKey(String key) {
set(ConfigKey.API_KEY, key);
}
public String getApiKey() {
return get(ConfigKey.API_KEY);
}
public String getPin() {
return get(ConfigKey.PIN);
}
public void setPin(String pin) {
set(ConfigKey.PIN, pin);
}
public String getUsername() {
return get(ConfigKey.USERNAME);
}
public void setUsername(String username) {
set(ConfigKey.USERNAME, username);
}
public long getMinimumVolumeMl() {
// TODO(mikey): Stored as a string due to EditTextPreference stupidity. Fix.
return Long.valueOf(get(ConfigKey.FLOW_MINIMUM_VOLUME_ML)).longValue();
}
public void setRunCore(boolean value) {
setBoolean(ConfigKey.RUN_CORE, value);
}
public boolean getRunCore() {
return getBoolean(ConfigKey.RUN_CORE);
}
public long getIdleTimeoutMs() {
// TODO(mikey): Stored as a string due to EditTextPreference stupidity. Fix.
return Long.valueOf(get(ConfigKey.FLOW_IDLE_TIMEOUT_SECONDS)).longValue() * 1000;
}
public long getIdleWarningMs() {
// TODO(mikey): Stored as a string due to EditTextPreference stupidity. Fix.
return Long.valueOf(get(ConfigKey.FLOW_IDLE_WARNING_SECONDS)).longValue() * 1000;
}
public int getSetupVersion() {
return getInteger(ConfigKey.SETUP_VERSION);
}
public void setSetupVersion(int value) {
setInteger(ConfigKey.SETUP_VERSION, value);
}
public boolean getAllowRegistration() {
return getBoolean(ConfigKey.ALLOW_REGISTRATION);
}
public boolean getAllowManualLogin() {
return getBoolean(ConfigKey.ALLOW_MANUAL_LOGIN);
}
public boolean getCacheCredentials() {
return getBoolean(ConfigKey.CACHE_CREDENTIALS);
}
public boolean getEnableFlowAutoStart() {
return getBoolean(ConfigKey.ENABLE_AUTOMATIC_FLOW_START);
}
public void setEnableFlowAutoStart(boolean value) {
setBoolean(ConfigKey.ENABLE_AUTOMATIC_FLOW_START, value);
}
public boolean getEnableAutoTakePhoto() {
return getBoolean(ConfigKey.AUTO_TAKE_PHOTOS);
}
public void setEnableAutoTakePhoto(boolean value) {
setBoolean(ConfigKey.AUTO_TAKE_PHOTOS, value);
}
public boolean getTakePhotosDuringRegistration() {
return getBoolean(ConfigKey.TAKE_PHOTOS_DURING_REGISTRATION);
}
public void setTakePhotosDuringRegistration(boolean value) {
setBoolean(ConfigKey.TAKE_PHOTOS_DURING_REGISTRATION, value);
}
public boolean getTakePhotosDuringPour() {
return getBoolean(ConfigKey.TAKE_PHOTOS_DURING_POUR);
}
public void setTakePhotosDuringPour(boolean value) {
setBoolean(ConfigKey.TAKE_PHOTOS_DURING_POUR, value);
}
public boolean getUseCamera() {
return getBoolean(ConfigKey.USE_CAMERA);
}
public void setUseCamera(boolean value) {
setBoolean(ConfigKey.USE_CAMERA, value);
}
public boolean getEnableCameraSounds() {
return getBoolean(ConfigKey.ENABLE_CAMERA_SOUNDS);
}
public void setEnableCameraSounds(boolean value) {
setBoolean(ConfigKey.ENABLE_CAMERA_SOUNDS, value);
}
public boolean getEnableAttractMode() {
return getBoolean(ConfigKey.ATTRACT_MODE);
}
public void setEnableAttractMode(boolean value) {
setBoolean(ConfigKey.ATTRACT_MODE, value);
}
public void setUpdateAvailable(boolean value) {
setBoolean(ConfigKey.UPDATE_AVAILABLE, value);
}
public boolean getUpdateAvailable() {
return getBoolean(ConfigKey.UPDATE_AVAILABLE);
}
public void setUpdateRequired(boolean value) {
setBoolean(ConfigKey.UPDATE_REQUIRED, value);
}
public boolean getUpdateRequired() {
return getBoolean(ConfigKey.UPDATE_REQUIRED);
}
public void setUseMetric(boolean value) {
setBoolean(ConfigKey.VOLUME_UNITS_METRIC, value);
}
public boolean getUseMetric() {
return getBoolean(ConfigKey.VOLUME_UNITS_METRIC);
}
public void setTemperaturesCelsius(boolean value) {
setBoolean(ConfigKey.TEMPERATURE_UNITS_CELSIUS, value);
}
public boolean getTemperaturesCelsius() {
return getBoolean(ConfigKey.TEMPERATURE_UNITS_CELSIUS);
}
public boolean stayAwake() {
return getBoolean(ConfigKey.STAY_AWAKE);
}
public boolean keepScreenOn() {
return getBoolean(ConfigKey.KEEP_SCREEN_ON);
}
public boolean wakeDuringPour() {
return getBoolean(ConfigKey.WAKE_DURING_POUR);
}
public boolean isLocalBackend() {
return getBoolean(ConfigKey.LOCAL_BACKEND);
}
public void setIsLocalBackend(boolean value) {
setBoolean(ConfigKey.LOCAL_BACKEND, value);
}
public boolean useAccounts() {
return !isLocalBackend();
}
public String getEmailAddress() {
return get(ConfigKey.EMAIL_ADDRESS);
}
public void setEmailAddress(String emailAddress) {
set(ConfigKey.EMAIL_ADDRESS, emailAddress);
}
public void setLastUsedKegSize(String size){
set(ConfigKey.LAST_USED_KEG_SIZE, size);
}
public String getLastUsedKegSize(){
return get(ConfigKey.LAST_USED_KEG_SIZE);
}
public String getNetworkControllerHost() {
return get(ConfigKey.NETWORK_CONTROLLER_HOST);
}
public int getNetworkControllerPort() {
return Integer.valueOf(get(ConfigKey.NETWORK_CONTROLLER_PORT)).intValue();
}
public String getMqttServer() {
return get(ConfigKey.MQTT_SERVER);
}
public int getMqttPort() {
return Integer.valueOf(get(ConfigKey.MQTT_PORT)).intValue();
}
public String getMqttUsername() {
return get(ConfigKey.MQTT_USERNAME);
}
public String getMqttPassword() {
return get(ConfigKey.MQTT_PASSWORD);
}
public String getMqttTopicPrefix() {
return get(ConfigKey.MQTT_TOPIC_PREFIX);
}
}