blob: b2a986a9cdcde8eee0b0bd742bcb4140b5e84b35 (
plain) (
blame)
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
|
// Author: cirakg & claude ai
// Summary: The outcome of one import: counts, per-item errors and skips, notes, and the texts for the status field and results screen.
import Toybox.Lang;
class ImportReport {
// At most this many detail lines are kept (the results screen scrolls).
static const MAX_DETAILS = 40;
var imported as Number = 0;
var pendingLocked as Number = 0;
var duplicates as Number = 0;
var errors as Number = 0;
var skipped as Number = 0;
var removed as Number = 0;
// Set when the whole import failed (not JSON, encrypted, storage full
// before anything was stored...).
var failure as String? = null;
// Set while a multi-part import waits for its next part.
var waitingChars as Number = -1;
var details as Array<String> = [] as Array<String>;
function initialize() {
}
function addDetail(line as String) as Void {
if (details.size() < MAX_DETAILS) {
details.add(line);
} else if (details.size() == MAX_DETAILS) {
details.add("…");
}
}
// One line for the phone's Import status field, for example
// "Imported 12 · 2 duplicates skipped · 1 error · 1 skipped".
function summary() as String {
var f = failure;
if (f != null) {
return "Not imported: " + f;
}
if (waitingChars >= 0) {
return "Waiting for more: received " + waitingChars
+ " characters. Paste the next part into the import fields and turn 'Import now' on again.";
}
var text = "Imported " + imported;
if (pendingLocked > 0) {
text += " (" + pendingLocked + " locked, waiting for your PIN)";
}
if (removed > 0) {
text += " · " + removed + " old imported removed";
}
if (duplicates > 0) {
text += " · " + duplicates + (duplicates == 1 ? " duplicate skipped" : " duplicates skipped");
}
if (errors > 0) {
text += " · " + errors + (errors == 1 ? " error" : " errors");
}
if (skipped > 0) {
text += " · " + skipped + " skipped";
}
return text;
}
// The summary followed by the details, for the results screen.
function lines() as Array<String> {
var out = [summary()] as Array<String>;
out.addAll(details);
return out;
}
}
|