| ... |
... |
@@ -17,10 +17,12 @@
|
|
17 |
17 |
#include <inttypes.h>
|
|
18 |
18 |
#include <pebble.h>
|
|
19 |
19 |
|
|
|
20 |
+#include "dict_tools.h"
|
|
20 |
21 |
#include "progress_layer.h"
|
|
21 |
22 |
|
|
22 |
23 |
#define MSG_KEY_LAST_SENT 110
|
|
23 |
24 |
#define MSG_KEY_MODAL_MESSAGE 120
|
|
|
25 |
+#define MSG_KEY_UPLOAD_DONE 130
|
|
24 |
26 |
#define MSG_KEY_DATA_KEY 210
|
|
25 |
27 |
#define MSG_KEY_DATA_LINE 220
|
|
26 |
28 |
|
| ... |
... |
@@ -42,31 +44,49 @@ static struct {
|
|
42 |
44 |
ProgressLayer *progress_layer;
|
|
43 |
45 |
uint32_t first_key;
|
|
44 |
46 |
uint32_t current_key;
|
|
45 |
|
-} ui;
|
|
|
47 |
+} phone, web;
|
|
46 |
48 |
|
|
47 |
49 |
static void
|
|
48 |
50 |
set_modal_mode(bool is_modal) {
|
|
49 |
51 |
if (is_modal == modal_displayed) return;
|
|
50 |
52 |
layer_set_hidden(text_layer_get_layer(modal_text_layer), !is_modal);
|
|
51 |
|
- layer_set_hidden(text_layer_get_layer(ui.label_layer), is_modal);
|
|
52 |
|
- layer_set_hidden(ui.progress_layer, is_modal);
|
|
|
53 |
+ layer_set_hidden(text_layer_get_layer(phone.label_layer), is_modal);
|
|
|
54 |
+ layer_set_hidden(phone.progress_layer, is_modal);
|
|
|
55 |
+ layer_set_hidden(text_layer_get_layer(web.label_layer), is_modal);
|
|
|
56 |
+ layer_set_hidden(web.progress_layer, is_modal);
|
|
53 |
57 |
modal_displayed = is_modal;
|
|
54 |
58 |
}
|
|
55 |
59 |
|
|
56 |
60 |
static void
|
|
57 |
61 |
update_progress(void) {
|
|
58 |
62 |
int32_t last_key = (time(0) + 59) / 60;
|
|
59 |
|
- int32_t key_span = last_key - ui.first_key;
|
|
60 |
|
- int32_t keys_done = ui.current_key - ui.first_key + 1;
|
|
61 |
63 |
|
|
62 |
|
- progress_layer_set_progress(ui.progress_layer,
|
|
63 |
|
- (keys_done * 100 + key_span / 2) / key_span);
|
|
64 |
|
- snprintf(ui.label, sizeof ui.label, "%" PRIi32 " / %" PRIi32,
|
|
65 |
|
- keys_done, key_span);
|
|
|
64 |
+ if (phone.current_key) {
|
|
|
65 |
+ int32_t key_span = last_key - phone.first_key;
|
|
|
66 |
+ int32_t keys_done = phone.current_key - phone.first_key + 1;
|
|
|
67 |
+
|
|
|
68 |
+ progress_layer_set_progress(phone.progress_layer,
|
|
|
69 |
+ (keys_done * 100 + key_span / 2) / key_span);
|
|
|
70 |
+ snprintf(phone.label, sizeof phone.label,
|
|
|
71 |
+ "%" PRIi32 " / %" PRIi32,
|
|
|
72 |
+ keys_done, key_span);
|
|
|
73 |
+ }
|
|
|
74 |
+
|
|
|
75 |
+ if (web.current_key) {
|
|
|
76 |
+ int32_t key_span = last_key - web.first_key;
|
|
|
77 |
+ int32_t keys_done = web.current_key - web.first_key + 1;
|
|
|
78 |
+
|
|
|
79 |
+ progress_layer_set_progress(web.progress_layer,
|
|
|
80 |
+ (keys_done * 100 + key_span / 2) / key_span);
|
|
|
81 |
+ snprintf(web.label, sizeof web.label,
|
|
|
82 |
+ "%" PRIi32 " / %" PRIi32,
|
|
|
83 |
+ keys_done, key_span);
|
|
|
84 |
+ }
|
|
66 |
85 |
}
|
|
67 |
86 |
|
|
68 |
87 |
#define PROGRESS_HEIGHT 10
|
|
69 |
88 |
#define PROGRESS_MARGIN 8
|
|
|
89 |
+#define LABEL_MARGIN (PROGRESS_HEIGHT + PROGRESS_MARGIN)
|
|
70 |
90 |
#define LABEL_HEIGHT 22
|
|
71 |
91 |
|
|
72 |
92 |
static void
|
| ... |
... |
@@ -82,26 +102,47 @@ window_load(Window *window) {
|
|
82 |
102 |
fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
|
|
83 |
103 |
layer_add_child(window_layer, text_layer_get_layer(modal_text_layer));
|
|
84 |
104 |
|
|
85 |
|
- ui.label_layer = text_layer_create(GRect(0,
|
|
86 |
|
- bounds.size.h / 2 - LABEL_HEIGHT - PROGRESS_MARGIN / 2,
|
|
|
105 |
+ phone.label_layer = text_layer_create(GRect(0,
|
|
|
106 |
+ bounds.size.h / 2 - LABEL_HEIGHT - LABEL_MARGIN,
|
|
87 |
107 |
bounds.size.w,
|
|
88 |
108 |
LABEL_HEIGHT));
|
|
89 |
|
- text_layer_set_text(ui.label_layer, ui.label);
|
|
90 |
|
- text_layer_set_text_alignment(ui.label_layer, GTextAlignmentCenter);
|
|
91 |
|
- text_layer_set_font(ui.label_layer,
|
|
|
109 |
+ text_layer_set_text(phone.label_layer, phone.label);
|
|
|
110 |
+ text_layer_set_text_alignment(phone.label_layer, GTextAlignmentCenter);
|
|
|
111 |
+ text_layer_set_font(phone.label_layer,
|
|
92 |
112 |
fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
|
|
93 |
|
- layer_add_child(window_layer, text_layer_get_layer(ui.label_layer));
|
|
|
113 |
+ layer_add_child(window_layer, text_layer_get_layer(phone.label_layer));
|
|
|
114 |
+
|
|
|
115 |
+ phone.progress_layer = progress_layer_create(GRect(bounds.size.w / 4,
|
|
|
116 |
+ bounds.size.h / 2 - PROGRESS_HEIGHT - PROGRESS_MARGIN / 2,
|
|
|
117 |
+ bounds.size.w / 2,
|
|
|
118 |
+ PROGRESS_HEIGHT));
|
|
|
119 |
+ progress_layer_set_progress(phone.progress_layer, 0);
|
|
|
120 |
+ progress_layer_set_corner_radius(phone.progress_layer, 3);
|
|
|
121 |
+ progress_layer_set_foreground_color(phone.progress_layer, GColorBlack);
|
|
|
122 |
+ progress_layer_set_background_color(phone.progress_layer,
|
|
|
123 |
+ GColorLightGray);
|
|
|
124 |
+ layer_add_child(window_layer, phone.progress_layer);
|
|
94 |
125 |
|
|
95 |
|
- ui.progress_layer = progress_layer_create(GRect(bounds.size.w / 4,
|
|
|
126 |
+ web.progress_layer = progress_layer_create(GRect(bounds.size.w / 4,
|
|
96 |
127 |
bounds.size.h / 2 + PROGRESS_MARGIN / 2,
|
|
97 |
128 |
bounds.size.w / 2,
|
|
98 |
129 |
PROGRESS_HEIGHT));
|
|
99 |
|
- progress_layer_set_progress(ui.progress_layer, 0);
|
|
100 |
|
- progress_layer_set_corner_radius(ui.progress_layer, 3);
|
|
101 |
|
- progress_layer_set_foreground_color(ui.progress_layer, GColorBlack);
|
|
102 |
|
- progress_layer_set_background_color(ui.progress_layer,
|
|
|
130 |
+ progress_layer_set_progress(web.progress_layer, 0);
|
|
|
131 |
+ progress_layer_set_corner_radius(web.progress_layer, 3);
|
|
|
132 |
+ progress_layer_set_foreground_color(web.progress_layer, GColorBlack);
|
|
|
133 |
+ progress_layer_set_background_color(web.progress_layer,
|
|
103 |
134 |
GColorLightGray);
|
|
104 |
|
- layer_add_child(window_layer, ui.progress_layer);
|
|
|
135 |
+ layer_add_child(window_layer, web.progress_layer);
|
|
|
136 |
+
|
|
|
137 |
+ web.label_layer = text_layer_create(GRect(0,
|
|
|
138 |
+ bounds.size.h / 2 + LABEL_MARGIN,
|
|
|
139 |
+ bounds.size.w,
|
|
|
140 |
+ LABEL_HEIGHT));
|
|
|
141 |
+ text_layer_set_text(web.label_layer, web.label);
|
|
|
142 |
+ text_layer_set_text_alignment(web.label_layer, GTextAlignmentCenter);
|
|
|
143 |
+ text_layer_set_font(web.label_layer,
|
|
|
144 |
+ fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
|
|
|
145 |
+ layer_add_child(window_layer, text_layer_get_layer(web.label_layer));
|
|
105 |
146 |
|
|
106 |
147 |
set_modal_mode(true);
|
|
107 |
148 |
}
|
| ... |
... |
@@ -109,8 +150,10 @@ window_load(Window *window) {
|
|
109 |
150 |
static void
|
|
110 |
151 |
window_unload(Window *window) {
|
|
111 |
152 |
text_layer_destroy(modal_text_layer);
|
|
112 |
|
- text_layer_destroy(ui.label_layer);
|
|
113 |
|
- progress_layer_destroy(ui.progress_layer);
|
|
|
153 |
+ text_layer_destroy(phone.label_layer);
|
|
|
154 |
+ text_layer_destroy(web.label_layer);
|
|
|
155 |
+ progress_layer_destroy(phone.progress_layer);
|
|
|
156 |
+ progress_layer_destroy(web.progress_layer);
|
|
114 |
157 |
}
|
|
115 |
158 |
|
|
116 |
159 |
static void
|
| ... |
... |
@@ -225,8 +268,8 @@ send_minute_data(HealthMinuteData *data, HealthActivityMask activity_mask,
|
|
225 |
268 |
(int)msg_result);
|
|
226 |
269 |
}
|
|
227 |
270 |
|
|
228 |
|
- if (!ui.first_key) ui.first_key = int_key;
|
|
229 |
|
- ui.current_key = int_key;
|
|
|
271 |
+ if (!phone.first_key) phone.first_key = int_key;
|
|
|
272 |
+ phone.current_key = int_key;
|
|
230 |
273 |
update_progress();
|
|
231 |
274 |
|
|
232 |
275 |
APP_LOG(APP_LOG_LEVEL_INFO, "sent data for key %" PRIi32, int_key);
|
| ... |
... |
@@ -346,6 +389,13 @@ inbox_received_handler(DictionaryIterator *iterator, void *context) {
|
|
346 |
389 |
set_modal_message(tuple->value->cstring);
|
|
347 |
390 |
}
|
|
348 |
391 |
}
|
|
|
392 |
+
|
|
|
393 |
+ tuple = dict_find(iterator, MSG_KEY_UPLOAD_DONE);
|
|
|
394 |
+ if (tuple) {
|
|
|
395 |
+ web.current_key = tuple_uint(tuple);
|
|
|
396 |
+ if (!web.first_key) web.first_key = web.current_key;
|
|
|
397 |
+ update_progress();
|
|
|
398 |
+ }
|
|
349 |
399 |
}
|
|
350 |
400 |
|
|
351 |
401 |
static void
|