summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
Diffstat (limited to 'core/src')
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/preferences/GpodnetPreferences.java49
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java11
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/GpodnetSyncService.java28
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/storage/FeedSearcher.java45
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java4
-rw-r--r--core/src/main/res/values/strings.xml12
6 files changed, 121 insertions, 28 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/preferences/GpodnetPreferences.java b/core/src/main/java/de/danoeh/antennapod/core/preferences/GpodnetPreferences.java
index 6d4d3baa6..f14c9e36c 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/preferences/GpodnetPreferences.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/preferences/GpodnetPreferences.java
@@ -37,6 +37,8 @@ public class GpodnetPreferences {
public static final String PREF_SYNC_ADDED = "de.danoeh.antennapod.preferences.gpoddernet.sync_added";
public static final String PREF_SYNC_REMOVED = "de.danoeh.antennapod.preferences.gpoddernet.sync_removed";
public static final String PREF_SYNC_EPISODE_ACTIONS = "de.danoeh.antennapod.preferences.gpoddernet.sync_queued_episode_actions";
+ public static final String PREF_LAST_SYNC_ATTEMPT_TIMESTAMP = "de.danoeh.antennapod.preferences.gpoddernet.last_sync_attempt_timestamp";
+ public static final String PREF_LAST_SYNC_ATTEMPT_RESULT = "de.danoeh.antennapod.preferences.gpoddernet.last_sync_attempt_result";
private static String username;
private static String password;
@@ -56,12 +58,26 @@ public class GpodnetPreferences {
private static long lastEpisodeActionsSyncTimeStamp;
+ private static long lastSyncAttemptTimestamp;
+
+ private static boolean lastSyncAttemptResult;
+
private static boolean preferencesLoaded = false;
private static SharedPreferences getPreferences() {
return ClientConfig.applicationCallbacks.getApplicationInstance().getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
}
+ public static void registerOnSharedPreferenceChangeListener(
+ SharedPreferences.OnSharedPreferenceChangeListener listener) {
+ getPreferences().registerOnSharedPreferenceChangeListener(listener);
+ }
+
+ public static void unregisterOnSharedPreferenceChangeListener(
+ SharedPreferences.OnSharedPreferenceChangeListener listener) {
+ getPreferences().unregisterOnSharedPreferenceChangeListener(listener);
+ }
+
private static synchronized void ensurePreferencesLoaded() {
if (!preferencesLoaded) {
SharedPreferences prefs = getPreferences();
@@ -70,6 +86,8 @@ public class GpodnetPreferences {
deviceID = prefs.getString(PREF_GPODNET_DEVICEID, null);
lastSubscriptionSyncTimestamp = prefs.getLong(PREF_LAST_SUBSCRIPTION_SYNC_TIMESTAMP, 0);
lastEpisodeActionsSyncTimeStamp = prefs.getLong(PREF_LAST_EPISODE_ACTIONS_SYNC_TIMESTAMP, 0);
+ lastSyncAttemptTimestamp = prefs.getLong(PREF_LAST_SYNC_ATTEMPT_TIMESTAMP, 0);
+ lastSyncAttemptResult = prefs.getBoolean(PREF_LAST_SYNC_ATTEMPT_RESULT, false);
addedFeeds = readListFromString(prefs.getString(PREF_SYNC_ADDED, ""));
removedFeeds = readListFromString(prefs.getString(PREF_SYNC_REMOVED, ""));
queuedEpisodeActions = readEpisodeActionsFromString(prefs.getString(PREF_SYNC_EPISODE_ACTIONS, ""));
@@ -82,19 +100,25 @@ public class GpodnetPreferences {
private static void writePreference(String key, String value) {
SharedPreferences.Editor editor = getPreferences().edit();
editor.putString(key, value);
- editor.commit();
+ editor.apply();
}
private static void writePreference(String key, long value) {
SharedPreferences.Editor editor = getPreferences().edit();
editor.putLong(key, value);
- editor.commit();
+ editor.apply();
}
private static void writePreference(String key, Collection<String> value) {
SharedPreferences.Editor editor = getPreferences().edit();
editor.putString(key, writeListToString(value));
- editor.commit();
+ editor.apply();
+ }
+
+ private static void writePreference(String key, boolean value) {
+ SharedPreferences.Editor editor = getPreferences().edit();
+ editor.putBoolean(key, value);
+ editor.apply();
}
public static String getUsername() {
@@ -147,6 +171,23 @@ public class GpodnetPreferences {
writePreference(PREF_LAST_EPISODE_ACTIONS_SYNC_TIMESTAMP, timestamp);
}
+ public static long getLastSyncAttemptTimestamp() {
+ ensurePreferencesLoaded();
+ return lastSyncAttemptTimestamp;
+ }
+
+ public static boolean getLastSyncAttemptResult() {
+ ensurePreferencesLoaded();
+ return lastSyncAttemptResult;
+ }
+
+ public static void setLastSyncAttempt(boolean result, long timestamp) {
+ GpodnetPreferences.lastSyncAttemptResult = result;
+ GpodnetPreferences.lastSyncAttemptTimestamp = timestamp;
+ writePreference(PREF_LAST_SYNC_ATTEMPT_RESULT, result);
+ writePreference(PREF_LAST_SYNC_ATTEMPT_TIMESTAMP, timestamp);
+ }
+
public static String getHostname() {
ensurePreferencesLoaded();
return hostname;
@@ -269,6 +310,8 @@ public class GpodnetPreferences {
writePreference(PREF_SYNC_EPISODE_ACTIONS, writeEpisodeActionsToString(queuedEpisodeActions));
feedListLock.unlock();
setLastSubscriptionSyncTimestamp(0);
+ setLastSyncAttempt(false, 0);
+ UserPreferences.setGpodnetNotificationsEnabled();
}
private static Set<String> readListFromString(String s) {
diff --git a/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java b/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java
index b5bbb0350..0772597a2 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java
@@ -92,6 +92,7 @@ public class UserPreferences {
// Services
public static final String PREF_AUTO_FLATTR = "pref_auto_flattr";
public static final String PREF_AUTO_FLATTR_PLAYED_DURATION_THRESHOLD = "prefAutoFlattrPlayedDurationThreshold";
+ public static final String PREF_GPODNET_NOTIFICATIONS = "pref_gpodnet_notifications";
// Other
public static final String PREF_DATA_FOLDER = "prefDataFolder";
@@ -546,6 +547,16 @@ public class UserPreferences {
.apply();
}
+ public static boolean gpodnetNotificationsEnabled() {
+ return prefs.getBoolean(PREF_GPODNET_NOTIFICATIONS, true);
+ }
+
+ public static void setGpodnetNotificationsEnabled() {
+ prefs.edit()
+ .putBoolean(PREF_GPODNET_NOTIFICATIONS, true)
+ .apply();
+ }
+
public static void setHiddenDrawerItems(List<String> items) {
String str = TextUtils.join(",", items);
prefs.edit()
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/GpodnetSyncService.java b/core/src/main/java/de/danoeh/antennapod/core/service/GpodnetSyncService.java
index 160ba487b..e9312b929 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/service/GpodnetSyncService.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/service/GpodnetSyncService.java
@@ -30,6 +30,7 @@ import de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeActionPostRespon
import de.danoeh.antennapod.core.gpoddernet.model.GpodnetSubscriptionChange;
import de.danoeh.antennapod.core.gpoddernet.model.GpodnetUploadChangesResponse;
import de.danoeh.antennapod.core.preferences.GpodnetPreferences;
+import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.storage.DBReader;
import de.danoeh.antennapod.core.storage.DBTasks;
import de.danoeh.antennapod.core.storage.DBWriter;
@@ -107,7 +108,7 @@ public class GpodnetSyncService extends Service {
private synchronized void sync() {
- if (GpodnetPreferences.loggedIn() == false || NetworkUtils.networkAvailable() == false) {
+ if (!GpodnetPreferences.loggedIn() || !NetworkUtils.networkAvailable()) {
stopSelf();
return;
}
@@ -161,6 +162,7 @@ public class GpodnetSyncService extends Service {
GpodnetPreferences.removeRemovedFeeds(localRemoved);
}
GpodnetPreferences.setLastSubscriptionSyncTimestamp(newTimeStamp);
+ GpodnetPreferences.setLastSyncAttempt(true, System.currentTimeMillis());
clearErrorNotifications();
} catch (GpodnetServiceException e) {
e.printStackTrace();
@@ -177,15 +179,15 @@ public class GpodnetSyncService extends Service {
// local changes are always superior to remote changes!
// add subscription if (1) not already subscribed and (2) not just unsubscribed
for (String downloadUrl : changes.getAdded()) {
- if (false == localSubscriptions.contains(downloadUrl) &&
- false == localRemoved.contains(downloadUrl)) {
+ if (!localSubscriptions.contains(downloadUrl) &&
+ !localRemoved.contains(downloadUrl)) {
Feed feed = new Feed(downloadUrl, null);
DownloadRequester.getInstance().downloadFeed(this, feed);
}
}
// remove subscription if not just subscribed (again)
for (String downloadUrl : changes.getRemoved()) {
- if(false == localAdded.contains(downloadUrl)) {
+ if(!localAdded.contains(downloadUrl)) {
DBTasks.removeFeedWithDownloadUrl(GpodnetSyncService.this, downloadUrl);
}
}
@@ -215,6 +217,7 @@ public class GpodnetSyncService extends Service {
GpodnetPreferences.removeQueuedEpisodeActions(localActions);
}
GpodnetPreferences.setLastEpisodeActionsSyncTimestamp(lastUpdate);
+ GpodnetPreferences.setLastSyncAttempt(true, System.currentTimeMillis());
clearErrorNotifications();
} catch (GpodnetServiceException e) {
e.printStackTrace();
@@ -298,8 +301,8 @@ public class GpodnetSyncService extends Service {
private void updateErrorNotification(GpodnetServiceException exception) {
Log.d(TAG, "Posting error notification");
+ GpodnetPreferences.setLastSyncAttempt(false, System.currentTimeMillis());
- NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
final String title;
final String description;
final int id;
@@ -308,18 +311,23 @@ public class GpodnetSyncService extends Service {
description = getString(R.string.gpodnetsync_auth_error_descr);
id = R.id.notification_gpodnet_sync_autherror;
} else {
- title = getString(R.string.gpodnetsync_error_title);
- description = getString(R.string.gpodnetsync_error_descr) + exception.getMessage();
- id = R.id.notification_gpodnet_sync_error;
+ if (UserPreferences.gpodnetNotificationsEnabled()) {
+ title = getString(R.string.gpodnetsync_error_title);
+ description = getString(R.string.gpodnetsync_error_descr) + exception.getMessage();
+ id = R.id.notification_gpodnet_sync_error;
+ } else {
+ return;
+ }
}
PendingIntent activityIntent = ClientConfig.gpodnetCallbacks.getGpodnetSyncServiceErrorNotificationPendingIntent(this);
- Notification notification = builder.setContentTitle(title)
+ Notification notification = new NotificationCompat.Builder(this)
+ .setContentTitle(title)
.setContentText(description)
.setContentIntent(activityIntent)
.setSmallIcon(R.drawable.stat_notify_sync_error)
.setAutoCancel(true)
- .setVisibility(Notification.VISIBILITY_PUBLIC)
+ .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.build();
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(id, notification);
diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/FeedSearcher.java b/core/src/main/java/de/danoeh/antennapod/core/storage/FeedSearcher.java
index b88d774a2..9d136273c 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/storage/FeedSearcher.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/storage/FeedSearcher.java
@@ -21,23 +21,32 @@ public class FeedSearcher {
/**
- * Performs a search in all feeds or one specific feed.
+ * Search through a feed, or all feeds, for episodes that match the query in either the title,
+ * chapter, or show notes. The search is first performed on titles, then chapters, and finally
+ * show notes. The list of resulting episodes also describes where the first match occurred
+ * (title, chapters, or show notes).
+ *
+ * @param context
+ * @param query search query
+ * @param selectedFeed feed to search, 0 to search through all feeds
+ * @return list of episodes containing the query
*/
public static List<SearchResult> performSearch(final Context context,
final String query, final long selectedFeed) {
- final int values[] = {0, 0, 1, 2};
- final String[] subtitles = {context.getString(R.string.found_in_shownotes_label),
- context.getString(R.string.found_in_shownotes_label),
+ final int values[] = {2, 1, 0, 0};
+ final String[] subtitles = {context.getString(R.string.found_in_title_label),
context.getString(R.string.found_in_chapters_label),
- context.getString(R.string.found_in_title_label)};
+ context.getString(R.string.found_in_shownotes_label),
+ context.getString(R.string.found_in_shownotes_label)};
List<SearchResult> result = new ArrayList<>();
List<FutureTask<List<FeedItem>>> tasks = new ArrayList<>();
- tasks.add(DBTasks.searchFeedItemContentEncoded(context, selectedFeed, query));
- tasks.add(DBTasks.searchFeedItemDescription(context, selectedFeed, query));
- tasks.add(DBTasks.searchFeedItemChapters(context, selectedFeed, query));
tasks.add(DBTasks.searchFeedItemTitle(context, selectedFeed, query));
+ tasks.add(DBTasks.searchFeedItemChapters(context, selectedFeed, query));
+ tasks.add(DBTasks.searchFeedItemDescription(context, selectedFeed, query));
+ tasks.add(DBTasks.searchFeedItemContentEncoded(context, selectedFeed, query));
+
for (FutureTask<List<FeedItem>> task : tasks) {
task.run();
}
@@ -46,7 +55,9 @@ public class FeedSearcher {
FutureTask<List<FeedItem>> task = tasks.get(i);
List<FeedItem> items = task.get();
for (FeedItem item : items) {
- result.add(new SearchResult(item, values[i], subtitles[i]));
+ if (result.isEmpty() || !isDuplicate(result, item)) {
+ result.add(new SearchResult(item, values[i], subtitles[i]));
+ }
}
}
@@ -56,4 +67,20 @@ public class FeedSearcher {
Collections.sort(result, new SearchResultValueComparator());
return result;
}
+
+ /**
+ * Determines if the feed item is already in the search result list.
+ *
+ * @param result list of search results
+ * @param item feed item to validate
+ * @return true if the feed item is already in the results
+ */
+ private static boolean isDuplicate(List<SearchResult> result, FeedItem item) {
+ for (SearchResult resultItem : result) {
+ if (resultItem.getComponent().getId() == item.getId()) {
+ return true;
+ }
+ }
+ return false;
+ }
}
diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java b/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java
index c0b417b81..13aadf027 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java
@@ -197,9 +197,7 @@ public abstract class PlaybackController {
mConnection, 0);
}
Log.d(TAG, "Result for service binding: " + bound);
- }, error -> {
- Log.e(TAG, Log.getStackTraceString(error));
- });
+ }, error -> Log.e(TAG, Log.getStackTraceString(error)));
}
/**
diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml
index 783f6c1d9..e243776f5 100644
--- a/core/src/main/res/values/strings.xml
+++ b/core/src/main/res/values/strings.xml
@@ -365,9 +365,12 @@
<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_title">Sync now</string>
- <string name="pref_gpodnet_sync_sum">Sync subscriptions and episode states with gpodder.net</string>
+ <string name="pref_gpodnet_sync_sum">Sync subscriptions and episode states with gpodder.net.</string>
+ <string name="pref_gpodnet_sync_sum_last_sync_line">Last sync attempt: %1$s (%2$s)</string>
<string name="pref_gpodnet_sync_started">Sync started</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>
+ <string name="pref_gpodnet_notifications_sum">This setting does not apply to authentication errors.</string>
<string name="pref_playback_speed_title">Playback Speeds</string>
<string name="pref_playback_speed_sum">Customize the speeds available for variable speed audio playback</string>
<string name="pref_fast_forward">Fast forward time</string>
@@ -415,12 +418,13 @@
<string name="auto_flattr_ater_end">Flattr episode when playback ends</string>
<!-- Search -->
- <string name="search_hint">Search for Feeds or Episodes</string>
- <string name="found_in_shownotes_label">Found in shownotes</string>
+ <string name="search_hint">Search for episodes</string>
+ <string name="found_in_shownotes_label">Found in show notes</string>
<string name="found_in_chapters_label">Found in chapters</string>
<string name="search_status_no_results">No results were found</string>
<string name="search_label">Search</string>
<string name="found_in_title_label">Found in title</string>
+ <string name="no_results_for_query">No results were found for \"%1$s\"</string>
<!-- OPML import and export -->
<string name="opml_import_txtv_button_lable">OPML files allow you to move your podcasts from one podcatcher to another.</string>
@@ -502,6 +506,8 @@
<string name="gpodnetsync_auth_error_descr">Wrong username or password</string>
<string name="gpodnetsync_error_title">gpodder.net sync error</string>
<string name="gpodnetsync_error_descr">An error occurred during syncing:\u0020</string>
+ <string name="gpodnetsync_pref_report_successful">Successful</string>
+ <string name="gpodnetsync_pref_report_failed">Failed</string>
<!-- Directory chooser -->
<string name="selected_folder_label">Selected folder:</string>