jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/343943 )

Change subject: Update EditSectionActivity to use the standard WikiErrorView
......................................................................


Update EditSectionActivity to use the standard WikiErrorView

Removes the old, custom error view in EditSectionActivity and replaces
it with the WikiErrorView used elsewhere in the app.

Besides improving consistency, this also makes the error view less
misleading, since the old, custom error view was hard-coded to say that
the app could not connect to the internet.

Bug: T154805
Bug: T157361
Change-Id: I76ef6c5ae1cd641b64b0f808a072d89a4ca04bb0
---
M app/src/main/java/org/wikipedia/dataclient/mwapi/MwException.java
M app/src/main/java/org/wikipedia/edit/EditSectionActivity.java
M app/src/main/java/org/wikipedia/edit/preview/EditPreviewFragment.java
M app/src/main/res/layout/activity_edit_section.xml
4 files changed, 140 insertions(+), 171 deletions(-)

Approvals:
  Niedzielski: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/app/src/main/java/org/wikipedia/dataclient/mwapi/MwException.java 
b/app/src/main/java/org/wikipedia/dataclient/mwapi/MwException.java
index 810a832..97521b8 100644
--- a/app/src/main/java/org/wikipedia/dataclient/mwapi/MwException.java
+++ b/app/src/main/java/org/wikipedia/dataclient/mwapi/MwException.java
@@ -10,7 +10,7 @@
         this.error = error;
     }
 
-    @Nullable String getTitle() {
+    @Nullable public String getTitle() {
         return error.getTitle();
     }
 
diff --git a/app/src/main/java/org/wikipedia/edit/EditSectionActivity.java 
b/app/src/main/java/org/wikipedia/edit/EditSectionActivity.java
index 96094b6..c0ba43c 100644
--- a/app/src/main/java/org/wikipedia/edit/EditSectionActivity.java
+++ b/app/src/main/java/org/wikipedia/edit/EditSectionActivity.java
@@ -26,7 +26,6 @@
 import android.widget.ScrollView;
 import android.widget.TextView;
 
-import org.mediawiki.api.json.ApiException;
 import org.wikipedia.Constants;
 import org.wikipedia.R;
 import org.wikipedia.WikipediaApp;
@@ -37,6 +36,7 @@
 import org.wikipedia.captcha.CaptchaResult;
 import org.wikipedia.csrf.CsrfToken;
 import org.wikipedia.csrf.CsrfTokenClient;
+import org.wikipedia.dataclient.mwapi.MwException;
 import org.wikipedia.dataclient.mwapi.MwQueryResponse;
 import org.wikipedia.edit.preview.EditPreviewFragment;
 import org.wikipedia.edit.richtext.SyntaxHighlighter;
@@ -54,6 +54,7 @@
 import org.wikipedia.util.StringUtil;
 import org.wikipedia.util.log.L;
 import org.wikipedia.views.ViewAnimations;
+import org.wikipedia.views.WikiErrorView;
 
 import java.util.concurrent.TimeUnit;
 
@@ -74,10 +75,6 @@
     private WikipediaApp app;
 
     private PageTitle title;
-    public PageTitle getPageTitle() {
-        return title;
-    }
-
     private int sectionID;
     private String sectionHeading;
     private PageProperties pageProps;
@@ -92,7 +89,7 @@
 
     private View sectionProgress;
     private ScrollView sectionContainer;
-    private View sectionError;
+    private WikiErrorView errorView;
 
     private View abusefilterContainer;
     private ImageView abuseFilterImage;
@@ -123,6 +120,10 @@
             finish();
         }
     };
+
+    public PageTitle getPageTitle() {
+        return title;
+    }
 
     @Override
     public void onCreate(Bundle savedInstanceState) {
@@ -158,8 +159,7 @@
         sectionProgress = findViewById(R.id.edit_section_load_progress);
         sectionContainer = (ScrollView) 
findViewById(R.id.edit_section_container);
         sectionContainer.setSmoothScrollingEnabled(false);
-        sectionError = findViewById(R.id.edit_section_error);
-        TextView sectionErrorRetry = (TextView) 
findViewById(R.id.edit_section_error_retry);
+        errorView = (WikiErrorView) findViewById(R.id.view_edit_section_error);
 
         abusefilterContainer = 
findViewById(R.id.edit_section_abusefilter_container);
         abuseFilterImage = (ImageView) 
findViewById(R.id.edit_section_abusefilter_image);
@@ -192,14 +192,20 @@
             handleAbuseFilter();
         }
 
-        sectionErrorRetry.setOnClickListener(new View.OnClickListener() {
+        errorView.setRetryClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
-                ViewAnimations.crossFade(sectionError, sectionProgress);
+                errorView.setVisibility(View.GONE);
                 fetchSectionText();
             }
         });
 
+        errorView.setBackClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                onBackPressed();
+            }
+        });
 
         setConditionalTextDirection(sectionText, 
title.getWikiSite().languageCode());
 
@@ -351,16 +357,14 @@
                                     // no longer attached to activity!
                                     return;
                                 }
-                                if (caught instanceof ApiException) {
-                                    // This is a fairly standard editing 
exception. Handle it appropriately.
-                                    handleEditingException((ApiException) 
caught);
-                                } else if (caught instanceof 
UserNotLoggedInException) {
+                                if (caught instanceof 
UserNotLoggedInException) {
                                     retry();
+                                } else if (caught instanceof MwException) {
+                                    handleEditingException((MwException) 
caught);
+                                    L.e(caught);
                                 } else {
-                                    // If it's not an API exception, we have 
no idea what's wrong.
-                                    // Show the user a generic error message.
-                                    L.w(caught);
                                     showRetryDialog(caught);
+                                    L.e(caught);
                                 }
                             }
                         });
@@ -368,9 +372,8 @@
 
             @Override
             public void failure(@NonNull Call<MwQueryResponse<CsrfToken>> 
call, @NonNull Throwable caught) {
-                // This is a simple, static API call and an API error is 
highly unlikely.
-                // In the event of failure, it's likely a network issue.
-                FeedbackUtil.showError(EditSectionActivity.this, caught);
+                showError(caught);
+                L.e(caught);
             }
         });
     }
@@ -408,10 +411,10 @@
 
     /**
      * Processes API error codes encountered during editing, and handles them 
as appropriate.
-     * @param e The ApiException to handle.
+     * @param caught The MwException to handle.
      */
-    private void handleEditingException(@NonNull ApiException e) {
-        String code = e.getCode();
+    private void handleEditingException(@NonNull MwException caught) {
+        String code = caught.getTitle();
         if (User.isLoggedIn() && ("badtoken".equals(code) || 
"assertuserfailed".equals(code))) {
             retry();
         } else if ("blocked".equals(code) || 
"wikimedia-globalblocking-ipblocked".equals(code)) {
@@ -452,7 +455,7 @@
         } else {
             // an unknown error occurred, so just dismiss the progress dialog 
and show a message.
             progressDialog.dismiss();
-            FeedbackUtil.showError(this, e);
+            FeedbackUtil.showError(this, caught);
         }
     }
 
@@ -466,35 +469,39 @@
                         if (result.pass()) {
                             doSave();
                         } else {
-                            onLoginError();
+                            if (!progressDialog.isShowing()) {
+                                // no longer attached to activity!
+                                return;
+                            }
+                            progressDialog.dismiss();
+                            FeedbackUtil.showMessage(EditSectionActivity.this, 
result.getMessage());
                         }
                     }
 
                     @Override
                     public void twoFactorPrompt(@NonNull Throwable caught, 
@Nullable String token) {
-                        FeedbackUtil.showError(EditSectionActivity.this,
-                                new 
LoginClient.LoginFailedException(getResources()
-                                        
.getString(R.string.login_2fa_other_workflow_error_msg)));
-                        onLoginError();
-                    }
-
-                    @Override
-                    public void error(@NonNull Throwable caught) {
-                        onLoginError();
-                    }
-
-                    private void onLoginError() {
                         if (!progressDialog.isShowing()) {
                             // no longer attached to activity!
                             return;
                         }
                         progressDialog.dismiss();
+                        FeedbackUtil.showError(EditSectionActivity.this,
+                                new 
LoginClient.LoginFailedException(getResources()
+                                        
.getString(R.string.login_2fa_other_workflow_error_msg)));
+                    }
 
-                        // TODO: The view shown here states "cannot connect to 
the Internet" regardless
-                        // of the actual cause of failure (which could also be 
an API error or malformed
-                        // response). Update this to provide more specificity 
and accuracy. (T154805)
-                        ViewAnimations.crossFade(sectionText, sectionError);
-                        sectionError.setVisibility(View.VISIBLE);
+                    @Override
+                    public void error(@NonNull Throwable caught) {
+                        showErrorView(caught);
+                    }
+
+                    private void showErrorView(@Nullable Throwable caught) {
+                        if (!progressDialog.isShowing()) {
+                            // no longer attached to activity!
+                            return;
+                        }
+                        progressDialog.dismiss();
+                        showError(caught);
                     }
                 });
     }
@@ -628,6 +635,11 @@
         return true;
     }
 
+    public void showError(@Nullable Throwable caught) {
+        errorView.setError(caught);
+        errorView.setVisibility(View.VISIBLE);
+    }
+
     @Override
     protected void onSaveInstanceState(Bundle outState) {
         super.onSaveInstanceState(outState);
@@ -647,15 +659,10 @@
                 }
 
                 @Override
-                public void failure(@NonNull Call<MwQueryResponse<Wikitext>> 
call, @NonNull Throwable throwable) {
-                    // TODO: The view shown here states "cannot connect to the 
Internet" regardless
-                    // of the actual cause of failure (which could also be an 
API error or malformed
-                    // response). Update this to provide more specificity and 
accuracy. (T154805)
-                    ViewAnimations.crossFade(sectionProgress, sectionError);
-                    // Not sure why this is required, but without it tapping 
retry hides langLinksError
-                    // FIXME: INVESTIGATE WHY THIS HAPPENS!
-                    // Also happens in {@link PageFragment}
-                    sectionError.setVisibility(View.VISIBLE);
+                public void failure(@NonNull Call<MwQueryResponse<Wikitext>> 
call, @NonNull Throwable caught) {
+                    sectionProgress.setVisibility(View.GONE);
+                    showError(caught);
+                    L.e(caught);
                 }
             });
         } else {
diff --git 
a/app/src/main/java/org/wikipedia/edit/preview/EditPreviewFragment.java 
b/app/src/main/java/org/wikipedia/edit/preview/EditPreviewFragment.java
index 793c7a4..3669bdb 100644
--- a/app/src/main/java/org/wikipedia/edit/preview/EditPreviewFragment.java
+++ b/app/src/main/java/org/wikipedia/edit/preview/EditPreviewFragment.java
@@ -332,26 +332,8 @@
                     return;
                 }
                 progressDialog.dismiss();
-
-                L.d(caught);
-                final AlertDialog retryDialog = new 
AlertDialog.Builder(getActivity())
-                        .setMessage(caught.getLocalizedMessage())
-                        
.setPositiveButton(R.string.dialog_message_edit_failed_retry,
-                                new DialogInterface.OnClickListener() {
-                                    @Override
-                                    public void onClick(DialogInterface 
dialog, int which) {
-                                        showPreview(title, wikiText);
-                                        dialog.dismiss();
-                                    }
-                                })
-                        
.setNegativeButton(R.string.dialog_message_edit_failed_cancel,
-                                new DialogInterface.OnClickListener() {
-                                    @Override
-                                    public void onClick(DialogInterface 
dialog, int which) {
-                                        dialog.dismiss();
-                                    }
-                                }).create();
-                retryDialog.show();
+                parentActivity.showError(caught);
+                L.e(caught);
             }
         });
     }
diff --git a/app/src/main/res/layout/activity_edit_section.xml 
b/app/src/main/res/layout/activity_edit_section.xml
index e56bd91..0186af0 100644
--- a/app/src/main/res/layout/activity_edit_section.xml
+++ b/app/src/main/res/layout/activity_edit_section.xml
@@ -1,129 +1,109 @@
 <?xml version="1.0" encoding="utf-8"?>
 
-<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android";
-             xmlns:app="http://schemas.android.com/apk/res-auto";
-             xmlns:tools="http://schemas.android.com/tools";
-             android:layout_width="match_parent"
-             android:layout_height="match_parent"
-             android:background="?attr/window_background_color">
+<FrameLayout
+    xmlns:android="http://schemas.android.com/apk/res/android";
+    xmlns:app="http://schemas.android.com/apk/res-auto";
+    xmlns:tools="http://schemas.android.com/tools";
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:background="?attr/window_background_color">
+
     <ProgressBar
-            android:id="@+id/edit_section_load_progress"
-            android:layout_gravity="center"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:indeterminate="true"
-            />
-    <LinearLayout
-            android:id="@+id/edit_section_error"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:layout_gravity="center_vertical"
-            android:orientation="vertical"
-            android:visibility="gone"
-            tools:visibility="visible"
-            >
-        <TextView android:layout_width="wrap_content" 
android:layout_height="wrap_content"
-                  android:layout_gravity="center"
-                  android:text="@string/error_network_error"
-                  style="?android:textAppearanceLarge"
-                />
+        android:id="@+id/edit_section_load_progress"
+        android:layout_gravity="center"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:indeterminate="true" />
 
-        <TextView
-            style="@style/ButtonProgressive"
-            android:id="@+id/edit_section_error_retry"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:text="@string/edit_section_error_retry"
-            android:layout_gravity="center" />
-
-    </LinearLayout>
     <ScrollView
-            android:id="@+id/edit_section_container"
-            android:visibility="gone"
-            tools:visibility="visible"
-            android:layout_width="match_parent"
-            android:layout_height="match_parent">
+        android:id="@+id/edit_section_container"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:visibility="gone"
+        tools:visibility="visible">
         <org.wikipedia.views.PlainPasteEditText
-                android:id="@+id/edit_section_text"
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:fontFamily="monospace"
-                android:gravity="top|start"
-                android:imeOptions="actionNone"
-                android:scrollbars="vertical"
-                android:textColor="?attr/edit_text_color"
-                />
+            android:id="@+id/edit_section_text"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:fontFamily="monospace"
+            android:gravity="top|start"
+            android:imeOptions="actionNone"
+            android:scrollbars="vertical"
+            android:textColor="?attr/edit_text_color" />
     </ScrollView>
 
     <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:orientation="vertical">
+        <fragment
+            android:id="@+id/edit_section_preview_fragment"
             android:layout_width="match_parent"
-            android:layout_height="match_parent"
-            android:orientation="vertical"
-            >
-        <fragment android:layout_width="match_parent"
-                  android:layout_height="0dp"
-                  android:layout_weight="1"
-                  class="org.wikipedia.edit.preview.EditPreviewFragment"
-                  android:id="@+id/edit_section_preview_fragment"
-                  tools:layout="@layout/fragment_preview_edit"/>
+            android:layout_height="0dp"
+            android:layout_weight="1"
+            class="org.wikipedia.edit.preview.EditPreviewFragment"
+            tools:layout="@layout/fragment_preview_edit"/>
     </LinearLayout>
 
     <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:orientation="vertical">
+        <fragment
+            android:id="@+id/edit_section_summary_fragment"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
-            android:orientation="vertical"
-            >
-        <fragment android:layout_width="match_parent"
-                  android:layout_height="match_parent"
-                  class="org.wikipedia.edit.summaries.EditSummaryFragment"
-                  android:id="@+id/edit_section_summary_fragment"
-                  tools:layout="@layout/fragment_preview_summary"/>
+            class="org.wikipedia.edit.summaries.EditSummaryFragment"
+            tools:layout="@layout/fragment_preview_summary"/>
     </LinearLayout>
 
     <include layout="@layout/group_captcha" />
 
-    <ScrollView android:id="@+id/edit_section_abusefilter_container"
-                android:layout_width="match_parent"
-                android:layout_height="match_parent"
-                android:visibility="gone"
-                tools:visibility="visible"
-                android:background="?attr/window_background_color"
-            >
+    <ScrollView
+        android:id="@+id/edit_section_abusefilter_container"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:background="?attr/window_background_color"
+        android:visibility="gone"
+        tools:visibility="visible">
         <LinearLayout
+            android:orientation="vertical"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent">
+            <LinearLayout
                 android:orientation="vertical"
                 android:layout_width="match_parent"
-                android:layout_height="match_parent"
-                >
-            <LinearLayout
-                    android:orientation="vertical"
-                    android:layout_width="match_parent"
-                    android:layout_height="wrap_content"
-                    android:background="?attr/abusefilter_background_color"
-                    >
+                android:layout_height="wrap_content"
+                android:background="?attr/abusefilter_background_color">
                 <ImageView
-                        android:id="@+id/edit_section_abusefilter_image"
-                        android:layout_width="48dp"
-                        android:layout_height="48dp"
-                        app:srcCompat="@drawable/ic_abusefilter_warn"
-                        android:layout_margin="24dp"
-                        android:layout_gravity="center_horizontal"
-                        android:contentDescription="@null"/>
+                    android:id="@+id/edit_section_abusefilter_image"
+                    android:layout_width="48dp"
+                    android:layout_height="48dp"
+                    android:layout_margin="24dp"
+                    android:layout_gravity="center_horizontal"
+                    app:srcCompat="@drawable/ic_abusefilter_warn"
+                    android:contentDescription="@null"/>
             </LinearLayout>
             <TextView
-                    android:id="@+id/edit_section_abusefilter_title"
-                    android:layout_width="match_parent"
-                    android:layout_height="wrap_content"
-                    android:padding="16dp"
-                    android:textAppearance="?android:attr/textAppearanceLarge"
-                    android:text="@string/abusefilter_title_warn"/>
+                android:id="@+id/edit_section_abusefilter_title"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:padding="16dp"
+                android:textAppearance="?android:attr/textAppearanceLarge"
+                android:text="@string/abusefilter_title_warn"/>
             <TextView
-                    android:id="@+id/edit_section_abusefilter_text"
-                    android:layout_width="match_parent"
-                    android:layout_height="wrap_content"
-                    android:padding="16dp"
-                    android:text="@string/abusefilter_text_warn"/>
-
+                android:id="@+id/edit_section_abusefilter_text"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:padding="16dp"
+                android:text="@string/abusefilter_text_warn"/>
         </LinearLayout>
     </ScrollView>
 
+    <org.wikipedia.views.WikiErrorView
+        android:id="@+id/view_edit_section_error"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:layout_gravity="center"
+        android:visibility="gone"/>
 </FrameLayout>

-- 
To view, visit https://gerrit.wikimedia.org/r/343943
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I76ef6c5ae1cd641b64b0f808a072d89a4ca04bb0
Gerrit-PatchSet: 11
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Mholloway <[email protected]>
Gerrit-Reviewer: Brion VIBBER <[email protected]>
Gerrit-Reviewer: Dbrant <[email protected]>
Gerrit-Reviewer: Niedzielski <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to