From 18c8d7e3919a74615ede5beed308cbda2b758cfe Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 23 Feb 2019 13:33:19 +0100 Subject: [PATCH] Get number of pending calls only if call system is available --- .../client/data/helpers/NotificationsHelper.java | 11 ++++++++--- .../client/data/services/NotificationsService.java | 3 ++- 2 files changed, 10 insertions(+), 4 deletions(-) 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 f4a7dd0..77e011c 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 @@ -44,16 +44,19 @@ public class NotificationsHelper { /** * Get the notifications count * + * @param include_calls Specify whether pending calls should be included or not in the count * @return Notifications count / NULL in case of failure */ @Nullable - public NotificationsCount pullCount(){ + public NotificationsCount pullCount(boolean include_calls){ //Perform an API request APIRequest params = new APIRequest(mContext, "notifications/count_all_news"); params.addBoolean("friends_request", true); - params.addBoolean("include_calls", true); + + if(include_calls) + params.addBoolean("include_calls", true); //Try to perform the request and parse results try { @@ -66,7 +69,9 @@ public class NotificationsHelper { res.setNotificationsCount(object.getInt("notifications")); res.setConversationsCount(object.getInt("conversations")); res.setFriendsRequestsCount(object.getInt("friends_request")); - res.setPendingCalls(object.getInt("calls")); + + if(include_calls) + res.setPendingCalls(object.getInt("calls")); return res; 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 8104d6e..553f45d 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 @@ -14,6 +14,7 @@ import android.util.Log; import org.communiquons.android.comunic.client.R; import org.communiquons.android.comunic.client.data.helpers.AccountHelper; +import org.communiquons.android.comunic.client.data.helpers.CallsHelper; import org.communiquons.android.comunic.client.data.models.NotificationsCount; import org.communiquons.android.comunic.client.data.helpers.NotificationsHelper; import org.communiquons.android.comunic.client.data.utils.PreferencesUtils; @@ -119,7 +120,7 @@ public class NotificationsService extends IntentService { } //Pull the number of notifications - NotificationsCount count = mNotifHelper.pullCount(); + NotificationsCount count = mNotifHelper.pullCount(CallsHelper.IsCallSystemAvailable()); //Check for error if(count == null){