Browse code

Refactor update of progress UI

Natasha Kerensikova authored on02/04/2016 19:04:12
Showing1 changed files
... ...
@@ -37,7 +37,7 @@ static time_t minute_first = 0, minute_last = 0;
37 37
 static bool modal_displayed = false;
38 38
 static char global_buffer[1024];
39 39
 
40
-static struct {
40
+static struct widget {
41 41
 	char		label[64];
42 42
 	TextLayer	*label_layer;
43 43
 	ProgressLayer	*progress_layer;
... ...
@@ -57,30 +57,24 @@ set_modal_mode(bool is_modal) {
57 57
 }
58 58
 
59 59
 static void
60
-update_progress(void) {
61
-	int32_t last_key = (time(0) + 59) / 60;
62
-
63
-	if (phone.current_key) {
64
-		int32_t key_span = last_key - phone.first_key;
65
-		int32_t keys_done = phone.current_key - phone.first_key + 1;
66
-
67
-		progress_layer_set_progress(phone.progress_layer,
68
-		    (keys_done * 100 + key_span / 2) / key_span);
69
-		snprintf(phone.label, sizeof phone.label,
70
-		    "%" PRIi32 " / %" PRIi32,
71
-		    keys_done, key_span);
72
-	}
60
+update_half_progress(struct widget *widget) {
61
+	if (!widget || !widget->current_key) return;
73 62
 
74
-	if (web.current_key) {
75
-		int32_t key_span = last_key - web.first_key;
76
-		int32_t keys_done = web.current_key - web.first_key + 1;
63
+	int32_t last_key = (time(0) + 59) / 60;
64
+	int32_t key_span = last_key - widget->first_key;
65
+	int32_t keys_done = widget->current_key - widget->first_key + 1;
66
+
67
+	progress_layer_set_progress(widget->progress_layer,
68
+	    (keys_done * 100 + key_span / 2) / key_span);
69
+	snprintf(widget->label, sizeof widget->label,
70
+	    "%" PRIi32 " / %" PRIi32,
71
+	    keys_done, key_span);
72
+}
77 73
 
78
-		progress_layer_set_progress(web.progress_layer,
79
-		    (keys_done * 100 + key_span / 2) / key_span);
80
-		snprintf(web.label, sizeof web.label,
81
-		    "%" PRIi32 " / %" PRIi32,
82
-		    keys_done, key_span);
83
-	}
74
+static void
75
+update_progress(void) {
76
+	update_half_progress(&phone);
77
+	update_half_progress(&web);
84 78
 }
85 79
 
86 80
 #define PROGRESS_HEIGHT 10