-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAttachment.java
More file actions
74 lines (68 loc) · 2.81 KB
/
Attachment.java
File metadata and controls
74 lines (68 loc) · 2.81 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
package com.etiaro.facebook;
import org.json.JSONException;
import org.json.JSONObject;
public class Attachment {
enum Type{
MessageImage,
MessageAnimatedImage,
MessageVideo,
MessageFile,
MessageAudio
}
public String id, filename, __typename, thumbnailUrl, previewUrl, largePreviewUrl, attachmentUrl; //Add dimensions to images - maybe new type Image?
public Type type;
public Attachment(JSONObject json) throws JSONException {
update(json);
}
public void update(JSONObject json) throws JSONException{
if(json.has("isCopy") && json.getBoolean("isCopy") == true){
id = json.getString("id");
filename = json.getString("filename");
__typename = json.getString("__typename");
thumbnailUrl = json.getString("thumbnailUrl");
previewUrl = json.getString("previewUrl");
largePreviewUrl = json.getString("largePreviewUrl");
attachmentUrl = json.getString("attachmentUrl");
type = Type.valueOf(json.getString("type"));
return;
}
id = json.getString("legacy_attachment_id");
filename = json.getString("filename");
__typename = json.getString("__typename");
switch (Type.valueOf(__typename)){
case MessageImage:
type = Type.MessageImage;
thumbnailUrl = json.getJSONObject("thumbnail").getString("uri");
previewUrl = json.getJSONObject("preview").getString("uri");
largePreviewUrl = json.getJSONObject("large_preview").getString("uri");
attachmentUrl = json.getJSONObject("large_preview").getString("uri");
break;
case MessageVideo:
type = Type.MessageVideo;
thumbnailUrl = json.getJSONObject("chat_image").getString("uri");
previewUrl = json.getJSONObject("inbox_image").getString("uri");
largePreviewUrl = json.getJSONObject("large_image").getString("uri");
attachmentUrl = json.getString("playable_url");
break;
}//TODO more types
}
public JSONObject toJSON() throws JSONException {
return new JSONObject().put("isCopy", true)
.put("id", id)
.put("filename", filename)
.put("__typename", __typename)
.put("thumbnailUrl", thumbnailUrl)
.put("previewUrl", previewUrl)
.put("largePreviewUrl", largePreviewUrl)
.put("attachmentUrl", attachmentUrl)
.put("type", type.toString());
}
public String toString(){
try {
return toJSON().toString();
} catch (JSONException e) {
e.printStackTrace();
return null;
}
}
}