Dbrant has uploaded a new change for review. https://gerrit.wikimedia.org/r/130226
Change subject: Fixed crash on nonexistent pages. ...................................................................... Fixed crash on nonexistent pages. Bug: 62639 Change-Id: Id357b37134bd288f02ae1f53c38ab7a84b2979b5 --- M wikipedia/res/layout/fragment_page.xml M wikipedia/res/values/strings.xml M wikipedia/src/main/java/org/wikipedia/page/PageViewFragment.java 3 files changed, 30 insertions(+), 8 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia refs/changes/26/130226/1 diff --git a/wikipedia/res/layout/fragment_page.xml b/wikipedia/res/layout/fragment_page.xml index 1e62dea..ea34b69 100644 --- a/wikipedia/res/layout/fragment_page.xml +++ b/wikipedia/res/layout/fragment_page.xml @@ -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_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_not_exist_error" + style="?android:textAppearanceLarge" + /> </LinearLayout> </FrameLayout> \ No newline at end of file diff --git a/wikipedia/res/values/strings.xml b/wikipedia/res/values/strings.xml index 9b2d905..d97387a 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_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..745a62c 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.*; @@ -37,6 +38,7 @@ private ProgressBar loadProgress; private View networkError; private View retryButton; + private View pageNotExistError; private SlidingPaneLayout tocSlider; private Page page; @@ -139,6 +141,7 @@ loadProgress = (ProgressBar) getView().findViewById(R.id.page_load_progress); networkError = getView().findViewById(R.id.page_error); retryButton = getView().findViewById(R.id.page_error_retry); + pageNotExistError = getView().findViewById(R.id.page_not_exist); quickReturnBar = getActivity().findViewById(quickReturnBarId); tocSlider = (SlidingPaneLayout) getView().findViewById(R.id.page_toc_slider); @@ -268,6 +271,9 @@ @Override public List<Section> processResult(ApiResult result) throws Throwable { + if(result.asObject().has("error")){ + throw new ApiException(new JSONException((String)result.asObject().getJSONObject("error").get("code"))); + } JSONObject mobileView = result.asObject().optJSONObject("mobileview"); pageProperties = new PageProperties(mobileView); if (mobileView.has("redirected")) { @@ -296,12 +302,15 @@ @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 - Utils.crossFade(loadProgress, networkError); - // Not sure why this is required, but without it tapping retry hides networkError - // FIXME: INVESTIGATE WHY THIS HAPPENS! - networkError.setVisibility(View.VISIBLE); + // Check for the source of the error and have different things turn up + if (((ApiException)caught).getMessage().contains("missingtitle")){ + Utils.crossFade(loadProgress, pageNotExistError); + }else{ + Utils.crossFade(loadProgress, networkError); + // Not sure why this is required, but without it tapping retry hides networkError + // FIXME: INVESTIGATE WHY THIS HAPPENS! + networkError.setVisibility(View.VISIBLE); + } } else { throw new RuntimeException(caught); } -- To view, visit https://gerrit.wikimedia.org/r/130226 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id357b37134bd288f02ae1f53c38ab7a84b2979b5 Gerrit-PatchSet: 1 Gerrit-Project: apps/android/wikipedia Gerrit-Branch: master Gerrit-Owner: Dbrant <dbr...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits