Merge pull request #1878 from mfietz/issue/1872-gpodder-sync

Fix initial gpodder sync
This commit is contained in:
Tom Hennen 2016-04-20 07:14:39 -04:00
commit 6df9c0d066
3 changed files with 22 additions and 5 deletions

View File

@ -111,12 +111,17 @@ public class GpodnetSyncService extends Service {
stopSelf(); stopSelf();
return; return;
} }
boolean initialSync = GpodnetPreferences.getLastSubscriptionSyncTimestamp() == 0 &&
GpodnetPreferences.getLastEpisodeActionsSyncTimestamp() == 0;
if(syncSubscriptions) { if(syncSubscriptions) {
syncSubscriptionChanges(); syncSubscriptionChanges();
syncSubscriptions = false; syncSubscriptions = false;
} }
if(syncActions) { if(syncActions) {
// we only sync episode actions after the subscriptions have been added to the database
if(!initialSync) {
syncEpisodeActions(); syncEpisodeActions();
}
syncActions = false; syncActions = false;
} }
stopSelf(); stopSelf();

View File

@ -61,6 +61,7 @@ import de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeAction;
import de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeAction.Action; import de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeAction.Action;
import de.danoeh.antennapod.core.preferences.GpodnetPreferences; import de.danoeh.antennapod.core.preferences.GpodnetPreferences;
import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.service.GpodnetSyncService;
import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBReader;
import de.danoeh.antennapod.core.storage.DBTasks; import de.danoeh.antennapod.core.storage.DBTasks;
import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.storage.DBWriter;
@ -318,6 +319,14 @@ public class DownloadService extends Service {
cancelNotificationUpdater(); cancelNotificationUpdater();
unregisterReceiver(cancelDownloadReceiver); unregisterReceiver(cancelDownloadReceiver);
// if this was the initial gpodder sync, i.e. we just synced the feeds successfully,
// it is now time to sync the episode actions
if(GpodnetPreferences.loggedIn() &&
GpodnetPreferences.getLastSubscriptionSyncTimestamp() > 0 &&
GpodnetPreferences.getLastEpisodeActionsSyncTimestamp() == 0) {
GpodnetSyncService.sendSyncActionsIntent(this);
}
// start auto download in case anything new has shown up // start auto download in case anything new has shown up
DBTasks.autodownloadUndownloadedItems(getApplicationContext()); DBTasks.autodownloadUndownloadedItems(getApplicationContext());
} }

View File

@ -1354,14 +1354,17 @@ public class PodDBAdapter {
} }
public final Cursor getFeedItemCursor(final String podcastUrl, final String episodeUrl) { public final Cursor getFeedItemCursor(final String podcastUrl, final String episodeUrl) {
String downloadUrl = DatabaseUtils.sqlEscapeString(podcastUrl); String escapedPodcastUrl = DatabaseUtils.sqlEscapeString(podcastUrl);
String itemIdentifier = DatabaseUtils.sqlEscapeString(episodeUrl); String escapedEpisodeUrl = DatabaseUtils.sqlEscapeString(episodeUrl);
final String query = "" final String query = ""
+ "SELECT " + SEL_FI_SMALL_STR + " FROM " + TABLE_NAME_FEED_ITEMS + "SELECT " + SEL_FI_SMALL_STR + " FROM " + TABLE_NAME_FEED_ITEMS
+ " INNER JOIN " + TABLE_NAME_FEEDS + " INNER JOIN " + TABLE_NAME_FEEDS
+ " ON " + TABLE_NAME_FEED_ITEMS + "." + KEY_FEED + "=" + TABLE_NAME_FEEDS + "." + KEY_ID + " ON " + TABLE_NAME_FEED_ITEMS + "." + KEY_FEED + "=" + TABLE_NAME_FEEDS + "." + KEY_ID
+ " WHERE " + TABLE_NAME_FEED_ITEMS + "." + KEY_ITEM_IDENTIFIER + "=" + itemIdentifier + " INNER JOIN " + TABLE_NAME_FEED_MEDIA
+ " AND " + TABLE_NAME_FEEDS + "." + KEY_DOWNLOAD_URL + "=" + downloadUrl; + " ON " + TABLE_NAME_FEED_MEDIA + "." + KEY_FEEDITEM + "=" + TABLE_NAME_FEED_ITEMS + "." + KEY_ID
+ " WHERE " + TABLE_NAME_FEED_MEDIA + "." + KEY_DOWNLOAD_URL + "=" + escapedEpisodeUrl
+ " AND " + TABLE_NAME_FEEDS + "." + KEY_DOWNLOAD_URL + "=" + escapedPodcastUrl;
Log.d(TAG, "SQL: " + query);
return db.rawQuery(query, null); return db.rawQuery(query, null);
} }