jenkins-bot has submitted this change and it was merged.

Change subject: Prevent crash after requesting empty definition from prod 
content service
......................................................................


Prevent crash after requesting empty definition from prod content service

Sending an empty string to the production content service to request
a Wiktionary definition causes the app to crash (though oddly enough this
does not happen when running locally).  This adds a check to immediately
fire a "no definitions found" dialog rather than sending the request when
selectedText.trim() is empty.

Also added a minor fix to hide the progress bar consistently when the "no
definitions found" message is displayed.

Bug: T123783
Change-Id: Iba04e02e16ca5cd1d7d8723999f618c8995fa761
---
M app/src/main/java/org/wikipedia/wiktionary/WiktionaryDialog.java
1 file changed, 6 insertions(+), 1 deletion(-)

Approvals:
  Sniedzielski: Looks good to me, approved
  Niedzielski: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/app/src/main/java/org/wikipedia/wiktionary/WiktionaryDialog.java 
b/app/src/main/java/org/wikipedia/wiktionary/WiktionaryDialog.java
index 1ac95cf..657a635 100644
--- a/app/src/main/java/org/wikipedia/wiktionary/WiktionaryDialog.java
+++ b/app/src/main/java/org/wikipedia/wiktionary/WiktionaryDialog.java
@@ -100,6 +100,11 @@
     }
 
     private void loadDefinitions() {
+        if (selectedText.trim().isEmpty()) {
+            displayNoDefinitionsFound();
+            return;
+        }
+
         PageService contentService = ContentServiceFactory.create(new 
Site(pageTitle.getSite().getLanguageCode() + WIKTIONARY_DOMAIN));
         if (contentService instanceof RbContentService) {
             ((RbContentService) contentService).define(
@@ -132,7 +137,6 @@
             if (!isAdded()) {
                 return;
             }
-            progressBar.setVisibility(View.GONE);
             displayNoDefinitionsFound();
             L.e("Wiktionary definition fetch error: " + error);
         }
@@ -141,6 +145,7 @@
     private void displayNoDefinitionsFound() {
         TextView noDefinitionsFoundView = (TextView) 
rootView.findViewById(R.id.wiktionary_no_definitions_found);
         noDefinitionsFoundView.setVisibility(View.VISIBLE);
+        progressBar.setVisibility(View.GONE);
     }
 
     private void layOutDefinitionsByUsage() {

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Iba04e02e16ca5cd1d7d8723999f618c8995fa761
Gerrit-PatchSet: 4
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: Sniedzielski <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to