Format and refactor ContentsJsonParser
This commit is contained in:
parent
0d7b5ffc2f
commit
eb13434471
1 changed files with 12 additions and 12 deletions
|
@ -1,6 +1,6 @@
|
||||||
package net.osmand.plus.wikivoyage.data;
|
package net.osmand.plus.wikivoyage.data;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
|
@ -10,15 +10,15 @@ import java.util.ArrayList;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
class ContentsJsonParser {
|
class ContentsJsonParser {
|
||||||
|
|
||||||
static ContentsContainer parseJsonContents(String contentsJson, Context context) {
|
@Nullable
|
||||||
LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
|
static ContentsContainer parseJsonContents(String contentsJson) {
|
||||||
ArrayList<String> listDataHeader = new ArrayList<String>();
|
LinkedHashMap<String, String> map = new LinkedHashMap<>();
|
||||||
LinkedHashMap<String, List<String>> listDataChild = new LinkedHashMap<String, List<String>>();
|
ArrayList<String> listDataHeader = new ArrayList<>();
|
||||||
|
LinkedHashMap<String, List<String>> listDataChild = new LinkedHashMap<>();
|
||||||
|
|
||||||
JSONObject reader = null;
|
JSONObject reader;
|
||||||
try {
|
try {
|
||||||
reader = new JSONObject(contentsJson);
|
reader = new JSONObject(contentsJson);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
|
@ -38,11 +38,11 @@ class ContentsJsonParser {
|
||||||
|
|
||||||
if (level == 2) {
|
if (level == 2) {
|
||||||
listDataHeader.add(reader.names().getString(i));
|
listDataHeader.add(reader.names().getString(i));
|
||||||
secondLevel = new ArrayList<String>();
|
secondLevel = new ArrayList<>();
|
||||||
}
|
}
|
||||||
if (level == 3) {
|
if (level == 3) {
|
||||||
if (secondLevel == null) {
|
if (secondLevel == null) {
|
||||||
secondLevel = new ArrayList<String>();
|
secondLevel = new ArrayList<>();
|
||||||
}
|
}
|
||||||
secondLevel.add(reader.names().getString(i));
|
secondLevel.add(reader.names().getString(i));
|
||||||
listDataChild.put(listDataHeader.get(listDataHeader.size() - 1), secondLevel);
|
listDataChild.put(listDataHeader.get(listDataHeader.size() - 1), secondLevel);
|
||||||
|
@ -60,12 +60,12 @@ class ContentsJsonParser {
|
||||||
public ArrayList<String> listDataHeader;
|
public ArrayList<String> listDataHeader;
|
||||||
public LinkedHashMap<String, List<String>> listDataChild;
|
public LinkedHashMap<String, List<String>> listDataChild;
|
||||||
|
|
||||||
public ContentsContainer(LinkedHashMap<String, String> map, ArrayList<String> listDataHeader,
|
ContentsContainer(LinkedHashMap<String, String> map,
|
||||||
|
ArrayList<String> listDataHeader,
|
||||||
LinkedHashMap<String, List<String>> listChildData) {
|
LinkedHashMap<String, List<String>> listChildData) {
|
||||||
this.map = map;
|
this.map = map;
|
||||||
this.listDataHeader = listDataHeader;
|
this.listDataHeader = listDataHeader;
|
||||||
this.listDataChild = listChildData;
|
this.listDataChild = listChildData;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue