Search in sources :

Example 1 with GpodnetEpisodeActionGetResponse

use of de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeActionGetResponse in project AntennaPod by AntennaPod.

the class GpodnetSyncService method syncEpisodeActions.

private synchronized void syncEpisodeActions() {
    final long timestamp = GpodnetPreferences.getLastEpisodeActionsSyncTimestamp();
    Log.d(TAG, "last episode actions sync timestamp: " + timestamp);
    try {
        GpodnetService service = tryLogin();
        // download episode actions
        GpodnetEpisodeActionGetResponse getResponse = service.getEpisodeChanges(timestamp);
        long lastUpdate = getResponse.getTimestamp();
        Log.d(TAG, "Downloaded episode actions: " + getResponse);
        List<GpodnetEpisodeAction> remoteActions = getResponse.getEpisodeActions();
        List<GpodnetEpisodeAction> localActions = GpodnetPreferences.getQueuedEpisodeActions();
        processEpisodeActions(localActions, remoteActions);
        // upload local actions
        if (localActions.size() > 0) {
            Log.d(TAG, "Uploading episode actions: " + localActions);
            GpodnetEpisodeActionPostResponse postResponse = service.uploadEpisodeActions(localActions);
            lastUpdate = postResponse.timestamp;
            Log.d(TAG, "Upload episode response: " + postResponse);
            GpodnetPreferences.removeQueuedEpisodeActions(localActions);
        }
        GpodnetPreferences.setLastEpisodeActionsSyncTimestamp(lastUpdate);
        GpodnetPreferences.setLastSyncAttempt(true, System.currentTimeMillis());
        clearErrorNotifications();
    } catch (GpodnetServiceException e) {
        e.printStackTrace();
        updateErrorNotification(e);
    } catch (DownloadRequestException e) {
        e.printStackTrace();
    }
}
Also used : GpodnetServiceException(de.danoeh.antennapod.core.gpoddernet.GpodnetServiceException) GpodnetService(de.danoeh.antennapod.core.gpoddernet.GpodnetService) GpodnetEpisodeAction(de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeAction) GpodnetEpisodeActionGetResponse(de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeActionGetResponse) DownloadRequestException(de.danoeh.antennapod.core.storage.DownloadRequestException) GpodnetEpisodeActionPostResponse(de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeActionPostResponse)

Example 2 with GpodnetEpisodeActionGetResponse

use of de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeActionGetResponse in project AntennaPod by AntennaPod.

the class GpodnetService method readEpisodeActionsFromJSONObject.

private GpodnetEpisodeActionGetResponse readEpisodeActionsFromJSONObject(@NonNull JSONObject object) throws JSONException {
    List<GpodnetEpisodeAction> episodeActions = new ArrayList<>();
    long timestamp = object.getLong("timestamp");
    JSONArray jsonActions = object.getJSONArray("actions");
    for (int i = 0; i < jsonActions.length(); i++) {
        JSONObject jsonAction = jsonActions.getJSONObject(i);
        GpodnetEpisodeAction episodeAction = GpodnetEpisodeAction.readFromJSONObject(jsonAction);
        if (episodeAction != null) {
            episodeActions.add(episodeAction);
        }
    }
    return new GpodnetEpisodeActionGetResponse(episodeActions, timestamp);
}
Also used : GpodnetEpisodeAction(de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeAction) JSONObject(org.json.JSONObject) GpodnetEpisodeActionGetResponse(de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeActionGetResponse) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray)

Aggregations

GpodnetEpisodeAction (de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeAction)2 GpodnetEpisodeActionGetResponse (de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeActionGetResponse)2 GpodnetService (de.danoeh.antennapod.core.gpoddernet.GpodnetService)1 GpodnetServiceException (de.danoeh.antennapod.core.gpoddernet.GpodnetServiceException)1 GpodnetEpisodeActionPostResponse (de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeActionPostResponse)1 DownloadRequestException (de.danoeh.antennapod.core.storage.DownloadRequestException)1 ArrayList (java.util.ArrayList)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1