summaryrefslogtreecommitdiff
path: root/core/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/main')
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java28
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java9
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/sync/SyncService.java25
-rw-r--r--core/src/main/res/values/strings.xml7
4 files changed, 45 insertions, 24 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java
index 534f7ba4c..2234fc35b 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java
@@ -364,7 +364,6 @@ public final class DBReader {
cursor = adapter.getPlayedItemsCursor();
List<FeedItem> items = extractItemlistFromCursor(adapter, cursor);
loadAdditionalFeedItemListData(items);
- Collections.sort(items, new FeedItemPubdateComparator());
return items;
} finally {
if (cursor != null) {
@@ -656,8 +655,16 @@ public final class DBReader {
}
}
+ /**
+ * Loads a specific FeedItem from the database.
+ *
+ * @param podcastUrl the corresponding feed's url
+ * @param episodeUrl the feed item's url
+ * @return The FeedItem or null if the FeedItem could not be found.
+ * Does NOT load additional attributes like feed or queue state.
+ */
@Nullable
- private static FeedItem getFeedItem(final String podcastUrl, final String episodeUrl, PodDBAdapter adapter) {
+ private static FeedItem getFeedItemByUrl(final String podcastUrl, final String episodeUrl, PodDBAdapter adapter) {
Log.d(TAG, "Loading feeditem with podcast url " + podcastUrl + " and episode url " + episodeUrl);
Cursor cursor = null;
try {
@@ -666,15 +673,10 @@ public final class DBReader {
return null;
}
List<FeedItem> list = extractItemlistFromCursor(adapter, cursor);
- FeedItem item = null;
if (!list.isEmpty()) {
- item = list.get(0);
- loadAdditionalFeedItemListData(list);
- if (item.hasChapters()) {
- loadChaptersOfFeedItem(adapter, item);
- }
+ return list.get(0);
}
- return item;
+ return null;
} finally {
if (cursor != null) {
cursor.close();
@@ -729,16 +731,16 @@ public final class DBReader {
*
* @param podcastUrl the corresponding feed's url
* @param episodeUrl the feed item's url
- * @return The FeedItem or null if the FeedItem could not be found. All FeedComponent-attributes
- * as well as chapter marks of the FeedItem will also be loaded from the database.
+ * @return The FeedItem or null if the FeedItem could not be found.
+ * Does NOT load additional attributes like feed or queue state.
*/
- public static FeedItem getFeedItem(final String podcastUrl, final String episodeUrl) {
+ public static FeedItem getFeedItemByUrl(final String podcastUrl, final String episodeUrl) {
Log.d(TAG, "getFeedItem() called with: " + "podcastUrl = [" + podcastUrl + "], episodeUrl = [" + episodeUrl + "]");
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
try {
- return getFeedItem(podcastUrl, episodeUrl, adapter);
+ return getFeedItemByUrl(podcastUrl, episodeUrl, adapter);
} finally {
adapter.close();
}
diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java
index 7625a3bfb..d411e8ba8 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java
@@ -743,6 +743,15 @@ public class DBWriter {
});
}
+ public static Future<?> setItemList(final List<FeedItem> items) {
+ return dbExec.submit(() -> {
+ PodDBAdapter adapter = PodDBAdapter.getInstance();
+ adapter.open();
+ adapter.setFeedItemlist(items);
+ adapter.close();
+ });
+ }
+
/**
* Saves a FeedMedia object in the database. This method will save all attributes of the FeedMedia object. The
* contents of FeedComponent-attributes (e.g. the FeedMedia's 'item'-attribute) will not be saved.
diff --git a/core/src/main/java/de/danoeh/antennapod/core/sync/SyncService.java b/core/src/main/java/de/danoeh/antennapod/core/sync/SyncService.java
index d9174255c..4996decd2 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/sync/SyncService.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/sync/SyncService.java
@@ -84,7 +84,6 @@ public class SyncService extends Worker {
syncServiceImpl.login();
EventBus.getDefault().postSticky(new SyncServiceEvent(R.string.sync_status_subscriptions));
syncSubscriptions();
- EventBus.getDefault().postSticky(new SyncServiceEvent(R.string.sync_status_episodes));
syncEpisodeActions();
syncServiceImpl.logout();
clearErrorNotifications();
@@ -94,7 +93,7 @@ public class SyncService extends Worker {
} catch (SyncServiceException e) {
EventBus.getDefault().postSticky(new SyncServiceEvent(R.string.sync_status_error));
prefs.putBoolean(PREF_LAST_SYNC_ATTEMPT_SUCCESS, false).apply();
- e.printStackTrace();
+ Log.e(TAG, Log.getStackTraceString(e));
updateErrorNotification(e);
return Result.retry();
}
@@ -164,6 +163,14 @@ public class SyncService extends Worker {
EventBus.getDefault().postSticky(new SyncServiceEvent(R.string.sync_status_started));
}
+ public static void syncImmediately(Context context) {
+ OneTimeWorkRequest workRequest = getWorkRequest()
+ .setInitialDelay(0L, TimeUnit.SECONDS)
+ .build();
+ WorkManager.getInstance().enqueueUniqueWork(WORK_ID_SYNC, ExistingWorkPolicy.REPLACE, workRequest);
+ EventBus.getDefault().postSticky(new SyncServiceEvent(R.string.sync_status_started));
+ }
+
public static void fullSync(Context context) {
synchronized (lock) {
context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE).edit()
@@ -305,12 +312,14 @@ public class SyncService extends Worker {
private void syncEpisodeActions() throws SyncServiceException {
final long lastSync = getApplicationContext().getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE)
.getLong(PREF_LAST_EPISODE_ACTIONS_SYNC_TIMESTAMP, 0);
+ 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 = getQueuedEpisodeActions();
if (lastSync == 0) {
EventBus.getDefault().postSticky(new SyncServiceEvent(R.string.sync_status_upload_played));
@@ -327,7 +336,6 @@ public class SyncService extends Worker {
.position(media.getDuration() / 1000)
.total(media.getDuration() / 1000)
.build();
- Log.d(TAG, "Played state: " + played.toString());
queuedEpisodeActions.add(played);
}
}
@@ -370,7 +378,7 @@ public class SyncService extends Worker {
Log.d(TAG, "Processing action: " + action.toString());
switch (action.getAction()) {
case NEW:
- FeedItem newItem = DBReader.getFeedItem(action.getPodcast(), action.getEpisode());
+ FeedItem newItem = DBReader.getFeedItemByUrl(action.getPodcast(), action.getEpisode());
if (newItem != null) {
DBWriter.markItemPlayed(newItem, FeedItem.UNPLAYED, true);
} else {
@@ -401,20 +409,21 @@ public class SyncService extends Worker {
}
}
+ List<FeedItem> updatedItems = new ArrayList<>();
for (EpisodeAction action : mostRecentPlayAction.values()) {
- FeedItem playItem = DBReader.getFeedItem(action.getPodcast(), action.getEpisode());
+ FeedItem playItem = DBReader.getFeedItemByUrl(action.getPodcast(), action.getEpisode());
Log.d(TAG, "Most recent play action: " + action.toString());
if (playItem != null) {
FeedMedia media = playItem.getMedia();
media.setPosition(action.getPosition() * 1000);
- DBWriter.setFeedMedia(media);
if (playItem.getMedia().hasAlmostEnded()) {
Log.d(TAG, "Marking as played");
- DBWriter.markItemPlayed(playItem, FeedItem.PLAYED, true);
- DBWriter.addItemToPlaybackHistory(playItem.getMedia());
+ playItem.setPlayed(true);
}
+ updatedItems.add(playItem);
}
}
+ DBWriter.setItemList(updatedItems);
}
private void clearErrorNotifications() {
diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml
index 829355f81..f10b92f73 100644
--- a/core/src/main/res/values/strings.xml
+++ b/core/src/main/res/values/strings.xml
@@ -437,9 +437,9 @@
<string name="pref_gpodnet_logout_toast">Logout was successful</string>
<string name="pref_gpodnet_setlogin_information_title">Change login information</string>
<string name="pref_gpodnet_setlogin_information_sum">Change the login information for your gpodder.net account.</string>
- <string name="pref_gpodnet_sync_changes_title">Sync changes now</string>
+ <string name="pref_gpodnet_sync_changes_title">Synchronize now</string>
<string name="pref_gpodnet_sync_changes_sum">Sync subscription and episode state changes with gpodder.net.</string>
- <string name="pref_gpodnet_full_sync_title">Full sync now</string>
+ <string name="pref_gpodnet_full_sync_title">Force full synchronization</string>
<string name="pref_gpodnet_full_sync_sum">Sync all subscriptions and episode states with gpodder.net.</string>
<string name="pref_gpodnet_login_status"><![CDATA[Logged in as <i>%1$s</i> with device <i>%2$s</i>]]></string>
<string name="pref_gpodnet_notifications_title">Show sync error notifications</string>
@@ -536,7 +536,8 @@
<!-- Synchronization -->
<string name="sync_status_started">Sync started</string>
- <string name="sync_status_episodes">Synchronizing episodes…</string>
+ <string name="sync_status_episodes_upload">Uploading episode changes…</string>
+ <string name="sync_status_episodes_download">Downloading episode changes…</string>
<string name="sync_status_upload_played">Uploading played status…</string>
<string name="sync_status_subscriptions">Synchronizing subscriptions…</string>
<string name="sync_status_success">Synchronization successful</string>