diff --git a/app/src/main/java/com/polar/nextcloudservices/API/NextcloudAbstractAPI.java b/app/src/main/java/com/polar/nextcloudservices/API/NextcloudAbstractAPI.java index 49ef8fc..0f10356 100644 --- a/app/src/main/java/com/polar/nextcloudservices/API/NextcloudAbstractAPI.java +++ b/app/src/main/java/com/polar/nextcloudservices/API/NextcloudAbstractAPI.java @@ -16,10 +16,55 @@ * The inheritors of this interface should be passed to NotificationService. */ public interface NextcloudAbstractAPI extends StatusCheckable { + /** + * Gets all notifications from server + * @param service PollUpdateListener which handles notifications + * @return notifications response as a JSONObject + */ JSONObject getNotifications(PollUpdateListener service); + + /** + * Removes notification from server + * @param id id of notification to remove + */ void removeNotification(int id); + + /** + * Sends reply to talk chatroom + * @param chatroom id of a chat + * @param message message to send + * @throws IOException in case of network error + */ void sendTalkReply(String chatroom, String message) throws IOException; + + /** + * Get user avatar + * @param userId username to get avatar of + * @return avatar bitmap + * @throws Exception in case of any errors + */ Bitmap getUserAvatar(String userId) throws Exception; + + /** + * Gets image preview from server + * @param path path to image + * @return bitmap received from server + * @throws Exception in case of any errors + */ Bitmap getImagePreview(String path) throws Exception; + + /** + * Executes action which is inside of notifications + * @param link Link to action + * @param method method which should be used for querying link + * @throws Exception in case of any errors + */ void sendAction(String link, String method) throws Exception; + + /** + * @doc Checks new notifications without querying all of them directly + * @return true if there is new notifications on server + * @throws Exception in case of any error + */ + boolean checkNewNotifications() throws Exception; } diff --git a/app/src/main/java/com/polar/nextcloudservices/API/NextcloudHttpAPI.java b/app/src/main/java/com/polar/nextcloudservices/API/NextcloudHttpAPI.java index b732e6a..0bf3a98 100644 --- a/app/src/main/java/com/polar/nextcloudservices/API/NextcloudHttpAPI.java +++ b/app/src/main/java/com/polar/nextcloudservices/API/NextcloudHttpAPI.java @@ -177,6 +177,12 @@ public void sendAction(String link, + link + "--" + responseCode); } + @Override + public boolean checkNewNotifications() throws Exception { + //TODO: implement checking that new notifications available via HEAD request + return false; + } + @Override public JSONObject getNotifications(PollUpdateListener service) { try { diff --git a/app/src/main/java/com/polar/nextcloudservices/API/NextcloudSSOAPI.java b/app/src/main/java/com/polar/nextcloudservices/API/NextcloudSSOAPI.java index 686ce86..476e7d3 100644 --- a/app/src/main/java/com/polar/nextcloudservices/API/NextcloudSSOAPI.java +++ b/app/src/main/java/com/polar/nextcloudservices/API/NextcloudSSOAPI.java @@ -166,6 +166,12 @@ public void sendAction(String link, String method) throws Exception { API.performNetworkRequest(request); } + @Override + public boolean checkNewNotifications() throws Exception { + //TODO: implement checking that new notifications available via HEAD request + return false; + } + @Override public Status getStatus(Context context) { if(lastPollSuccessful){ diff --git a/app/src/main/java/com/polar/nextcloudservices/Services/NotificationService.java b/app/src/main/java/com/polar/nextcloudservices/Services/NotificationService.java index 81e7f4a..64d7e16 100644 --- a/app/src/main/java/com/polar/nextcloudservices/Services/NotificationService.java +++ b/app/src/main/java/com/polar/nextcloudservices/Services/NotificationService.java @@ -29,10 +29,19 @@ import com.polar.nextcloudservices.Services.Status.StatusController; class PollTask extends AsyncTask { - + private static final String TAG = "NotificationService.PollTask"; @Override protected JSONObject doInBackground(NotificationService... services) { - return services[0].getAPI().getNotifications(services[0]); + NextcloudAbstractAPI api = services[0].getAPI(); + try { + if(api.checkNewNotifications()) { + return api.getNotifications(services[0]); + } + } catch (Exception e) { + Log.e(TAG, "Can not check new notifications"); + e.printStackTrace(); + } + return null; } } @@ -57,7 +66,9 @@ public String getStatus() { } public void onPollFinished(JSONObject response) { - mNotificationController.onNotificationsUpdated(response); + if(response != null) { + mNotificationController.onNotificationsUpdated(response); + } } @Override