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

Change subject: Fix OnThisDayPagesViewHolder crash
......................................................................


Fix OnThisDayPagesViewHolder crash

- App crash on null pages response fixed by adding a null check and removing 
any null pages.

Bug: T181668
Change-Id: I1a6061a625e73d485c66332e5558ae25c9ca629e
---
M app/src/main/java/org/wikipedia/feed/onthisday/OnThisDay.java
M app/src/main/java/org/wikipedia/feed/onthisday/OnThisDayCard.java
M app/src/main/java/org/wikipedia/feed/onthisday/OnThisDayCardView.java
M app/src/main/java/org/wikipedia/feed/onthisday/OnThisDayFragment.java
4 files changed, 35 insertions(+), 8 deletions(-)

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



diff --git a/app/src/main/java/org/wikipedia/feed/onthisday/OnThisDay.java 
b/app/src/main/java/org/wikipedia/feed/onthisday/OnThisDay.java
index 1c7ea30..d771e95 100644
--- a/app/src/main/java/org/wikipedia/feed/onthisday/OnThisDay.java
+++ b/app/src/main/java/org/wikipedia/feed/onthisday/OnThisDay.java
@@ -9,6 +9,7 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
+import java.util.Iterator;
 import java.util.List;
 
 public class OnThisDay {
@@ -59,7 +60,14 @@
             return year;
         }
 
-        @NonNull public List<RbPageSummary> pages() {
+        @Nullable
+        public List<RbPageSummary> pages() {
+            Iterator iterator = pages.iterator();
+            while ((iterator.hasNext())) {
+                if (iterator.next() == null) {
+                    iterator.remove();
+                }
+            }
             return pages;
         }
     }
diff --git a/app/src/main/java/org/wikipedia/feed/onthisday/OnThisDayCard.java 
b/app/src/main/java/org/wikipedia/feed/onthisday/OnThisDayCard.java
index 363458f..151c644 100644
--- a/app/src/main/java/org/wikipedia/feed/onthisday/OnThisDayCard.java
+++ b/app/src/main/java/org/wikipedia/feed/onthisday/OnThisDayCard.java
@@ -1,6 +1,7 @@
 package org.wikipedia.feed.onthisday;
 
 import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
 
 import org.wikipedia.R;
 import org.wikipedia.WikipediaApp;
@@ -85,7 +86,7 @@
         return wiki;
     }
 
-    @NonNull public List<RbPageSummary> pages() {
+    @Nullable public List<RbPageSummary> pages() {
         return eventShownOnCard.pages();
     }
 
diff --git 
a/app/src/main/java/org/wikipedia/feed/onthisday/OnThisDayCardView.java 
b/app/src/main/java/org/wikipedia/feed/onthisday/OnThisDayCardView.java
index 5e0e16c..2ce1cc6 100644
--- a/app/src/main/java/org/wikipedia/feed/onthisday/OnThisDayCardView.java
+++ b/app/src/main/java/org/wikipedia/feed/onthisday/OnThisDayCardView.java
@@ -115,7 +115,7 @@
     public void setCard(@NonNull OnThisDayCard card) {
         super.setCard(card);
         this.age = card.getAge();
-        pagesRecycler.setAdapter(new RecyclerAdapter(card.pages(), 
card.wiki(), true));
+        setPagesRecycler(card);
         header(card);
     }
 
@@ -128,4 +128,12 @@
         getContext().startActivity(OnThisDayActivity.newIntent(getContext(), 
age,
                 OnThisDayActivity.INVOKE_SOURCE_CARD_FOOTER));
     }
+
+    private void setPagesRecycler(OnThisDayCard card) {
+        if (card.pages() != null) {
+            pagesRecycler.setAdapter(new RecyclerAdapter(card.pages(), 
card.wiki(), true));
+        } else {
+            pagesRecycler.setVisibility(GONE);
+        }
+    }
 }
diff --git 
a/app/src/main/java/org/wikipedia/feed/onthisday/OnThisDayFragment.java 
b/app/src/main/java/org/wikipedia/feed/onthisday/OnThisDayFragment.java
index cb2d41f..2d24bf0 100644
--- a/app/src/main/java/org/wikipedia/feed/onthisday/OnThisDayFragment.java
+++ b/app/src/main/java/org/wikipedia/feed/onthisday/OnThisDayFragment.java
@@ -43,6 +43,7 @@
 import retrofit2.Callback;
 import retrofit2.Response;
 
+import static android.view.View.GONE;
 import static org.wikipedia.feed.onthisday.OnThisDayActivity.AGE;
 
 public class OnThisDayFragment extends Fragment implements 
DatePickerFragment.Callback {
@@ -150,7 +151,7 @@
                     return;
                 }
                 onThisDay = response.body();
-                progressBar.setVisibility(View.GONE);
+                progressBar.setVisibility(GONE);
                 eventsRecycler.setVisibility(View.VISIBLE);
                 updateRecyclerView();
                 updateTextView();
@@ -176,7 +177,7 @@
                     dayTextView.setVisibility(View.VISIBLE);
                 } else if (verticalOffset == 0) {
                     // Expanded
-                    dayTextView.setVisibility(View.GONE);
+                    dayTextView.setVisibility(GONE);
                 }
             }
         });
@@ -233,7 +234,7 @@
     @Override
     public void onDatePicked(int year, int month, int day) {
 
-        eventsRecycler.setVisibility(View.GONE);
+        eventsRecycler.setVisibility(GONE);
         progressBar.setVisibility(View.VISIBLE);
         date.set(year, month, day, 0, 0);
         requestEvents("" + (month + 1), "" + day);
@@ -299,11 +300,20 @@
         }
 
         public void setFields(final OnThisDay.Event event) {
-            pagesRecycler.setAdapter(new 
OnThisDayCardView.RecyclerAdapter(event.pages(), wiki, false));
+            setPagesRecycler(event);
             descTextView.setText(event.text());
             yearTextView.setText(DateUtil.yearToStringWithEra(event.year()));
             
yearsInfoTextView.setText(DateUtil.getYearDifferenceString(event.year()));
             
yearsInfoTextView.setBackground(ContextCompat.getDrawable(getContext(), 
R.drawable.button_shape_light_gray_corner_rounded));
+        }
+
+
+        private void setPagesRecycler(OnThisDay.Event event) {
+            if (event.pages() != null) {
+                pagesRecycler.setAdapter(new 
OnThisDayCardView.RecyclerAdapter(event.pages(), wiki, false));
+            } else {
+                pagesRecycler.setVisibility(GONE);
+            }
         }
 
         void setDarkView() {
@@ -319,7 +329,7 @@
         }
 
         void hidePadding() {
-            space.setVisibility(View.GONE);
+            space.setVisibility(GONE);
         }
     }
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I1a6061a625e73d485c66332e5558ae25c9ca629e
Gerrit-PatchSet: 2
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Sharvaniharan <sha...@wikimedia.org>
Gerrit-Reviewer: Brion VIBBER <br...@wikimedia.org>
Gerrit-Reviewer: Cooltey <cf...@wikimedia.org>
Gerrit-Reviewer: Dbrant <dbr...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to