From e9fff846f0193187aca6fce15ff8b540e4d7442e Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Fri, 24 Aug 2018 08:34:39 +0200 Subject: [PATCH] Display on navbar the number of friendship requests received by the user. --- .idea/vcs.xml | 2 +- .../client/data/helpers/NotificationsHelper.java | 3 +++ .../comunic/client/data/models/NotificationsCount.java | 10 ++++++++++ .../client/data/services/NotificationsService.java | 6 ++++-- .../comunic/client/ui/activities/MainActivity.java | 7 ++++++- 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 94a25f7..35eb1dd 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/helpers/NotificationsHelper.java b/app/src/main/java/org/communiquons/android/comunic/client/data/helpers/NotificationsHelper.java index 36d891e..fece44d 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/data/helpers/NotificationsHelper.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/data/helpers/NotificationsHelper.java @@ -52,6 +52,7 @@ public class NotificationsHelper { //Perform an API request APIRequest params = new APIRequest(mContext, "notifications/count_all_news"); + params.addBoolean("friends_request", true); //Try to perform the request and parse results try { @@ -63,6 +64,8 @@ public class NotificationsHelper { NotificationsCount res = new NotificationsCount(); res.setNotificationsCount(object.getInt("notifications")); res.setConversationsCount(object.getInt("conversations")); + res.setFriendsRequestsCount(object.getInt("friends_request")); + return res; } catch (Exception e) { diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/models/NotificationsCount.java b/app/src/main/java/org/communiquons/android/comunic/client/data/models/NotificationsCount.java index 39509b4..609ed71 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/data/models/NotificationsCount.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/data/models/NotificationsCount.java @@ -12,6 +12,7 @@ public class NotificationsCount { //Private fields private int notificationsCount; private int conversationsCount; + private int friendsRequestsCount; //Set and get notifications count @@ -32,4 +33,13 @@ public class NotificationsCount { public int getConversationsCount() { return conversationsCount; } + + //Getter and setter for friends requests + public int getFriendsRequestsCount() { + return friendsRequestsCount; + } + + public void setFriendsRequestsCount(int friendsRequestsCount) { + this.friendsRequestsCount = friendsRequestsCount; + } } diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/services/NotificationsService.java b/app/src/main/java/org/communiquons/android/comunic/client/data/services/NotificationsService.java index 2b8b620..2706dc7 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/data/services/NotificationsService.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/data/services/NotificationsService.java @@ -43,7 +43,8 @@ public class NotificationsService extends IntentService { * Notification extras */ public static final String BROADCAST_EXTRA_NUMBER_NOTIFICATIONS = "NumberNotifications"; - public static final String BROADCAST_EXTRACT_UNREAD_CONVERSATIONS = "UnreadConversations"; + public static final String BROADCAST_EXTRA_UNREAD_CONVERSATIONS = "UnreadConversations"; + public static final String BROADCAST_EXTRA_NUMBER_FRIENDSHIP_REQUESTS = "NumberFriendsRequests"; /** * Notification channel ID @@ -154,7 +155,8 @@ public class NotificationsService extends IntentService { //Create an intent and push nut data Intent pushIntent = new Intent(BROADCAST_ACTION) .putExtra(BROADCAST_EXTRA_NUMBER_NOTIFICATIONS, count.getNotificationsCount()) - .putExtra(BROADCAST_EXTRACT_UNREAD_CONVERSATIONS, count.getConversationsCount()); + .putExtra(BROADCAST_EXTRA_UNREAD_CONVERSATIONS, count.getConversationsCount()) + .putExtra(BROADCAST_EXTRA_NUMBER_FRIENDSHIP_REQUESTS, count.getFriendsRequestsCount()); LocalBroadcastManager.getInstance(this).sendBroadcast(pushIntent); } diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/activities/MainActivity.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/activities/MainActivity.java index 0749722..84ffb15 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/activities/MainActivity.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/activities/MainActivity.java @@ -112,7 +112,9 @@ public class MainActivity extends AppCompatActivity implements count.setNotificationsCount(intent.getExtras().getInt( NotificationsService.BROADCAST_EXTRA_NUMBER_NOTIFICATIONS)); count.setConversationsCount(intent.getExtras().getInt( - NotificationsService.BROADCAST_EXTRACT_UNREAD_CONVERSATIONS)); + NotificationsService.BROADCAST_EXTRA_UNREAD_CONVERSATIONS)); + count.setFriendsRequestsCount(intent.getExtras().getInt( + NotificationsService.BROADCAST_EXTRA_NUMBER_FRIENDSHIP_REQUESTS)); updateNumberNotifications(count); } } @@ -345,6 +347,9 @@ public class MainActivity extends AppCompatActivity implements mNavBar.getItemIdentifierView(R.id.action_conversations).setNumberNews( count.getConversationsCount()); + + mNavBar.getItemIdentifierView(R.id.action_friendslist).setNumberNews( + count.getFriendsRequestsCount()); }