jenkins-bot has submitted this change and it was merged.
Change subject: Retrofit editing
......................................................................
Retrofit editing
Change-Id: I54e551b3f4802350740db5450f018549373558f8
---
D app/src/androidTest/java/org/wikipedia/editing/EditTaskTest.java
A app/src/androidTest/java/org/wikipedia/editing/EditTest.java
A app/src/main/java/org/wikipedia/editing/Edit.java
A app/src/main/java/org/wikipedia/editing/EditClient.java
M app/src/main/java/org/wikipedia/editing/EditSectionActivity.java
5 files changed, 426 insertions(+), 253 deletions(-)
Approvals:
BearND: Looks good to me, approved
jenkins-bot: Verified
diff --git a/app/src/androidTest/java/org/wikipedia/editing/EditTaskTest.java
b/app/src/androidTest/java/org/wikipedia/editing/EditTaskTest.java
deleted file mode 100644
index 7b5d84f..0000000
--- a/app/src/androidTest/java/org/wikipedia/editing/EditTaskTest.java
+++ /dev/null
@@ -1,182 +0,0 @@
-package org.wikipedia.editing;
-
-import android.support.annotation.NonNull;
-import android.support.test.filters.SmallTest;
-import android.support.test.runner.AndroidJUnit4;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.wikipedia.WikipediaApp;
-import org.wikipedia.dataclient.WikiSite;
-import org.wikipedia.page.PageTitle;
-import org.wikipedia.testlib.TestLatch;
-
-import static android.support.test.InstrumentationRegistry.getTargetContext;
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-@SmallTest
-@RunWith(AndroidJUnit4.class)
-public class EditTaskTest {
- private static final WikiSite TEST_WIKI = WikiSite.forLanguageCode("test");
-
- private static final String ABUSE_FILTER_ERROR_PAGE_TITLE =
"Test_page_for_app_testing/AbuseFilter";
-
- @Before
- public void setUp() {
- // Cookies for a logged in session cannot be used with the anonymous
edit token.
- app().getCookieManager().clearAllCookies();
- }
-
- @Test
- public void testEdit() {
- PageTitle title = new PageTitle(null,
"Test_page_for_app_testing/Section1", TEST_WIKI);
- String wikitext = "== Section 2 ==\n\nEditing section INSERT RANDOM &
HERE test at "
- + System.currentTimeMillis();
- final int sectionId = 3;
-
- EditingResult result = Subject.execute(title, wikitext, sectionId);
- assertThat(result, instanceOf(SuccessEditResult.class));
- }
-
- @Test
- public void testCaptcha() {
- PageTitle title = new PageTitle(null,
"Test_page_for_app_testing/Captcha", TEST_WIKI);
- String wikitext = "== Section 2 ==\n\nEditing by inserting an external
link https://"
- + System.currentTimeMillis();
-
- EditingResult result = Subject.execute(title, wikitext);
- validateCaptcha(result);
- }
-
- /**
- * Test handling of abuse filter warnings which warn users about making
edits of a certain kind.
- *
- * Type: warn
- * Action: editing any userspace page while logged out
- * Filter: https://test.wikipedia.org/wiki/Special:AbuseFilter/94
- */
- @Test
- public void testAbuseFilterTriggerWarn() {
- PageTitle title = new PageTitle(null, "User:Yuvipandaaaaaaaa",
TEST_WIKI);
-
- // Rule 94 is only a warning so the initial attempt may be successful.
The second is
- // guaranteed to be a warning if different content is used.
@FlakyTest(tolerance = 2)
- // doesn't work with JUnit 4.
- EditingResult result = null;
- for (int i = 0; !(result instanceof AbuseFilterEditResult) && i < 2;
++i) {
- String wikitext = "Testing Abusefilter by simply editing this
page. Triggering rule 94 at "
- + System.nanoTime();
- result = Subject.execute(title, wikitext);
- }
-
- assertThat(result, instanceOf(AbuseFilterEditResult.class));
- // todo: test against a warning, not an error. Rule 94 is currently
returning
- // abusefilter-disallowed instead of abusefilter-warning.
EditTask needs to be
- // reworked to a data client that can consume mock data
- //noinspection ConstantConditions
- assertThat(((AbuseFilterEditResult) result).getType(),
is(AbuseFilterEditResult.TYPE_ERROR));
- }
-
- /**
- * Test handling of abuse filter errors which completely disallow edits of
a certain kind.
- *
- * Type: disallow
- * Action: adding string "poop" to page text
- * Filter: https://test.wikipedia.org/wiki/Special:AbuseFilter/2
- */
- @Test
- public void testAbuseFilterTriggerStop() {
- PageTitle title = new PageTitle(null, ABUSE_FILTER_ERROR_PAGE_TITLE,
TEST_WIKI);
- String wikitext = "== Section 2 ==\n\nTriggering AbuseFilter number 2
by saying poop many times at "
- + System.currentTimeMillis();
-
- EditingResult result = Subject.execute(title, wikitext);
- assertThat(result, instanceOf(AbuseFilterEditResult.class));
- assertThat(((AbuseFilterEditResult) result).getType(),
is(AbuseFilterEditResult.TYPE_ERROR));
- }
-
- /**
- * Test the app's handling of the abuse filter emitting arbitrary error
codes.
- *
- * Type: warn
- * Action: adding string "appcrashtest" to page text
- * Filter: https://test.wikipedia.org/wiki/Special:AbuseFilter/152
- */
- @Test
- public void testAbuseFilterTriggerStopOnArbitraryErrorCode() {
- PageTitle title = new PageTitle(null, ABUSE_FILTER_ERROR_PAGE_TITLE,
TEST_WIKI);
- String wikitext = "== Section 2 ==\n\nTriggering AbuseFilter number
152 by saying appcrashtest many times at "
- + System.currentTimeMillis();
-
- EditingResult result = Subject.execute(title, wikitext);
- assertThat(result, instanceOf(AbuseFilterEditResult.class));
- assertThat(((AbuseFilterEditResult) result).getType(),
is(AbuseFilterEditResult.TYPE_ERROR));
- }
-
- private void validateCaptcha(EditingResult result) {
- assertThat(result, instanceOf(CaptchaResult.class));
- CaptchaResult captchaResult = (CaptchaResult) result;
- String url = captchaResult.getCaptchaUrl(TEST_WIKI);
- assertThat(isValidCaptchaUrl(url), is(true));
- }
-
- private boolean isValidCaptchaUrl(String url) {
- return url.startsWith(getNetworkProtocol()
- +
"://test.wikipedia.org/w/index.php?title=Special:Captcha/image");
- }
-
- private String getNetworkProtocol() {
- return app().getWikiSite().scheme();
- }
-
- private WikipediaApp app() {
- return WikipediaApp.getInstance();
- }
-
- private static class Subject extends EditTask {
- private static final int DEFAULT_SECTION_ID = 0;
-
- //
https://www.mediawiki.org/wiki/Manual:Edit_token#The_edit_token_suffix
- private static final String ANONYMOUS_TOKEN = "+\\";
-
- private static final String DEFAULT_SUMMARY = "";
-
- public static EditingResult execute(PageTitle title, String
sectionWikitext) {
- return execute(title, sectionWikitext, DEFAULT_SECTION_ID);
- }
-
- public static EditingResult execute(PageTitle title, String
sectionWikitext, int sectionId) {
- return execute(title, sectionWikitext, sectionId, ANONYMOUS_TOKEN);
- }
-
- public static EditingResult execute(PageTitle title, String
sectionWikitext, int sectionId,
- String token) {
- Subject subject = new Subject(title, sectionWikitext, sectionId,
token);
- subject.execute();
- return subject.await();
- }
-
- @NonNull private final TestLatch latch = new TestLatch();
- private EditingResult result;
-
- Subject(PageTitle title, String sectionWikitext, int sectionId, String
token) {
- super(getTargetContext(), title, sectionWikitext, sectionId,
token, DEFAULT_SUMMARY,
- false);
- }
-
- @Override
- public void onFinish(EditingResult result) {
- super.onFinish(result);
- this.result = result;
- latch.countDown();
- }
-
- public EditingResult await() {
- latch.await();
- return result;
- }
- }
-}
diff --git a/app/src/androidTest/java/org/wikipedia/editing/EditTest.java
b/app/src/androidTest/java/org/wikipedia/editing/EditTest.java
new file mode 100644
index 0000000..24f9f67
--- /dev/null
+++ b/app/src/androidTest/java/org/wikipedia/editing/EditTest.java
@@ -0,0 +1,207 @@
+package org.wikipedia.editing;
+
+import android.support.annotation.NonNull;
+import android.support.test.filters.LargeTest;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.wikipedia.WikipediaApp;
+import org.wikipedia.dataclient.WikiSite;
+import org.wikipedia.page.PageTitle;
+import org.wikipedia.testlib.TestLatch;
+
+import retrofit2.Call;
+
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+@LargeTest
+public class EditTest {
+ private static final WikiSite TEST_WIKI_SITE =
WikiSite.forLanguageCode("test");
+ private static final String ABUSE_FILTER_ERROR_PAGE_TITLE =
"Test_page_for_app_testing/AbuseFilter";
+ private static final int DEFAULT_SECTION_ID = 0;
+ // https://www.mediawiki.org/wiki/Manual:Edit_token#The_edit_token_suffix
+ private static final String ANONYMOUS_TOKEN = "+\\";
+ private static final String DEFAULT_SUMMARY = "";
+
+ private EditClient client = new EditClient();
+
+ @Before
+ public void setUp() {
+ // Cookies for a logged in session cannot be used with the anonymous
edit token.
+ app().getCookieManager().clearAllCookies();
+ }
+
+ @Test
+ public void testEdit() {
+ PageTitle title = new PageTitle(null,
"Test_page_for_app_testing/Section1", TEST_WIKI_SITE);
+ String wikitext = "== Section 2 ==\n\nEditing section INSERT RANDOM &
HERE test at "
+ + System.currentTimeMillis();
+ final int sectionId = 3;
+ final TestLatch latch = new TestLatch();
+
+ client.request(TEST_WIKI_SITE, title, sectionId, wikitext,
ANONYMOUS_TOKEN, DEFAULT_SUMMARY,
+ false, null, null, new EditClient.Callback() {
+ @Override
+ public void success(@NonNull Call<Edit> call, @NonNull
EditingResult result) {
+ assertThat(result,
instanceOf(SuccessEditResult.class));
+ latch.countDown();
+ }
+
+ @Override
+ public void failure(@NonNull Call<Edit> call, @NonNull
Throwable caught) {
+ throw new RuntimeException(caught);
+ }
+ });
+ latch.await();
+ }
+
+ @Test
+ public void testCaptcha() {
+ PageTitle title = new PageTitle(null,
"Test_page_for_app_testing/Captcha", TEST_WIKI_SITE);
+ String wikitext = "== Section 2 ==\n\nEditing by inserting an external
link https://"
+ + System.currentTimeMillis();
+ final TestLatch latch = new TestLatch();
+
+ client.request(TEST_WIKI_SITE, title, DEFAULT_SECTION_ID, wikitext,
ANONYMOUS_TOKEN,
+ DEFAULT_SUMMARY, false, null, null, new EditClient.Callback() {
+ @Override
+ public void success(@NonNull Call<Edit> call, @NonNull
EditingResult result) {
+ validateCaptcha(result);
+ latch.countDown();
+ }
+
+ @Override
+ public void failure(@NonNull Call<Edit> call, @NonNull
Throwable caught) {
+ throw new RuntimeException(caught);
+ }
+ });
+ latch.await();
+ }
+
+ /**
+ * Test handling of abuse filter warnings which warn users about making
edits of a certain kind.
+ *
+ * Type: warn
+ * Action: editing any userspace page while logged out
+ * Filter: https://test.wikipedia.org/wiki/Special:AbuseFilter/94
+ */
+ @Test
+ public void testAbuseFilterTriggerWarn() {
+ PageTitle title = new PageTitle(null, "User:Yuvipandaaaaaaaa",
TEST_WIKI_SITE);
+
+ // Rule 94 is only a warning so the initial attempt may be successful.
The second is
+ // guaranteed to be a warning if different content is used.
@FlakyTest(tolerance = 2)
+ // doesn't work with JUnit 4.
+ for (int i = 0; i < 2; ++i) {
+ String wikitext = "Testing Abusefilter by simply editing this
page. Triggering rule 94"
+ + "at " + System.nanoTime();
+ final TestLatch latch = new TestLatch();
+
+ client.request(TEST_WIKI_SITE, title, DEFAULT_SECTION_ID,
wikitext, ANONYMOUS_TOKEN,
+ DEFAULT_SUMMARY, false, null, null, new
EditClient.Callback() {
+ @Override
+ public void success(@NonNull Call<Edit> call, @NonNull
EditingResult result) {
+ if (!(result instanceof SuccessEditResult)) {
+ assertThat(result,
instanceOf(AbuseFilterEditResult.class));
+ //noinspection ConstantConditions
+ assertThat(((AbuseFilterEditResult)
result).getType(),
+ is(AbuseFilterEditResult.TYPE_ERROR));
+ }
+ latch.countDown();
+ }
+
+ @Override
+ public void failure(@NonNull Call<Edit> call, @NonNull
Throwable caught) {
+ throw new RuntimeException(caught);
+ }
+ });
+ latch.await();
+ }
+ }
+
+ /**
+ * Test handling of abuse filter errors which completely disallow edits of
a certain kind.
+ *
+ * Type: disallow
+ * Action: adding string "poop" to page text
+ * Filter: https://test.wikipedia.org/wiki/Special:AbuseFilter/2
+ */
+ @Test
+ public void testAbuseFilterTriggerStop() {
+ PageTitle title = new PageTitle(null, ABUSE_FILTER_ERROR_PAGE_TITLE,
TEST_WIKI_SITE);
+ String wikitext = "== Section 2 ==\n\nTriggering AbuseFilter number 2
by saying poop many"
+ + "times at " + System.currentTimeMillis();
+ final TestLatch latch = new TestLatch();
+
+ client.request(TEST_WIKI_SITE, title, DEFAULT_SECTION_ID, wikitext,
ANONYMOUS_TOKEN,
+ DEFAULT_SUMMARY, false, null, null, new EditClient.Callback() {
+ @Override
+ public void success(@NonNull Call<Edit> call, @NonNull
EditingResult result) {
+ assertThat(result,
instanceOf(AbuseFilterEditResult.class));
+ assertThat(((AbuseFilterEditResult) result).getType(),
+ is(AbuseFilterEditResult.TYPE_ERROR));
+ latch.countDown();
+ }
+
+ @Override
+ public void failure(@NonNull Call<Edit> call, @NonNull
Throwable caught) {
+ throw new RuntimeException(caught);
+ }
+ });
+ latch.await();
+ }
+
+ /**
+ * Test the app's handling of the abuse filter emitting arbitrary error
codes.
+ *
+ * Type: warn
+ * Action: adding string "appcrashtest" to page text
+ * Filter: https://test.wikipedia.org/wiki/Special:AbuseFilter/152
+ */
+ @Test
+ public void testAbuseFilterTriggerStopOnArbitraryErrorCode() {
+ PageTitle title = new PageTitle(null, ABUSE_FILTER_ERROR_PAGE_TITLE,
TEST_WIKI_SITE);
+ String wikitext = "== Section 2 ==\n\nTriggering AbuseFilter number
152 by saying"
+ + "appcrashtest many times at " + System.currentTimeMillis();
+ final TestLatch latch = new TestLatch();
+
+ client.request(TEST_WIKI_SITE, title, DEFAULT_SECTION_ID, wikitext,
ANONYMOUS_TOKEN,
+ DEFAULT_SUMMARY, false, null, null, new EditClient.Callback() {
+ @Override
+ public void success(@NonNull Call<Edit> call, @NonNull
EditingResult result) {
+ assertThat(result,
instanceOf(AbuseFilterEditResult.class));
+ assertThat(((AbuseFilterEditResult) result).getType(),
+ is(AbuseFilterEditResult.TYPE_ERROR));
+ latch.countDown();
+ }
+
+ @Override
+ public void failure(@NonNull Call<Edit> call, @NonNull
Throwable caught) {
+ throw new RuntimeException(caught);
+ }
+ });
+ latch.await();
+ }
+
+ private void validateCaptcha(EditingResult result) {
+ assertThat(result, instanceOf(CaptchaResult.class));
+ CaptchaResult captchaResult = (CaptchaResult) result;
+ String url = captchaResult.getCaptchaUrl(TEST_WIKI_SITE);
+ assertThat(isValidCaptchaUrl(url), is(true));
+ }
+
+ private boolean isValidCaptchaUrl(String url) {
+ return url.startsWith(getNetworkProtocol()
+ +
"://test.wikipedia.org/w/index.php?title=Special:Captcha/image");
+ }
+
+ private String getNetworkProtocol() {
+ return app().getWikiSite().scheme();
+ }
+
+ private WikipediaApp app() {
+ return WikipediaApp.getInstance();
+ }
+}
diff --git a/app/src/main/java/org/wikipedia/editing/Edit.java
b/app/src/main/java/org/wikipedia/editing/Edit.java
new file mode 100644
index 0000000..1b18608
--- /dev/null
+++ b/app/src/main/java/org/wikipedia/editing/Edit.java
@@ -0,0 +1,57 @@
+package org.wikipedia.editing;
+
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+
+public class Edit {
+ @SuppressWarnings("unused,NullableProblems") @NonNull private Result edit;
+ @NonNull protected Result edit() {
+ return edit;
+ }
+
+ protected class Result {
+ @Nullable private String result;
+ @Nullable protected String status() {
+ return result;
+ }
+
+ private int newrevid;
+ protected int newRevId() {
+ return newrevid;
+ }
+
+ @Nullable private Captcha captcha;
+ @Nullable protected Captcha captcha() {
+ return captcha;
+ }
+
+ @Nullable private String code;
+ @Nullable protected String code() {
+ return code;
+ }
+
+ protected boolean hasErrorCode() {
+ return code != null;
+ }
+
+ protected boolean hasCaptchaResponse() {
+ return captcha != null;
+ }
+
+ @Nullable private String spamblacklist;
+ @Nullable protected String spamblacklist() {
+ return spamblacklist;
+ }
+
+ protected boolean hasSpamBlacklistResponse() {
+ return spamblacklist != null;
+ }
+ }
+
+ protected class Captcha {
+ @SuppressWarnings("unused,NullableProblems") @NonNull private String
id;
+ @NonNull protected String id() {
+ return id;
+ }
+ }
+}
diff --git a/app/src/main/java/org/wikipedia/editing/EditClient.java
b/app/src/main/java/org/wikipedia/editing/EditClient.java
new file mode 100644
index 0000000..de0d486
--- /dev/null
+++ b/app/src/main/java/org/wikipedia/editing/EditClient.java
@@ -0,0 +1,99 @@
+package org.wikipedia.editing;
+
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+import android.support.annotation.VisibleForTesting;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.wikipedia.dataclient.WikiSite;
+import org.wikipedia.dataclient.retrofit.MwCachedService;
+import org.wikipedia.json.GsonMarshaller;
+import org.wikipedia.page.PageTitle;
+
+import java.util.concurrent.TimeUnit;
+
+import retrofit2.Call;
+import retrofit2.Response;
+import retrofit2.http.Field;
+import retrofit2.http.FormUrlEncoded;
+import retrofit2.http.POST;
+
+public class EditClient {
+ @NonNull private final MwCachedService<Service> cachedService
+ = new MwCachedService<>(Service.class);
+
+ @SuppressWarnings("checkstyle:parameternumber")
+ public Call<Edit> request(@NonNull WikiSite wiki, @NonNull PageTitle
title, int section,
+ @NonNull String text, @NonNull String token, @NonNull
String summary,
+ boolean loggedIn, @Nullable String captchaId,
@Nullable String captchaWord,
+ @NonNull Callback cb) {
+ Service service = cachedService.service(wiki);
+ return request(service, title, section, text, token, summary,
loggedIn, captchaId, captchaWord, cb);
+ }
+
+ @SuppressWarnings("checkstyle:parameternumber")
+ @VisibleForTesting Call<Edit> request(@NonNull Service service, @NonNull
PageTitle title, int section,
+ @NonNull String text, @NonNull String token, @NonNull
String summary,
+ boolean loggedIn, @Nullable String captchaId, @Nullable
String captchaWord,
+ @NonNull final Callback cb) {
+ Call<Edit> call = service.edit(title.getPrefixedText(), section, text,
+ token, summary, loggedIn ? "user" : null, captchaId,
captchaWord);
+ call.enqueue(new retrofit2.Callback<Edit>() {
+ @Override
+ public void onResponse(Call<Edit> call, Response<Edit> response) {
+ if (response.isSuccessful()) {
+ Edit.Result result = response.body().edit();
+ if ("Success".equals(result.status())) {
+ try {
+ // TODO: remove when the server reflects the
updated page content
+ // immediately after submitting the edit, instead
of a short while after.
+ Thread.sleep(TimeUnit.SECONDS.toMillis(2));
+ cb.success(call, new
SuccessEditResult(result.newRevId()));
+ } catch (InterruptedException e) {
+ cb.failure(call, e);
+ }
+ } else if (result.hasErrorCode()) {
+ try {
+ JSONObject json = new
JSONObject(GsonMarshaller.marshal(result));
+ cb.success(call, new AbuseFilterEditResult(json));
+ } catch (JSONException e) {
+ cb.failure(call, e);
+ }
+ } else if (result.hasSpamBlacklistResponse()) {
+ cb.success(call, new
SpamBlacklistEditResult(result.spamblacklist()));
+ } else if (result.hasCaptchaResponse()) {
+ cb.success(call, new
CaptchaResult(result.captcha().id()));
+ } else {
+ cb.failure(call, new RuntimeException("Received
unrecognized edit response"));
+ }
+ }
+ }
+
+ @Override
+ public void onFailure(Call<Edit> call, Throwable t) {
+ cb.failure(call, t);
+ }
+ });
+ return call;
+ }
+
+ @VisibleForTesting interface Callback {
+ void success(@NonNull Call<Edit> call, @NonNull EditingResult result);
+ void failure(@NonNull Call<Edit> call, @NonNull Throwable caught);
+ }
+
+ private interface Service {
+ @FormUrlEncoded
+ @POST("w/api.php?action=edit&format=json")
+ @SuppressWarnings("checkstyle:parameternumber")
+ Call<Edit> edit(@NonNull @Field("title") String title,
+ @Field("section") int section,
+ @NonNull @Field("text") String text,
+ @NonNull @Field("token") String token,
+ @NonNull @Field("summary") String summary,
+ @Nullable @Field("assert") String user,
+ @Nullable @Field("captchaId") String captchaId,
+ @Nullable @Field("captchaWord") String captchaWord);
+ }
+}
diff --git a/app/src/main/java/org/wikipedia/editing/EditSectionActivity.java
b/app/src/main/java/org/wikipedia/editing/EditSectionActivity.java
index dbd7787..b8b709f 100644
--- a/app/src/main/java/org/wikipedia/editing/EditSectionActivity.java
+++ b/app/src/main/java/org/wikipedia/editing/EditSectionActivity.java
@@ -25,9 +25,7 @@
import android.widget.ScrollView;
import android.widget.TextView;
-import org.mediawiki.api.json.Api;
import org.mediawiki.api.json.ApiException;
-import org.mediawiki.api.json.RequestBuilder;
import org.wikipedia.Constants;
import org.wikipedia.R;
import org.wikipedia.ViewAnimations;
@@ -275,79 +273,73 @@
// Summaries are plaintext, so remove any HTML that's made its
way into the summary
summaryText = StringUtil.fromHtml(summaryText).toString();
- new EditTask(EditSectionActivity.this, title,
sectionText.getText().toString(),
- sectionID, token, summaryText, User.isLoggedIn()) {
- @Override
- public void onBeforeExecute() {
- if (!isFinishing()) {
- progressDialog.show();
- }
- }
+ if (!isFinishing()) {
+ progressDialog.show();
+ }
- @Override
- public RequestBuilder buildRequest(Api api) {
- return
captchaHandler.populateBuilder(super.buildRequest(api));
- }
+ new EditClient().request(title.getWikiSite(), title, sectionID,
+ sectionText.getText().toString(), token, summaryText,
User.isLoggedIn(),
+ captchaHandler.isActive() ? captchaHandler.captchaId()
: "null",
+ captchaHandler.isActive() ?
captchaHandler.captchaWord() : "null",
+ new EditClient.Callback() {
+ @Override
+ public void success(@NonNull Call<Edit> call,
@NonNull EditingResult result) {
+ if (isFinishing() ||
!progressDialog.isShowing()) {
+ // no longer attached to activity!
+ return;
+ }
+ if (result instanceof SuccessEditResult) {
+ funnel.logSaved(((SuccessEditResult)
result).getRevID());
+ progressDialog.dismiss();
- @Override
- public void onCatch(Throwable caught) {
- if (isFinishing() || !progressDialog.isShowing()) {
- // 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 it's not an API exception, we have no idea
what's wrong.
- // Show the user a generic error message.
- L.w("Caught " + caught.toString());
- showRetryDialog();
- }
- }
-
- @Override
- public void onFinish(EditingResult result) {
- if (isFinishing() || !progressDialog.isShowing()) {
- // no longer attached to activity!
- return;
- }
- if (result instanceof SuccessEditResult) {
- funnel.logSaved(((SuccessEditResult)
result).getRevID());
- progressDialog.dismiss();
-
- //Build intent that includes the section we were
editing, so we can scroll to it later
- Intent data = new Intent();
- data.putExtra(EXTRA_SECTION_ID, sectionID);
- setResult(EditHandler.RESULT_REFRESH_PAGE, data);
- hideSoftKeyboard(EditSectionActivity.this);
- finish();
- } else if (result instanceof CaptchaResult) {
- if (captchaHandler.isActive()) {
- // Captcha entry failed!
- funnel.logCaptchaFailure();
+ //Build intent that includes the section
we were editing, so we can scroll to it later
+ Intent data = new Intent();
+ data.putExtra(EXTRA_SECTION_ID, sectionID);
+ setResult(EditHandler.RESULT_REFRESH_PAGE,
data);
+ hideSoftKeyboard(EditSectionActivity.this);
+ finish();
+ } else if (result instanceof CaptchaResult) {
+ if (captchaHandler.isActive()) {
+ // Captcha entry failed!
+ funnel.logCaptchaFailure();
+ }
+ captchaHandler.handleCaptcha(null,
(CaptchaResult) result);
+ funnel.logCaptchaShown();
+ } else if (result instanceof
AbuseFilterEditResult) {
+ abusefilterEditResult =
(AbuseFilterEditResult) result;
+ handleAbuseFilter();
+ if (abusefilterEditResult.getType() ==
AbuseFilterEditResult.TYPE_ERROR) {
+ editPreviewFragment.hide();
+ }
+ } else if (result instanceof
SpamBlacklistEditResult) {
+
FeedbackUtil.showMessage(EditSectionActivity.this,
+
R.string.editing_error_spamblacklist);
+ progressDialog.dismiss();
+ editPreviewFragment.hide();
+ } else {
+ funnel.logError(result.getResult());
+ // Expand to do everything.
+ failure(call, new Throwable());
+ }
}
- captchaHandler.handleCaptcha(null, (CaptchaResult)
result);
- funnel.logCaptchaShown();
- } else if (result instanceof AbuseFilterEditResult) {
- abusefilterEditResult = (AbuseFilterEditResult)
result;
- handleAbuseFilter();
- if (abusefilterEditResult.getType() ==
AbuseFilterEditResult.TYPE_ERROR) {
- editPreviewFragment.hide();
- }
- } else if (result instanceof SpamBlacklistEditResult) {
- FeedbackUtil.showMessage(EditSectionActivity.this,
- R.string.editing_error_spamblacklist);
- progressDialog.dismiss();
- editPreviewFragment.hide();
- } else {
- funnel.logError(result.getResult());
- // Expand to do everything.
- onCatch(null);
- }
- }
- }.execute();
+ @Override
+ public void failure(@NonNull Call<Edit> call,
@NonNull Throwable caught) {
+ if (isFinishing() ||
!progressDialog.isShowing()) {
+ // 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 it's not an API exception, we have
no idea what's wrong.
+ // Show the user a generic error message.
+ L.w("Caught " + caught.toString());
+ showRetryDialog();
+ }
+ }
+ });
}
@Override
--
To view, visit https://gerrit.wikimedia.org/r/318112
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I54e551b3f4802350740db5450f018549373558f8
Gerrit-PatchSet: 2
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Mholloway <[email protected]>
Gerrit-Reviewer: BearND <[email protected]>
Gerrit-Reviewer: Brion VIBBER <[email protected]>
Gerrit-Reviewer: Dbrant <[email protected]>
Gerrit-Reviewer: Mholloway <[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