From fb1fcb06005e925f6c1ebabeb1f31007bc86a48c Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Sun, 6 Jul 2014 13:48:38 +0200 Subject: [PATCH] Increased use of library methods --- .../activity/AudioplayerActivity.java | 20 +++- .../DownloadAuthenticationActivity.java | 6 +- .../antennapod/activity/MainActivity.java | 5 +- .../activity/StorageErrorActivity.java | 5 +- .../antennapod/adapter/ActionButtonUtils.java | 9 +- .../adapter/DefaultActionButtonCallback.java | 5 +- .../asynctask/DownloadObserver.java | 11 +- .../asynctask/FlattrClickWorker.java | 3 +- .../antennapod/asynctask/ImageDiskCache.java | 10 +- .../antennapod/dialog/FeedItemDialog.java | 11 +- .../antennapod/feed/EventDistributor.java | 8 +- .../antennapod/fragment/ItemlistFragment.java | 5 +- .../fragment/gpodnet/SearchListFragment.java | 8 +- .../fragment/gpodnet/TagFragment.java | 7 +- .../antennapod/gpoddernet/GpodnetService.java | 104 ++++++++---------- .../gpoddernet/model/GpodnetDevice.java | 6 +- .../gpoddernet/model/GpodnetPodcast.java | 9 +- .../model/GpodnetSubscriptionChange.java | 9 +- .../gpoddernet/model/GpodnetTag.java | 6 +- .../preferences/PlaybackPreferences.java | 7 +- .../preferences/UserPreferences.java | 5 +- .../receiver/AlarmUpdateReceiver.java | 7 +- .../receiver/ConnectivityActionReceiver.java | 5 +- .../receiver/FeedUpdateReceiver.java | 5 +- .../antennapod/receiver/PlayerWidget.java | 7 +- .../service/download/DownloadRequest.java | 23 ++-- .../service/download/DownloadService.java | 28 ++--- .../service/download/DownloadStatus.java | 11 +- .../service/playback/PlaybackService.java | 12 +- .../playback/PlaybackServiceMediaPlayer.java | 24 ++-- .../playback/PlaybackServiceTaskManager.java | 15 ++- src/de/danoeh/antennapod/spa/SPAUtil.java | 5 +- .../antennapod/storage/DownloadRequester.java | 6 +- .../antennapod/storage/PodDBAdapter.java | 22 ++-- .../antennapod/util/playback/Playable.java | 6 +- .../util/playback/PlaybackController.java | 10 +- .../antennapod/util/playback/Timeline.java | 3 +- 37 files changed, 251 insertions(+), 197 deletions(-) diff --git a/src/de/danoeh/antennapod/activity/AudioplayerActivity.java b/src/de/danoeh/antennapod/activity/AudioplayerActivity.java index 54a22ec0b..92094ec5a 100644 --- a/src/de/danoeh/antennapod/activity/AudioplayerActivity.java +++ b/src/de/danoeh/antennapod/activity/AudioplayerActivity.java @@ -16,16 +16,27 @@ import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnLongClickListener; -import android.view.Window; -import android.widget.*; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.ImageButton; import android.widget.ImageView.ScaleType; +import android.widget.ListView; +import android.widget.TextView; + +import org.apache.commons.lang3.StringUtils; + import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.R; import de.danoeh.antennapod.adapter.ChapterListAdapter; import de.danoeh.antennapod.adapter.NavListAdapter; import de.danoeh.antennapod.asynctask.ImageLoader; import de.danoeh.antennapod.dialog.VariableSpeedDialog; -import de.danoeh.antennapod.feed.*; +import de.danoeh.antennapod.feed.Chapter; +import de.danoeh.antennapod.feed.EventDistributor; +import de.danoeh.antennapod.feed.Feed; +import de.danoeh.antennapod.feed.MediaType; +import de.danoeh.antennapod.feed.SimpleChapter; import de.danoeh.antennapod.fragment.CoverFragment; import de.danoeh.antennapod.fragment.ItemDescriptionFragment; import de.danoeh.antennapod.preferences.UserPreferences; @@ -215,8 +226,7 @@ public class AudioplayerActivity extends MediaplayerActivity implements ItemDesc @Override protected void onResume() { super.onResume(); - if (getIntent().getAction() != null - && getIntent().getAction().equals(Intent.ACTION_VIEW)) { + if (StringUtils.equals(getIntent().getAction(), Intent.ACTION_VIEW)) { Intent intent = getIntent(); if (BuildConfig.DEBUG) Log.d(TAG, "Received VIEW intent: " diff --git a/src/de/danoeh/antennapod/activity/DownloadAuthenticationActivity.java b/src/de/danoeh/antennapod/activity/DownloadAuthenticationActivity.java index 4b8420e45..c5f25d813 100644 --- a/src/de/danoeh/antennapod/activity/DownloadAuthenticationActivity.java +++ b/src/de/danoeh/antennapod/activity/DownloadAuthenticationActivity.java @@ -9,6 +9,9 @@ import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; + +import org.apache.commons.lang3.Validate; + import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.R; import de.danoeh.antennapod.preferences.UserPreferences; @@ -58,7 +61,8 @@ public class DownloadAuthenticationActivity extends ActionBarActivity { butCancel = (Button) findViewById(R.id.butCancel); txtvDescription = (TextView) findViewById(R.id.txtvDescription); - if (!getIntent().hasExtra(ARG_DOWNLOAD_REQUEST)) throw new IllegalArgumentException("Download request missing"); + Validate.isTrue(getIntent().hasExtra(ARG_DOWNLOAD_REQUEST), "Download request missing"); + request = getIntent().getParcelableExtra(ARG_DOWNLOAD_REQUEST); sendToDownloadRequester = getIntent().getBooleanExtra(ARG_SEND_TO_DOWNLOAD_REQUESTER_BOOL, false); diff --git a/src/de/danoeh/antennapod/activity/MainActivity.java b/src/de/danoeh/antennapod/activity/MainActivity.java index b1dad0934..7e83c5d95 100644 --- a/src/de/danoeh/antennapod/activity/MainActivity.java +++ b/src/de/danoeh/antennapod/activity/MainActivity.java @@ -19,6 +19,9 @@ import android.util.Log; import android.view.*; import android.widget.AdapterView; import android.widget.ListView; + +import org.apache.commons.lang3.Validate; + import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.R; import de.danoeh.antennapod.adapter.NavListAdapter; @@ -219,7 +222,7 @@ public class MainActivity extends ActionBarActivity { } public void loadChildFragment(Fragment fragment) { - if (fragment == null) throw new IllegalArgumentException("fragment = null"); + Validate.notNull(fragment); FragmentManager fm = getSupportFragmentManager(); fm.beginTransaction() .replace(R.id.main_view, fragment, "main") diff --git a/src/de/danoeh/antennapod/activity/StorageErrorActivity.java b/src/de/danoeh/antennapod/activity/StorageErrorActivity.java index 2cd56ba8b..d8a137eb9 100644 --- a/src/de/danoeh/antennapod/activity/StorageErrorActivity.java +++ b/src/de/danoeh/antennapod/activity/StorageErrorActivity.java @@ -7,6 +7,9 @@ import android.content.IntentFilter; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.util.Log; + +import org.apache.commons.lang3.StringUtils; + import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.R; import de.danoeh.antennapod.preferences.UserPreferences; @@ -54,7 +57,7 @@ public class StorageErrorActivity extends ActionBarActivity { @Override public void onReceive(Context context, Intent intent) { - if (intent.getAction().equals(Intent.ACTION_MEDIA_MOUNTED)) { + if (StringUtils.equals(intent.getAction(), Intent.ACTION_MEDIA_MOUNTED)) { if (intent.getBooleanExtra("read-only", true)) { if (BuildConfig.DEBUG) Log.d(TAG, "Media was mounted; Finishing activity"); diff --git a/src/de/danoeh/antennapod/adapter/ActionButtonUtils.java b/src/de/danoeh/antennapod/adapter/ActionButtonUtils.java index 17c61a86c..4308f4f2c 100644 --- a/src/de/danoeh/antennapod/adapter/ActionButtonUtils.java +++ b/src/de/danoeh/antennapod/adapter/ActionButtonUtils.java @@ -4,6 +4,9 @@ import android.content.Context; import android.content.res.TypedArray; import android.view.View; import android.widget.ImageButton; + +import org.apache.commons.lang3.Validate; + import de.danoeh.antennapod.R; import de.danoeh.antennapod.feed.FeedItem; import de.danoeh.antennapod.feed.FeedMedia; @@ -20,7 +23,8 @@ public class ActionButtonUtils { private final Context context; public ActionButtonUtils(Context context) { - if (context == null) throw new IllegalArgumentException("context = null"); + Validate.notNull(context); + this.context = context; drawables = context.obtainStyledAttributes(new int[]{ R.attr.av_play, R.attr.navigation_cancel, R.attr.av_download, R.attr.navigation_chapters}); @@ -32,7 +36,8 @@ public class ActionButtonUtils { * action button so that it matches the state of the FeedItem. */ public void configureActionButton(ImageButton butSecondary, FeedItem item) { - if (butSecondary == null || item == null) throw new IllegalArgumentException("butSecondary or item was null"); + Validate.isTrue(butSecondary != null && item != null, "butSecondary or item was null"); + final FeedMedia media = item.getMedia(); if (media != null) { final boolean isDownloadingMedia = DownloadRequester.getInstance().isDownloadingFile(media); diff --git a/src/de/danoeh/antennapod/adapter/DefaultActionButtonCallback.java b/src/de/danoeh/antennapod/adapter/DefaultActionButtonCallback.java index 3acd587af..801cd1e12 100644 --- a/src/de/danoeh/antennapod/adapter/DefaultActionButtonCallback.java +++ b/src/de/danoeh/antennapod/adapter/DefaultActionButtonCallback.java @@ -2,6 +2,9 @@ package de.danoeh.antennapod.adapter; import android.content.Context; import android.widget.Toast; + +import org.apache.commons.lang3.Validate; + import de.danoeh.antennapod.R; import de.danoeh.antennapod.dialog.DownloadRequestErrorDialogCreator; import de.danoeh.antennapod.feed.FeedItem; @@ -19,7 +22,7 @@ public class DefaultActionButtonCallback implements ActionButtonCallback { private final Context context; public DefaultActionButtonCallback(Context context) { - if (context == null) throw new IllegalArgumentException("context = null"); + Validate.notNull(context); this.context = context; } diff --git a/src/de/danoeh/antennapod/asynctask/DownloadObserver.java b/src/de/danoeh/antennapod/asynctask/DownloadObserver.java index 1c5003ab3..21ae5291e 100644 --- a/src/de/danoeh/antennapod/asynctask/DownloadObserver.java +++ b/src/de/danoeh/antennapod/asynctask/DownloadObserver.java @@ -5,6 +5,9 @@ import android.content.*; import android.os.Handler; import android.os.IBinder; import android.util.Log; + +import org.apache.commons.lang3.Validate; + import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.service.download.DownloadService; import de.danoeh.antennapod.service.download.Downloader; @@ -45,9 +48,9 @@ public class DownloadObserver { * @throws java.lang.IllegalArgumentException if one of the arguments is null. */ public DownloadObserver(Activity activity, Handler handler, Callback callback) { - if (activity == null) throw new IllegalArgumentException("activity = null"); - if (handler == null) throw new IllegalArgumentException("handler = null"); - if (callback == null) throw new IllegalArgumentException("callback = null"); + Validate.notNull(activity); + Validate.notNull(handler); + Validate.notNull(callback); this.activity = activity; this.handler = handler; @@ -166,7 +169,7 @@ public class DownloadObserver { } public void setActivity(Activity activity) { - if (activity == null) throw new IllegalArgumentException("activity = null"); + Validate.notNull(activity); this.activity = activity; } diff --git a/src/de/danoeh/antennapod/asynctask/FlattrClickWorker.java b/src/de/danoeh/antennapod/asynctask/FlattrClickWorker.java index 06828944c..9210ac1d1 100644 --- a/src/de/danoeh/antennapod/asynctask/FlattrClickWorker.java +++ b/src/de/danoeh/antennapod/asynctask/FlattrClickWorker.java @@ -11,6 +11,7 @@ import android.support.v4.app.NotificationCompat; import android.util.Log; import android.widget.Toast; +import org.apache.commons.lang3.Validate; import org.shredzone.flattr4j.exception.FlattrException; import java.util.LinkedList; @@ -65,7 +66,7 @@ public class FlattrClickWorker extends AsyncTask getPodcastsForTag(GpodnetTag tag, int count) throws GpodnetServiceException { - if (tag == null) { - throw new IllegalArgumentException( - "Tag and title of tag must not be null"); - } + Validate.notNull(tag); + try { URI uri = new URI(BASE_SCHEME, BASE_HOST, String.format( "/api/2/tag/%s/%d.json", tag.getName(), count), null); @@ -120,9 +124,8 @@ public class GpodnetService { */ public List getPodcastToplist(int count) throws GpodnetServiceException { - if (count < 1 || count > 100) { - throw new IllegalArgumentException("Count must be in range 1..100"); - } + Validate.isTrue(count >= 1 && count <= 100, "Count must be in range 1..100"); + try { URI uri = new URI(BASE_SCHEME, BASE_HOST, String.format( "/toplist/%d.json", count), null); @@ -155,9 +158,8 @@ public class GpodnetService { * @throws GpodnetServiceAuthenticationException If there is an authentication error. */ public List getSuggestions(int count) throws GpodnetServiceException { - if (count < 1 || count > 100) { - throw new IllegalArgumentException("Count must be in range 1..100"); - } + Validate.isTrue(count >= 1 && count <= 100, "Count must be in range 1..100"); + try { URI uri = new URI(BASE_SCHEME, BASE_HOST, String.format( "/suggestions/%d.json", count), null); @@ -220,9 +222,8 @@ public class GpodnetService { */ public List getDevices(String username) throws GpodnetServiceException { - if (username == null) { - throw new IllegalArgumentException("Username must not be null"); - } + Validate.notNull(username); + try { URI uri = new URI(BASE_SCHEME, BASE_HOST, String.format( "/api/2/devices/%s.json", username), null); @@ -255,10 +256,9 @@ public class GpodnetService { public void configureDevice(String username, String deviceId, String caption, GpodnetDevice.DeviceType type) throws GpodnetServiceException { - if (username == null || deviceId == null) { - throw new IllegalArgumentException( - "Username and device ID must not be null"); - } + Validate.notNull(username); + Validate.notNull(deviceId); + try { URI uri = new URI(BASE_SCHEME, BASE_HOST, String.format( "/api/2/devices/%s/%s.json", username, deviceId), null); @@ -303,10 +303,9 @@ public class GpodnetService { */ public String getSubscriptionsOfDevice(String username, String deviceId) throws GpodnetServiceException { - if (username == null || deviceId == null) { - throw new IllegalArgumentException( - "Username and device ID must not be null"); - } + Validate.notNull(username); + Validate.notNull(deviceId); + try { URI uri = new URI(BASE_SCHEME, BASE_HOST, String.format( "/subscriptions/%s/%s.opml", username, deviceId), null); @@ -332,9 +331,8 @@ public class GpodnetService { */ public String getSubscriptionsOfUser(String username) throws GpodnetServiceException { - if (username == null) { - throw new IllegalArgumentException("Username must not be null"); - } + Validate.notNull(username); + try { URI uri = new URI(BASE_SCHEME, BASE_HOST, String.format( "/subscriptions/%s.opml", username), null); @@ -406,10 +404,11 @@ public class GpodnetService { */ public GpodnetUploadChangesResponse uploadChanges(String username, String deviceId, Collection added, Collection removed) throws GpodnetServiceException { - if (username == null || deviceId == null || added == null || removed == null) { - throw new IllegalArgumentException( - "Username, device ID, added and removed must not be null"); - } + Validate.notNull(username); + Validate.notNull(deviceId); + Validate.notNull(added); + Validate.notNull(removed); + try { URI uri = new URI(BASE_SCHEME, BASE_HOST, String.format( "/api/2/subscriptions/%s/%s.json", username, deviceId), null); @@ -453,10 +452,9 @@ public class GpodnetService { */ public GpodnetSubscriptionChange getSubscriptionChanges(String username, String deviceId, long timestamp) throws GpodnetServiceException { - if (username == null || deviceId == null) { - throw new IllegalArgumentException( - "Username and device ID must not be null"); - } + Validate.notNull(username); + Validate.notNull(deviceId); + String params = String.format("since=%d", timestamp); String path = String.format("/api/2/subscriptions/%s/%s.json", username, deviceId); @@ -486,10 +484,9 @@ public class GpodnetService { */ public void authenticate(String username, String password) throws GpodnetServiceException { - if (username == null || password == null) { - throw new IllegalArgumentException( - "Username and password must not be null"); - } + Validate.notNull(username); + Validate.notNull(password); + URI uri; try { uri = new URI(BASE_SCHEME, BASE_HOST, String.format( @@ -517,9 +514,8 @@ public class GpodnetService { private String executeRequest(HttpRequestBase request) throws GpodnetServiceException { - if (request == null) { - throw new IllegalArgumentException("request must not be null"); - } + Validate.notNull(request); + String responseString = null; HttpResponse response = null; try { @@ -586,9 +582,8 @@ public class GpodnetService { private String getStringFromEntity(HttpEntity entity) throws GpodnetServiceException { - if (entity == null) { - throw new IllegalArgumentException("entity must not be null"); - } + Validate.notNull(entity); + ByteArrayOutputStream outputStream; int contentLength = (int) entity.getContentLength(); if (contentLength > 0) { @@ -613,9 +608,7 @@ public class GpodnetService { private void checkStatusCode(HttpResponse response) throws GpodnetServiceException { - if (response == null) { - throw new IllegalArgumentException("response must not be null"); - } + Validate.notNull(response); int responseCode = response.getStatusLine().getStatusCode(); if (responseCode != HttpStatus.SC_OK) { if (responseCode == HttpStatus.SC_UNAUTHORIZED) { @@ -629,9 +622,8 @@ public class GpodnetService { private List readPodcastListFromJSONArray(JSONArray array) throws JSONException { - if (array == null) { - throw new IllegalArgumentException("array must not be null"); - } + Validate.notNull(array); + List result = new ArrayList( array.length()); for (int i = 0; i < array.length(); i++) { @@ -685,9 +677,8 @@ public class GpodnetService { private List readDeviceListFromJSONArray(JSONArray array) throws JSONException { - if (array == null) { - throw new IllegalArgumentException("array must not be null"); - } + Validate.notNull(array); + List result = new ArrayList( array.length()); for (int i = 0; i < array.length(); i++) { @@ -707,9 +698,8 @@ public class GpodnetService { private GpodnetSubscriptionChange readSubscriptionChangesFromJSONObject( JSONObject object) throws JSONException { - if (object == null) { - throw new IllegalArgumentException("object must not be null"); - } + Validate.notNull(object); + List added = new LinkedList(); JSONArray jsonAdded = object.getJSONArray("add"); for (int i = 0; i < jsonAdded.length(); i++) { diff --git a/src/de/danoeh/antennapod/gpoddernet/model/GpodnetDevice.java b/src/de/danoeh/antennapod/gpoddernet/model/GpodnetDevice.java index ae7199fcc..86a2171fa 100644 --- a/src/de/danoeh/antennapod/gpoddernet/model/GpodnetDevice.java +++ b/src/de/danoeh/antennapod/gpoddernet/model/GpodnetDevice.java @@ -1,5 +1,7 @@ package de.danoeh.antennapod.gpoddernet.model; +import org.apache.commons.lang3.Validate; + public class GpodnetDevice { private String id; @@ -9,9 +11,7 @@ public class GpodnetDevice { public GpodnetDevice(String id, String caption, String type, int subscriptions) { - if (id == null) { - throw new IllegalArgumentException("ID must not be null"); - } + Validate.notNull(id); this.id = id; this.caption = caption; diff --git a/src/de/danoeh/antennapod/gpoddernet/model/GpodnetPodcast.java b/src/de/danoeh/antennapod/gpoddernet/model/GpodnetPodcast.java index aa01b66e2..b002035c9 100644 --- a/src/de/danoeh/antennapod/gpoddernet/model/GpodnetPodcast.java +++ b/src/de/danoeh/antennapod/gpoddernet/model/GpodnetPodcast.java @@ -1,5 +1,7 @@ package de.danoeh.antennapod.gpoddernet.model; +import org.apache.commons.lang3.Validate; + public class GpodnetPodcast { private String url; private String title; @@ -11,10 +13,9 @@ public class GpodnetPodcast { public GpodnetPodcast(String url, String title, String description, int subscribers, String logoUrl, String website, String mygpoLink) { - if (url == null || title == null || description == null) { - throw new IllegalArgumentException( - "URL, title and description must not be null"); - } + Validate.notNull(url); + Validate.notNull(title); + Validate.notNull(description); this.url = url; this.title = title; diff --git a/src/de/danoeh/antennapod/gpoddernet/model/GpodnetSubscriptionChange.java b/src/de/danoeh/antennapod/gpoddernet/model/GpodnetSubscriptionChange.java index dccb53e5d..a4617118d 100644 --- a/src/de/danoeh/antennapod/gpoddernet/model/GpodnetSubscriptionChange.java +++ b/src/de/danoeh/antennapod/gpoddernet/model/GpodnetSubscriptionChange.java @@ -1,5 +1,7 @@ package de.danoeh.antennapod.gpoddernet.model; +import org.apache.commons.lang3.Validate; + import java.util.List; public class GpodnetSubscriptionChange { @@ -9,10 +11,9 @@ public class GpodnetSubscriptionChange { public GpodnetSubscriptionChange(List added, List removed, long timestamp) { - if (added == null || removed == null) { - throw new IllegalArgumentException( - "added and remove must not be null"); - } + Validate.notNull(added); + Validate.notNull(removed); + this.added = added; this.removed = removed; this.timestamp = timestamp; diff --git a/src/de/danoeh/antennapod/gpoddernet/model/GpodnetTag.java b/src/de/danoeh/antennapod/gpoddernet/model/GpodnetTag.java index e8a36a554..80b84095e 100644 --- a/src/de/danoeh/antennapod/gpoddernet/model/GpodnetTag.java +++ b/src/de/danoeh/antennapod/gpoddernet/model/GpodnetTag.java @@ -1,5 +1,7 @@ package de.danoeh.antennapod.gpoddernet.model; +import org.apache.commons.lang3.Validate; + import java.util.Comparator; public class GpodnetTag { @@ -8,9 +10,7 @@ public class GpodnetTag { private int usage; public GpodnetTag(String name, int usage) { - if (name == null) { - throw new IllegalArgumentException("Name must not be null"); - } + Validate.notNull(name); this.name = name; this.usage = usage; diff --git a/src/de/danoeh/antennapod/preferences/PlaybackPreferences.java b/src/de/danoeh/antennapod/preferences/PlaybackPreferences.java index 80e0768dd..1d1ab052f 100644 --- a/src/de/danoeh/antennapod/preferences/PlaybackPreferences.java +++ b/src/de/danoeh/antennapod/preferences/PlaybackPreferences.java @@ -4,6 +4,9 @@ import android.content.Context; import android.content.SharedPreferences; import android.preference.PreferenceManager; import android.util.Log; + +import org.apache.commons.lang3.Validate; + import de.danoeh.antennapod.BuildConfig; /** @@ -66,8 +69,8 @@ public class PlaybackPreferences implements public static void createInstance(Context context) { if (BuildConfig.DEBUG) Log.d(TAG, "Creating new instance of UserPreferences"); - if (context == null) - throw new IllegalArgumentException("Context must not be null"); + Validate.notNull(context); + instance = new PlaybackPreferences(context); PreferenceManager.getDefaultSharedPreferences(context) diff --git a/src/de/danoeh/antennapod/preferences/UserPreferences.java b/src/de/danoeh/antennapod/preferences/UserPreferences.java index bb10e46d1..fa6331631 100644 --- a/src/de/danoeh/antennapod/preferences/UserPreferences.java +++ b/src/de/danoeh/antennapod/preferences/UserPreferences.java @@ -12,6 +12,7 @@ import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.OpmlImportFromPathActivity; import de.danoeh.antennapod.receiver.FeedUpdateReceiver; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.Validate; import org.json.JSONArray; import org.json.JSONException; @@ -92,8 +93,8 @@ public class UserPreferences implements public static void createInstance(Context context) { if (BuildConfig.DEBUG) Log.d(TAG, "Creating new instance of UserPreferences"); - if (context == null) - throw new IllegalArgumentException("Context must not be null"); + Validate.notNull(context); + instance = new UserPreferences(context); createImportDirectory(); diff --git a/src/de/danoeh/antennapod/receiver/AlarmUpdateReceiver.java b/src/de/danoeh/antennapod/receiver/AlarmUpdateReceiver.java index 7b8879f21..a0539e276 100644 --- a/src/de/danoeh/antennapod/receiver/AlarmUpdateReceiver.java +++ b/src/de/danoeh/antennapod/receiver/AlarmUpdateReceiver.java @@ -4,6 +4,9 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.util.Log; + +import org.apache.commons.lang3.StringUtils; + import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.preferences.UserPreferences; @@ -15,10 +18,10 @@ public class AlarmUpdateReceiver extends BroadcastReceiver { public void onReceive(Context context, Intent intent) { if (BuildConfig.DEBUG) Log.d(TAG, "Received intent"); - if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) { + if (StringUtils.equals(intent.getAction(), Intent.ACTION_BOOT_COMPLETED)) { if (BuildConfig.DEBUG) Log.d(TAG, "Resetting update alarm after reboot"); - } else if (intent.getAction().equals(Intent.ACTION_PACKAGE_REPLACED)) { + } else if (StringUtils.equals(intent.getAction(), Intent.ACTION_PACKAGE_REPLACED)) { if (BuildConfig.DEBUG) Log.d(TAG, "Resetting update alarm after app upgrade"); } diff --git a/src/de/danoeh/antennapod/receiver/ConnectivityActionReceiver.java b/src/de/danoeh/antennapod/receiver/ConnectivityActionReceiver.java index 31c053386..4dcf0b6aa 100644 --- a/src/de/danoeh/antennapod/receiver/ConnectivityActionReceiver.java +++ b/src/de/danoeh/antennapod/receiver/ConnectivityActionReceiver.java @@ -6,6 +6,9 @@ import android.content.Intent; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.util.Log; + +import org.apache.commons.lang3.StringUtils; + import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.storage.DBTasks; import de.danoeh.antennapod.storage.DownloadRequester; @@ -16,7 +19,7 @@ public class ConnectivityActionReceiver extends BroadcastReceiver { @Override public void onReceive(final Context context, Intent intent) { - if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) { + if (StringUtils.equals(intent.getAction(), ConnectivityManager.CONNECTIVITY_ACTION)) { if (BuildConfig.DEBUG) Log.d(TAG, "Received intent"); diff --git a/src/de/danoeh/antennapod/receiver/FeedUpdateReceiver.java b/src/de/danoeh/antennapod/receiver/FeedUpdateReceiver.java index a7482fbf4..3c283a30b 100644 --- a/src/de/danoeh/antennapod/receiver/FeedUpdateReceiver.java +++ b/src/de/danoeh/antennapod/receiver/FeedUpdateReceiver.java @@ -6,6 +6,9 @@ import android.content.Intent; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.util.Log; + +import org.apache.commons.lang3.StringUtils; + import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.preferences.UserPreferences; import de.danoeh.antennapod.storage.DBTasks; @@ -17,7 +20,7 @@ public class FeedUpdateReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { - if (intent.getAction().equals(ACTION_REFRESH_FEEDS)) { + if (StringUtils.equals(intent.getAction(), ACTION_REFRESH_FEEDS)) { if (BuildConfig.DEBUG) Log.d(TAG, "Received intent"); boolean mobileUpdate = UserPreferences.isAllowMobileUpdate(); diff --git a/src/de/danoeh/antennapod/receiver/PlayerWidget.java b/src/de/danoeh/antennapod/receiver/PlayerWidget.java index 5748ced3b..9f8892181 100644 --- a/src/de/danoeh/antennapod/receiver/PlayerWidget.java +++ b/src/de/danoeh/antennapod/receiver/PlayerWidget.java @@ -5,6 +5,9 @@ import android.appwidget.AppWidgetProvider; import android.content.Context; import android.content.Intent; import android.util.Log; + +import org.apache.commons.lang3.StringUtils; + import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.service.playback.PlayerWidgetService; @@ -15,9 +18,9 @@ public class PlayerWidget extends AppWidgetProvider { @Override public void onReceive(Context context, Intent intent) { - if (intent.getAction().equals(FORCE_WIDGET_UPDATE)) { + if (StringUtils.equals(intent.getAction(), FORCE_WIDGET_UPDATE)) { startUpdate(context); - } else if (intent.getAction().equals(STOP_WIDGET_UPDATE)) { + } else if (StringUtils.equals(intent.getAction(), STOP_WIDGET_UPDATE)) { stopUpdate(context); } diff --git a/src/de/danoeh/antennapod/service/download/DownloadRequest.java b/src/de/danoeh/antennapod/service/download/DownloadRequest.java index 7ff9bc01c..e803d30d4 100644 --- a/src/de/danoeh/antennapod/service/download/DownloadRequest.java +++ b/src/de/danoeh/antennapod/service/download/DownloadRequest.java @@ -3,6 +3,8 @@ package de.danoeh.antennapod.service.download; import android.os.Parcel; import android.os.Parcelable; +import org.apache.commons.lang3.Validate; + public class DownloadRequest implements Parcelable { private final String destination; @@ -21,15 +23,9 @@ public class DownloadRequest implements Parcelable { public DownloadRequest(String destination, String source, String title, long feedfileId, int feedfileType, String username, String password, boolean deleteOnFailure) { - if (destination == null) { - throw new IllegalArgumentException("Destination must not be null"); - } - if (source == null) { - throw new IllegalArgumentException("Source must not be null"); - } - if (title == null) { - throw new IllegalArgumentException("Title must not be null"); - } + Validate.notNull(destination); + Validate.notNull(source); + Validate.notNull(title); this.destination = destination; this.source = source; @@ -110,11 +106,14 @@ public class DownloadRequest implements Parcelable { if (size != that.size) return false; if (soFar != that.soFar) return false; if (statusMsg != that.statusMsg) return false; - if (destination != null ? !destination.equals(that.destination) : that.destination != null) return false; - if (password != null ? !password.equals(that.password) : that.password != null) return false; + if (destination != null ? !destination.equals(that.destination) : that.destination != null) + return false; + if (password != null ? !password.equals(that.password) : that.password != null) + return false; if (source != null ? !source.equals(that.source) : that.source != null) return false; if (title != null ? !title.equals(that.title) : that.title != null) return false; - if (username != null ? !username.equals(that.username) : that.username != null) return false; + if (username != null ? !username.equals(that.username) : that.username != null) + return false; return true; } diff --git a/src/de/danoeh/antennapod/service/download/DownloadService.java b/src/de/danoeh/antennapod/service/download/DownloadService.java index 4f60ef8d6..9a599f0ec 100644 --- a/src/de/danoeh/antennapod/service/download/DownloadService.java +++ b/src/de/danoeh/antennapod/service/download/DownloadService.java @@ -34,6 +34,7 @@ import de.danoeh.antennapod.util.DownloadError; import de.danoeh.antennapod.util.InvalidFeedException; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.Validate; import org.apache.http.HttpStatus; import org.xml.sax.SAXException; @@ -394,12 +395,10 @@ public class DownloadService extends Service { @Override public void onReceive(Context context, Intent intent) { - if (intent.getAction().equals(ACTION_CANCEL_DOWNLOAD)) { + if (StringUtils.equals(intent.getAction(), ACTION_CANCEL_DOWNLOAD)) { String url = intent.getStringExtra(EXTRA_DOWNLOAD_URL); - if (url == null) { - throw new IllegalArgumentException( - "ACTION_CANCEL_DOWNLOAD intent needs download url extra"); - } + Validate.notNull(url, "ACTION_CANCEL_DOWNLOAD intent needs download url extra"); + if (BuildConfig.DEBUG) Log.d(TAG, "Cancelling download with url " + url); Downloader d = getDownloader(url); @@ -409,7 +408,7 @@ public class DownloadService extends Service { Log.e(TAG, "Could not cancel download with url " + url); } - } else if (intent.getAction().equals(ACTION_CANCEL_ALL_DOWNLOADS)) { + } else if (StringUtils.equals(intent.getAction(), ACTION_CANCEL_ALL_DOWNLOADS)) { for (Downloader d : downloads) { d.cancel(); if (BuildConfig.DEBUG) @@ -1033,12 +1032,9 @@ public class DownloadService extends Service { private DownloadStatus status; public ImageHandlerThread(DownloadStatus status, DownloadRequest request) { - if (status == null) { - throw new IllegalArgumentException("Status must not be null"); - } - if (request == null) { - throw new IllegalArgumentException("Request must not be null"); - } + Validate.notNull(status); + Validate.notNull(request); + this.status = status; this.request = request; } @@ -1070,12 +1066,8 @@ public class DownloadService extends Service { private DownloadStatus status; public MediaHandlerThread(DownloadStatus status, DownloadRequest request) { - if (status == null) { - throw new IllegalArgumentException("Status must not be null"); - } - if (request == null) { - throw new IllegalArgumentException("Request must not be null"); - } + Validate.notNull(status); + Validate.notNull(request); this.status = status; this.request = request; diff --git a/src/de/danoeh/antennapod/service/download/DownloadStatus.java b/src/de/danoeh/antennapod/service/download/DownloadStatus.java index b240cddbc..1d76770bb 100644 --- a/src/de/danoeh/antennapod/service/download/DownloadStatus.java +++ b/src/de/danoeh/antennapod/service/download/DownloadStatus.java @@ -1,5 +1,7 @@ package de.danoeh.antennapod.service.download; +import org.apache.commons.lang3.Validate; + import de.danoeh.antennapod.feed.FeedFile; import de.danoeh.antennapod.util.DownloadError; @@ -59,9 +61,8 @@ public class DownloadStatus { public DownloadStatus(DownloadRequest request, DownloadError reason, boolean successful, boolean cancelled, String reasonDetailed) { - if (request == null) { - throw new IllegalArgumentException("request must not be null"); - } + Validate.notNull(request); + this.title = request.getTitle(); this.feedfileId = request.getFeedfileId(); this.feedfileType = request.getFeedfileType(); @@ -75,9 +76,7 @@ public class DownloadStatus { /** Constructor for creating new completed downloads. */ public DownloadStatus(FeedFile feedfile, String title, DownloadError reason, boolean successful, String reasonDetailed) { - if (feedfile == null) { - throw new IllegalArgumentException("feedfile must not be null"); - } + Validate.notNull(feedfile); this.title = title; this.done = true; diff --git a/src/de/danoeh/antennapod/service/playback/PlaybackService.java b/src/de/danoeh/antennapod/service/playback/PlaybackService.java index 4ecf5db8a..5b25bd675 100644 --- a/src/de/danoeh/antennapod/service/playback/PlaybackService.java +++ b/src/de/danoeh/antennapod/service/playback/PlaybackService.java @@ -23,6 +23,9 @@ import android.util.Pair; import android.view.KeyEvent; import android.view.SurfaceHolder; import android.widget.Toast; + +import org.apache.commons.lang3.StringUtils; + import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.PodcastApp; import de.danoeh.antennapod.R; @@ -896,8 +899,7 @@ public class PlaybackService extends Service { @Override public void onReceive(Context context, Intent intent) { - if (intent.getAction() != null && - intent.getAction().equals(Intent.ACTION_HEADSET_PLUG)) { + if (StringUtils.equals(intent.getAction(), Intent.ACTION_HEADSET_PLUG)) { int state = intent.getIntExtra("state", -1); if (state != -1) { if (BuildConfig.DEBUG) @@ -939,8 +941,7 @@ public class PlaybackService extends Service { @Override public void onReceive(Context context, Intent intent) { - if (intent.getAction() != null && - intent.getAction().equals(ACTION_SHUTDOWN_PLAYBACK_SERVICE)) { + if (StringUtils.equals(intent.getAction(), ACTION_SHUTDOWN_PLAYBACK_SERVICE)) { stopSelf(); } } @@ -950,8 +951,7 @@ public class PlaybackService extends Service { private BroadcastReceiver skipCurrentEpisodeReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { - if (intent.getAction() != null && - intent.getAction().equals(ACTION_SKIP_CURRENT_EPISODE)) { + if (StringUtils.equals(intent.getAction(), ACTION_SKIP_CURRENT_EPISODE)) { if (BuildConfig.DEBUG) Log.d(TAG, "Received SKIP_CURRENT_EPISODE intent"); mediaPlayer.endPlayback(); diff --git a/src/de/danoeh/antennapod/service/playback/PlaybackServiceMediaPlayer.java b/src/de/danoeh/antennapod/service/playback/PlaybackServiceMediaPlayer.java index 2915da5a1..ea99d882d 100644 --- a/src/de/danoeh/antennapod/service/playback/PlaybackServiceMediaPlayer.java +++ b/src/de/danoeh/antennapod/service/playback/PlaybackServiceMediaPlayer.java @@ -7,6 +7,9 @@ import android.media.RemoteControlClient; import android.util.Log; import android.util.Pair; import android.view.SurfaceHolder; + +import org.apache.commons.lang3.Validate; + import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.feed.Chapter; import de.danoeh.antennapod.feed.MediaType; @@ -61,10 +64,8 @@ public class PlaybackServiceMediaPlayer { private final ThreadPoolExecutor executor; public PlaybackServiceMediaPlayer(Context context, PSMPCallback callback) { - if (context == null) - throw new IllegalArgumentException("context = null"); - if (callback == null) - throw new IllegalArgumentException("callback = null"); + Validate.notNull(context); + Validate.notNull(callback); this.context = context; this.callback = callback; @@ -115,8 +116,8 @@ public class PlaybackServiceMediaPlayer { * @param prepareImmediately Set to true if the method should also prepare the episode for playback. */ public void playMediaObject(final Playable playable, final boolean stream, final boolean startWhenPrepared, final boolean prepareImmediately) { - if (playable == null) - throw new IllegalArgumentException("playable = null"); + Validate.notNull(playable); + if (BuildConfig.DEBUG) Log.d(TAG, "Play media object."); executor.submit(new Runnable() { @Override @@ -142,8 +143,7 @@ public class PlaybackServiceMediaPlayer { * @see #playMediaObject(de.danoeh.antennapod.util.playback.Playable, boolean, boolean, boolean) */ private void playMediaObject(final Playable playable, final boolean forceReset, final boolean stream, final boolean startWhenPrepared, final boolean prepareImmediately) { - if (playable == null) - throw new IllegalArgumentException("playable = null"); + Validate.notNull(playable); if (!playerLock.isHeldByCurrentThread()) throw new IllegalStateException("method requires playerLock"); @@ -458,8 +458,8 @@ public class PlaybackServiceMediaPlayer { * Seek to the start of the specified chapter. */ public void seekToChapter(Chapter c) { - if (c == null) - throw new IllegalArgumentException("c = null"); + Validate.notNull(c); + seekTo((int) c.getStart()); } @@ -662,8 +662,8 @@ public class PlaybackServiceMediaPlayer { * @param newMedia The new playable object of the PSMP object. This can be null. */ private synchronized void setPlayerStatus(PlayerStatus newStatus, Playable newMedia) { - if (newStatus == null) - throw new IllegalArgumentException("newStatus = null"); + Validate.notNull(newStatus); + if (BuildConfig.DEBUG) Log.d(TAG, "Setting player status to " + newStatus); this.playerStatus = newStatus; diff --git a/src/de/danoeh/antennapod/service/playback/PlaybackServiceTaskManager.java b/src/de/danoeh/antennapod/service/playback/PlaybackServiceTaskManager.java index 3ab06910a..680ec2e2f 100644 --- a/src/de/danoeh/antennapod/service/playback/PlaybackServiceTaskManager.java +++ b/src/de/danoeh/antennapod/service/playback/PlaybackServiceTaskManager.java @@ -2,6 +2,9 @@ package de.danoeh.antennapod.service.playback; import android.content.Context; import android.util.Log; + +import org.apache.commons.lang3.Validate; + import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.feed.EventDistributor; import de.danoeh.antennapod.feed.FeedItem; @@ -52,10 +55,8 @@ public class PlaybackServiceTaskManager { * @param callback A PSTMCallback object for notifying the user about updates. Must not be null. */ public PlaybackServiceTaskManager(Context context, PSTMCallback callback) { - if (context == null) - throw new IllegalArgumentException("context must not be null"); - if (callback == null) - throw new IllegalArgumentException("callback must not be null"); + Validate.notNull(context); + Validate.notNull(callback); this.context = context; this.callback = callback; @@ -195,8 +196,7 @@ public class PlaybackServiceTaskManager { * @throws java.lang.IllegalArgumentException if waitingTime <= 0 */ public synchronized void setSleepTimer(long waitingTime) { - if (waitingTime <= 0) - throw new IllegalArgumentException("waitingTime <= 0"); + Validate.isTrue(waitingTime > 0, "Waiting time <= 0"); if (BuildConfig.DEBUG) Log.d(TAG, "Setting sleep timer to " + Long.toString(waitingTime) @@ -271,8 +271,7 @@ public class PlaybackServiceTaskManager { * On completion, the callback's onChapterLoaded method will be called. */ public synchronized void startChapterLoader(final Playable media) { - if (media == null) - throw new IllegalArgumentException("media = null"); + Validate.notNull(media); if (isChapterLoaderActive()) { cancelChapterLoader(); diff --git a/src/de/danoeh/antennapod/spa/SPAUtil.java b/src/de/danoeh/antennapod/spa/SPAUtil.java index 0d83741ed..75cbd8b5a 100644 --- a/src/de/danoeh/antennapod/spa/SPAUtil.java +++ b/src/de/danoeh/antennapod/spa/SPAUtil.java @@ -5,6 +5,9 @@ import android.content.Intent; import android.content.SharedPreferences; import android.preference.PreferenceManager; import android.util.Log; + +import org.apache.commons.lang3.Validate; + import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.receiver.SPAReceiver; @@ -56,7 +59,7 @@ public class SPAUtil { */ public static void resetSPAPreferences(Context c) { if (BuildConfig.DEBUG) { - if (c == null) throw new IllegalArgumentException("c = null"); + Validate.notNull(c); SharedPreferences.Editor editor = PreferenceManager .getDefaultSharedPreferences(c.getApplicationContext()).edit(); editor.putBoolean(PREF_HAS_QUERIED_SP_APPS, false); diff --git a/src/de/danoeh/antennapod/storage/DownloadRequester.java b/src/de/danoeh/antennapod/storage/DownloadRequester.java index 7bf21352a..d305c572b 100644 --- a/src/de/danoeh/antennapod/storage/DownloadRequester.java +++ b/src/de/danoeh/antennapod/storage/DownloadRequester.java @@ -14,6 +14,7 @@ import de.danoeh.antennapod.util.URLChecker; import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang3.StringEscapeUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.Validate; import java.io.File; import java.util.Map; @@ -57,8 +58,9 @@ public class DownloadRequester { * @return True if the download request was accepted, false otherwise. */ public boolean download(Context context, DownloadRequest request) { - if (context == null) throw new IllegalArgumentException("context = null"); - if (request == null) throw new IllegalArgumentException("request = null"); + Validate.notNull(context); + Validate.notNull(request); + if (downloads.containsKey(request.getSource())) { if (BuildConfig.DEBUG) Log.i(TAG, "DownloadRequest is already stored."); return false; diff --git a/src/de/danoeh/antennapod/storage/PodDBAdapter.java b/src/de/danoeh/antennapod/storage/PodDBAdapter.java index 06c8b1fc9..671ac30d5 100644 --- a/src/de/danoeh/antennapod/storage/PodDBAdapter.java +++ b/src/de/danoeh/antennapod/storage/PodDBAdapter.java @@ -10,14 +10,23 @@ import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase.CursorFactory; import android.database.sqlite.SQLiteOpenHelper; import android.util.Log; -import de.danoeh.antennapod.BuildConfig; -import de.danoeh.antennapod.feed.*; -import de.danoeh.antennapod.service.download.DownloadStatus; -import de.danoeh.antennapod.util.flattr.FlattrStatus; + +import org.apache.commons.lang3.Validate; import java.util.Arrays; import java.util.List; +import de.danoeh.antennapod.BuildConfig; +import de.danoeh.antennapod.feed.Chapter; +import de.danoeh.antennapod.feed.Feed; +import de.danoeh.antennapod.feed.FeedComponent; +import de.danoeh.antennapod.feed.FeedImage; +import de.danoeh.antennapod.feed.FeedItem; +import de.danoeh.antennapod.feed.FeedMedia; +import de.danoeh.antennapod.feed.FeedPreferences; +import de.danoeh.antennapod.service.download.DownloadStatus; +import de.danoeh.antennapod.util.flattr.FlattrStatus; + // TODO Remove media column from feeditem table /** @@ -1024,9 +1033,8 @@ public class PodDBAdapter { * @throws IllegalArgumentException if limit < 0 */ public final Cursor getCompletedMediaCursor(int limit) { - if (limit < 0) { - throw new IllegalArgumentException("Limit must be >= 0"); - } + Validate.isTrue(limit >= 0, "Limit must be >= 0"); + Cursor c = db.query(TABLE_NAME_FEED_MEDIA, null, KEY_PLAYBACK_COMPLETION_DATE + " > 0 LIMIT " + limit, null, null, null, null); diff --git a/src/de/danoeh/antennapod/util/playback/Playable.java b/src/de/danoeh/antennapod/util/playback/Playable.java index 8eefb0be5..9ed45abfc 100644 --- a/src/de/danoeh/antennapod/util/playback/Playable.java +++ b/src/de/danoeh/antennapod/util/playback/Playable.java @@ -12,6 +12,7 @@ import de.danoeh.antennapod.feed.MediaType; import de.danoeh.antennapod.storage.DBReader; import de.danoeh.antennapod.util.ShownotesProvider; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.Validate; import java.io.ByteArrayInputStream; import java.io.InputStream; @@ -216,9 +217,8 @@ public interface Playable extends Parcelable, private Playable playable; public DefaultPlayableImageLoader(Playable playable) { - if (playable == null) { - throw new IllegalArgumentException("Playable must not be null"); - } + Validate.notNull(playable); + this.playable = playable; } diff --git a/src/de/danoeh/antennapod/util/playback/PlaybackController.java b/src/de/danoeh/antennapod/util/playback/PlaybackController.java index a979ddc1c..64dbf4868 100644 --- a/src/de/danoeh/antennapod/util/playback/PlaybackController.java +++ b/src/de/danoeh/antennapod/util/playback/PlaybackController.java @@ -15,6 +15,10 @@ import android.view.View.OnClickListener; import android.widget.ImageButton; import android.widget.SeekBar; import android.widget.TextView; + +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.Validate; + import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.R; import de.danoeh.antennapod.feed.Chapter; @@ -62,8 +66,8 @@ public abstract class PlaybackController { private boolean reinitOnPause; public PlaybackController(Activity activity, boolean reinitOnPause) { - if (activity == null) - throw new IllegalArgumentException("activity = null"); + Validate.notNull(activity); + this.activity = activity; this.reinitOnPause = reinitOnPause; schedExecutor = new ScheduledThreadPoolExecutor(SCHED_EX_POOLSIZE, @@ -360,7 +364,7 @@ public abstract class PlaybackController { @Override public void onReceive(Context context, Intent intent) { if (isConnectedToPlaybackService()) { - if (intent.getAction().equals( + if (StringUtils.equals(intent.getAction(), PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE)) { release(); onShutdownNotification(); diff --git a/src/de/danoeh/antennapod/util/playback/Timeline.java b/src/de/danoeh/antennapod/util/playback/Timeline.java index 96df359d6..ceed68183 100644 --- a/src/de/danoeh/antennapod/util/playback/Timeline.java +++ b/src/de/danoeh/antennapod/util/playback/Timeline.java @@ -5,6 +5,7 @@ import android.content.res.TypedArray; import android.util.Log; import android.util.TypedValue; +import org.apache.commons.lang3.Validate; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; @@ -154,7 +155,7 @@ public class Timeline { public void setShownotesProvider(ShownotesProvider shownotesProvider) { - if (shownotesProvider == null) throw new IllegalArgumentException("shownotesProvider = null"); + Validate.notNull(shownotesProvider); this.shownotesProvider = shownotesProvider; } }