2
2
3
3
[ ![ "Buy Me A Coffee"] ( https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png )] ( https://www.buymeacoffee.com/pokeumcho )
4
4
5
- [ ![ Generic badge] ( https://img.shields.io/badge/jitpack-v0 .0.2 -darkyellow?logo=jitpack&logoColor=white.svg )] ( https://jitpack.io/#pokeum/jsonviewer-xml/ )
5
+ [ ![ Generic badge] ( https://img.shields.io/badge/jitpack-v1 .0.0 -darkyellow?logo=jitpack&logoColor=white.svg )] ( https://jitpack.io/#pokeum/jsonviewer-xml/ )
6
6
7
7
---
8
8
@@ -24,24 +24,16 @@ https://github.com/pokeum/jsonviewer-xml/assets/102505472/e2f260f0-cc28-4607-9ec
24
24
25
25
---
26
26
27
- ** Easiest way to format Json String**
27
+ ### Easiest way to format Json String
28
28
29
29
``` xml
30
- <kr .pokeum.jsonviewer_xml .JsonRecyclerView
30
+ <co .pokeum.jsonviewer.xml .JsonRecyclerView
31
31
android : layout_width =" match_parent"
32
32
android : layout_height =" wrap_content"
33
33
app : text =" {PUT_YOUR_JSON_STRING}" />
34
34
```
35
35
36
- ## Table of Contents
37
- - [ Installation] ( #installation )
38
- - [ Usage] ( #usage )
39
- - [ Basic] ( #basic )
40
- - [ Advance] ( #advance )
41
- - [ Custom Styles] ( #styles )
42
-
43
-
44
- ## <a id =" installation " > Installation
36
+ ## Installation
45
37
46
38
Add it in your root ` build.gradle ` at the end of repositories:
47
39
@@ -57,103 +49,125 @@ allprojects {
57
49
Add the dependency
58
50
59
51
``` gradle
60
- implementation 'com.github.pokeum:jsonviewer-xml:0 .0.2 '
52
+ implementation 'com.github.pokeum:jsonviewer-xml:1 .0.0 '
61
53
```
62
54
63
- ## < a id = " usage " > Usage
55
+ ## Usage
64
56
65
- - ## < a id = " basic " > Basic
57
+ ### JsonParser.parse()
66
58
67
- ### JsonParser.parse()
68
-
69
- Convert ` String ` into a ` JsonElement ` object
59
+ Convert ` String ` into a ` JsonElement ` object
70
60
71
- ** Example - Parsing JSON**
72
- ``` kotlin
73
- val jsonString = " { \" abc\" : \" def\" ,\" xyz\" : 123 }"
61
+ ** Example - Parsing JSON**
62
+
63
+ ``` kotlin
64
+ val jsonString = " { \" abc\" : \" def\" ,\" xyz\" : 123 }"
74
65
75
- val jsonParser = JsonParser .Builder ().build()
76
- val jsonElement: JsonElement ? = try {
77
- jsonParser.parse(jsonString)
78
- }
79
- // Raise a JSONException if it is not a JSONObject or JSONArray.
80
- catch (e: JSONException ) { null }
81
- ```
66
+ val jsonParser = JsonParser .Builder ().build()
67
+ val jsonElement: JsonElement ? = try {
68
+ jsonParser.parse(jsonString)
69
+ }
70
+ // Raise a JSONException if it is not a JSONObject or JSONArray.
71
+ catch (e: JSONException ) { null }
72
+ ```
82
73
83
- ### Display JSON
74
+ ### Use JsonRecyclerView to display JSON
84
75
85
- #### [ Method 1 ] Use JsonRecyclerView
76
+ Add ` JsonRecyclerView ` in XML layout file:
86
77
87
- Add ` JsonRecyclerView ` in XML layout file:
88
- ``` xml
89
- <kr .pokeum.jsonviewer_xml.JsonRecyclerView
90
- android : id =" @+id/jsonViewer"
91
- android : layout_width =" match_parent"
92
- android : layout_height =" wrap_content"
93
- app : text =" {PUT_YOUR_JSON_STRING}" />
94
- ```
78
+ ``` xml
79
+ <co .pokeum.jsonviewer.xml.JsonRecyclerView
80
+ android : id =" @+id/jsonViewer"
81
+ android : layout_width =" match_parent"
82
+ android : layout_height =" wrap_content"
83
+ app : text =" {PUT_YOUR_JSON_STRING}" />
84
+ ```
95
85
96
- Change ` JsonRecyclerView ` text from the code:
97
- ``` kotlin
98
- findViewById<JsonRecyclerView >(R .id.jsonViewer).setText(" {PUT_YOUR_JSON_STRING}" )
99
- ```
86
+ Change ` JsonRecyclerView ` text from the code:
100
87
101
- #### [ Method 2] Use RecyclerView
88
+ ``` kotlin
89
+ findViewById<JsonRecyclerView >(R .id.jsonViewer).setText(" {PUT_YOUR_JSON_STRING}" )
90
+ ```
102
91
103
- Add ` RecyclerView ` in XML layout file:
104
- ``` xml
105
- <androidx .recyclerview.widget.RecyclerView
106
- android : id =" @+id/jsonViewer"
107
- android : layout_width =" match_parent"
108
- android : layout_height =" wrap_content"
109
- android : orientation =" vertical"
110
- app : layoutManager =" androidx.recyclerview.widget.LinearLayoutManager"
111
- tools : ignore =" SpeakableTextPresentCheck"
112
- tools : listitem =" @layout/item_json_object" />
113
- ```
92
+ ### Use RecyclerView to display JSON
93
+
94
+ Add ` RecyclerView ` in XML layout file:
95
+
96
+ ``` xml
97
+ <androidx .recyclerview.widget.RecyclerView
98
+ android : id =" @+id/jsonViewer"
99
+ android : layout_width =" match_parent"
100
+ android : layout_height =" wrap_content"
101
+ android : orientation =" vertical"
102
+ app : layoutManager =" androidx.recyclerview.widget.LinearLayoutManager"
103
+ tools : ignore =" SpeakableTextPresentCheck"
104
+ tools : listitem =" @layout/item_json_object" />
105
+ ```
114
106
115
- Set Adapter in ` RecyclerView ` :
116
- ``` kotlin
117
- val recyclerView = findViewById<RecyclerView >(R .id.jsonViewer)
118
- recyclerView.adapter = JsonViewerAdapter (/* JsonElement */ )
119
- ```
107
+ Set Adapter in ` RecyclerView ` :
120
108
121
- - ## <a id =" advance " > Advance
109
+ ``` kotlin
110
+ val recyclerView = findViewById<RecyclerView >(R .id.jsonViewer)
111
+ recyclerView.adapter = JsonViewerAdapter (/* JsonElement */ )
112
+ ```
122
113
123
- ### JsonParser - Sort JSON
114
+ ## Advance
124
115
125
- ** Example - Alphabetically**
126
- ``` kotlin
127
- JsonParser .Builder ()
128
- .setComparator(compareBy { it.key })
129
- .build()
130
- ```
116
+ ### JsonParser - Sort JSON
117
+
118
+ ** Example - Alphabetically**
131
119
132
- ### JsonElement - Save and Restore
120
+ ``` kotlin
121
+ JsonParser .Builder ()
122
+ .setComparator(compareBy { it.key })
123
+ .build()
124
+ ```
133
125
134
- Save and Restore Data on Configuration Changed in Android using Bundle
126
+ ### JsonElement - Save and Restore
127
+
128
+ Save and Restore Data on Configuration Changed in Android using Bundle
135
129
136
- ``` kotlin
137
- class YourActivity : AppCompatActivity () {
130
+ ``` kotlin
131
+ class YourActivity : AppCompatActivity () {
138
132
139
- private var jsonElement: JsonElement ? = null
133
+ private var jsonElement: JsonElement ? = null
140
134
141
- override fun onCreate (savedInstanceState : Bundle ? ) {
142
- // ...
135
+ override fun onCreate (savedInstanceState : Bundle ? ) {
136
+ // ...
143
137
144
- if (savedInstanceState != null ) {
145
- jsonElement = savedInstanceState.getParcelable(" JSON_ELEMENT_KEY" ) /* Restore */
146
- }
138
+ if (savedInstanceState != null ) {
139
+ jsonElement = savedInstanceState.getParcelable(" JSON_ELEMENT_KEY" ) /* Restore */
147
140
}
141
+ }
148
142
149
- override fun onSaveInstanceState (outState : Bundle ) {
150
- super .onSaveInstanceState(outState)
151
- outState.putParcelable(" JSON_ELEMENT_KEY" , jsonElement) /* Save */
152
- }
143
+ override fun onSaveInstanceState (outState : Bundle ) {
144
+ super .onSaveInstanceState(outState)
145
+ outState.putParcelable(" JSON_ELEMENT_KEY" , jsonElement) /* Save */
153
146
}
154
- ```
147
+ }
148
+ ```
155
149
156
- ## <a id =" styles " > Custom Styles
150
+ ### Expand All & Collapse All
151
+
152
+ #### Use JsonRecyclerView
153
+
154
+ ``` kotlin
155
+ findViewById<JsonRecyclerView >(R .id.jsonViewer).expandAll()
156
+ findViewById<JsonRecyclerView >(R .id.jsonViewer).collapseAll()
157
+ ```
158
+
159
+ #### Use RecyclerView
160
+
161
+ ``` kotlin
162
+ val recyclerView = findViewById<RecyclerView >(R .id.jsonViewer)
163
+ recyclerView.adapter = JsonViewerAdapter (/* JsonElement */ )
164
+
165
+ val jsonViewerAdapter = recyclerView.adapter as JsonViewerAdapter
166
+ jsonViewerAdapter.expandAll()
167
+ jsonViewerAdapter.collapseAll()
168
+ ```
169
+
170
+ ## Custom Styles
157
171
158
172
### Color
159
173
@@ -170,7 +184,7 @@ implementation 'com.github.pokeum:jsonviewer-xml:0.0.2'
170
184
#### Use JsonRecyclerView
171
185
172
186
``` xml
173
- <kr .pokeum.jsonviewer_xml .JsonRecyclerView
187
+ <co .pokeum.jsonviewer.xml .JsonRecyclerView
174
188
...
175
189
app : keyColor =" @color/key_color"
176
190
app : valueColor =" @color/value_color"
@@ -193,4 +207,4 @@ implementation 'com.github.pokeum:jsonviewer-xml:0.0.2'
193
207
setBracketColor(JsonViewerColor (/* ... */ ))
194
208
setDividerColor(JsonViewerColor (/* ... */ ))
195
209
}
196
- ```
210
+ ```
0 commit comments