use of de.danoeh.antennapod.net.sync.model.UploadChangesResponse in project AntennaPod by AntennaPod.
the class GpodnetService method uploadEpisodeActions.
/**
* Updates the episode actions
* <p/>
* This method requires authentication.
*
* @param episodeActions Collection of episode actions.
* @return a GpodnetUploadChangesResponse. See {@link GpodnetUploadChangesResponse}
* for details.
* @throws GpodnetServiceException if added or removed contain duplicates or if there
* is an authentication error.
*/
@Override
public UploadChangesResponse uploadEpisodeActions(List<EpisodeAction> episodeActions) throws SyncServiceException {
requireLoggedIn();
UploadChangesResponse response = null;
for (int i = 0; i < episodeActions.size(); i += UPLOAD_BULK_SIZE) {
response = uploadEpisodeActionsPartial(episodeActions, i, Math.min(episodeActions.size(), i + UPLOAD_BULK_SIZE));
}
return response;
}
use of de.danoeh.antennapod.net.sync.model.UploadChangesResponse in project AntennaPod by AntennaPod.
the class SyncService method syncEpisodeActions.
private void syncEpisodeActions(ISyncService syncServiceImpl) throws SyncServiceException {
final long lastSync = SynchronizationSettings.getLastEpisodeActionSynchronizationTimestamp();
EventBus.getDefault().postSticky(new SyncServiceEvent(R.string.sync_status_episodes_download));
EpisodeActionChanges getResponse = syncServiceImpl.getEpisodeActionChanges(lastSync);
long newTimeStamp = getResponse.getTimestamp();
List<EpisodeAction> remoteActions = getResponse.getEpisodeActions();
processEpisodeActions(remoteActions);
// upload local actions
EventBus.getDefault().postSticky(new SyncServiceEvent(R.string.sync_status_episodes_upload));
List<EpisodeAction> queuedEpisodeActions = synchronizationQueueStorage.getQueuedEpisodeActions();
if (lastSync == 0) {
EventBus.getDefault().postSticky(new SyncServiceEvent(R.string.sync_status_upload_played));
List<FeedItem> readItems = DBReader.getPlayedItems();
Log.d(TAG, "First sync. Upload state for all " + readItems.size() + " played episodes");
for (FeedItem item : readItems) {
FeedMedia media = item.getMedia();
if (media == null) {
continue;
}
EpisodeAction played = new EpisodeAction.Builder(item, EpisodeAction.PLAY).currentTimestamp().started(media.getDuration() / 1000).position(media.getDuration() / 1000).total(media.getDuration() / 1000).build();
queuedEpisodeActions.add(played);
}
}
if (queuedEpisodeActions.size() > 0) {
LockingAsyncExecutor.lock.lock();
try {
Log.d(TAG, "Uploading " + queuedEpisodeActions.size() + " actions: " + StringUtils.join(queuedEpisodeActions, ", "));
UploadChangesResponse postResponse = syncServiceImpl.uploadEpisodeActions(queuedEpisodeActions);
newTimeStamp = postResponse.timestamp;
Log.d(TAG, "Upload episode response: " + postResponse);
synchronizationQueueStorage.clearEpisodeActionQueue();
} finally {
LockingAsyncExecutor.lock.unlock();
}
}
SynchronizationSettings.setLastEpisodeActionSynchronizationAttemptTimestamp(newTimeStamp);
}
use of de.danoeh.antennapod.net.sync.model.UploadChangesResponse in project AntennaPod by AntennaPod.
the class SyncService method syncSubscriptions.
private void syncSubscriptions(ISyncService syncServiceImpl) throws SyncServiceException {
final long lastSync = SynchronizationSettings.getLastSubscriptionSynchronizationTimestamp();
EventBus.getDefault().postSticky(new SyncServiceEvent(R.string.sync_status_subscriptions));
final List<String> localSubscriptions = DBReader.getFeedListDownloadUrls();
SubscriptionChanges subscriptionChanges = syncServiceImpl.getSubscriptionChanges(lastSync);
long newTimeStamp = subscriptionChanges.getTimestamp();
List<String> queuedRemovedFeeds = synchronizationQueueStorage.getQueuedRemovedFeeds();
List<String> queuedAddedFeeds = synchronizationQueueStorage.getQueuedAddedFeeds();
Log.d(TAG, "Downloaded subscription changes: " + subscriptionChanges);
for (String downloadUrl : subscriptionChanges.getAdded()) {
if (!URLChecker.containsUrl(localSubscriptions, downloadUrl) && !queuedRemovedFeeds.contains(downloadUrl)) {
Feed feed = new Feed(downloadUrl, null);
DownloadRequest.Builder builder = DownloadRequestCreator.create(feed);
DownloadService.download(getApplicationContext(), false, builder.build());
}
}
// remove subscription if not just subscribed (again)
for (String downloadUrl : subscriptionChanges.getRemoved()) {
if (!queuedAddedFeeds.contains(downloadUrl)) {
DBTasks.removeFeedWithDownloadUrl(getApplicationContext(), downloadUrl);
}
}
if (lastSync == 0) {
Log.d(TAG, "First sync. Adding all local subscriptions.");
queuedAddedFeeds = localSubscriptions;
queuedAddedFeeds.removeAll(subscriptionChanges.getAdded());
queuedRemovedFeeds.removeAll(subscriptionChanges.getRemoved());
}
if (queuedAddedFeeds.size() > 0 || queuedRemovedFeeds.size() > 0) {
Log.d(TAG, "Added: " + StringUtils.join(queuedAddedFeeds, ", "));
Log.d(TAG, "Removed: " + StringUtils.join(queuedRemovedFeeds, ", "));
LockingAsyncExecutor.lock.lock();
try {
UploadChangesResponse uploadResponse = syncServiceImpl.uploadSubscriptionChanges(queuedAddedFeeds, queuedRemovedFeeds);
synchronizationQueueStorage.clearFeedQueues();
newTimeStamp = uploadResponse.timestamp;
} finally {
LockingAsyncExecutor.lock.unlock();
}
}
SynchronizationSettings.setLastSubscriptionSynchronizationAttemptTimestamp(newTimeStamp);
}
Aggregations