diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleContentsFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleContentsFragment.java index 3d8e1df10a..c9c92bbdf0 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleContentsFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleContentsFragment.java @@ -29,6 +29,7 @@ public class WikivoyageArticleContentsFragment extends MenuBottomSheetDialogFrag public static final String CONTENTS_JSON_KEY = "contents_json"; public static final String CONTENTS_LINK_KEY = "contents_link"; + public static final String CONTENTS_TITLE_KEY = "title"; public static final int REQUEST_LINK_CODE = 0; @@ -70,8 +71,10 @@ public class WikivoyageArticleContentsFragment extends MenuBottomSheetDialogFrag @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { - String link = contentItem.getSubItems().get(groupPosition).getSubItems().get(childPosition).getLink(); - sendResult(link); + WikivoyageContentItem wikivoyageContentItem = contentItem.getSubItems().get(groupPosition); + String link = wikivoyageContentItem.getSubItems().get(childPosition).getLink(); + String name = wikivoyageContentItem.getLink().substring(1); + sendResults(link, name); dismiss(); return false; } @@ -79,8 +82,10 @@ public class WikivoyageArticleContentsFragment extends MenuBottomSheetDialogFrag expListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() { @Override public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) { - String link = contentItem.getSubItems().get(groupPosition).getLink(); - sendResult(link); + WikivoyageContentItem wikivoyageContentItem = contentItem.getSubItems().get(groupPosition); + String link = wikivoyageContentItem.getLink(); + String name = wikivoyageContentItem.getLink().substring(1); + sendResults(link, name); dismiss(); return false; } @@ -91,9 +96,10 @@ public class WikivoyageArticleContentsFragment extends MenuBottomSheetDialogFrag items.add(new SimpleBottomSheetItem.Builder().setCustomView(container).create()); } - private void sendResult(String link) { + private void sendResults(String link, String name) { Intent intent = new Intent(); intent.putExtra(CONTENTS_LINK_KEY, link); + intent.putExtra(CONTENTS_TITLE_KEY, name); Fragment fragment = getTargetFragment(); if (fragment != null) { fragment.onActivityResult(getTargetRequestCode(), REQUEST_LINK_CODE, intent); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java index 216390f1db..093ace0b11 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java @@ -48,9 +48,29 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen "\n" + "\n" + "\n" + - "\n" + ""; - private static final String FOOTER_INNER = ""; + "\n"; + private static final String FOOTER_INNER = "" + + ""; private long cityId = NO_VALUE; private ArrayList langs; @@ -144,7 +164,8 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen super.onActivityResult(requestCode, resultCode, data); if (requestCode == WikivoyageArticleContentsFragment.REQUEST_LINK_CODE) { String link = data.getStringExtra(WikivoyageArticleContentsFragment.CONTENTS_LINK_KEY); - moveToAnchor(link); + String title = data.getStringExtra(WikivoyageArticleContentsFragment.CONTENTS_TITLE_KEY); + moveToAnchor(link, title); } } @@ -227,8 +248,8 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen contentWebView.loadDataWithBaseURL(getBaseUrl(), createHtmlContent(article), "text/html", "UTF-8", null); } - private void moveToAnchor(String id) { - contentWebView.loadUrl("javascript:scrollAnchor(\"" + id + "\")"); + private void moveToAnchor(String id, String title) { + contentWebView.loadUrl("javascript:scrollAnchor(\"" + id + "\", \"" + title.trim() + "\")"); } @NonNull diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageJsonParser.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageJsonParser.java index 533cb511dc..db40a2ee7c 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageJsonParser.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageJsonParser.java @@ -1,6 +1,7 @@ package net.osmand.plus.wikivoyage.data; import android.support.annotation.Nullable; +import android.util.Log; import org.json.JSONArray; import org.json.JSONException; @@ -11,6 +12,8 @@ import java.util.List; public class WikivoyageJsonParser { + private static final String TAG = WikivoyageJsonParser.class.getSimpleName(); + private static final String HEADERS = "headers"; private static final String SUBHEADERS = "subheaders"; private static final String LINK = "link"; @@ -25,7 +28,7 @@ public class WikivoyageJsonParser { reader = new JSONObject(contentsJson); jArray = reader.getJSONObject(HEADERS); } catch (JSONException e) { - e.printStackTrace(); + Log.e(TAG, e.getMessage(), e); return null; } @@ -37,22 +40,23 @@ public class WikivoyageJsonParser { WikivoyageContentItem headerItem = new WikivoyageContentItem(jArray.names().getString(i), link, topContentItem); topContentItem.subItems.add(headerItem); - JSONArray subheaders = header.getJSONArray(SUBHEADERS); + JSONObject subheaders = header.getJSONObject(SUBHEADERS); + JSONArray subNames = subheaders.names(); List subheaderNames = null; for (int j = 0; j < subheaders.length(); j++) { - JSONObject subheader = subheaders.getJSONObject(j); - JSONObject subheaderLink = subheader.getJSONObject(subheader.keys().next()); + String title = subNames.get(j).toString(); + JSONObject subheaderLink = subheaders.getJSONObject(title); if (subheaderNames == null) { subheaderNames = new ArrayList<>(); } - subheaderNames.add(subheader.keys().next()); + subheaderNames.add(title); link = subheaderLink.getString(LINK); - WikivoyageContentItem subheaderItem = new WikivoyageContentItem(subheader.names().getString(0), link, headerItem); + WikivoyageContentItem subheaderItem = new WikivoyageContentItem(title, link, headerItem); headerItem.subItems.add(subheaderItem); } } catch (JSONException e) { - e.printStackTrace(); + Log.e(TAG, e.getMessage(), e); } } return topContentItem;