Repository navigation
Expand file tree
/
Copy pathTask.java
More file actions
114 lines (100 loc) · 3.67 KB
/
Copy pathTask.java
File metadata and controls
114 lines (100 loc) · 3.67 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
package com.qoder.taskdeck;
import java.util.ArrayList;
import java.util.List;
/**
* One ledger row, mirroring DeckTask on the Mac field for field so the two
* stores can be merged without translation. Times are epoch milliseconds; the
* wire format uses ISO-8601 with milliseconds, same as tasks.json.
*/
public final class Task {
public static final String OPEN = "open";
public static final String SOMEDAY = "someday";
public static final String DONE = "done";
public String id;
public String title = "";
public String notes = "";
public String status = OPEN;
public String priority = "normal"; // low | normal | high | urgent
public Long dueMillis; // null = no date
public boolean timed; // dueMillis carries a real clock time
public String recur; // daily|weekdays|weekly|biweekly|monthly|yearly|onWeekdays|null
public List<Integer> recurWeekdays; // 1 = Sunday, only for onWeekdays
public List<String> tags = new ArrayList<>();
public String source = "typed"; // typed | voice | agent | app | imported
public long createdAt;
public long updatedAt;
public Long completedAt;
public List<Log> log = new ArrayList<>();
public int order;
public Task() {
}
public Task(String id, String title) {
this.id = id;
this.title = title;
long now = System.currentTimeMillis();
this.createdAt = now;
this.updatedAt = now;
}
public Task copy() {
Task t = new Task();
t.id = id;
t.title = title;
t.notes = notes;
t.status = status;
t.priority = priority;
t.dueMillis = dueMillis;
t.timed = timed;
t.recur = recur;
t.recurWeekdays = recurWeekdays == null ? null : new ArrayList<>(recurWeekdays);
t.tags = new ArrayList<>(tags);
t.source = source;
t.createdAt = createdAt;
t.updatedAt = updatedAt;
t.completedAt = completedAt;
t.log = new ArrayList<>(log);
t.order = order;
return t;
}
public boolean isOpen() {
return OPEN.equals(status);
}
public boolean isDone() {
return DONE.equals(status);
}
/** Same ranking the Mac uses: priority, then due, then order, then age. */
public static int rank(Task a, Task b) {
int pa = priorityRank(a.priority), pb = priorityRank(b.priority);
if (pa != pb) return pa - pb;
long da = a.dueMillis == null ? Long.MAX_VALUE : a.dueMillis;
long db = b.dueMillis == null ? Long.MAX_VALUE : b.dueMillis;
if (da != db) return Long.compare(da, db);
if (a.order != b.order) return a.order - b.order;
return Long.compare(a.createdAt, b.createdAt);
}
public static int priorityRank(String p) {
if ("urgent".equals(p)) return 0;
if ("high".equals(p)) return 1;
if ("low".equals(p)) return 3;
return 2;
}
/** A short, typeable id in the same alphabet the Mac CLI uses. */
public static String newId() {
String alphabet = "0123456789abcdefghjkmnpqrstvwxyz";
StringBuilder sb = new StringBuilder("t");
java.util.Random r = new java.util.Random();
for (int i = 0; i < 5; i++) sb.append(alphabet.charAt(r.nextInt(alphabet.length())));
return sb.toString();
}
public static final class Log {
public long at;
public String author = "user";
public String text = "";
public Log() {
}
public Log(long at, String author, String text) {
this.at = at;
this.author = author;
this.text = text;
}
}
}