blob: 192a273a4a56a6209297f67e466f7a7bf5f2cdff (
plain)
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
|
package org.wordpress.android.models;
import java.util.Date;
public enum PostStatus {
UNKNOWN,
PUBLISHED,
DRAFT,
PRIVATE,
PENDING,
TRASHED,
SCHEDULED; //NOTE: Only used locally, WP has a 'future' status but it is not returned from the metaWeblog API
private synchronized static PostStatus fromStringAndDateGMT(String value, long dateCreatedGMT) {
if (value == null) {
return PostStatus.UNKNOWN;
} else if (value.equals("publish")) {
// Check if post is scheduled
Date d = new Date();
// Subtract 10 seconds from the server GMT date, in case server and device time slightly differ
if (dateCreatedGMT - 10000 > d.getTime()) {
return SCHEDULED;
}
return PUBLISHED;
} else if (value.equals("draft")) {
return PostStatus.DRAFT;
} else if (value.equals("private")) {
return PostStatus.PRIVATE;
} else if (value.equals("pending")) {
return PENDING;
} else if (value.equals("trash")) {
return TRASHED;
} else if (value.equals("future")) {
return SCHEDULED;
} else {
return PostStatus.UNKNOWN;
}
}
public synchronized static PostStatus fromPost(Post post) {
String value = post.getPostStatus();
long dateCreatedGMT = post.getDate_created_gmt();
return fromStringAndDateGMT(value, dateCreatedGMT);
}
public synchronized static PostStatus fromPostsListPost(PostsListPost post) {
String value = post.getOriginalStatus();
long dateCreatedGMT = post.getDateCreatedGmt();
return fromStringAndDateGMT(value, dateCreatedGMT);
}
public static String toString(PostStatus status) {
switch (status) {
case PUBLISHED:
return "publish";
case DRAFT:
return "draft";
case PRIVATE:
return "private";
case PENDING:
return "pending";
case TRASHED:
return "trash";
case SCHEDULED:
return "future";
default:
return "";
}
}
}
|