mirror of
				https://github.com/pierre42100/ComunicAndroid
				synced 2025-11-04 11:34:06 +00:00 
			
		
		
		
	Display on navbar the number of friendship requests received by the user.
This commit is contained in:
		@@ -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) {
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -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());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user