Deskana has uploaded a new change for review. https://gerrit.wikimedia.org/r/156012
Change subject: Scroll to section after you're done editing it. ...................................................................... Scroll to section after you're done editing it. When you tap edit on a section and successfully save your edit, return to that section rather than returning to the top of the article. Change-Id: I17a61aaa9cd02223bb857283853802a893028a4f --- M wikipedia/src/main/java/org/wikipedia/editing/EditSectionActivity.java M wikipedia/src/main/java/org/wikipedia/page/PageViewFragment.java 2 files changed, 29 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia refs/changes/12/156012/1 diff --git a/wikipedia/src/main/java/org/wikipedia/editing/EditSectionActivity.java b/wikipedia/src/main/java/org/wikipedia/editing/EditSectionActivity.java index db8b80f..f4d4049 100644 --- a/wikipedia/src/main/java/org/wikipedia/editing/EditSectionActivity.java +++ b/wikipedia/src/main/java/org/wikipedia/editing/EditSectionActivity.java @@ -312,7 +312,11 @@ if (result instanceof SuccessEditResult) { funnel.logSaved(((SuccessEditResult) result).getRevID()); progressDialog.dismiss(); - setResult(EditHandler.RESULT_REFRESH_PAGE); + + //Build intent that includes the section we were editing, so we can scroll to it later + Intent data = new Intent(); + data.putExtra(EXTRA_SECTION, section); + setResult(EditHandler.RESULT_REFRESH_PAGE,data); Toast.makeText(EditSectionActivity.this, R.string.edit_saved_successfully, Toast.LENGTH_LONG).show(); Utils.hideSoftKeyboard(EditSectionActivity.this); finish(); diff --git a/wikipedia/src/main/java/org/wikipedia/page/PageViewFragment.java b/wikipedia/src/main/java/org/wikipedia/page/PageViewFragment.java index 5fe8c34..1ef50aa 100644 --- a/wikipedia/src/main/java/org/wikipedia/page/PageViewFragment.java +++ b/wikipedia/src/main/java/org/wikipedia/page/PageViewFragment.java @@ -18,6 +18,7 @@ import org.mediawiki.api.json.RequestBuilder; import org.wikipedia.NightModeHandler; import org.wikipedia.analytics.ConnectionIssueFunnel; +import org.wikipedia.editing.EditSectionActivity; import org.wikipedia.pageimages.PageImage; import org.wikipedia.views.ObservableWebView; import org.wikipedia.PageTitle; @@ -122,6 +123,7 @@ private View pageFragmentContainer; private Page page; private HistoryEntry curEntry; + private Section section; private CommunicationBridge bridge; private LinkHandler linkHandler; @@ -149,6 +151,9 @@ this.title = title; this.curEntry = historyEntry; this.quickReturnBarId = quickReturnBarId; + + //FIXME: Make this hold the section to scroll to if you follow a section wikilink, e.g. [[Article#Section]] + this.section = null; } public PageViewFragment() { @@ -419,6 +424,22 @@ wrapper.put("isLast", index == page.getSections().size() - 1); wrapper.put("fragment", page.getTitle().getFragment()); bridge.sendMessage("displaySection", wrapper); + + //If we have a section to scroll to, and we've just loaded the last section, then scroll to it + if (section != null && index == page.getSections().size() - 1) { + JSONObject payload = new JSONObject(); + try { + payload.put("anchor", section.isLead() ? "heading_" + section.getId() : section.getAnchor()); + } catch (JSONException e) { + // This won't happen + throw new RuntimeException(e); + } + + bridge.sendMessage("scrollToSection", payload); + + //Set the section to null so we don't accidentally try to scroll to it again in the future + section = null; + } } } catch (JSONException e) { // Won't happen @@ -439,6 +460,9 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == EditHandler.RESULT_REFRESH_PAGE) { + //Retrieve section from intent so where know where to scroll to + section = data.getParcelableExtra(EditSectionActivity.EXTRA_SECTION); + ViewAnimations.crossFade(webView, loadProgress); setState(STATE_NO_FETCH); performActionForState(state); -- To view, visit https://gerrit.wikimedia.org/r/156012 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I17a61aaa9cd02223bb857283853802a893028a4f Gerrit-PatchSet: 1 Gerrit-Project: apps/android/wikipedia Gerrit-Branch: master Gerrit-Owner: Deskana <dga...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits