Skip to content

Commit 7e440c6

Browse files
authored
Merge pull request #3 from pokeum/develop
v1.0.0
2 parents 2ca5efa + 7d92753 commit 7e440c6

39 files changed

+299
-237
lines changed

README.md

Lines changed: 99 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/pokeumcho)
44

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/)
66

77
---
88

@@ -24,24 +24,16 @@ https://github.com/pokeum/jsonviewer-xml/assets/102505472/e2f260f0-cc28-4607-9ec
2424

2525
---
2626

27-
**Easiest way to format Json String**
27+
### Easiest way to format Json String
2828

2929
```xml
30-
<kr.pokeum.jsonviewer_xml.JsonRecyclerView
30+
<co.pokeum.jsonviewer.xml.JsonRecyclerView
3131
android:layout_width="match_parent"
3232
android:layout_height="wrap_content"
3333
app:text="{PUT_YOUR_JSON_STRING}" />
3434
```
3535

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
4537

4638
Add it in your root `build.gradle` at the end of repositories:
4739

@@ -57,103 +49,125 @@ allprojects {
5749
Add the dependency
5850

5951
```gradle
60-
implementation 'com.github.pokeum:jsonviewer-xml:0.0.2'
52+
implementation 'com.github.pokeum:jsonviewer-xml:1.0.0'
6153
```
6254

63-
## <a id="usage"> Usage
55+
## Usage
6456

65-
- ## <a id="basic"> Basic
57+
### JsonParser.parse()
6658

67-
### JsonParser.parse()
68-
69-
Convert `String` into a `JsonElement` object
59+
Convert `String` into a `JsonElement` object
7060

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 }"
7465

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+
```
8273

83-
### Display JSON
74+
### Use JsonRecyclerView to display JSON
8475

85-
#### [Method 1] Use JsonRecyclerView
76+
Add `JsonRecyclerView` in XML layout file:
8677

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+
```
9585

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:
10087

101-
#### [Method 2] Use RecyclerView
88+
```kotlin
89+
findViewById<JsonRecyclerView>(R.id.jsonViewer).setText("{PUT_YOUR_JSON_STRING}")
90+
```
10291

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+
```
114106

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`:
120108

121-
- ## <a id="advance"> Advance
109+
```kotlin
110+
val recyclerView = findViewById<RecyclerView>(R.id.jsonViewer)
111+
recyclerView.adapter = JsonViewerAdapter(/* JsonElement */)
112+
```
122113

123-
### JsonParser - Sort JSON
114+
## Advance
124115

125-
**Example - Alphabetically**
126-
```kotlin
127-
JsonParser.Builder()
128-
.setComparator(compareBy { it.key })
129-
.build()
130-
```
116+
### JsonParser - Sort JSON
117+
118+
**Example - Alphabetically**
131119

132-
### JsonElement - Save and Restore
120+
```kotlin
121+
JsonParser.Builder()
122+
.setComparator(compareBy { it.key })
123+
.build()
124+
```
133125

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
135129

136-
```kotlin
137-
class YourActivity : AppCompatActivity() {
130+
```kotlin
131+
class YourActivity : AppCompatActivity() {
138132

139-
private var jsonElement: JsonElement? = null
133+
private var jsonElement: JsonElement? = null
140134

141-
override fun onCreate(savedInstanceState: Bundle?) {
142-
// ...
135+
override fun onCreate(savedInstanceState: Bundle?) {
136+
// ...
143137

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 */
147140
}
141+
}
148142

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 */
153146
}
154-
```
147+
}
148+
```
155149

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
157171

158172
### Color
159173

@@ -170,7 +184,7 @@ implementation 'com.github.pokeum:jsonviewer-xml:0.0.2'
170184
#### Use JsonRecyclerView
171185

172186
```xml
173-
<kr.pokeum.jsonviewer_xml.JsonRecyclerView
187+
<co.pokeum.jsonviewer.xml.JsonRecyclerView
174188
...
175189
app:keyColor="@color/key_color"
176190
app:valueColor="@color/value_color"
@@ -193,4 +207,4 @@ implementation 'com.github.pokeum:jsonviewer-xml:0.0.2'
193207
setBracketColor(JsonViewerColor(/* ... */))
194208
setDividerColor(JsonViewerColor(/* ... */))
195209
}
196-
```
210+
```

app/build.gradle

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ android {
1717
buildToolsVersion BUILD_TOOL_VERSION
1818

1919
defaultConfig {
20-
applicationId "kr.pokeum.jsonviewer.app"
20+
applicationId "co.pokeum.jsonviewer.app"
2121
minSdkVersion MIN_SDK_VERSION
2222
targetSdkVersion TARGET_SDK_VERSION
2323
versionCode VERSION_CODE
@@ -55,11 +55,8 @@ android {
5555
}
5656

5757
dependencies {
58-
5958
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
60-
61-
// implementation(project(":jsonviewer"))
62-
implementation 'com.github.pokeum:jsonviewer-xml:0.0.2'
59+
implementation(project(":jsonviewer"))
6360

6461
implementation stdlib.kotlin
6562
implementation androidx.core
@@ -73,7 +70,4 @@ dependencies {
7370
implementation platform(firebase.bom)
7471

7572
testImplementation test.junit
76-
77-
androidTestImplementation androidTest.junit
78-
androidTestImplementation androidTest.espressoCore
7973
}

app/google-services.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
"project_info": {
33
"project_number": "1019350039203",
44
"project_id": "jsonviewer-86f73",
5-
"storage_bucket": "jsonviewer-86f73.appspot.com"
5+
"storage_bucket": "jsonviewer-86f73.firebasestorage.app"
66
},
77
"client": [
88
{
99
"client_info": {
10-
"mobilesdk_app_id": "1:1019350039203:android:9cd8b741a970ae86e2dd16",
10+
"mobilesdk_app_id": "1:1019350039203:android:54eb2638c6d6c410e2dd16",
1111
"android_client_info": {
12-
"package_name": "kr.pokeum.jsonviewer.app"
12+
"package_name": "co.pokeum.jsonviewer.app"
1313
}
1414
},
1515
"oauth_client": [],

app/src/androidTest/java/kr/pokeum/app/ExampleInstrumentedTest.kt

Lines changed: 0 additions & 24 deletions
This file was deleted.

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="kr.pokeum.app">
3+
package="co.pokeum.app">
44

55
<uses-permission android:name="android.permission.INTERNET" />
66
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

app/src/main/java/kr/pokeum/app/JsonGenerator.kt renamed to app/src/main/java/co/pokeum/app/JsonGenerator.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
package kr.pokeum.app
1+
package co.pokeum.app
22

33
import android.content.Context
44
import android.net.Uri
55
import android.widget.Toast
6-
import kr.pokeum.app.util.readAssetsFile
7-
import kr.pokeum.app.util.readCacheFile
8-
import kr.pokeum.app.util.readFileFromUri
9-
import kr.pokeum.app.util.writeCacheFile
10-
import kr.pokeum.jsonviewer_xml.JsonParser
11-
import kr.pokeum.jsonviewer_xml.model.JsonElement
12-
import kr.pokeum.jsonviewer_xml.model.JsonObject
6+
import co.pokeum.app.util.readAssetsFile
7+
import co.pokeum.app.util.readCacheFile
8+
import co.pokeum.app.util.readFileFromUri
9+
import co.pokeum.app.util.writeCacheFile
10+
import co.pokeum.jsonviewer.xml.JsonParser
11+
import co.pokeum.jsonviewer.xml.model.JsonElement
12+
import co.pokeum.jsonviewer.xml.model.JsonObject
1313
import org.json.JSONException
1414

1515
class JsonGenerator(

app/src/main/java/kr/pokeum/app/api/ApiService.kt renamed to app/src/main/java/co/pokeum/app/api/ApiService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package kr.pokeum.app.api
1+
package co.pokeum.app.api
22

33
import kotlinx.coroutines.Dispatchers
44
import kotlinx.coroutines.GlobalScope

0 commit comments

Comments
 (0)