Display on navbar the number of friendship requests received by the user.

This commit is contained in:
Pierre HUBERT 2018-08-24 08:34:39 +02:00
parent 2cb7bf7eb2
commit e9fff846f0
5 changed files with 24 additions and 4 deletions

2
.idea/vcs.xml generated
View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@ -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) {

View File

@ -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;
}
}

View File

@ -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);
}

View File

@ -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());
}