|
@@ -1,9 +1,10 @@
|
1
|
1
|
package com.reactnativenavigation.parse.params;
|
2
|
2
|
|
3
|
|
-import android.support.annotation.ColorInt;
|
4
|
3
|
import android.view.MenuItem;
|
5
|
4
|
|
6
|
5
|
import com.reactnativenavigation.parse.parsers.BoolParser;
|
|
6
|
+import com.reactnativenavigation.parse.parsers.ColorParser;
|
|
7
|
+import com.reactnativenavigation.parse.parsers.NumberParser;
|
7
|
8
|
import com.reactnativenavigation.parse.parsers.TextParser;
|
8
|
9
|
|
9
|
10
|
import org.json.JSONArray;
|
|
@@ -11,56 +12,54 @@ import org.json.JSONObject;
|
11
|
12
|
|
12
|
13
|
import java.util.ArrayList;
|
13
|
14
|
|
14
|
|
-import static com.reactnativenavigation.parse.Options.NO_INT_VALUE;
|
15
|
|
-
|
16
|
15
|
public class Button {
|
17
|
|
- public String id;
|
18
|
|
- public Text title = new NullText();
|
19
|
|
- public Bool enabled = new NullBool();
|
20
|
|
- public Bool disableIconTint = new NullBool();
|
21
|
|
- public int showAsAction;
|
22
|
|
- @ColorInt public int buttonColor;
|
23
|
|
- public int buttonFontSize;
|
24
|
|
- private Text buttonFontWeight = new NullText();
|
25
|
|
- public Text icon = new NullText();
|
26
|
|
- public Text testId = new NullText();
|
|
16
|
+ public String id;
|
|
17
|
+ public Text title = new NullText();
|
|
18
|
+ public Bool enabled = new NullBool();
|
|
19
|
+ public Bool disableIconTint = new NullBool();
|
|
20
|
+ public int showAsAction;
|
|
21
|
+ public Color buttonColor = new NullColor();
|
|
22
|
+ public Number buttonFontSize = new NullNumber();
|
|
23
|
+ private Text buttonFontWeight = new NullText();
|
|
24
|
+ public Text icon = new NullText();
|
|
25
|
+ public Text testId = new NullText();
|
27
|
26
|
public Text component = new NullText();
|
28
|
27
|
|
29
|
|
- private static Button parseJson(JSONObject json) {
|
30
|
|
- Button button = new Button();
|
31
|
|
- button.id = json.optString("id");
|
32
|
|
- button.title = TextParser.parse(json, "title");
|
33
|
|
- button.enabled = BoolParser.parse(json,"enabled");
|
34
|
|
- button.disableIconTint = BoolParser.parse(json,"disableIconTint");
|
35
|
|
- button.showAsAction = parseShowAsAction(json);
|
36
|
|
- button.buttonColor = json.optInt("buttonColor", NO_INT_VALUE);
|
37
|
|
- button.buttonFontSize = json.optInt("buttonFontSize", NO_INT_VALUE);
|
38
|
|
- button.buttonFontWeight = TextParser.parse(json, "buttonFontWeight");
|
|
28
|
+ private static Button parseJson(JSONObject json) {
|
|
29
|
+ Button button = new Button();
|
|
30
|
+ button.id = json.optString("id");
|
|
31
|
+ button.title = TextParser.parse(json, "title");
|
|
32
|
+ button.enabled = BoolParser.parse(json, "enabled");
|
|
33
|
+ button.disableIconTint = BoolParser.parse(json, "disableIconTint");
|
|
34
|
+ button.showAsAction = parseShowAsAction(json);
|
|
35
|
+ button.buttonColor = ColorParser.parse(json, "buttonColor");
|
|
36
|
+ button.buttonFontSize = NumberParser.parse(json, "buttonFontSize");
|
|
37
|
+ button.buttonFontWeight = TextParser.parse(json, "buttonFontWeight");
|
39
|
38
|
button.testId = TextParser.parse(json, "testID");
|
40
|
39
|
button.component = TextParser.parse(json, "component");
|
41
|
40
|
|
42
|
|
- if (json.has("icon")) {
|
43
|
|
- button.icon = TextParser.parse(json.optJSONObject("icon"), "uri");
|
44
|
|
- }
|
|
41
|
+ if (json.has("icon")) {
|
|
42
|
+ button.icon = TextParser.parse(json.optJSONObject("icon"), "uri");
|
|
43
|
+ }
|
45
|
44
|
|
46
|
|
- return button;
|
47
|
|
- }
|
|
45
|
+ return button;
|
|
46
|
+ }
|
48
|
47
|
|
49
|
|
- public static ArrayList<Button> parseJsonArray(JSONArray jsonArray) {
|
50
|
|
- ArrayList<Button> buttons = new ArrayList<>();
|
|
48
|
+ public static ArrayList<Button> parseJsonArray(JSONArray jsonArray) {
|
|
49
|
+ ArrayList<Button> buttons = new ArrayList<>();
|
51
|
50
|
|
52
|
|
- if (jsonArray == null) {
|
53
|
|
- return null;
|
54
|
|
- }
|
|
51
|
+ if (jsonArray == null) {
|
|
52
|
+ return null;
|
|
53
|
+ }
|
55
|
54
|
|
56
|
|
- for (int i = 0; i < jsonArray.length(); i++) {
|
57
|
|
- JSONObject json = jsonArray.optJSONObject(i);
|
58
|
|
- Button button = Button.parseJson(json);
|
59
|
|
- buttons.add(button);
|
60
|
|
- }
|
|
55
|
+ for (int i = 0; i < jsonArray.length(); i++) {
|
|
56
|
+ JSONObject json = jsonArray.optJSONObject(i);
|
|
57
|
+ Button button = Button.parseJson(json);
|
|
58
|
+ buttons.add(button);
|
|
59
|
+ }
|
61
|
60
|
|
62
|
|
- return buttons;
|
63
|
|
- }
|
|
61
|
+ return buttons;
|
|
62
|
+ }
|
64
|
63
|
|
65
|
64
|
public boolean hasComponent() {
|
66
|
65
|
return component.hasValue();
|
|
@@ -70,22 +69,22 @@ public class Button {
|
70
|
69
|
return icon.hasValue();
|
71
|
70
|
}
|
72
|
71
|
|
73
|
|
- private static int parseShowAsAction(JSONObject json) {
|
74
|
|
- final Text showAsAction = TextParser.parse(json, "showAsAction");
|
75
|
|
- if (!showAsAction.hasValue()) {
|
76
|
|
- return MenuItem.SHOW_AS_ACTION_IF_ROOM;
|
77
|
|
- }
|
78
|
|
-
|
79
|
|
- switch (showAsAction.get()) {
|
80
|
|
- case "always":
|
81
|
|
- return MenuItem.SHOW_AS_ACTION_ALWAYS;
|
82
|
|
- case "never":
|
83
|
|
- return MenuItem.SHOW_AS_ACTION_NEVER;
|
84
|
|
- case "withText":
|
85
|
|
- return MenuItem.SHOW_AS_ACTION_WITH_TEXT;
|
86
|
|
- case "ifRoom":
|
87
|
|
- default:
|
88
|
|
- return MenuItem.SHOW_AS_ACTION_IF_ROOM;
|
89
|
|
- }
|
90
|
|
- }
|
|
72
|
+ private static int parseShowAsAction(JSONObject json) {
|
|
73
|
+ final Text showAsAction = TextParser.parse(json, "showAsAction");
|
|
74
|
+ if (!showAsAction.hasValue()) {
|
|
75
|
+ return MenuItem.SHOW_AS_ACTION_IF_ROOM;
|
|
76
|
+ }
|
|
77
|
+
|
|
78
|
+ switch (showAsAction.get()) {
|
|
79
|
+ case "always":
|
|
80
|
+ return MenuItem.SHOW_AS_ACTION_ALWAYS;
|
|
81
|
+ case "never":
|
|
82
|
+ return MenuItem.SHOW_AS_ACTION_NEVER;
|
|
83
|
+ case "withText":
|
|
84
|
+ return MenuItem.SHOW_AS_ACTION_WITH_TEXT;
|
|
85
|
+ case "ifRoom":
|
|
86
|
+ default:
|
|
87
|
+ return MenuItem.SHOW_AS_ACTION_IF_ROOM;
|
|
88
|
+ }
|
|
89
|
+ }
|
91
|
90
|
}
|