jenkins-bot has submitted this change and it was merged. Change subject: Fixed crash on nonexistent pages. ......................................................................
Fixed crash on nonexistent pages. Also disables ToC for nonexistent pages (and on network error) Also seems to fix the grey bar appearing when tapping during error or loading. Bug: 62639 Change-Id: Id357b37134bd288f02ae1f53c38ab7a84b2979b5 --- M wikipedia/res/layout/fragment_page.xml M wikipedia/res/values-qq/strings.xml M wikipedia/res/values/strings.xml M wikipedia/src/main/java/org/wikipedia/page/PageViewFragment.java A wikipedia/src/main/java/org/wikipedia/page/SectionsFetchException.java M wikipedia/src/main/java/org/wikipedia/page/SectionsFetchTask.java A wikipedia/src/main/java/org/wikipedia/styledviews/DisableableSlidingPaneLayout.java 7 files changed, 103 insertions(+), 16 deletions(-) Approvals: Yuvipanda: Looks good to me, approved jenkins-bot: Verified diff --git a/wikipedia/res/layout/fragment_page.xml b/wikipedia/res/layout/fragment_page.xml index 1e62dea..69f9ee5 100644 --- a/wikipedia/res/layout/fragment_page.xml +++ b/wikipedia/res/layout/fragment_page.xml @@ -13,7 +13,7 @@ android:layout_height="wrap_content" android:indeterminate="true" /> - <android.support.v4.widget.SlidingPaneLayout + <org.wikipedia.styledviews.DisableableSlidingPaneLayout android:id="@+id/page_toc_slider" android:layout_width="match_parent" android:layout_height="match_parent" @@ -45,7 +45,7 @@ android:layout_height="match_parent" android:visibility="gone" /> - </android.support.v4.widget.SlidingPaneLayout> + </org.wikipedia.styledviews.DisableableSlidingPaneLayout> <LinearLayout android:id="@+id/page_error" android:layout_width="match_parent" @@ -65,7 +65,19 @@ android:text="@string/page_error_retry" android:layout_gravity="center" android:layout_width="wrap_content" android:layout_height="wrap_content"/> - - + </LinearLayout> + <LinearLayout + android:id="@+id/page_does_not_exist" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_gravity="center_vertical" + android:orientation="vertical" + android:visibility="gone" + > + <org.wikipedia.styledviews.StyledTextView android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_gravity="center" + android:text="@string/page_does_not_exist_error" + style="?android:textAppearanceLarge" + /> </LinearLayout> </FrameLayout> \ No newline at end of file diff --git a/wikipedia/res/values-qq/strings.xml b/wikipedia/res/values-qq/strings.xml index 7bd28ec..01e3d60 100644 --- a/wikipedia/res/values-qq/strings.xml +++ b/wikipedia/res/values-qq/strings.xml @@ -10,6 +10,7 @@ <string name="search_network_error">Error message shown when network cannot be reached when searching. Tapping the message retries the search.</string> <string name="page_error_retry">Text for button that retries page loading when tapped</string> <string name="menu_clear_all_history">Menu item text for clearing your reading history</string> + <string name="page_does_not_exist_error">Text shown when the requested page does not exist</string> <string name="dialog_title_clear_history">Title for dialog box asking if you want to clear your reading history</string> <string name="dialog_message_clear_history">Message for dialog box asking if you want to clear your reading history</string> <string name="saved_pages_activity_title">Title for screen that shows list of locally saved pages. diff --git a/wikipedia/res/values/strings.xml b/wikipedia/res/values/strings.xml index 9b2d905..1886458 100644 --- a/wikipedia/res/values/strings.xml +++ b/wikipedia/res/values/strings.xml @@ -16,6 +16,7 @@ <string name="search_network_error">Network error. Tap to try again.</string> <string name="page_error_retry">Retry</string> <string name="menu_clear_all_history">Clear history</string> + <string name="page_does_not_exist_error">This page does not exist.</string> <string name="dialog_title_clear_history">Clear history?</string> <string name="dialog_message_clear_history">Are you sure you want to clear all history?</string> diff --git a/wikipedia/src/main/java/org/wikipedia/page/PageViewFragment.java b/wikipedia/src/main/java/org/wikipedia/page/PageViewFragment.java index 9e88a76..3240ff9 100644 --- a/wikipedia/src/main/java/org/wikipedia/page/PageViewFragment.java +++ b/wikipedia/src/main/java/org/wikipedia/page/PageViewFragment.java @@ -1,6 +1,7 @@ package org.wikipedia.page; import android.content.*; +import android.net.Uri; import android.os.*; import android.support.v4.app.*; import android.support.v4.widget.*; @@ -15,6 +16,7 @@ import org.wikipedia.history.*; import org.wikipedia.pageimages.*; import org.wikipedia.savedpages.*; +import org.wikipedia.styledviews.*; import java.util.*; @@ -37,7 +39,8 @@ private ProgressBar loadProgress; private View networkError; private View retryButton; - private SlidingPaneLayout tocSlider; + private View pageDoesNotExistError; + private DisableableSlidingPaneLayout tocSlider; private Page page; private HistoryEntry curEntry; @@ -139,8 +142,11 @@ loadProgress = (ProgressBar) getView().findViewById(R.id.page_load_progress); networkError = getView().findViewById(R.id.page_error); retryButton = getView().findViewById(R.id.page_error_retry); + pageDoesNotExistError = getView().findViewById(R.id.page_does_not_exist); quickReturnBar = getActivity().findViewById(quickReturnBarId); - tocSlider = (SlidingPaneLayout) getView().findViewById(R.id.page_toc_slider); + tocSlider = (DisableableSlidingPaneLayout) getView().findViewById(R.id.page_toc_slider); + // disable TOC slider until the page is loaded + tocSlider.setSlidingEnabled(false); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // Enable Pinch-Zoom @@ -249,6 +255,8 @@ tocHandler = new ToCHandler(tocSlider, quickReturnBar, bridge); } tocHandler.setupToC(page); + // enable sliding TOC + tocSlider.setSlidingEnabled(true); } } @@ -269,13 +277,15 @@ @Override public List<Section> processResult(ApiResult result) throws Throwable { JSONObject mobileView = result.asObject().optJSONObject("mobileview"); - pageProperties = new PageProperties(mobileView); - if (mobileView.has("redirected")) { - // Handle redirects properly. - title = new PageTitle(mobileView.optString("redirected"), title.getSite()); - } else if (mobileView.has("normalizedtitle")) { - // We care about the normalized title only if we were not redirected - title = new PageTitle(mobileView.optString("normalizedtitle"), title.getSite()); + if(mobileView != null){ + pageProperties = new PageProperties(mobileView); + if (mobileView.has("redirected")) { + // Handle redirects properly. + title = new PageTitle(mobileView.optString("redirected"), title.getSite()); + } else if (mobileView.has("normalizedtitle")) { + // We care about the normalized title only if we were not redirected + title = new PageTitle(mobileView.optString("normalizedtitle"), title.getSite()); + } } return super.processResult(result); } @@ -295,9 +305,17 @@ @Override public void onCatch(Throwable caught) { - if (caught instanceof ApiException) { - // Should check for the source of the error and have different things turn up - // But good enough for now + // in any case, make sure the TOC drawer is closed and disabled + tocSlider.closePane(); + tocSlider.setSlidingEnabled(false); + + if (caught instanceof SectionsFetchException) { + if (((SectionsFetchException)caught).getCode().equals("missingtitle")){ + Utils.crossFade(loadProgress, pageDoesNotExistError); + + } + } else if (caught instanceof ApiException) { + // Check for the source of the error and have different things turn up Utils.crossFade(loadProgress, networkError); // Not sure why this is required, but without it tapping retry hides networkError // FIXME: INVESTIGATE WHY THIS HAPPENS! diff --git a/wikipedia/src/main/java/org/wikipedia/page/SectionsFetchException.java b/wikipedia/src/main/java/org/wikipedia/page/SectionsFetchException.java new file mode 100644 index 0000000..a32a055 --- /dev/null +++ b/wikipedia/src/main/java/org/wikipedia/page/SectionsFetchException.java @@ -0,0 +1,19 @@ +package org.wikipedia.page; + +public class SectionsFetchException extends Exception { + private final String code; + private final String info; + + public SectionsFetchException(String code, String info) { + this.code = code; + this.info = info; + } + + public String getCode() { + return code; + } + + public String getMessage() { + return info; + } +} diff --git a/wikipedia/src/main/java/org/wikipedia/page/SectionsFetchTask.java b/wikipedia/src/main/java/org/wikipedia/page/SectionsFetchTask.java index b8cef7d..9e4df41 100644 --- a/wikipedia/src/main/java/org/wikipedia/page/SectionsFetchTask.java +++ b/wikipedia/src/main/java/org/wikipedia/page/SectionsFetchTask.java @@ -35,6 +35,11 @@ @Override public List<Section> processResult(ApiResult result) throws Throwable { + if (result.asObject().has("error")) { + JSONObject errorJSON = result.asObject().optJSONObject("error"); + throw new SectionsFetchException(errorJSON.optString("code"), errorJSON.optString("info")); + } + JSONArray sectionsJSON = result.asObject().optJSONObject("mobileview").optJSONArray("sections"); ArrayList<Section> sections = new ArrayList<Section>(); diff --git a/wikipedia/src/main/java/org/wikipedia/styledviews/DisableableSlidingPaneLayout.java b/wikipedia/src/main/java/org/wikipedia/styledviews/DisableableSlidingPaneLayout.java new file mode 100644 index 0000000..9e2afdb --- /dev/null +++ b/wikipedia/src/main/java/org/wikipedia/styledviews/DisableableSlidingPaneLayout.java @@ -0,0 +1,31 @@ +package org.wikipedia.styledviews; + +import android.content.*; +import android.support.v4.widget.*; +import android.util.AttributeSet; +import android.view.*; + +public class DisableableSlidingPaneLayout extends SlidingPaneLayout { + + private boolean enableSliding = true; + public boolean getSlidingEnabled() { return enableSliding; } + public void setSlidingEnabled(boolean enable) { enableSliding = enable; } + + public DisableableSlidingPaneLayout(Context context) { + super(context); + } + + public DisableableSlidingPaneLayout(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public DisableableSlidingPaneLayout(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + } + + @Override + public boolean onTouchEvent(MotionEvent ev) { + // if sliding is disabled, then consume the touch event. + return enableSliding ? super.onTouchEvent(ev) : true; + } +} -- To view, visit https://gerrit.wikimedia.org/r/130226 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Id357b37134bd288f02ae1f53c38ab7a84b2979b5 Gerrit-PatchSet: 4 Gerrit-Project: apps/android/wikipedia Gerrit-Branch: master Gerrit-Owner: Dbrant <dbr...@wikimedia.org> Gerrit-Reviewer: Yuvipanda <yuvipa...@gmail.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits