Fixed contents

This commit is contained in:
PaulStets 2018-04-15 11:22:40 +03:00
parent febeba6708
commit fa65d7337b
2 changed files with 25 additions and 11 deletions

View file

@ -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);

View file

@ -48,8 +48,7 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n" +
"<meta http-equiv=\"cleartype\" content=\"on\" />\n" +
"<link href=\"article_style.css\" type=\"text/css\" rel=\"stylesheet\"/>\n" +
"</head><body>\n" + "<script>" + "function scrollAnchor(id) {" +
"window.location.hash = id;}</script>";
"</head><body>\n";
private static final String FOOTER_INNER = "<script>var coll = document.getElementsByTagName(\"H2\");" +
"var i;" +
"for (i = 0; i < coll.length; i++) {" +
@ -62,8 +61,16 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
" content.style.display = \"block\";" +
" }" +
" });" +
"}" + "function scrollAnchor(id, title) {" +
"openContent(title);" +
"window.location.hash = id;}\n" +
"function openContent(id) {\n" +
"var doc = document.getElementById(id).parentElement;\n" +
" doc.classList.toggle(\"active\");\n" +
" var content = doc.nextElementSibling;\n" +
"content.style.display = \"block\";\n" +
"}</script>"
+ "</div></body></html>";
+ "</body></html>";
private long cityId = NO_VALUE;
private ArrayList<String> langs;
@ -157,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);
}
}
@ -240,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