From 528faa1c5284dfd68d1722dd307ab2a658be0ecd Mon Sep 17 00:00:00 2001 From: maskara Date: Thu, 15 Mar 2018 00:35:34 +0530 Subject: [PATCH] Null fix for notifications --- .../mwapi/ApacheHttpClientMediaWikiApi.java | 15 ++++----------- .../notification/NotificationActivity.java | 2 ++ .../notification/NotificationRenderer.java | 6 +----- app/src/main/res/values/strings.xml | 2 ++ 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/mwapi/ApacheHttpClientMediaWikiApi.java b/app/src/main/java/fr/free/nrw/commons/mwapi/ApacheHttpClientMediaWikiApi.java index 8fcf660f2..471c5c9c7 100644 --- a/app/src/main/java/fr/free/nrw/commons/mwapi/ApacheHttpClientMediaWikiApi.java +++ b/app/src/main/java/fr/free/nrw/commons/mwapi/ApacheHttpClientMediaWikiApi.java @@ -23,7 +23,6 @@ import org.apache.http.params.CoreProtocolPNames; import org.apache.http.util.EntityUtils; import org.mediawiki.api.ApiResult; import org.mediawiki.api.MWApi; -import org.w3c.dom.Node; import org.w3c.dom.NodeList; import java.io.IOException; @@ -47,14 +46,6 @@ import io.reactivex.Observable; import io.reactivex.Single; import timber.log.Timber; -import static fr.free.nrw.commons.notification.NotificationType.THANK_YOU_EDIT; -import static fr.free.nrw.commons.notification.NotificationType.UNKNOWN; -import static fr.free.nrw.commons.notification.NotificationUtils.getNotificationFromApiResult; -import static fr.free.nrw.commons.notification.NotificationUtils.getNotificationType; -import static fr.free.nrw.commons.notification.NotificationUtils.getNotificationsFromBundle; -import static fr.free.nrw.commons.notification.NotificationUtils.isBundledNotification; -import static fr.free.nrw.commons.notification.NotificationUtils.isCommonsNotification; - /** * @author Addshore */ @@ -439,14 +430,16 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi { .param("format", "xml") .param("meta", "notifications") .param("notformat", "model") - //.param("notfilter", "!read") .get() .getNode("/api/query/notifications/list"); } catch (IOException e) { Timber.e("Failed to obtain searchCategories", e); } - if (notificationNode == null) { + if (notificationNode == null + || notificationNode.getDocument() == null + || notificationNode.getDocument().getChildNodes() == null + || notificationNode.getDocument().getChildNodes().getLength() == 0) { return new ArrayList<>(); } diff --git a/app/src/main/java/fr/free/nrw/commons/notification/NotificationActivity.java b/app/src/main/java/fr/free/nrw/commons/notification/NotificationActivity.java index 79e4c36f3..46c98319b 100644 --- a/app/src/main/java/fr/free/nrw/commons/notification/NotificationActivity.java +++ b/app/src/main/java/fr/free/nrw/commons/notification/NotificationActivity.java @@ -24,6 +24,7 @@ import butterknife.ButterKnife; import fr.free.nrw.commons.R; import fr.free.nrw.commons.Utils; import fr.free.nrw.commons.theme.NavigationBaseActivity; +import fr.free.nrw.commons.utils.ViewUtil; import io.reactivex.Observable; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.schedulers.Schedulers; @@ -81,6 +82,7 @@ public class NotificationActivity extends NavigationBaseActivity { progressBar.setVisibility(View.GONE); }, throwable -> { Timber.e(throwable, "Error occurred while loading notifications"); + ViewUtil.showSnackbar(this, R.string.error_notifications); progressBar.setVisibility(View.GONE); }); } else { diff --git a/app/src/main/java/fr/free/nrw/commons/notification/NotificationRenderer.java b/app/src/main/java/fr/free/nrw/commons/notification/NotificationRenderer.java index a02b9eff4..2fb81bbcd 100644 --- a/app/src/main/java/fr/free/nrw/commons/notification/NotificationRenderer.java +++ b/app/src/main/java/fr/free/nrw/commons/notification/NotificationRenderer.java @@ -20,7 +20,6 @@ import fr.free.nrw.commons.R; public class NotificationRenderer extends Renderer { @BindView(R.id.title) ReadMoreTextView title; - @BindView(R.id.description) ReadMoreTextView description; @BindView(R.id.time) TextView time; @BindView(R.id.icon) ImageView icon; private NotificationClicked listener; @@ -49,12 +48,9 @@ public class NotificationRenderer extends Renderer { public void render() { Notification notification = getContent(); StringBuilder str = new StringBuilder(notification.notificationText); - str.append(" " ); + str.append(" "); title.setText(str); time.setText(notification.date); - StringBuilder desc = new StringBuilder(notification.description); - desc.append(" "); - description.setText(desc); switch (notification.notificationType) { case THANK_YOU_EDIT: icon.setImageResource(R.drawable.ic_edit_black_24dp); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 17fbd6ff9..72b20431c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -247,4 +247,6 @@ Rate Us Frequently Asked Questions Skip Tutorial + + Error fetching notifications