Skip to content

Commit 528faa1

Browse files
author
maskara
committed
Null fix for notifications
1 parent f34af1e commit 528faa1

File tree

4 files changed

+9
-16
lines changed

4 files changed

+9
-16
lines changed

app/src/main/java/fr/free/nrw/commons/mwapi/ApacheHttpClientMediaWikiApi.java

+4-11
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.apache.http.util.EntityUtils;
2424
import org.mediawiki.api.ApiResult;
2525
import org.mediawiki.api.MWApi;
26-
import org.w3c.dom.Node;
2726
import org.w3c.dom.NodeList;
2827

2928
import java.io.IOException;
@@ -47,14 +46,6 @@
4746
import io.reactivex.Single;
4847
import timber.log.Timber;
4948

50-
import static fr.free.nrw.commons.notification.NotificationType.THANK_YOU_EDIT;
51-
import static fr.free.nrw.commons.notification.NotificationType.UNKNOWN;
52-
import static fr.free.nrw.commons.notification.NotificationUtils.getNotificationFromApiResult;
53-
import static fr.free.nrw.commons.notification.NotificationUtils.getNotificationType;
54-
import static fr.free.nrw.commons.notification.NotificationUtils.getNotificationsFromBundle;
55-
import static fr.free.nrw.commons.notification.NotificationUtils.isBundledNotification;
56-
import static fr.free.nrw.commons.notification.NotificationUtils.isCommonsNotification;
57-
5849
/**
5950
* @author Addshore
6051
*/
@@ -439,14 +430,16 @@ public List<Notification> getNotifications() {
439430
.param("format", "xml")
440431
.param("meta", "notifications")
441432
.param("notformat", "model")
442-
//.param("notfilter", "!read")
443433
.get()
444434
.getNode("/api/query/notifications/list");
445435
} catch (IOException e) {
446436
Timber.e("Failed to obtain searchCategories", e);
447437
}
448438

449-
if (notificationNode == null) {
439+
if (notificationNode == null
440+
|| notificationNode.getDocument() == null
441+
|| notificationNode.getDocument().getChildNodes() == null
442+
|| notificationNode.getDocument().getChildNodes().getLength() == 0) {
450443
return new ArrayList<>();
451444
}
452445

app/src/main/java/fr/free/nrw/commons/notification/NotificationActivity.java

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import fr.free.nrw.commons.R;
2525
import fr.free.nrw.commons.Utils;
2626
import fr.free.nrw.commons.theme.NavigationBaseActivity;
27+
import fr.free.nrw.commons.utils.ViewUtil;
2728
import io.reactivex.Observable;
2829
import io.reactivex.android.schedulers.AndroidSchedulers;
2930
import io.reactivex.schedulers.Schedulers;
@@ -81,6 +82,7 @@ private void addNotifications() {
8182
progressBar.setVisibility(View.GONE);
8283
}, throwable -> {
8384
Timber.e(throwable, "Error occurred while loading notifications");
85+
ViewUtil.showSnackbar(this, R.string.error_notifications);
8486
progressBar.setVisibility(View.GONE);
8587
});
8688
} else {

app/src/main/java/fr/free/nrw/commons/notification/NotificationRenderer.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
public class NotificationRenderer extends Renderer<Notification> {
2222
@BindView(R.id.title) ReadMoreTextView title;
23-
@BindView(R.id.description) ReadMoreTextView description;
2423
@BindView(R.id.time) TextView time;
2524
@BindView(R.id.icon) ImageView icon;
2625
private NotificationClicked listener;
@@ -49,12 +48,9 @@ protected View inflate(LayoutInflater layoutInflater, ViewGroup viewGroup) {
4948
public void render() {
5049
Notification notification = getContent();
5150
StringBuilder str = new StringBuilder(notification.notificationText);
52-
str.append(" " );
51+
str.append(" ");
5352
title.setText(str);
5453
time.setText(notification.date);
55-
StringBuilder desc = new StringBuilder(notification.description);
56-
desc.append(" ");
57-
description.setText(desc);
5854
switch (notification.notificationType) {
5955
case THANK_YOU_EDIT:
6056
icon.setImageResource(R.drawable.ic_edit_black_24dp);

app/src/main/res/values/strings.xml

+2
Original file line numberDiff line numberDiff line change
@@ -247,4 +247,6 @@
247247
<string name="about_rate_us"><u>Rate Us</u></string>
248248
<string name="about_faq">Frequently Asked Questions</string>
249249
<string name="welcome_skip_button">Skip Tutorial</string>
250+
251+
<string name="error_notifications">Error fetching notifications</string>
250252
</resources>

0 commit comments

Comments
 (0)