aboutsummaryrefslogtreecommitdiff
path: root/src/org/happysanta/gd/API/NotificationsResponse.java
blob: 06dca09ed459a516aa722a53066af5da4a29830d (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
71
72
73
74
75
76
package org.happysanta.gd.API;

import org.json.JSONArray;
import org.json.JSONObject;

public class NotificationsResponse {

	private String title;
	private String message;
	private String url;
	private int buttonsCount = 1;
	private String[] buttons = new String[2];
	private boolean empty = true;
	private boolean isURL = false;

	public NotificationsResponse(Response response) {
		parse(response);
	}

	protected void parse(Response response) {
		JSONArray json = response.getJSON();
		try {
			JSONArray jsonResponse = json.getJSONArray(1);
			if (jsonResponse.length() > 0) {
				JSONObject notification = jsonResponse.getJSONObject(0);
				title = notification.getString("title");
				message = notification.getString("message");
				buttons[0] = notification.getString("button_ok");
				if (notification.has("button_cancel")) {
					buttonsCount = 2;
					buttons[1] = notification.getString("button_cancel");
				}
				if (notification.has("open_url")) {
					url = notification.getString("open_url");
					isURL = true;
				}
				empty = false;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public boolean isEmpty() {
		return empty;
	}

	public boolean hasURL() {
		return isURL;
	}

	public String getURL() {
		return url;
	}

	public String getTitle() {
		return title;
	}

	public String getMessage() {
		return message;
	}

	public boolean hasTwoButtons() {
		return buttonsCount == 2;
	}

	public String getOKButton() {
		return buttons[0];
	}

	public String getCancelButton() {
		return buttons[1];
	}

}