From 21a6b1f00ca24e2f29b88b1a7abdd4e8cb24cb97 Mon Sep 17 00:00:00 2001 From: maskara Date: Thu, 8 Mar 2018 03:38:12 +0530 Subject: [PATCH 1/9] Fixes in notifications for pending issues --- app/build.gradle | 8 +++ .../mwapi/ApacheHttpClientMediaWikiApi.java | 3 +- .../commons/notification/Notification.java | 4 +- .../notification/NotificationUtils.java | 61 +++++++++++++++---- 4 files changed, 61 insertions(+), 15 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 15cb7c312..16f7c49fa 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -102,6 +102,12 @@ dependencies { compile 'com.android.support.constraint:constraint-layout:1.0.2' } +repositories { + mavenCentral() + google() +} + + android { compileSdkVersion project.compileSdkVersion buildToolsVersion project.buildToolsVersion @@ -150,6 +156,7 @@ android { buildConfigField "String", "WIKIMEDIA_FORGE_API_HOST", "\"https://tools.wmflabs.org/\"" buildConfigField "String", "IMAGE_URL_BASE", "\"https://upload.wikimedia.org/wikipedia/commons\"" buildConfigField "String", "HOME_URL", "\"https://commons.wikimedia.org/wiki/\"" + buildConfigField "String", "COMMONS_URL", "\"https://commons.wikimedia.org\"" buildConfigField "String", "MOBILE_HOME_URL", "\"https://commons.m.wikimedia.org/wiki/\"" buildConfigField "String", "EVENTLOG_URL", "\"https://www.wikimedia.org/beacon/event\"" buildConfigField "String", "EVENTLOG_WIKI", "\"commonswiki\"" @@ -165,6 +172,7 @@ android { buildConfigField "String", "WIKIMEDIA_FORGE_API_HOST", "\"https://tools.wmflabs.org/\"" buildConfigField "String", "IMAGE_URL_BASE", "\"https://upload.beta.wmflabs.org/wikipedia/commons\"" buildConfigField "String", "HOME_URL", "\"https://commons.wikimedia.beta.wmflabs.org/wiki/\"" + buildConfigField "String", "COMMONS_URL", "\"https://commons.wikimedia.beta.wmflabs.org\"" buildConfigField "String", "MOBILE_HOME_URL", "\"https://commons.m.wikimedia.beta.wmflabs.org/wiki/\"" buildConfigField "String", "EVENTLOG_URL", "\"https://commons.wikimedia.beta.wmflabs.org/beacon/event\"" buildConfigField "String", "EVENTLOG_WIKI", "\"commonswiki\"" 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 32ca96174..1a059fcd4 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 @@ -434,7 +434,8 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi { .param("notprop", "list") .param("format", "xml") .param("meta", "notifications") - .param("notfilter", "!read") + .param("notformat", "model") + //.param("notfilter", "!read") .get() .getNode("/api/query/notifications/list"); } catch (IOException e) { diff --git a/app/src/main/java/fr/free/nrw/commons/notification/Notification.java b/app/src/main/java/fr/free/nrw/commons/notification/Notification.java index e4efbff6c..e6d759f66 100644 --- a/app/src/main/java/fr/free/nrw/commons/notification/Notification.java +++ b/app/src/main/java/fr/free/nrw/commons/notification/Notification.java @@ -10,12 +10,14 @@ public class Notification { public String date; public String description; public String link; + public String iconUrl; - public Notification(NotificationType notificationType, String notificationText, String date, String description, String link) { + public Notification(NotificationType notificationType, String notificationText, String date, String description, String link, String iconUrl) { this.notificationType = notificationType; this.notificationText = notificationText; this.date = date; this.description = description; this.link = link; + this.iconUrl = iconUrl; } } diff --git a/app/src/main/java/fr/free/nrw/commons/notification/NotificationUtils.java b/app/src/main/java/fr/free/nrw/commons/notification/NotificationUtils.java index 7f32da126..a5ce1655c 100644 --- a/app/src/main/java/fr/free/nrw/commons/notification/NotificationUtils.java +++ b/app/src/main/java/fr/free/nrw/commons/notification/NotificationUtils.java @@ -1,5 +1,6 @@ package fr.free.nrw.commons.notification; +import android.annotation.SuppressLint; import android.content.Context; import org.w3c.dom.Element; @@ -33,23 +34,52 @@ public class NotificationUtils { NotificationType type = getNotificationType(document); String notificationText = ""; - String link = getNotificationLink(document); + String link = getPrimaryLink(document); String description = getNotificationDescription(document); + String iconUrl = getNotificationIconUrl(document); + switch (type) { case THANK_YOU_EDIT: notificationText = context.getString(R.string.notifications_thank_you_edit); break; case EDIT_USER_TALK: - notificationText = getUserTalkMessage(context, document); + notificationText = getNotificationHeader(document); break; case MENTION: notificationText = getMentionMessage(context, document); + description = getMentionDescription(document); break; case WELCOME: notificationText = getWelcomeMessage(context, document); break; } - return new Notification(type, notificationText, getTimestamp(document), description, link); + return new Notification(type, notificationText, getTimestamp(document), description, link, iconUrl); + } + + private static String getNotificationHeader(Node document) { + Node body = getNode(getModel(document), "header"); + if (body != null) { + String textContent = body.getTextContent(); + return textContent.replace("", "").replace("", ""); + } else { + return ""; + } + } + + private static String getMentionDescription(Node document) { + Node body = getNode(getModel(document), "body"); + return body != null ? body.getTextContent() : ""; + } + + private static String getNotificationIconUrl(Node document) { + String format = "%s%s"; + Node iconUrl = getNode(getModel(document), "iconUrl"); + if(iconUrl == null) { + return null; + } else { + String url = iconUrl.getTextContent(); + return String.format(format, BuildConfig.COMMONS_URL, url); + } } public static String getMentionMessage(Context context, Node document) { @@ -57,16 +87,31 @@ public class NotificationUtils { return String.format(format, getAgent(document), getNotificationDescription(document)); } + @SuppressLint("StringFormatMatches") public static String getUserTalkMessage(Context context, Node document) { String format = context.getString(R.string.notifications_talk_page_message); return String.format(format, getAgent(document)); } + @SuppressLint("StringFormatInvalid") public static String getWelcomeMessage(Context context, Node document) { String welcomeMessageFormat = context.getString(R.string.notifications_welcome); return String.format(welcomeMessageFormat, getAgent(document)); } + private static String getPrimaryLink(Node document) { + Node links = getNode(getModel(document), "links"); + Element primaryLink = (Element) getNode(links, "primary"); + if (primaryLink != null) { + return primaryLink.getAttribute("url"); + } + return ""; + } + + private static Node getModel(Node document) { + return getNode(document, "_.2A."); + } + private static String getAgent(Node document) { Element agentElement = (Element) getNode(document, "agent"); if (agentElement != null) { @@ -83,16 +128,6 @@ public class NotificationUtils { return ""; } - private static String getNotificationLink(Node document) { - String format = "%s%s"; - Element titleElement = (Element) getNode(document, "title"); - if (titleElement != null) { - String fullName = titleElement.getAttribute("full"); - return String.format(format, BuildConfig.HOME_URL, fullName); - } - return ""; - } - private static String getNotificationDescription(Node document) { Element titleElement = (Element) getNode(document, "title"); if (titleElement != null) { From e5c8e40b766bb40cdb4479dbf21df5fb9c64c5ef Mon Sep 17 00:00:00 2001 From: maskara Date: Sat, 10 Mar 2018 22:44:37 +0530 Subject: [PATCH 2/9] Suggested changes for notification fixes --- app/build.gradle | 6 ------ .../nrw/commons/mwapi/ApacheHttpClientMediaWikiApi.java | 4 +++- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 16f7c49fa..a7af07ac0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -102,12 +102,6 @@ dependencies { compile 'com.android.support.constraint:constraint-layout:1.0.2' } -repositories { - mavenCentral() - google() -} - - android { compileSdkVersion project.compileSdkVersion buildToolsVersion project.buildToolsVersion 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 1a059fcd4..34435a444 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 @@ -46,6 +46,7 @@ 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; @@ -453,7 +454,8 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi { for (int i = 0; i < childNodes.getLength(); i++) { Node node = childNodes.item(i); if (isCommonsNotification(node) - && !getNotificationType(node).equals(UNKNOWN)) { + && !getNotificationType(node).equals(UNKNOWN) + && !getNotificationType(node).equals(THANK_YOU_EDIT)) { notifications.add(getNotificationFromApiResult(context, node)); } } From 59abd022e36a6c055d78a76dee23fd1739d05b0f Mon Sep 17 00:00:00 2001 From: maskara Date: Wed, 14 Mar 2018 03:42:23 +0530 Subject: [PATCH 3/9] Minor notification fixes --- app/src/main/java/fr/free/nrw/commons/Utils.java | 2 +- .../commons/notification/NotificationActivity.java | 13 ++----------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/Utils.java b/app/src/main/java/fr/free/nrw/commons/Utils.java index 05873782c..91c23ce26 100644 --- a/app/src/main/java/fr/free/nrw/commons/Utils.java +++ b/app/src/main/java/fr/free/nrw/commons/Utils.java @@ -177,7 +177,7 @@ public class Utils { } } - public static void handleWebUrl(Context context,Uri url){ + public static void handleWebUrl(Context context, Uri url) { Intent browserIntent = new Intent(Intent.ACTION_VIEW, url); if (browserIntent.resolveActivity(context.getPackageManager()) == null) { Toast toast = Toast.makeText(context, context.getString(R.string.no_web_browser), LENGTH_SHORT); 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 d6fcd2685..be863b578 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 @@ -9,7 +9,6 @@ import android.os.Bundle; import android.support.v7.widget.DividerItemDecoration; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; -import android.widget.Toast; import com.pedrogomez.renderers.RVRendererAdapter; @@ -20,14 +19,13 @@ import javax.inject.Inject; import butterknife.BindView; import butterknife.ButterKnife; import fr.free.nrw.commons.R; +import fr.free.nrw.commons.Utils; import fr.free.nrw.commons.theme.NavigationBaseActivity; import io.reactivex.Observable; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.schedulers.Schedulers; import timber.log.Timber; -import static android.widget.Toast.LENGTH_SHORT; - /** * Created by root on 18.12.2017. */ @@ -82,14 +80,7 @@ public class NotificationActivity extends NavigationBaseActivity { if (url == null || url.equals("")) { return; } - Intent browser = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); - //check if web browser available - if(browser.resolveActivity(this.getPackageManager()) != null){ - startActivity(browser); - } else { - Toast toast = Toast.makeText(this, getString(R.string.no_web_browser), LENGTH_SHORT); - toast.show(); - } + Utils.handleWebUrl(this, Uri.parse(url)); } private void setAdapter(List notificationList) { From f34af1ee4bc62f6e6b71622bd25ab03204f6ce94 Mon Sep 17 00:00:00 2001 From: maskara Date: Wed, 14 Mar 2018 04:42:18 +0530 Subject: [PATCH 4/9] With support for bundled notifications --- .../mwapi/ApacheHttpClientMediaWikiApi.java | 18 +---- .../notification/NotificationActivity.java | 18 ++++- .../notification/NotificationUtils.java | 77 ++++++++++++++++++- .../main/res/layout/activity_notification.xml | 6 ++ 4 files changed, 101 insertions(+), 18 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 34435a444..8fcf660f2 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 @@ -41,6 +41,7 @@ import java.util.concurrent.Callable; import fr.free.nrw.commons.BuildConfig; import fr.free.nrw.commons.PageTitle; import fr.free.nrw.commons.notification.Notification; +import fr.free.nrw.commons.notification.NotificationUtils; import in.yuvi.http.fluent.Http; import io.reactivex.Observable; import io.reactivex.Single; @@ -50,6 +51,8 @@ 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; /** @@ -447,23 +450,10 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi { return new ArrayList<>(); } - List notifications = new ArrayList<>(); - NodeList childNodes = notificationNode.getDocument().getChildNodes(); - - for (int i = 0; i < childNodes.getLength(); i++) { - Node node = childNodes.item(i); - if (isCommonsNotification(node) - && !getNotificationType(node).equals(UNKNOWN) - && !getNotificationType(node).equals(THANK_YOU_EDIT)) { - notifications.add(getNotificationFromApiResult(context, node)); - } - } - - return notifications; + return NotificationUtils.getNotificationsFromList(context, childNodes); } - @Override public boolean existingFile(String fileSha1) throws IOException { return api.action("query") 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 be863b578..79e4c36f3 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 @@ -9,9 +9,12 @@ import android.os.Bundle; import android.support.v7.widget.DividerItemDecoration; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; +import android.view.View; +import android.widget.ProgressBar; import com.pedrogomez.renderers.RVRendererAdapter; +import java.util.Collections; import java.util.List; import javax.inject.Inject; @@ -34,6 +37,8 @@ public class NotificationActivity extends NavigationBaseActivity { NotificationAdapterFactory notificationAdapterFactory; @BindView(R.id.listView) RecyclerView recyclerView; + @BindView(R.id.progressBar) + ProgressBar progressBar; @Inject NotificationController controller; @@ -63,14 +68,21 @@ public class NotificationActivity extends NavigationBaseActivity { Timber.d("Add notifications"); if(mNotificationWorkerFragment == null){ - Observable.fromCallable(() -> controller.getNotifications()) + Observable.fromCallable(() -> { + progressBar.setVisibility(View.VISIBLE); + return controller.getNotifications(); + }) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(notificationList -> { + Collections.reverse(notificationList); Timber.d("Number of notifications is %d", notificationList.size()); - initializeAndSetNotificationList(notificationList); setAdapter(notificationList); - }, throwable -> Timber.e(throwable, "Error occurred while loading notifications")); + progressBar.setVisibility(View.GONE); + }, throwable -> { + Timber.e(throwable, "Error occurred while loading notifications"); + progressBar.setVisibility(View.GONE); + }); } else { setAdapter(mNotificationWorkerFragment.getNotificationList()); } diff --git a/app/src/main/java/fr/free/nrw/commons/notification/NotificationUtils.java b/app/src/main/java/fr/free/nrw/commons/notification/NotificationUtils.java index a5ce1655c..68c3add1c 100644 --- a/app/src/main/java/fr/free/nrw/commons/notification/NotificationUtils.java +++ b/app/src/main/java/fr/free/nrw/commons/notification/NotificationUtils.java @@ -2,16 +2,23 @@ package fr.free.nrw.commons.notification; import android.annotation.SuppressLint; import android.content.Context; +import android.support.annotation.NonNull; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; +import java.util.ArrayList; +import java.util.List; + import javax.annotation.Nullable; import fr.free.nrw.commons.BuildConfig; import fr.free.nrw.commons.R; +import static fr.free.nrw.commons.notification.NotificationType.THANK_YOU_EDIT; +import static fr.free.nrw.commons.notification.NotificationType.UNKNOWN; + public class NotificationUtils { private static final String COMMONS_WIKI = "commonswiki"; @@ -30,6 +37,56 @@ public class NotificationUtils { return NotificationType.handledValueOf(type); } + public static List getNotificationsFromBundle(Context context, Node document) { + Element bundledNotifications = getBundledNotifications(document); + NodeList childNodes = bundledNotifications.getChildNodes(); + + List notifications = new ArrayList<>(); + for (int i = 0; i < childNodes.getLength(); i++) { + Node node = childNodes.item(i); + if (isUsefulNotification(node)) { + notifications.add(getNotificationFromApiResult(context, node)); + } + } + return notifications; + } + + @NonNull + public static List getNotificationsFromList(Context context, NodeList childNodes) { + List notifications = new ArrayList<>(); + for (int i = 0; i < childNodes.getLength(); i++) { + Node node = childNodes.item(i); + if (isUsefulNotification(node)) { + if (isBundledNotification(node)) { + notifications.addAll(getNotificationsFromBundle(context, node)); + } else { + notifications.add(getNotificationFromApiResult(context, node)); + } + } + } + + return notifications; + } + + private static boolean isUsefulNotification(Node node) { + return isCommonsNotification(node) + && !getNotificationType(node).equals(UNKNOWN) + && !getNotificationType(node).equals(THANK_YOU_EDIT); + } + + public static boolean isBundledNotification(Node document) { + Element bundleElement = getBundledNotifications(document); + if (bundleElement == null) { + return false; + } + + return bundleElement.getChildNodes().getLength() > 0; + } + + private static Element getBundledNotifications(Node document) { + return (Element) getNode(document, "bundledNotifications"); + } + public static Notification getNotificationFromApiResult(Context context, Node document) { NotificationType type = getNotificationType(document); @@ -43,7 +100,7 @@ public class NotificationUtils { notificationText = context.getString(R.string.notifications_thank_you_edit); break; case EDIT_USER_TALK: - notificationText = getNotificationHeader(document); + notificationText = getNotificationText(document); break; case MENTION: notificationText = getMentionMessage(context, document); @@ -56,6 +113,14 @@ public class NotificationUtils { return new Notification(type, notificationText, getTimestamp(document), description, link, iconUrl); } + private static String getNotificationText(Node document) { + String notificationBody = getNotificationBody(document); + if (notificationBody == null || notificationBody.trim().equals("")) { + return getNotificationHeader(document); + } + return notificationBody; + } + private static String getNotificationHeader(Node document) { Node body = getNode(getModel(document), "header"); if (body != null) { @@ -66,6 +131,16 @@ public class NotificationUtils { } } + private static String getNotificationBody(Node document) { + Node body = getNode(getModel(document), "body"); + if (body != null) { + String textContent = body.getTextContent(); + return textContent.replace("", "").replace("", ""); + } else { + return ""; + } + } + private static String getMentionDescription(Node document) { Node body = getNode(getModel(document), "body"); return body != null ? body.getTextContent() : ""; diff --git a/app/src/main/res/layout/activity_notification.xml b/app/src/main/res/layout/activity_notification.xml index b2eb38475..7380fef98 100644 --- a/app/src/main/res/layout/activity_notification.xml +++ b/app/src/main/res/layout/activity_notification.xml @@ -15,6 +15,12 @@ android:layout_width="match_parent" android:layout_height="wrap_content" /> + Date: Thu, 15 Mar 2018 00:35:34 +0530 Subject: [PATCH 5/9] 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 From 365bbc470d3565dd590a02bd833b8a8149a0c1f3 Mon Sep 17 00:00:00 2001 From: maskara Date: Wed, 21 Mar 2018 12:33:40 +0530 Subject: [PATCH 6/9] Fix crash due to read more text view --- .../mwapi/ApacheHttpClientMediaWikiApi.java | 1 + .../notification/NotificationActivity.java | 11 +++++++--- .../notification/NotificationRenderer.java | 2 +- .../main/res/layout/activity_notification.xml | 1 + app/src/main/res/layout/item_notification.xml | 22 +++---------------- app/src/main/res/values/strings.xml | 1 + 6 files changed, 15 insertions(+), 23 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 471c5c9c7..78051abd8 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 @@ -429,6 +429,7 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi { .param("notprop", "list") .param("format", "xml") .param("meta", "notifications") +// .param("meta", "notifications") .param("notformat", "model") .get() .getNode("/api/query/notifications/list"); 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 46c98319b..7c01a44b8 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 @@ -11,6 +11,7 @@ import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.View; import android.widget.ProgressBar; +import android.widget.RelativeLayout; import com.pedrogomez.renderers.RVRendererAdapter; @@ -38,8 +39,8 @@ public class NotificationActivity extends NavigationBaseActivity { NotificationAdapterFactory notificationAdapterFactory; @BindView(R.id.listView) RecyclerView recyclerView; - @BindView(R.id.progressBar) - ProgressBar progressBar; + @BindView(R.id.progressBar) ProgressBar progressBar; + @BindView(R.id.container) RelativeLayout relativeLayout; @Inject NotificationController controller; @@ -82,7 +83,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); + ViewUtil.showSnackbar(relativeLayout, R.string.error_notifications); progressBar.setVisibility(View.GONE); }); } else { @@ -98,6 +99,10 @@ public class NotificationActivity extends NavigationBaseActivity { } private void setAdapter(List notificationList) { + if(notificationList == null || notificationList.isEmpty()) { + ViewUtil.showSnackbar(relativeLayout, R.string.no_notifications); + return; + } notificationAdapterFactory = new NotificationAdapterFactory(notification -> { Timber.d("Notification clicked %s", notification.link); handleUrl(notification.link); 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 2fb81bbcd..73dcaf7b5 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 @@ -47,7 +47,7 @@ public class NotificationRenderer extends Renderer { @Override public void render() { Notification notification = getContent(); - StringBuilder str = new StringBuilder(notification.notificationText); + StringBuilder str = new StringBuilder(notification.notificationText.trim()); str.append(" "); title.setText(str); time.setText(notification.date); diff --git a/app/src/main/res/layout/activity_notification.xml b/app/src/main/res/layout/activity_notification.xml index 7380fef98..f8294eb66 100644 --- a/app/src/main/res/layout/activity_notification.xml +++ b/app/src/main/res/layout/activity_notification.xml @@ -6,6 +6,7 @@ android:layout_height="match_parent"> diff --git a/app/src/main/res/layout/item_notification.xml b/app/src/main/res/layout/item_notification.xml index bd364c029..ce43e4430 100644 --- a/app/src/main/res/layout/item_notification.xml +++ b/app/src/main/res/layout/item_notification.xml @@ -45,27 +45,11 @@ android:layout_toRightOf="@id/icon" android:layout_toStartOf="@id/time" android:ellipsize="end" - app:trimLines="2" + app:trimMode="trimModeLength" + app:trimLength="60" + android:layout_alignParentTop="true" app:colorClickableText="#969494" android:textAppearance="@style/TextAppearance.AppCompat.Body2" tools:text="@string/placeholder_place_name" /> - - - \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 72b20431c..cdb00ff47 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -249,4 +249,5 @@ Skip Tutorial Error fetching notifications + No notifications found From dcc3ea067973b86486ff4ff772be82c13c0c3867 Mon Sep 17 00:00:00 2001 From: Jatin Rao Date: Wed, 21 Mar 2018 19:36:06 +0530 Subject: [PATCH 7/9] Fix for issue #1317 Dividing nav bar into sections --- app/src/main/res/menu/drawer.xml | 74 +++++++++++++++++++------------- 1 file changed, 44 insertions(+), 30 deletions(-) diff --git a/app/src/main/res/menu/drawer.xml b/app/src/main/res/menu/drawer.xml index ee0bb4726..b2ba40228 100644 --- a/app/src/main/res/menu/drawer.xml +++ b/app/src/main/res/menu/drawer.xml @@ -1,43 +1,57 @@ + + - + + + + - - + - + + + + - + - - + + - + android:title="@string/navigation_item_logout" /> + From 2ec6855d89178deda01dad409ada816634eeb07d Mon Sep 17 00:00:00 2001 From: Jatin Rao Date: Wed, 21 Mar 2018 19:51:16 +0530 Subject: [PATCH 8/9] Reformated code --- app/src/main/res/menu/drawer.xml | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/app/src/main/res/menu/drawer.xml b/app/src/main/res/menu/drawer.xml index b2ba40228..61c0739fe 100644 --- a/app/src/main/res/menu/drawer.xml +++ b/app/src/main/res/menu/drawer.xml @@ -1,6 +1,5 @@ - + - + - + - - + + From 46a6481ee8dcb5c973c2d4faad0f6a937c627ad9 Mon Sep 17 00:00:00 2001 From: mac Date: Thu, 22 Mar 2018 22:08:48 +0100 Subject: [PATCH 9/9] Fix whole page map issue --- app/src/main/res/layout/activity_nearby.xml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/main/res/layout/activity_nearby.xml b/app/src/main/res/layout/activity_nearby.xml index 31eceff07..70f991c23 100644 --- a/app/src/main/res/layout/activity_nearby.xml +++ b/app/src/main/res/layout/activity_nearby.xml @@ -21,9 +21,10 @@ android:layout_width="match_parent" android:layout_height="wrap_content" /> - @@ -37,7 +38,7 @@ android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" /> - + - +