diff options
author | ByteHamster <info@bytehamster.com> | 2018-12-26 08:40:40 +0100 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2018-12-26 08:40:40 +0100 |
commit | bb4b4655d25713dfddca7a52c5088938c604114b (patch) | |
tree | 29546dd59b232b0843cd52e80d950111aefddb81 /core/src/main/java | |
parent | 20328dbd97c0ff561b815efe3cc088884f7378eb (diff) | |
parent | 9a92e66ffdcb7648ad641fa4f17ffe11d4d72298 (diff) | |
download | AntennaPod-bb4b4655d25713dfddca7a52c5088938c604114b.zip |
Merge branch 'develop' into rxjava2
Diffstat (limited to 'core/src/main/java')
54 files changed, 269 insertions, 129 deletions
diff --git a/core/src/main/java/android/support/v4/app/SafeJobIntentService.java b/core/src/main/java/android/support/v4/app/SafeJobIntentService.java new file mode 100644 index 000000000..c07c409ee --- /dev/null +++ b/core/src/main/java/android/support/v4/app/SafeJobIntentService.java @@ -0,0 +1,118 @@ +package android.support.v4.app; + +import android.app.job.JobParameters; +import android.app.job.JobServiceEngine; +import android.app.job.JobWorkItem; +import android.content.Intent; +import android.os.Build; +import android.os.IBinder; +import android.support.annotation.RequiresApi; +import android.util.Log; + + +public abstract class SafeJobIntentService extends JobIntentService { + + @Override + public void onCreate() { + super.onCreate(); + if (Build.VERSION.SDK_INT >= 26) { + mJobImpl = new SafeJobServiceEngineImpl(this); + } + } + + /** + * Implementation of a safe JobServiceEngine for interaction with JobIntentService. + */ + @RequiresApi(26) + static final class SafeJobServiceEngineImpl extends JobServiceEngine + implements JobIntentService.CompatJobEngine { + static final String TAG = "JobServiceEngineImpl"; + + static final boolean DEBUG = false; + + final JobIntentService mService; + final Object mLock = new Object(); + JobParameters mParams; + + final class WrapperWorkItem implements JobIntentService.GenericWorkItem { + final JobWorkItem mJobWork; + + WrapperWorkItem(JobWorkItem jobWork) { + mJobWork = jobWork; + } + + @Override + public Intent getIntent() { + return mJobWork.getIntent(); + } + + @Override + public void complete() { + synchronized (mLock) { + if (mParams != null) { + try { + mParams.completeWork(mJobWork); + } catch (SecurityException e) { + Log.e(TAG, Log.getStackTraceString(e)); + } + } + } + } + } + + SafeJobServiceEngineImpl(JobIntentService service) { + super(service); + mService = service; + } + + @Override + public IBinder compatGetBinder() { + return getBinder(); + } + + @Override + public boolean onStartJob(JobParameters params) { + if (DEBUG) Log.d(TAG, "onStartJob: " + params); + mParams = params; + // We can now start dequeuing work! + mService.ensureProcessorRunningLocked(false); + return true; + } + + @Override + public boolean onStopJob(JobParameters params) { + if (DEBUG) Log.d(TAG, "onStartJob: " + params); + boolean result = mService.doStopCurrentWork(); + synchronized (mLock) { + // Once we return, the job is stopped, so its JobParameters are no + // longer valid and we should not be doing anything with them. + mParams = null; + } + return result; + } + + /** + * Dequeue some work. + */ + @Override + public JobIntentService.GenericWorkItem dequeueWork() { + JobWorkItem work = null; + synchronized (mLock) { + if (mParams == null) { + return null; + } + try { + work = mParams.dequeueWork(); + } catch (SecurityException e) { + Log.e(TAG, Log.getStackTraceString(e)); + } + } + if (work != null) { + work.getIntent().setExtrasClassLoader(mService.getClassLoader()); + return new WrapperWorkItem(work); + } else { + return null; + } + } + } +} diff --git a/core/src/main/java/de/danoeh/antennapod/core/UpdateManager.java b/core/src/main/java/de/danoeh/antennapod/core/UpdateManager.java index ea07fc76e..8ad70c328 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/UpdateManager.java +++ b/core/src/main/java/de/danoeh/antennapod/core/UpdateManager.java @@ -10,20 +10,15 @@ import android.util.Log; import org.antennapod.audio.MediaPlayer; -import java.io.File; -import java.util.List; - -import de.danoeh.antennapod.core.feed.Feed; -import de.danoeh.antennapod.core.feed.FeedItem; import de.danoeh.antennapod.core.preferences.UserPreferences; -import de.danoeh.antennapod.core.storage.DBReader; -import de.danoeh.antennapod.core.storage.DBWriter; /* * This class's job is do perform maintenance tasks whenever the app has been updated */ class UpdateManager { + private UpdateManager(){} + private static final String TAG = UpdateManager.class.getSimpleName(); private static final String PREF_NAME = "app_version"; diff --git a/core/src/main/java/de/danoeh/antennapod/core/asynctask/FeedRemover.java b/core/src/main/java/de/danoeh/antennapod/core/asynctask/FeedRemover.java index 74693cf21..4504b2e7f 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/asynctask/FeedRemover.java +++ b/core/src/main/java/de/danoeh/antennapod/core/asynctask/FeedRemover.java @@ -2,14 +2,12 @@ package de.danoeh.antennapod.core.asynctask; import android.app.ProgressDialog; import android.content.Context; -import android.content.Intent; import android.os.AsyncTask; import java.util.concurrent.ExecutionException; import de.danoeh.antennapod.core.R; import de.danoeh.antennapod.core.feed.Feed; -import de.danoeh.antennapod.core.service.download.DownloadService; import de.danoeh.antennapod.core.service.playback.PlaybackService; import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.util.IntentUtils; diff --git a/core/src/main/java/de/danoeh/antennapod/core/asynctask/FlattrClickWorker.java b/core/src/main/java/de/danoeh/antennapod/core/asynctask/FlattrClickWorker.java index f4c99011a..318e404c8 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/asynctask/FlattrClickWorker.java +++ b/core/src/main/java/de/danoeh/antennapod/core/asynctask/FlattrClickWorker.java @@ -10,7 +10,6 @@ import android.support.v4.app.NotificationCompat; import android.util.Log; import android.widget.Toast; -import de.danoeh.antennapod.core.util.gui.NotificationUtils; import org.shredzone.flattr4j.exception.FlattrException; import java.util.LinkedList; @@ -27,6 +26,7 @@ import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.util.NetworkUtils; import de.danoeh.antennapod.core.util.flattr.FlattrThing; import de.danoeh.antennapod.core.util.flattr.FlattrUtils; +import de.danoeh.antennapod.core.util.gui.NotificationUtils; /** * Performs a click action in a background thread. diff --git a/core/src/main/java/de/danoeh/antennapod/core/asynctask/FlattrStatusFetcher.java b/core/src/main/java/de/danoeh/antennapod/core/asynctask/FlattrStatusFetcher.java index 420a60469..6d9ab2bd3 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/asynctask/FlattrStatusFetcher.java +++ b/core/src/main/java/de/danoeh/antennapod/core/asynctask/FlattrStatusFetcher.java @@ -19,11 +19,9 @@ import de.danoeh.antennapod.core.util.flattr.FlattrUtils; public class FlattrStatusFetcher extends Thread { private static final String TAG = "FlattrStatusFetcher"; - private final Context context; public FlattrStatusFetcher(Context context) { super(); - this.context = context; } @Override diff --git a/core/src/main/java/de/danoeh/antennapod/core/feed/FeedComponent.java b/core/src/main/java/de/danoeh/antennapod/core/feed/FeedComponent.java index a3f91b1c9..2610d253f 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/feed/FeedComponent.java +++ b/core/src/main/java/de/danoeh/antennapod/core/feed/FeedComponent.java @@ -50,7 +50,7 @@ public abstract class FeedComponent { @Override public boolean equals(Object o) { if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (o == null || !(o instanceof FeedComponent)) return false; FeedComponent that = (FeedComponent) o; @@ -62,4 +62,4 @@ public abstract class FeedComponent { public int hashCode() { return (int) (id ^ (id >>> 32)); } -}
\ No newline at end of file +} diff --git a/core/src/main/java/de/danoeh/antennapod/core/feed/FeedItem.java b/core/src/main/java/de/danoeh/antennapod/core/feed/FeedItem.java index b0a87c885..0f0343f25 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/feed/FeedItem.java +++ b/core/src/main/java/de/danoeh/antennapod/core/feed/FeedItem.java @@ -2,9 +2,8 @@ package de.danoeh.antennapod.core.feed; import android.database.Cursor; import android.support.annotation.Nullable; - import android.text.TextUtils; -import de.danoeh.antennapod.core.asynctask.ImageResource; + import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; @@ -15,6 +14,7 @@ import java.util.Set; import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; +import de.danoeh.antennapod.core.asynctask.ImageResource; import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.PodDBAdapter; import de.danoeh.antennapod.core.util.ShownotesProvider; @@ -194,7 +194,7 @@ public class FeedItem extends FeedComponent implements ShownotesProvider, Flattr if (other.link != null) { link = other.link; } - if (other.pubDate != null && other.pubDate != pubDate) { + if (other.pubDate != null && other.pubDate.equals(pubDate)) { pubDate = other.pubDate; } if (other.media != null) { diff --git a/core/src/main/java/de/danoeh/antennapod/core/feed/FeedItemFilter.java b/core/src/main/java/de/danoeh/antennapod/core/feed/FeedItemFilter.java index 200153876..719383d23 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/feed/FeedItemFilter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/feed/FeedItemFilter.java @@ -8,6 +8,8 @@ import java.util.List; import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.util.LongList; +import static de.danoeh.antennapod.core.feed.FeedItem.TAG_FAVORITE; + public class FeedItemFilter { private final String[] mProperties; @@ -19,6 +21,7 @@ public class FeedItemFilter { private boolean showDownloaded = false; private boolean showNotDownloaded = false; private boolean showHasMedia = false; + private boolean showIsFavorite = false; public FeedItemFilter(String properties) { this(TextUtils.split(properties, ",")); @@ -53,6 +56,9 @@ public class FeedItemFilter { case "has_media": showHasMedia = true; break; + case "is_favorite": + showIsFavorite = true; + break; } } } @@ -88,6 +94,8 @@ public class FeedItemFilter { if (showHasMedia && !item.hasMedia()) continue; + if (showIsFavorite && !item.isTagged(TAG_FAVORITE)) continue; + // If the item reaches here, it meets all criteria result.add(item); } diff --git a/core/src/main/java/de/danoeh/antennapod/core/feed/FeedMedia.java b/core/src/main/java/de/danoeh/antennapod/core/feed/FeedMedia.java index 73d2bb34d..39994ec16 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/feed/FeedMedia.java +++ b/core/src/main/java/de/danoeh/antennapod/core/feed/FeedMedia.java @@ -532,8 +532,8 @@ public class FeedMedia extends FeedFile implements Playable { UserPreferences.isAutoFlattr() && item.getPaymentLink() != null && item.getFlattrStatus().getUnflattred() && - (completed && autoFlattrThreshold <= 1.0f || - played_duration >= autoFlattrThreshold * duration)) { + ((completed && autoFlattrThreshold <= 1.0f) || + (played_duration >= autoFlattrThreshold * duration))) { DBTasks.flattrItemIfLoggedIn(context, item); } } @@ -626,6 +626,9 @@ public class FeedMedia extends FeedFile implements Playable { @Override public boolean equals(Object o) { + if (o == null) { + return false; + } if (FeedMediaFlavorHelper.instanceOfRemoteMedia(o)) { return o.equals(this); } diff --git a/core/src/main/java/de/danoeh/antennapod/core/glide/ApGlideSettings.java b/core/src/main/java/de/danoeh/antennapod/core/glide/ApGlideSettings.java index fc1acd0e1..d0061af99 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/glide/ApGlideSettings.java +++ b/core/src/main/java/de/danoeh/antennapod/core/glide/ApGlideSettings.java @@ -6,6 +6,7 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy; * The settings that AntennaPod will use for various Glide options */ public class ApGlideSettings { + private ApGlideSettings(){} public static final DiskCacheStrategy AP_DISK_CACHE_STRATEGY = DiskCacheStrategy.ALL; } diff --git a/core/src/main/java/de/danoeh/antennapod/core/gpoddernet/model/GpodnetEpisodeAction.java b/core/src/main/java/de/danoeh/antennapod/core/gpoddernet/model/GpodnetEpisodeAction.java index b76988fd8..330cde525 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/gpoddernet/model/GpodnetEpisodeAction.java +++ b/core/src/main/java/de/danoeh/antennapod/core/gpoddernet/model/GpodnetEpisodeAction.java @@ -169,7 +169,7 @@ public class GpodnetEpisodeAction { @Override public boolean equals(Object o) { if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (o == null || !(o instanceof GpodnetEpisodeAction)) return false; GpodnetEpisodeAction that = (GpodnetEpisodeAction) o; 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 b51b8d996..5b17dd338 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 @@ -24,6 +24,8 @@ import de.danoeh.antennapod.core.service.GpodnetSyncService; */ public class GpodnetPreferences { + private GpodnetPreferences(){} + private static final String TAG = "GpodnetPreferences"; private static final String PREF_NAME = "gpodder.net"; diff --git a/core/src/main/java/de/danoeh/antennapod/core/preferences/SleepTimerPreferences.java b/core/src/main/java/de/danoeh/antennapod/core/preferences/SleepTimerPreferences.java index b7ed890f5..0f3a9fcb3 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/preferences/SleepTimerPreferences.java +++ b/core/src/main/java/de/danoeh/antennapod/core/preferences/SleepTimerPreferences.java @@ -23,7 +23,6 @@ public class SleepTimerPreferences { private static final String DEFAULT_VALUE = "15"; private static final int DEFAULT_TIME_UNIT = 1; - private static Context context; private static SharedPreferences prefs; /** 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 58071495a..049dd120d 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 @@ -36,6 +36,7 @@ import de.danoeh.antennapod.core.util.download.AutoUpdateManager; * when called. */ public class UserPreferences { + private UserPreferences(){} private static final String IMPORT_DIR = "import/"; @@ -46,11 +47,13 @@ public class UserPreferences { public static final String PREF_HIDDEN_DRAWER_ITEMS = "prefHiddenDrawerItems"; private static final String PREF_DRAWER_FEED_ORDER = "prefDrawerFeedOrder"; private static final String PREF_DRAWER_FEED_COUNTER = "prefDrawerFeedIndicator"; - private static final String PREF_EXPANDED_NOTIFICATION = "prefExpandNotify"; + public static final String PREF_EXPANDED_NOTIFICATION = "prefExpandNotify"; private static final String PREF_PERSISTENT_NOTIFICATION = "prefPersistNotify"; public static final String PREF_COMPACT_NOTIFICATION_BUTTONS = "prefCompactNotificationButtons"; public static final String PREF_LOCKSCREEN_BACKGROUND = "prefLockscreenBackground"; private static final String PREF_SHOW_DOWNLOAD_REPORT = "prefShowDownloadReport"; + public static final String PREF_BACK_BUTTON_BEHAVIOR = "prefBackButtonBehavior"; + private static final String PREF_BACK_BUTTON_GO_TO_PAGE = "prefBackButtonGoToPage"; // Queue private static final String PREF_QUEUE_ADD_TO_FRONT = "prefQueueAddToFront"; @@ -809,4 +812,29 @@ public class UserPreferences { public enum VideoBackgroundBehavior { STOP, PICTURE_IN_PICTURE, CONTINUE_PLAYING } + + public enum BackButtonBehavior { + DEFAULT, OPEN_DRAWER, DOUBLE_TAP, SHOW_PROMPT, GO_TO_PAGE + } + + public static BackButtonBehavior getBackButtonBehavior() { + switch (prefs.getString(PREF_BACK_BUTTON_BEHAVIOR, "default")) { + case "default": return BackButtonBehavior.DEFAULT; + case "drawer": return BackButtonBehavior.OPEN_DRAWER; + case "doubletap": return BackButtonBehavior.DOUBLE_TAP; + case "prompt": return BackButtonBehavior.SHOW_PROMPT; + case "page": return BackButtonBehavior.GO_TO_PAGE; + default: return BackButtonBehavior.DEFAULT; + } + } + + public static String getBackButtonGoToPage() { + return prefs.getString(PREF_BACK_BUTTON_GO_TO_PAGE, "QueueFragment"); + } + + public static void setBackButtonGoToPage(String tag) { + prefs.edit() + .putString(PREF_BACK_BUTTON_GO_TO_PAGE, tag) + .apply(); + } } diff --git a/core/src/main/java/de/danoeh/antennapod/core/receiver/PlayerWidget.java b/core/src/main/java/de/danoeh/antennapod/core/receiver/PlayerWidget.java index edc2ea3e0..7663cdbe4 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/receiver/PlayerWidget.java +++ b/core/src/main/java/de/danoeh/antennapod/core/receiver/PlayerWidget.java @@ -6,10 +6,11 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.util.Log; -import de.danoeh.antennapod.core.service.PlayerWidgetJobService; import java.util.Arrays; +import de.danoeh.antennapod.core.service.PlayerWidgetJobService; + public class PlayerWidget extends AppWidgetProvider { private static final String TAG = "PlayerWidget"; diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/FeedUpdateJobService.java b/core/src/main/java/de/danoeh/antennapod/core/service/FeedUpdateJobService.java index 55a8d6b86..7d80d4e7c 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/FeedUpdateJobService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/FeedUpdateJobService.java @@ -5,6 +5,7 @@ import android.app.job.JobService; import android.os.Build; import android.support.annotation.RequiresApi; import android.util.Log; + import de.danoeh.antennapod.core.ClientConfig; import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.util.FeedUpdateUtils; 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 fe6e8c400..5584991ca 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 @@ -6,8 +6,8 @@ import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.support.annotation.NonNull; -import android.support.v4.app.JobIntentService; import android.support.v4.app.NotificationCompat; +import android.support.v4.app.SafeJobIntentService; import android.support.v4.util.ArrayMap; import android.util.Log; import android.util.Pair; @@ -44,7 +44,7 @@ import de.danoeh.antennapod.core.util.gui.NotificationUtils; * Synchronizes local subscriptions with gpodder.net service. The service should be started with ACTION_SYNC as an action argument. * This class also provides static methods for starting the GpodnetSyncService. */ -public class GpodnetSyncService extends JobIntentService { +public class GpodnetSyncService extends SafeJobIntentService { private static final String TAG = "GpodnetSyncService"; diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/PlayerWidgetJobService.java b/core/src/main/java/de/danoeh/antennapod/core/service/PlayerWidgetJobService.java index d2214cac8..6dab9a561 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/PlayerWidgetJobService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/PlayerWidgetJobService.java @@ -9,23 +9,24 @@ import android.content.ServiceConnection; import android.os.Build; import android.os.IBinder; import android.support.annotation.NonNull; -import android.support.v4.app.JobIntentService; +import android.support.v4.app.SafeJobIntentService; import android.util.Log; import android.view.KeyEvent; import android.view.View; import android.widget.RemoteViews; + import de.danoeh.antennapod.core.R; import de.danoeh.antennapod.core.receiver.MediaButtonReceiver; +import de.danoeh.antennapod.core.receiver.PlayerWidget; import de.danoeh.antennapod.core.service.playback.PlaybackService; import de.danoeh.antennapod.core.service.playback.PlayerStatus; import de.danoeh.antennapod.core.util.Converter; import de.danoeh.antennapod.core.util.playback.Playable; -import de.danoeh.antennapod.core.receiver.PlayerWidget; /** * Updates the state of the player widget */ -public class PlayerWidgetJobService extends JobIntentService { +public class PlayerWidgetJobService extends SafeJobIntentService { private static final String TAG = "PlayerWidgetJobService"; diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/AntennapodHttpClient.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/AntennapodHttpClient.java index 57d099dfc..97007a214 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/AntennapodHttpClient.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/AntennapodHttpClient.java @@ -40,6 +40,9 @@ import okhttp3.internal.http.StatusLine; * Provides access to a HttpClient singleton. */ public class AntennapodHttpClient { + + private AntennapodHttpClient(){} + private static final String TAG = "AntennapodHttpClient"; private static final int CONNECTION_TIMEOUT = 30000; diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadRequest.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadRequest.java index 75c28564e..48234c387 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadRequest.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadRequest.java @@ -124,7 +124,7 @@ public class DownloadRequest implements Parcelable { @Override public boolean equals(Object o) { if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (o == null || !(o instanceof DownloadRequest)) return false; DownloadRequest that = (DownloadRequest) o; diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java index 4bd2d8f19..ae1e9de86 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java @@ -13,15 +13,12 @@ import android.os.Build; import android.os.Handler; import android.os.IBinder; import android.support.annotation.NonNull; -import android.support.annotation.VisibleForTesting; import android.support.v4.app.NotificationCompat; import android.text.TextUtils; import android.util.Log; import android.util.Pair; import android.webkit.URLUtil; -import de.danoeh.antennapod.core.storage.PodDBAdapter; -import de.danoeh.antennapod.core.util.gui.NotificationUtils; import org.apache.commons.io.FileUtils; import org.xml.sax.SAXException; @@ -31,10 +28,8 @@ import java.net.HttpURLConnection; import java.util.ArrayList; import java.util.Collections; import java.util.Date; -import java.util.HashSet; import java.util.LinkedList; import java.util.List; -import java.util.Set; import java.util.concurrent.BlockingQueue; import java.util.concurrent.Callable; import java.util.concurrent.CompletionService; @@ -75,6 +70,7 @@ import de.danoeh.antennapod.core.syndication.handler.UnsupportedFeedtypeExceptio import de.danoeh.antennapod.core.util.ChapterUtils; import de.danoeh.antennapod.core.util.DownloadError; import de.danoeh.antennapod.core.util.InvalidFeedException; +import de.danoeh.antennapod.core.util.gui.NotificationUtils; import de.greenrobot.event.EventBus; /** @@ -117,11 +113,6 @@ public class DownloadService extends Service { private CompletionService<Downloader> downloadExecutor; private FeedSyncThread feedSyncThread; - /** - * Number of threads of downloadExecutor. - */ - private static final int NUM_PARALLEL_DOWNLOADS = 6; - private DownloadRequester requester; @@ -257,7 +248,6 @@ public class DownloadService extends Service { public void onCreate() { Log.d(TAG, "Service started"); isRunning = true; - PodDBAdapter.getInstance().open(); // Prevent thrashing the database by opening and closing rapidly handler = new Handler(); reportQueue = Collections.synchronizedList(new ArrayList<>()); downloads = Collections.synchronizedList(new ArrayList<>()); @@ -337,7 +327,6 @@ public class DownloadService extends Service { // start auto download in case anything new has shown up DBTasks.autodownloadUndownloadedItems(getApplicationContext()); - PodDBAdapter.getInstance().close(); } private void setupNotificationBuilders() { @@ -862,22 +851,6 @@ public class DownloadService extends Service { return true; } - /** - * Delete files that aren't needed anymore - */ - private void cleanup(Feed feed) { - if (feed.getFile_url() != null) { - if (new File(feed.getFile_url()).delete()) { - Log.d(TAG, "Successfully deleted cache file."); - } else { - Log.e(TAG, "Failed to delete cache file."); - } - feed.setFile_url(null); - } else { - Log.d(TAG, "Didn't delete cache file: File url is not set."); - } - } - public void shutdown() { isActive = false; if (isCollectingRequests) { diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/HttpDownloader.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/HttpDownloader.java index 8cce02155..842ad0c60 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/HttpDownloader.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/HttpDownloader.java @@ -304,7 +304,7 @@ public class HttpDownloader extends Downloader { String encoded = ByteString.of(bytes).base64(); return "Basic " + encoded; } catch (UnsupportedEncodingException e) { - throw new AssertionError(); + throw new AssertionError(e); } } diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/ExoPlayerWrapper.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/ExoPlayerWrapper.java index cc9d2ce2d..e1d87e1d5 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/ExoPlayerWrapper.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/ExoPlayerWrapper.java @@ -3,6 +3,7 @@ package de.danoeh.antennapod.core.service.playback; import android.content.Context; import android.net.Uri; import android.view.SurfaceHolder; + import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.DefaultLoadControl; import com.google.android.exoplayer2.DefaultRenderersFactory; @@ -22,9 +23,11 @@ import com.google.android.exoplayer2.trackselection.TrackSelectionArray; import com.google.android.exoplayer2.upstream.DataSource; import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory; import com.google.android.exoplayer2.util.Util; -import de.danoeh.antennapod.core.util.playback.IPlayer; + import org.antennapod.audio.MediaPlayer; +import de.danoeh.antennapod.core.util.playback.IPlayer; + public class ExoPlayerWrapper implements IPlayer { private final Context mContext; diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java index 979857381..68c9ac0ce 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java @@ -24,13 +24,13 @@ import android.os.Vibrator; import android.preference.PreferenceManager; import android.support.annotation.NonNull; import android.support.annotation.StringRes; +import android.support.v4.app.NotificationCompat; import android.support.v4.media.MediaBrowserCompat; import android.support.v4.media.MediaBrowserServiceCompat; import android.support.v4.media.MediaDescriptionCompat; import android.support.v4.media.MediaMetadataCompat; import android.support.v4.media.session.MediaSessionCompat; import android.support.v4.media.session.PlaybackStateCompat; -import android.support.v4.app.NotificationCompat; import android.text.TextUtils; import android.util.Log; import android.util.Pair; @@ -66,8 +66,8 @@ import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.storage.FeedSearcher; import de.danoeh.antennapod.core.util.IntList; import de.danoeh.antennapod.core.util.IntentUtils; -import de.danoeh.antennapod.core.util.gui.NotificationUtils; import de.danoeh.antennapod.core.util.QueueAccess; +import de.danoeh.antennapod.core.util.gui.NotificationUtils; import de.danoeh.antennapod.core.util.playback.ExternalMedia; import de.danoeh.antennapod.core.util.playback.Playable; import de.greenrobot.event.EventBus; @@ -602,14 +602,6 @@ public class PlaybackService extends MediaBrowserServiceCompat { mediaPlayer.setVideoSurface(sh); } - /** - * Called when the surface holder of the mediaplayer has to be changed. - */ - private void resetVideoSurface() { - taskManager.cancelPositionSaver(); - mediaPlayer.resetVideoSurface(); - } - public void notifyVideoSurfaceAbandoned() { mediaPlayer.pause(true, false); mediaPlayer.resetVideoSurface(); @@ -1104,7 +1096,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { } else { state = PlaybackStateCompat.STATE_NONE; } - sessionState.setState(state, mediaPlayer.getPosition(), mediaPlayer.getPlaybackSpeed()); + sessionState.setState(state, getCurrentPosition(), getCurrentPlaybackSpeed()); long capabilities = PlaybackStateCompat.ACTION_PLAY_PAUSE | PlaybackStateCompat.ACTION_REWIND | PlaybackStateCompat.ACTION_FAST_FORWARD @@ -1644,6 +1636,9 @@ public class PlaybackService extends MediaBrowserServiceCompat { } public float getCurrentPlaybackSpeed() { + if(mediaPlayer == null) { + return 1.0f; + } return mediaPlayer.getPlaybackSpeed(); } @@ -1807,7 +1802,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { public boolean onMediaButtonEvent(final Intent mediaButton) { Log.d(TAG, "onMediaButtonEvent(" + mediaButton + ")"); if (mediaButton != null) { - KeyEvent keyEvent = (KeyEvent) mediaButton.getParcelableExtra(Intent.EXTRA_KEY_EVENT); + KeyEvent keyEvent = mediaButton.getParcelableExtra(Intent.EXTRA_KEY_EVENT); if (keyEvent != null && keyEvent.getAction() == KeyEvent.ACTION_DOWN && keyEvent.getRepeatCount() == 0) { diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlayerStatus.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlayerStatus.java index 8a222d7ec..4f2ae34f8 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlayerStatus.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlayerStatus.java @@ -12,7 +12,7 @@ public enum PlayerStatus { INITIALIZING(9), // playback service is loading the Playable's metadata INITIALIZED(10); // playback service was started, data source of media player was set. - private int statusValue; + private final int statusValue; private static final PlayerStatus[] fromOrdinalLookup; static { 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 9b574be47..83aa4c780 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 @@ -76,7 +76,7 @@ public final class DBReader { cursor = adapter.getAllFeedsCursor(); List<Feed> feeds = new ArrayList<>(cursor.getCount()); while (cursor.moveToNext()) { - Feed feed = extractFeedFromCursorRow(adapter, cursor); + Feed feed = extractFeedFromCursorRow(cursor); feeds.add(feed); } return feeds; @@ -244,7 +244,7 @@ public final class DBReader { return result; } - private static Feed extractFeedFromCursorRow(PodDBAdapter adapter, Cursor cursor) { + private static Feed extractFeedFromCursorRow(Cursor cursor) { Feed feed = Feed.fromCursor(cursor); FeedPreferences preferences = FeedPreferences.fromCursor(cursor); feed.setPreferences(preferences); @@ -582,7 +582,7 @@ public final class DBReader { try { cursor = adapter.getFeedCursor(feedId); if (cursor.moveToNext()) { - feed = extractFeedFromCursorRow(adapter, cursor); + feed = extractFeedFromCursorRow(cursor); feed.setItems(getFeedItemList(feed)); } else { Log.e(TAG, "getFeed could not find feed with id " + feedId); @@ -1009,7 +1009,7 @@ public final class DBReader { Cursor feedCursor = adapter.getFeedsInFlattrQueueCursor(); if (feedCursor.moveToFirst()) { do { - result.add(extractFeedFromCursorRow(adapter, feedCursor)); + result.add(extractFeedFromCursorRow(feedCursor)); } while (feedCursor.moveToNext()); } feedCursor.close(); diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java index 8eed10cd7..ba7d4b47b 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBTasks.java @@ -1,11 +1,9 @@ package de.danoeh.antennapod.core.storage; import android.content.Context; -import android.content.Intent; import android.content.SharedPreferences; import android.database.Cursor; import android.support.annotation.Nullable; -import android.support.v4.content.ContextCompat; import android.util.Log; import java.util.ArrayList; @@ -777,10 +775,8 @@ public final class DBTasks { */ abstract static class QueryTask<T> implements Callable<T> { private T result; - private final Context context; public QueryTask(Context context) { - this.context = context; } @Override diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBUpgrader.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBUpgrader.java index 29ed5f7f9..0beb765e7 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBUpgrader.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBUpgrader.java @@ -5,6 +5,7 @@ import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.media.MediaMetadataRetriever; import android.util.Log; + import de.danoeh.antennapod.core.feed.FeedItem; class DBUpgrader { 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 8bb5bc31a..bbe6145ea 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 @@ -7,7 +7,6 @@ import android.content.SharedPreferences; import android.preference.PreferenceManager; import android.util.Log; -import de.danoeh.antennapod.core.util.IntentUtils; import org.shredzone.flattr4j.model.Flattr; import java.io.File; @@ -42,6 +41,7 @@ import de.danoeh.antennapod.core.preferences.PlaybackPreferences; import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.service.download.DownloadStatus; import de.danoeh.antennapod.core.service.playback.PlaybackService; +import de.danoeh.antennapod.core.util.IntentUtils; import de.danoeh.antennapod.core.util.LongList; import de.danoeh.antennapod.core.util.Permutor; import de.danoeh.antennapod.core.util.flattr.FlattrStatus; diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DownloadRequester.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DownloadRequester.java index 827874f54..892a4675a 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/DownloadRequester.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DownloadRequester.java @@ -9,8 +9,6 @@ import android.text.TextUtils; import android.util.Log; import android.webkit.URLUtil; -import de.danoeh.antennapod.core.service.playback.PlaybackService; -import de.danoeh.antennapod.core.util.IntentUtils; import org.apache.commons.io.FilenameUtils; import java.io.File; @@ -25,6 +23,7 @@ import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.service.download.DownloadRequest; import de.danoeh.antennapod.core.service.download.DownloadService; import de.danoeh.antennapod.core.util.FileNameGenerator; +import de.danoeh.antennapod.core.util.IntentUtils; import de.danoeh.antennapod.core.util.URLChecker; 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 aa5706ad0..f91e2ad08 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 @@ -19,6 +19,8 @@ import de.danoeh.antennapod.core.util.comparator.SearchResultValueComparator; * Performs search on Feeds and FeedItems */ public class FeedSearcher { + private FeedSearcher(){} + private static final String TAG = "FeedSearcher"; diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java b/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java index 51b41d3b3..4566df2fc 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java @@ -12,8 +12,20 @@ import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase.CursorFactory; import android.database.sqlite.SQLiteOpenHelper; import android.media.MediaMetadataRetriever; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.text.TextUtils; import android.util.Log; + +import org.apache.commons.io.FileUtils; + +import java.io.File; +import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Set; + import de.danoeh.antennapod.core.R; import de.danoeh.antennapod.core.event.ProgressEvent; import de.danoeh.antennapod.core.feed.Chapter; @@ -26,14 +38,6 @@ import de.danoeh.antennapod.core.service.download.DownloadStatus; import de.danoeh.antennapod.core.util.LongIntMap; import de.danoeh.antennapod.core.util.flattr.FlattrStatus; import de.greenrobot.event.EventBus; -import org.apache.commons.io.FileUtils; - -import java.io.File; -import java.io.IOException; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Set; // TODO Remove media column from feeditem table @@ -297,7 +301,6 @@ public class PodDBAdapter { private static Context context; private static volatile SQLiteDatabase db; - private static int counter = 0; public static void init(Context context) { PodDBAdapter.context = context.getApplicationContext(); @@ -317,9 +320,6 @@ public class PodDBAdapter { } public synchronized PodDBAdapter open() { - counter++; - Log.v(TAG, "Opening DB #" + counter); - if (db == null || !db.isOpen() || db.isReadOnly()) { db = openDb(); } @@ -330,7 +330,6 @@ public class PodDBAdapter { SQLiteDatabase newDb; try { newDb = SingletonHolder.dbHelper.getWritableDatabase(); - newDb.enableWriteAheadLogging(); } catch (SQLException ex) { Log.e(TAG, Log.getStackTraceString(ex)); newDb = SingletonHolder.dbHelper.getReadableDatabase(); @@ -339,14 +338,7 @@ public class PodDBAdapter { } public synchronized void close() { - counter--; - Log.v(TAG, "Closing DB #" + counter); - - if (counter == 0) { - Log.v(TAG, "Closing DB, really"); - db.close(); - db = null; - } + // do nothing } public static boolean deleteDatabase() { diff --git a/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/NSRSS20.java b/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/NSRSS20.java index a1100a976..e391af1b2 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/NSRSS20.java +++ b/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/NSRSS20.java @@ -5,7 +5,6 @@ import android.util.Log; import org.xml.sax.Attributes; -import de.danoeh.antennapod.core.feed.Feed; import de.danoeh.antennapod.core.feed.FeedItem; import de.danoeh.antennapod.core.feed.FeedMedia; import de.danoeh.antennapod.core.syndication.handler.HandlerState; @@ -22,9 +21,6 @@ public class NSRSS20 extends Namespace { private static final String TAG = "NSRSS20"; - private static final String NSTAG = "rss"; - private static final String NSURI = ""; - public static final String CHANNEL = "channel"; public static final String ITEM = "item"; private static final String GUID = "guid"; diff --git a/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/Namespace.java b/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/Namespace.java index 1836bbec1..e5fbdb9bb 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/Namespace.java +++ b/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/Namespace.java @@ -15,7 +15,6 @@ public abstract class Namespace { public abstract SyndElement handleElementStart(String localName, HandlerState state, Attributes attributes); /** Called by a Feedhandler when in endElement and it detects a namespace element - * @return true if namespace handled the element, false if it ignored it * */ public abstract void handleElementEnd(String localName, HandlerState state); diff --git a/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/atom/NSAtom.java b/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/atom/NSAtom.java index aab1b1a5b..83957456a 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/atom/NSAtom.java +++ b/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/atom/NSAtom.java @@ -47,8 +47,6 @@ public class NSAtom extends Namespace { private static final String LINK_REL_ARCHIVES = "archives"; private static final String LINK_REL_ENCLOSURE = "enclosure"; private static final String LINK_REL_PAYMENT = "payment"; - private static final String LINK_REL_RELATED = "related"; - private static final String LINK_REL_SELF = "self"; private static final String LINK_REL_NEXT = "next"; // type-values private static final String LINK_TYPE_ATOM = "application/atom+xml"; diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/Converter.java b/core/src/main/java/de/danoeh/antennapod/core/util/Converter.java index b513fbe99..3cb226add 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/Converter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/Converter.java @@ -28,7 +28,6 @@ public final class Converter { /** Determines the length of the number for best readability.*/ private static final int NUM_LENGTH = 1024; - private static final int DAYS_MIL = 86400000; private static final int HOURS_MIL = 3600000; private static final int MINUTES_MIL = 60000; private static final int SECONDS_MIL = 1000; diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/DateUtils.java b/core/src/main/java/de/danoeh/antennapod/core/util/DateUtils.java index e17d8de3e..5141e3a78 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/DateUtils.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/DateUtils.java @@ -17,7 +17,9 @@ import java.util.TimeZone; */ public class DateUtils { - private static final String TAG = "DateUtils"; + private DateUtils(){} + + private static final String TAG = "DateUtils"; private static final TimeZone defaultTimezone = TimeZone.getTimeZone("GMT"); @@ -135,7 +137,7 @@ public class DateUtils { if (parts.length >= 2) { result += Integer.parseInt(parts[idx]) * 60000L; idx++; - result += (Float.parseFloat(parts[idx])) * 1000L; + result += (long) (Float.parseFloat(parts[idx]) * 1000L); } return result; } diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/FeedItemUtil.java b/core/src/main/java/de/danoeh/antennapod/core/util/FeedItemUtil.java index 76a6549ae..826c06822 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/FeedItemUtil.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/FeedItemUtil.java @@ -5,6 +5,7 @@ import java.util.List; import de.danoeh.antennapod.core.feed.FeedItem; public class FeedItemUtil { + private FeedItemUtil(){} public static int indexOfItemWithDownloadUrl(List<FeedItem> items, String downloadUrl) { if(items == null) { diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/FeedUpdateUtils.java b/core/src/main/java/de/danoeh/antennapod/core/util/FeedUpdateUtils.java index 24e0da9ed..afaf13390 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/FeedUpdateUtils.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/FeedUpdateUtils.java @@ -2,20 +2,30 @@ package de.danoeh.antennapod.core.util; import android.content.Context; import android.util.Log; + +import org.awaitility.core.ConditionTimeoutException; + +import java.util.concurrent.TimeUnit; + import de.danoeh.antennapod.core.storage.DBTasks; +import static org.awaitility.Awaitility.with; + public class FeedUpdateUtils { private static final String TAG = "FeedUpdateUtils"; - private FeedUpdateUtils() { - - } + private FeedUpdateUtils() {} public static void startAutoUpdate(Context context, Runnable callback) { - if (NetworkUtils.networkAvailable() && NetworkUtils.isDownloadAllowed()) { + try { + with().pollInterval(1, TimeUnit.SECONDS) + .await() + .atMost(10, TimeUnit.SECONDS) + .until(() -> NetworkUtils.networkAvailable() && NetworkUtils.isDownloadAllowed()); DBTasks.refreshAllFeeds(context, null, callback); - } else { + } catch (ConditionTimeoutException ignore) { Log.d(TAG, "Blocking automatic update: no wifi available / no mobile updates allowed"); } } + } diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/IntentUtils.java b/core/src/main/java/de/danoeh/antennapod/core/util/IntentUtils.java index aaaaf8f4d..e81ab47ed 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/IntentUtils.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/IntentUtils.java @@ -8,6 +8,7 @@ import android.content.pm.ResolveInfo; import java.util.List; public class IntentUtils { + private IntentUtils(){} /* * Checks if there is at least one exported activity that can be performed for the intent diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/LangUtils.java b/core/src/main/java/de/danoeh/antennapod/core/util/LangUtils.java index 7ec7f84c4..90e0b0981 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/LangUtils.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/LangUtils.java @@ -5,6 +5,9 @@ import android.support.v4.util.ArrayMap; import java.nio.charset.Charset; public class LangUtils { + + private LangUtils(){} + public static final Charset UTF_8 = Charset.forName("UTF-8"); private static final ArrayMap<String, String> languages; diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/NetworkUtils.java b/core/src/main/java/de/danoeh/antennapod/core/util/NetworkUtils.java index 3349ed176..b34ba196d 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/NetworkUtils.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/NetworkUtils.java @@ -27,6 +27,7 @@ import okhttp3.Request; import okhttp3.Response; public class NetworkUtils { + private NetworkUtils(){} private static final String TAG = NetworkUtils.class.getSimpleName(); diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/RewindAfterPauseUtils.java b/core/src/main/java/de/danoeh/antennapod/core/util/RewindAfterPauseUtils.java index ee306a401..d1818aeef 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/RewindAfterPauseUtils.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/RewindAfterPauseUtils.java @@ -9,6 +9,7 @@ import java.util.concurrent.TimeUnit; * Media file should be "rewinded" x seconds after user resumes the playback. */ public class RewindAfterPauseUtils { + private RewindAfterPauseUtils(){} public static final long ELAPSED_TIME_FOR_SHORT_REWIND = TimeUnit.MINUTES.toMillis(1); public static final long ELAPSED_TIME_FOR_MEDIUM_REWIND = TimeUnit.HOURS.toMillis(1); diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/StorageUtils.java b/core/src/main/java/de/danoeh/antennapod/core/util/StorageUtils.java index 1ef81bf64..3a6bf5755 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/StorageUtils.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/StorageUtils.java @@ -14,6 +14,8 @@ import de.danoeh.antennapod.core.preferences.UserPreferences; * Utility functions for handling storage errors */ public class StorageUtils { + private StorageUtils(){} + private static final String TAG = "StorageUtils"; public static boolean storageAvailable() { diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/ThemeUtils.java b/core/src/main/java/de/danoeh/antennapod/core/util/ThemeUtils.java index 03d0f10ff..14f091249 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/ThemeUtils.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/ThemeUtils.java @@ -3,14 +3,15 @@ package de.danoeh.antennapod.core.util; import android.content.Context; import android.support.annotation.AttrRes; import android.support.annotation.ColorInt; -import android.support.annotation.ColorRes; import android.util.Log; - import android.util.TypedValue; + import de.danoeh.antennapod.core.R; import de.danoeh.antennapod.core.preferences.UserPreferences; public class ThemeUtils { + private ThemeUtils(){} + private static final String TAG = "ThemeUtils"; public static int getSelectionBackgroundColor() { diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/download/AutoUpdateManager.java b/core/src/main/java/de/danoeh/antennapod/core/util/download/AutoUpdateManager.java index ad723c685..3a2a4ac80 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/download/AutoUpdateManager.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/download/AutoUpdateManager.java @@ -11,12 +11,13 @@ import android.os.Build; import android.os.SystemClock; import android.support.annotation.RequiresApi; import android.util.Log; -import de.danoeh.antennapod.core.receiver.FeedUpdateReceiver; -import de.danoeh.antennapod.core.service.FeedUpdateJobService; import java.util.Calendar; import java.util.concurrent.TimeUnit; +import de.danoeh.antennapod.core.receiver.FeedUpdateReceiver; +import de.danoeh.antennapod.core.service.FeedUpdateJobService; + public class AutoUpdateManager { private static final int JOB_ID_FEED_UPDATE = 42; private static final String TAG = "AutoUpdateManager"; diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/flattr/FlattrServiceCreator.java b/core/src/main/java/de/danoeh/antennapod/core/util/flattr/FlattrServiceCreator.java index 45cb56988..d4d5843d2 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/flattr/FlattrServiceCreator.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/flattr/FlattrServiceCreator.java @@ -11,7 +11,9 @@ import de.danoeh.antennapod.core.BuildConfig; /** Ensures that only one instance of the FlattrService class exists at a time */ class FlattrServiceCreator { - private static final String TAG = "FlattrServiceCreator"; + private FlattrServiceCreator(){} + + public static final String TAG = "FlattrServiceCreator"; private static volatile FlattrService flattrService; diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/flattr/FlattrUtils.java b/core/src/main/java/de/danoeh/antennapod/core/util/flattr/FlattrUtils.java index 313d1c2f2..919fc82f2 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/flattr/FlattrUtils.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/flattr/FlattrUtils.java @@ -1,8 +1,6 @@ package de.danoeh.antennapod.core.util.flattr; import android.content.Context; -import android.content.DialogInterface; -import android.content.DialogInterface.OnClickListener; import android.content.Intent; import android.content.SharedPreferences; import android.net.Uri; @@ -36,6 +34,8 @@ import de.danoeh.antennapod.core.storage.DBWriter; */ public class FlattrUtils { + private FlattrUtils(){} + private static final String TAG = "FlattrUtils"; private static final String HOST_NAME = "de.danoeh.antennapod"; diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/gui/MoreContentListFooterUtil.java b/core/src/main/java/de/danoeh/antennapod/core/util/gui/MoreContentListFooterUtil.java index 386f46724..6e5c3e84b 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/gui/MoreContentListFooterUtil.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/gui/MoreContentListFooterUtil.java @@ -27,8 +27,8 @@ public class MoreContentListFooterUtil { } public void setLoadingState(boolean newState) { - final ImageView imageView = (ImageView) root.findViewById(R.id.imgExpand); - final ProgressBar progressBar = (ProgressBar) root.findViewById(R.id.progBar); + final ImageView imageView = root.findViewById(R.id.imgExpand); + final ProgressBar progressBar = root.findViewById(R.id.progBar); if (newState) { imageView.setVisibility(View.GONE); progressBar.setVisibility(View.VISIBLE); diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/gui/NotificationUtils.java b/core/src/main/java/de/danoeh/antennapod/core/util/gui/NotificationUtils.java index 2a537dc62..52a43aab2 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/gui/NotificationUtils.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/gui/NotificationUtils.java @@ -6,6 +6,7 @@ import android.app.NotificationManager; import android.content.Context; import android.os.Build; import android.support.annotation.RequiresApi; + import de.danoeh.antennapod.core.R; public class NotificationUtils { diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/playback/MediaPlayerError.java b/core/src/main/java/de/danoeh/antennapod/core/util/playback/MediaPlayerError.java index a576dd497..b04c02075 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/playback/MediaPlayerError.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/playback/MediaPlayerError.java @@ -7,6 +7,7 @@ import de.danoeh.antennapod.core.R; /** Utility class for MediaPlayer errors. */ public class MediaPlayerError { + private MediaPlayerError(){} /** Get a human-readable string for a specific error code. */ public static String getErrorString(Context context, int code) { diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/playback/Playable.java b/core/src/main/java/de/danoeh/antennapod/core/util/playback/Playable.java index ff7f5b79d..da9b96430 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/playback/Playable.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/playback/Playable.java @@ -176,6 +176,8 @@ public interface Playable extends Parcelable, * Provides utility methods for Playable objects. */ class PlayableUtils { + private PlayableUtils(){} + private static final String TAG = "PlayableUtils"; /** 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 036ca446c..0555351d4 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 @@ -698,7 +698,7 @@ public abstract class PlaybackController { return org.antennapod.audio.MediaPlayer.isPrestoLibraryInstalled(activity.getApplicationContext()) || UserPreferences.useSonic() || Build.VERSION.SDK_INT >= 23 - || playbackService != null && playbackService.canSetSpeed(); + || (playbackService != null && playbackService.canSetSpeed()); } public void setPlaybackSpeed(float speed) { diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackServiceStarter.java b/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackServiceStarter.java index 3ba553d12..f7d2ee409 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackServiceStarter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackServiceStarter.java @@ -3,7 +3,9 @@ package de.danoeh.antennapod.core.util.playback; import android.content.Context; import android.content.Intent; import android.media.MediaPlayer; +import android.support.annotation.NonNull; import android.support.v4.content.ContextCompat; + import de.danoeh.antennapod.core.preferences.PlaybackPreferences; import de.danoeh.antennapod.core.service.playback.PlaybackService; |