Null fix for notifications

This commit is contained in:
maskara 2018-03-15 00:35:34 +05:30
parent f34af1ee4b
commit 528faa1c52
4 changed files with 9 additions and 16 deletions

View file

@ -23,7 +23,6 @@ import org.apache.http.params.CoreProtocolPNames;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
import org.mediawiki.api.ApiResult; import org.mediawiki.api.ApiResult;
import org.mediawiki.api.MWApi; import org.mediawiki.api.MWApi;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
import java.io.IOException; import java.io.IOException;
@ -47,14 +46,6 @@ import io.reactivex.Observable;
import io.reactivex.Single; import io.reactivex.Single;
import timber.log.Timber; 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 * @author Addshore
*/ */
@ -439,14 +430,16 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
.param("format", "xml") .param("format", "xml")
.param("meta", "notifications") .param("meta", "notifications")
.param("notformat", "model") .param("notformat", "model")
//.param("notfilter", "!read")
.get() .get()
.getNode("/api/query/notifications/list"); .getNode("/api/query/notifications/list");
} catch (IOException e) { } catch (IOException e) {
Timber.e("Failed to obtain searchCategories", 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<>(); return new ArrayList<>();
} }

View file

@ -24,6 +24,7 @@ import butterknife.ButterKnife;
import fr.free.nrw.commons.R; import fr.free.nrw.commons.R;
import fr.free.nrw.commons.Utils; import fr.free.nrw.commons.Utils;
import fr.free.nrw.commons.theme.NavigationBaseActivity; import fr.free.nrw.commons.theme.NavigationBaseActivity;
import fr.free.nrw.commons.utils.ViewUtil;
import io.reactivex.Observable; import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers;
@ -81,6 +82,7 @@ public class NotificationActivity extends NavigationBaseActivity {
progressBar.setVisibility(View.GONE); progressBar.setVisibility(View.GONE);
}, throwable -> { }, throwable -> {
Timber.e(throwable, "Error occurred while loading notifications"); Timber.e(throwable, "Error occurred while loading notifications");
ViewUtil.showSnackbar(this, R.string.error_notifications);
progressBar.setVisibility(View.GONE); progressBar.setVisibility(View.GONE);
}); });
} else { } else {

View file

@ -20,7 +20,6 @@ import fr.free.nrw.commons.R;
public class NotificationRenderer extends Renderer<Notification> { public class NotificationRenderer extends Renderer<Notification> {
@BindView(R.id.title) ReadMoreTextView title; @BindView(R.id.title) ReadMoreTextView title;
@BindView(R.id.description) ReadMoreTextView description;
@BindView(R.id.time) TextView time; @BindView(R.id.time) TextView time;
@BindView(R.id.icon) ImageView icon; @BindView(R.id.icon) ImageView icon;
private NotificationClicked listener; private NotificationClicked listener;
@ -49,12 +48,9 @@ public class NotificationRenderer extends Renderer<Notification> {
public void render() { public void render() {
Notification notification = getContent(); Notification notification = getContent();
StringBuilder str = new StringBuilder(notification.notificationText); StringBuilder str = new StringBuilder(notification.notificationText);
str.append(" " ); str.append(" ");
title.setText(str); title.setText(str);
time.setText(notification.date); time.setText(notification.date);
StringBuilder desc = new StringBuilder(notification.description);
desc.append(" ");
description.setText(desc);
switch (notification.notificationType) { switch (notification.notificationType) {
case THANK_YOU_EDIT: case THANK_YOU_EDIT:
icon.setImageResource(R.drawable.ic_edit_black_24dp); icon.setImageResource(R.drawable.ic_edit_black_24dp);

View file

@ -247,4 +247,6 @@
<string name="about_rate_us"><u>Rate Us</u></string> <string name="about_rate_us"><u>Rate Us</u></string>
<string name="about_faq">Frequently Asked Questions</string> <string name="about_faq">Frequently Asked Questions</string>
<string name="welcome_skip_button">Skip Tutorial</string> <string name="welcome_skip_button">Skip Tutorial</string>
<string name="error_notifications">Error fetching notifications</string>
</resources> </resources>