Replace commons-lang3 where possible

This commit is contained in:
Martin Fietz 2015-12-02 18:01:17 +01:00
parent 5f0ecb5d59
commit 833f76fc3b
36 changed files with 225 additions and 279 deletions

View File

@ -41,7 +41,6 @@ public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActiv
@Override
protected void setUp() throws Exception {
super.setUp();
solo = new Solo(getInstrumentation(), getActivity());
uiTestUtils = new UITestUtils(getInstrumentation().getTargetContext());
uiTestUtils.setup();
@ -54,6 +53,8 @@ public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActiv
// override first launch preference
prefs = getInstrumentation().getTargetContext().getSharedPreferences(MainActivity.PREF_NAME, Context.MODE_PRIVATE);
prefs.edit().putBoolean(MainActivity.PREF_IS_FIRST_LAUNCH, false).commit();
solo = new Solo(getInstrumentation(), getActivity());
}
@Override

View File

@ -13,6 +13,7 @@ import android.support.v4.app.ListFragment;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.util.Log;
import android.view.ContextMenu;
import android.view.Gravity;
@ -35,7 +36,6 @@ import android.widget.TextView;
import com.bumptech.glide.Glide;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.adapter.ChapterListAdapter;
@ -246,7 +246,7 @@ public class AudioplayerActivity extends MediaplayerActivity implements ItemDesc
@Override
protected void onResume() {
super.onResume();
if (StringUtils.equals(getIntent().getAction(), Intent.ACTION_VIEW)) {
if (TextUtils.equals(getIntent().getAction(), Intent.ACTION_VIEW)) {
Intent intent = getIntent();
Log.d(TAG, "Received VIEW intent: " + intent.getData().getPath());
ExternalMedia media = new ExternalMedia(intent.getData().getPath(),

View File

@ -9,6 +9,7 @@ import android.os.Looper;
import android.support.v4.app.NavUtils;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MenuItem;
@ -145,9 +146,9 @@ public class OnlineFeedViewActivity extends ActionBarActivity {
final String feedUrl;
if (getIntent().hasExtra(ARG_FEEDURL)) {
feedUrl = getIntent().getStringExtra(ARG_FEEDURL);
} else if (StringUtils.equals(getIntent().getAction(), Intent.ACTION_SEND)
|| StringUtils.equals(getIntent().getAction(), Intent.ACTION_VIEW)) {
feedUrl = (StringUtils.equals(getIntent().getAction(), Intent.ACTION_SEND))
} else if (TextUtils.equals(getIntent().getAction(), Intent.ACTION_SEND)
|| TextUtils.equals(getIntent().getAction(), Intent.ACTION_VIEW)) {
feedUrl = (TextUtils.equals(getIntent().getAction(), Intent.ACTION_SEND))
? getIntent().getStringExtra(Intent.EXTRA_TEXT) : getIntent().getDataString();
getSupportActionBar().setTitle(R.string.add_new_feed_label);
} else {
@ -322,7 +323,7 @@ public class OnlineFeedViewActivity extends ActionBarActivity {
subscriber.onNext(result);
} catch (UnsupportedFeedtypeException e) {
Log.d(TAG, "Unsupported feed type detected");
if (StringUtils.equalsIgnoreCase("html", e.getRootElement())) {
if (TextUtils.equals("html", e.getRootElement().toLowerCase())) {
showFeedDiscoveryDialog(new File(feed.getFile_url()), feed.getDownload_url());
} else {
subscriber.onError(e);

View File

@ -6,10 +6,9 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.text.TextUtils;
import android.util.Log;
import org.apache.commons.lang3.StringUtils;
import de.danoeh.antennapod.BuildConfig;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.core.preferences.UserPreferences;
@ -57,7 +56,7 @@ public class StorageErrorActivity extends ActionBarActivity {
@Override
public void onReceive(Context context, Intent intent) {
if (StringUtils.equals(intent.getAction(), Intent.ACTION_MEDIA_MOUNTED)) {
if (TextUtils.equals(intent.getAction(), Intent.ACTION_MEDIA_MOUNTED)) {
if (intent.getBooleanExtra("read-only", true)) {
if (BuildConfig.DEBUG)
Log.d(TAG, "Media was mounted; Finishing activity");

View File

@ -5,10 +5,9 @@ import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.text.TextUtils;
import android.util.Log;
import org.apache.commons.lang3.StringUtils;
import de.danoeh.antennapod.core.storage.DBTasks;
import de.danoeh.antennapod.core.storage.DownloadRequester;
import de.danoeh.antennapod.core.util.NetworkUtils;
@ -18,7 +17,7 @@ public class ConnectivityActionReceiver extends BroadcastReceiver {
@Override
public void onReceive(final Context context, Intent intent) {
if (StringUtils.equals(intent.getAction(), ConnectivityManager.CONNECTIVITY_ACTION)) {
if (TextUtils.equals(intent.getAction(), ConnectivityManager.CONNECTIVITY_ACTION)) {
Log.d(TAG, "Received intent");
if (NetworkUtils.autodownloadNetworkAvailable()) {

View File

@ -5,11 +5,9 @@ import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.text.TextUtils;
import android.util.Log;
import org.apache.commons.lang3.StringUtils;
import de.danoeh.antennapod.core.BuildConfig;
import de.danoeh.antennapod.core.service.playback.PlaybackService;
import de.danoeh.antennapod.service.PlayerWidgetService;
@ -28,9 +26,9 @@ public class PlayerWidget extends AppWidgetProvider {
}
// these come from the PlaybackService when things should get updated
if (StringUtils.equals(intent.getAction(), PlaybackService.FORCE_WIDGET_UPDATE)) {
if (TextUtils.equals(intent.getAction(), PlaybackService.FORCE_WIDGET_UPDATE)) {
startUpdate(context);
} else if (StringUtils.equals(intent.getAction(), PlaybackService.STOP_WIDGET_UPDATE)) {
} else if (TextUtils.equals(intent.getAction(), PlaybackService.STOP_WIDGET_UPDATE)) {
stopUpdate(context);
}
}

View File

@ -3,11 +3,10 @@ package de.danoeh.antennapod.receiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;
import org.apache.commons.lang3.StringUtils;
import java.util.Arrays;
import java.util.Date;
@ -29,7 +28,7 @@ public class SPAReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
if (StringUtils.equals(intent.getAction(), ACTION_SP_APPS_QUERY_FEEDS_REPSONSE)) {
if (TextUtils.equals(intent.getAction(), ACTION_SP_APPS_QUERY_FEEDS_REPSONSE)) {
if (BuildConfig.DEBUG) Log.d(TAG, "Received SP_APPS_QUERY_RESPONSE");
if (intent.hasExtra(ACTION_SP_APPS_QUERY_FEEDS_REPSONSE_FEEDS_EXTRA)) {
String[] feedUrls = intent.getStringArrayExtra(ACTION_SP_APPS_QUERY_FEEDS_REPSONSE_FEEDS_EXTRA);

View File

@ -6,11 +6,11 @@ import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.os.AsyncTask;
import android.support.annotation.NonNull;
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;
@ -63,8 +63,7 @@ public class FlattrClickWorker extends AsyncTask<Void, Integer, FlattrClickWorke
*
* @param context A context for accessing the database and posting notifications. Must not be null.
*/
public FlattrClickWorker(Context context) {
Validate.notNull(context);
public FlattrClickWorker(@NonNull Context context) {
this.context = context.getApplicationContext();
}

View File

@ -3,8 +3,6 @@ package de.danoeh.antennapod.core.feed;
import android.os.Handler;
import android.util.Log;
import org.apache.commons.lang3.Validate;
import java.util.AbstractQueue;
import java.util.Observable;
import java.util.Observer;
@ -84,7 +82,6 @@ public class EventDistributor extends Observable {
@Override
public void addObserver(Observer observer) {
super.addObserver(observer);
Validate.isInstanceOf(EventListener.class, observer);
}
public void sendUnreadItemsUpdateBroadcast() {

View File

@ -4,8 +4,7 @@ import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.support.annotation.Nullable;
import org.apache.commons.lang3.StringUtils;
import android.text.TextUtils;
import java.util.ArrayList;
import java.util.Date;
@ -367,7 +366,7 @@ public class Feed extends FeedFile implements FlattrThing, ImageResource {
if (other.isPaged() && !this.isPaged()) {
return true;
}
if (!StringUtils.equals(other.getNextPageLink(), this.getNextPageLink())) {
if (!TextUtils.equals(other.getNextPageLink(), this.getNextPageLink())) {
return true;
}
return false;

View File

@ -1,8 +1,6 @@
package de.danoeh.antennapod.core.feed;
import android.content.Context;
import org.apache.commons.lang3.StringUtils;
import android.text.TextUtils;
import java.util.ArrayList;
import java.util.List;
@ -22,7 +20,7 @@ public class FeedItemFilter {
private boolean hideNotDownloaded = false;
public FeedItemFilter(String properties) {
this(StringUtils.split(properties, ','));
this(TextUtils.split(",", properties));
}
public FeedItemFilter(String[] properties) {

View File

@ -2,8 +2,7 @@ package de.danoeh.antennapod.core.feed;
import android.content.Context;
import android.database.Cursor;
import org.apache.commons.lang3.StringUtils;
import android.text.TextUtils;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.storage.DBWriter;
@ -60,10 +59,10 @@ public class FeedPreferences {
public boolean compareWithOther(FeedPreferences other) {
if (other == null)
return true;
if (!StringUtils.equals(username, other.username)) {
if (!TextUtils.equals(username, other.username)) {
return true;
}
if (!StringUtils.equals(password, other.password)) {
if (!TextUtils.equals(password, other.password)) {
return true;
}
return false;

View File

@ -1,5 +1,7 @@
package de.danoeh.antennapod.core.gpoddernet;
import android.support.annotation.NonNull;
import com.squareup.okhttp.Credentials;
import com.squareup.okhttp.MediaType;
import com.squareup.okhttp.OkHttpClient;
@ -8,7 +10,6 @@ import com.squareup.okhttp.RequestBody;
import com.squareup.okhttp.Response;
import com.squareup.okhttp.ResponseBody;
import org.apache.commons.lang3.Validate;
import org.apache.http.HttpStatus;
import org.apache.http.client.ClientProtocolException;
import org.json.JSONArray;
@ -101,10 +102,9 @@ public class GpodnetService {
*
* @throws IllegalArgumentException if tag is null
*/
public List<GpodnetPodcast> getPodcastsForTag(GpodnetTag tag, int count)
public List<GpodnetPodcast> getPodcastsForTag(@NonNull GpodnetTag tag,
int count)
throws GpodnetServiceException {
Validate.notNull(tag);
try {
URL url = new URI(BASE_SCHEME, BASE_HOST, String.format(
"/api/2/tag/%s/%d.json", tag.getTag(), count), null).toURL();
@ -128,7 +128,9 @@ public class GpodnetService {
*/
public List<GpodnetPodcast> getPodcastToplist(int count)
throws GpodnetServiceException {
Validate.isTrue(count >= 1 && count <= 100, "Count must be in range 1..100");
if(count < 1 || count > 100) {
throw new IllegalArgumentException("Count must be in range 1..100");
}
try {
URL url = new URI(BASE_SCHEME, BASE_HOST, String.format(
@ -158,7 +160,9 @@ public class GpodnetService {
* @throws GpodnetServiceAuthenticationException If there is an authentication error.
*/
public List<GpodnetPodcast> getSuggestions(int count) throws GpodnetServiceException {
Validate.isTrue(count >= 1 && count <= 100, "Count must be in range 1..100");
if(count < 1 || count > 100) {
throw new IllegalArgumentException("Count must be in range 1..100");
}
try {
URL url = new URI(BASE_SCHEME, BASE_HOST, String.format(
@ -215,10 +219,8 @@ public class GpodnetService {
* @throws IllegalArgumentException If username is null.
* @throws GpodnetServiceAuthenticationException If there is an authentication error.
*/
public List<GpodnetDevice> getDevices(String username)
public List<GpodnetDevice> getDevices(@NonNull String username)
throws GpodnetServiceException {
Validate.notNull(username);
try {
URL url = new URI(BASE_SCHEME, BASE_HOST, String.format(
"/api/2/devices/%s.json", username), null).toURL();
@ -243,12 +245,11 @@ public class GpodnetService {
* @throws IllegalArgumentException If username or deviceId is null.
* @throws GpodnetServiceAuthenticationException If there is an authentication error.
*/
public void configureDevice(String username, String deviceId,
String caption, GpodnetDevice.DeviceType type)
public void configureDevice(@NonNull String username,
@NonNull String deviceId,
String caption,
GpodnetDevice.DeviceType type)
throws GpodnetServiceException {
Validate.notNull(username);
Validate.notNull(deviceId);
try {
URL url = new URI(BASE_SCHEME, BASE_HOST, String.format(
"/api/2/devices/%s/%s.json", username, deviceId), null).toURL();
@ -286,11 +287,9 @@ public class GpodnetService {
* @throws IllegalArgumentException If username or deviceId is null.
* @throws GpodnetServiceAuthenticationException If there is an authentication error.
*/
public String getSubscriptionsOfDevice(String username, String deviceId)
public String getSubscriptionsOfDevice(@NonNull String username,
@NonNull String deviceId)
throws GpodnetServiceException {
Validate.notNull(username);
Validate.notNull(deviceId);
try {
URL url = new URI(BASE_SCHEME, BASE_HOST, String.format(
"/subscriptions/%s/%s.opml", username, deviceId), null).toURL();
@ -313,9 +312,8 @@ public class GpodnetService {
* @throws IllegalArgumentException If username is null.
* @throws GpodnetServiceAuthenticationException If there is an authentication error.
*/
public String getSubscriptionsOfUser(String username)
public String getSubscriptionsOfUser(@NonNull String username)
throws GpodnetServiceException {
Validate.notNull(username);
try {
URL url = new URI(BASE_SCHEME, BASE_HOST, String.format(
@ -342,12 +340,11 @@ public class GpodnetService {
* @throws IllegalArgumentException If username, deviceId or subscriptions is null.
* @throws GpodnetServiceAuthenticationException If there is an authentication error.
*/
public void uploadSubscriptions(String username, String deviceId,
List<String> subscriptions) throws GpodnetServiceException {
if (username == null || deviceId == null || subscriptions == null) {
throw new IllegalArgumentException(
"Username, device ID and subscriptions must not be null");
}
public void uploadSubscriptions(@NonNull String username,
@NonNull String deviceId,
@NonNull List<String> subscriptions)
throws GpodnetServiceException {
try {
URL url = new URI(BASE_SCHEME, BASE_HOST, String.format(
"/subscriptions/%s/%s.txt", username, deviceId), null).toURL();
@ -363,6 +360,7 @@ public class GpodnetService {
e.printStackTrace();
throw new GpodnetServiceException(e);
}
}
/**
@ -381,12 +379,11 @@ public class GpodnetService {
* @throws de.danoeh.antennapod.core.gpoddernet.GpodnetServiceException if added or removed contain duplicates or if there
* is an authentication error.
*/
public GpodnetUploadChangesResponse uploadChanges(String username, String deviceId, Collection<String> added,
Collection<String> removed) throws GpodnetServiceException {
Validate.notNull(username);
Validate.notNull(deviceId);
Validate.notNull(added);
Validate.notNull(removed);
public GpodnetUploadChangesResponse uploadChanges(@NonNull String username,
@NonNull String deviceId,
@NonNull Collection<String> added,
@NonNull Collection<String> removed)
throws GpodnetServiceException {
try {
URL url = new URI(BASE_SCHEME, BASE_HOST, String.format(
@ -422,10 +419,9 @@ public class GpodnetService {
* @throws IllegalArgumentException If username or deviceId is null.
* @throws GpodnetServiceAuthenticationException If there is an authentication error.
*/
public GpodnetSubscriptionChange getSubscriptionChanges(String username,
String deviceId, long timestamp) throws GpodnetServiceException {
Validate.notNull(username);
Validate.notNull(deviceId);
public GpodnetSubscriptionChange getSubscriptionChanges(@NonNull String username,
@NonNull String deviceId,
long timestamp) throws GpodnetServiceException {
String params = String.format("since=%d", timestamp);
String path = String.format("/api/2/subscriptions/%s/%s.json",
@ -460,11 +456,9 @@ public class GpodnetService {
* @throws de.danoeh.antennapod.core.gpoddernet.GpodnetServiceException if added or removed contain duplicates or if there
* is an authentication error.
*/
public GpodnetEpisodeActionPostResponse uploadEpisodeActions(Collection<GpodnetEpisodeAction> episodeActions)
public GpodnetEpisodeActionPostResponse uploadEpisodeActions(@NonNull Collection<GpodnetEpisodeAction> episodeActions)
throws GpodnetServiceException {
Validate.notNull(episodeActions);
String username = GpodnetPreferences.getUsername();
try {
@ -533,11 +527,9 @@ public class GpodnetService {
*
* @throws IllegalArgumentException If username or password is null.
*/
public void authenticate(String username, String password)
public void authenticate(@NonNull String username,
@NonNull String password)
throws GpodnetServiceException {
Validate.notNull(username);
Validate.notNull(password);
URL url;
try {
url = new URI(BASE_SCHEME, BASE_HOST, String.format(
@ -564,10 +556,8 @@ public class GpodnetService {
}.start();
}
private String executeRequest(Request.Builder requestB)
private String executeRequest(@NonNull Request.Builder requestB)
throws GpodnetServiceException {
Validate.notNull(requestB);
Request request = requestB.header("User-Agent", ClientConfig.USER_AGENT).build();
String responseString = null;
Response response = null;
@ -631,10 +621,8 @@ public class GpodnetService {
return result;
}
private String getStringFromResponseBody(ResponseBody body)
private String getStringFromResponseBody(@NonNull ResponseBody body)
throws GpodnetServiceException {
Validate.notNull(body);
ByteArrayOutputStream outputStream;
int contentLength = 0;
try {
@ -661,9 +649,8 @@ public class GpodnetService {
return outputStream.toString();
}
private void checkStatusCode(Response response)
private void checkStatusCode(@NonNull Response response)
throws GpodnetServiceException {
Validate.notNull(response);
int responseCode = response.code();
if (responseCode != HttpStatus.SC_OK) {
if (responseCode == HttpStatus.SC_UNAUTHORIZED) {
@ -675,17 +662,14 @@ public class GpodnetService {
}
}
private List<GpodnetPodcast> readPodcastListFromJSONArray(JSONArray array)
private List<GpodnetPodcast> readPodcastListFromJSONArray(@NonNull JSONArray array)
throws JSONException {
Validate.notNull(array);
List<GpodnetPodcast> result = new ArrayList<GpodnetPodcast>(
array.length());
for (int i = 0; i < array.length(); i++) {
result.add(readPodcastFromJSONObject(array.getJSONObject(i)));
}
return result;
}
private GpodnetPodcast readPodcastFromJSONObject(JSONObject object)
@ -730,10 +714,8 @@ public class GpodnetService {
logoUrl, website, mygpoLink);
}
private List<GpodnetDevice> readDeviceListFromJSONArray(JSONArray array)
private List<GpodnetDevice> readDeviceListFromJSONArray(@NonNull JSONArray array)
throws JSONException {
Validate.notNull(array);
List<GpodnetDevice> result = new ArrayList<GpodnetDevice>(
array.length());
for (int i = 0; i < array.length(); i++) {
@ -752,8 +734,7 @@ public class GpodnetService {
}
private GpodnetSubscriptionChange readSubscriptionChangesFromJSONObject(
JSONObject object) throws JSONException {
Validate.notNull(object);
@NonNull JSONObject object) throws JSONException {
List<String> added = new LinkedList<String>();
JSONArray jsonAdded = object.getJSONArray("add");
@ -772,8 +753,7 @@ public class GpodnetService {
}
private GpodnetEpisodeActionGetResponse readEpisodeActionsFromJSONObject(
JSONObject object) throws JSONException {
Validate.notNull(object);
@NonNull JSONObject object) throws JSONException {
List<GpodnetEpisodeAction> episodeActions = new ArrayList<GpodnetEpisodeAction>();
@ -789,5 +769,4 @@ public class GpodnetService {
return new GpodnetEpisodeActionGetResponse(episodeActions, timestamp);
}
}

View File

@ -1,6 +1,6 @@
package de.danoeh.antennapod.core.gpoddernet.model;
import org.apache.commons.lang3.Validate;
import android.support.annotation.NonNull;
public class GpodnetDevice {
@ -9,10 +9,10 @@ public class GpodnetDevice {
private DeviceType type;
private int subscriptions;
public GpodnetDevice(String id, String caption, String type,
public GpodnetDevice(@NonNull String id,
String caption,
String type,
int subscriptions) {
Validate.notNull(id);
this.id = id;
this.caption = caption;
this.type = DeviceType.fromString(type);

View File

@ -1,13 +1,9 @@
package de.danoeh.antennapod.core.gpoddernet.model;
import android.text.TextUtils;
import android.util.Log;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.json.JSONException;
import org.json.JSONObject;
@ -90,7 +86,7 @@ public class GpodnetEpisodeAction {
String podcast = object.optString("podcast", null);
String episode = object.optString("episode", null);
String actionString = object.optString("action", null);
if(StringUtils.isEmpty(podcast) || StringUtils.isEmpty(episode) || StringUtils.isEmpty(actionString)) {
if(TextUtils.isEmpty(podcast) || TextUtils.isEmpty(episode) || TextUtils.isEmpty(actionString)) {
return null;
}
GpodnetEpisodeAction.Action action;
@ -103,7 +99,7 @@ public class GpodnetEpisodeAction {
GpodnetEpisodeAction.Builder builder = new GpodnetEpisodeAction.Builder(podcast, episode, action)
.deviceId(deviceId);
String utcTimestamp = object.optString("timestamp", null);
if(StringUtils.isNotEmpty(utcTimestamp)) {
if(!TextUtils.isEmpty(utcTimestamp)) {
builder.timestamp(DateUtils.parse(utcTimestamp));
}
if(action == GpodnetEpisodeAction.Action.PLAY) {
@ -173,34 +169,34 @@ public class GpodnetEpisodeAction {
@Override
public boolean equals(Object o) {
if(o == null) return false;
if(this == o) return true;
if(this.getClass() != o.getClass()) return false;
GpodnetEpisodeAction that = (GpodnetEpisodeAction)o;
return new EqualsBuilder()
.append(this.podcast, that.podcast)
.append(this.episode, that.episode)
.append(this.deviceId, that.deviceId)
.append(this.action, that.action)
.append(this.timestamp, that.timestamp)
.append(this.started, that.started)
.append(this.position, that.position)
.append(this.total, that.total)
.isEquals();
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
GpodnetEpisodeAction that = (GpodnetEpisodeAction) o;
if (started != that.started) return false;
if (position != that.position) return false;
if (total != that.total) return false;
if (podcast != null ? !podcast.equals(that.podcast) : that.podcast != null) return false;
if (episode != null ? !episode.equals(that.episode) : that.episode != null) return false;
if (deviceId != null ? !deviceId.equals(that.deviceId) : that.deviceId != null)
return false;
if (action != that.action) return false;
return !(timestamp != null ? !timestamp.equals(that.timestamp) : that.timestamp != null);
}
@Override
public int hashCode() {
return new HashCodeBuilder()
.append(this.podcast)
.append(this.episode)
.append(this.deviceId)
.append(this.action)
.append(this.timestamp)
.append(this.started)
.append(this.position)
.append(this.total)
.toHashCode();
int result = podcast != null ? podcast.hashCode() : 0;
result = 31 * result + (episode != null ? episode.hashCode() : 0);
result = 31 * result + (deviceId != null ? deviceId.hashCode() : 0);
result = 31 * result + (action != null ? action.hashCode() : 0);
result = 31 * result + (timestamp != null ? timestamp.hashCode() : 0);
result = 31 * result + started;
result = 31 * result + position;
result = 31 * result + total;
return result;
}
public String writeToString() {
@ -245,7 +241,16 @@ public class GpodnetEpisodeAction {
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
return "GpodnetEpisodeAction{" +
"podcast='" + podcast + '\'' +
", episode='" + episode + '\'' +
", deviceId='" + deviceId + '\'' +
", action=" + action +
", timestamp=" + timestamp +
", started=" + started +
", position=" + position +
", total=" + total +
'}';
}
public static class Builder {

View File

@ -1,9 +1,7 @@
package de.danoeh.antennapod.core.gpoddernet.model;
import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import android.support.annotation.NonNull;
import java.util.List;
@ -12,8 +10,8 @@ public class GpodnetEpisodeActionGetResponse {
private final List<GpodnetEpisodeAction> episodeActions;
private final long timestamp;
public GpodnetEpisodeActionGetResponse(List<GpodnetEpisodeAction> episodeActions, long timestamp) {
Validate.notNull(episodeActions);
public GpodnetEpisodeActionGetResponse(@NonNull List<GpodnetEpisodeAction> episodeActions,
long timestamp) {
this.episodeActions = episodeActions;
this.timestamp = timestamp;
}
@ -28,7 +26,9 @@ public class GpodnetEpisodeActionGetResponse {
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
return "GpodnetEpisodeActionGetResponse{" +
"episodeActions=" + episodeActions +
", timestamp=" + timestamp +
'}';
}
}

View File

@ -1,6 +1,6 @@
package de.danoeh.antennapod.core.gpoddernet.model;
import org.apache.commons.lang3.Validate;
import android.support.annotation.NonNull;
public class GpodnetPodcast {
private String url;
@ -11,12 +11,13 @@ public class GpodnetPodcast {
private String website;
private String mygpoLink;
public GpodnetPodcast(String url, String title, String description,
int subscribers, String logoUrl, String website, String mygpoLink) {
Validate.notNull(url);
Validate.notNull(title);
Validate.notNull(description);
public GpodnetPodcast(@NonNull String url,
@NonNull String title,
@NonNull String description,
int subscribers,
String logoUrl,
String website,
String mygpoLink) {
this.url = url;
this.title = title;
this.description = description;

View File

@ -1,6 +1,6 @@
package de.danoeh.antennapod.core.gpoddernet.model;
import org.apache.commons.lang3.Validate;
import android.support.annotation.NonNull;
import java.util.List;
@ -9,11 +9,9 @@ public class GpodnetSubscriptionChange {
private List<String> removed;
private long timestamp;
public GpodnetSubscriptionChange(List<String> added, List<String> removed,
public GpodnetSubscriptionChange(@NonNull List<String> added,
@NonNull List<String> removed,
long timestamp) {
Validate.notNull(added);
Validate.notNull(removed);
this.added = added;
this.removed = removed;
this.timestamp = timestamp;

View File

@ -2,8 +2,7 @@ package de.danoeh.antennapod.core.gpoddernet.model;
import android.os.Parcel;
import android.os.Parcelable;
import org.apache.commons.lang3.Validate;
import android.support.annotation.NonNull;
public class GpodnetTag implements Parcelable {
@ -11,10 +10,7 @@ public class GpodnetTag implements Parcelable {
private final String tag;
private final int usage;
public GpodnetTag(String title, String tag, int usage) {
Validate.notNull(title);
Validate.notNull(tag);
public GpodnetTag(@NonNull String title, @NonNull String tag, int usage) {
this.title = title;
this.tag = tag;
this.usage = usage;

View File

@ -2,10 +2,9 @@ package de.danoeh.antennapod.core.preferences;
import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;
import android.util.Log;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
@ -293,7 +292,7 @@ public class GpodnetPreferences {
String[] lines = s.split("\n");
List<GpodnetEpisodeAction> result = new ArrayList<GpodnetEpisodeAction>(lines.length);
for(String line : lines) {
if(StringUtils.isNotBlank(line)) {
if(TextUtils.isEmpty(line)) {
GpodnetEpisodeAction action = GpodnetEpisodeAction.readFromString(line);
if(action != null) {
result.add(GpodnetEpisodeAction.readFromString(line));

View File

@ -7,12 +7,11 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.os.SystemClock;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.v4.app.NotificationCompat;
import android.text.TextUtils;
import android.util.Log;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
import org.json.JSONArray;
import org.json.JSONException;
@ -122,9 +121,8 @@ public class UserPreferences {
*
* @throws IllegalArgumentException if context is null
*/
public static void init(Context context) {
public static void init(@NonNull Context context) {
Log.d(TAG, "Creating new instance of UserPreferences");
Validate.notNull(context);
UserPreferences.context = context.getApplicationContext();
UserPreferences.prefs = PreferenceManager.getDefaultSharedPreferences(context);
@ -153,7 +151,7 @@ public class UserPreferences {
public static List<String> getHiddenDrawerItems() {
String hiddenItems = prefs.getString(PREF_HIDDEN_DRAWER_ITEMS, "");
return new ArrayList<String>(Arrays.asList(StringUtils.split(hiddenItems, ',')));
return new ArrayList<>(Arrays.asList(TextUtils.split(hiddenItems, ",")));
}
public static int getFeedOrder() {
@ -348,7 +346,7 @@ public class UserPreferences {
public static String[] getAutodownloadSelectedNetworks() {
String selectedNetWorks = prefs.getString(PREF_AUTODL_SELECTED_NETWORKS, "");
return StringUtils.split(selectedNetWorks, ',');
return TextUtils.split(selectedNetWorks, ",");
}
public static boolean shouldResumeAfterCall() {
@ -423,7 +421,9 @@ public class UserPreferences {
* flattrd. Must be a value between 0 and 1 (inclusive)
* */
public static void setAutoFlattrSettings( boolean enabled, float autoFlattrThreshold) {
Validate.inclusiveBetween(0.0, 1.0, autoFlattrThreshold);
if(autoFlattrThreshold < 0.0 || autoFlattrThreshold > 1.0) {
throw new IllegalArgumentException("Flattr threshold must be in range [0.0, 1.0]");
}
prefs.edit()
.putBoolean(PREF_AUTO_FLATTR, enabled)
.putFloat(PREF_AUTO_FLATTR_PLAYED_DURATION_THRESHOLD, autoFlattrThreshold)

View File

@ -3,10 +3,9 @@ package de.danoeh.antennapod.core.receiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.util.Log;
import org.apache.commons.lang3.StringUtils;
import de.danoeh.antennapod.core.preferences.PlaybackPreferences;
import de.danoeh.antennapod.core.preferences.UserPreferences;
@ -18,9 +17,9 @@ public class AlarmUpdateReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "Received intent");
if (StringUtils.equals(intent.getAction(), Intent.ACTION_BOOT_COMPLETED)) {
if (TextUtils.equals(intent.getAction(), Intent.ACTION_BOOT_COMPLETED)) {
Log.d(TAG, "Resetting update alarm after reboot");
} else if (StringUtils.equals(intent.getAction(), Intent.ACTION_PACKAGE_REPLACED)) {
} else if (TextUtils.equals(intent.getAction(), Intent.ACTION_PACKAGE_REPLACED)) {
Log.d(TAG, "Resetting update alarm after app upgrade");
}
PlaybackPreferences.init(context);

View File

@ -3,8 +3,7 @@ package de.danoeh.antennapod.core.service.download;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import org.apache.commons.lang3.Validate;
import android.support.annotation.NonNull;
import de.danoeh.antennapod.core.feed.FeedFile;
import de.danoeh.antennapod.core.util.URLChecker;
@ -27,11 +26,15 @@ public class DownloadRequest implements Parcelable {
protected long size;
protected int statusMsg;
public DownloadRequest(String destination, String source, String title,
long feedfileId, int feedfileType, String username, String password, boolean deleteOnFailure, Bundle arguments) {
Validate.notNull(destination);
Validate.notNull(source);
Validate.notNull(title);
public DownloadRequest(@NonNull String destination,
@NonNull String source,
@NonNull String title,
long feedfileId,
int feedfileType,
String username,
String password,
boolean deleteOnFailure,
Bundle arguments) {
this.destination = destination;
this.source = source;
@ -260,7 +263,7 @@ public class DownloadRequest implements Parcelable {
private int feedfileType;
private Bundle arguments;
public Builder(String destination, FeedFile item) {
public Builder(@NonNull String destination, @NonNull FeedFile item) {
this.destination = destination;
this.source = URLChecker.prepareURL(item.getDownload_url());
this.title = item.getHumanReadableIdentifier();
@ -285,9 +288,6 @@ public class DownloadRequest implements Parcelable {
}
public DownloadRequest build() {
Validate.notNull(destination);
Validate.notNull(source);
Validate.notNull(title);
return new DownloadRequest(this);
}

View File

@ -14,14 +14,14 @@ import android.media.MediaMetadataRetriever;
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
import android.support.annotation.NonNull;
import android.support.v4.app.NotificationCompat;
import android.support.v4.util.Pair;
import android.text.TextUtils;
import android.util.Log;
import android.webkit.URLUtil;
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;
@ -407,9 +407,11 @@ public class DownloadService extends Service {
@Override
public void onReceive(Context context, Intent intent) {
if (StringUtils.equals(intent.getAction(), ACTION_CANCEL_DOWNLOAD)) {
if (TextUtils.equals(intent.getAction(), ACTION_CANCEL_DOWNLOAD)) {
String url = intent.getStringExtra(EXTRA_DOWNLOAD_URL);
Validate.notNull(url, "ACTION_CANCEL_DOWNLOAD intent needs download url extra");
if(url == null) {
throw new IllegalArgumentException("ACTION_CANCEL_DOWNLOAD intent needs download url extra");
}
Log.d(TAG, "Cancelling download with url " + url);
Downloader d = getDownloader(url);
@ -420,7 +422,7 @@ public class DownloadService extends Service {
}
postDownloaders();
} else if (StringUtils.equals(intent.getAction(), ACTION_CANCEL_ALL_DOWNLOADS)) {
} else if (TextUtils.equals(intent.getAction(), ACTION_CANCEL_ALL_DOWNLOADS)) {
for (Downloader d : downloads) {
d.cancel();
Log.d(TAG, "Cancelled all downloads");
@ -909,7 +911,7 @@ public class DownloadService extends Service {
FeedItem item1 = feed.getItems().get(x);
FeedItem item2 = feed.getItems().get(y);
if (item1.hasItemImage() && item2.hasItemImage()) {
if (StringUtils.equals(item1.getImage().getDownload_url(), item2.getImage().getDownload_url())) {
if (TextUtils.equals(item1.getImage().getDownload_url(), item2.getImage().getDownload_url())) {
item2.setImage(null);
}
}
@ -1017,10 +1019,8 @@ public class DownloadService extends Service {
private DownloadRequest request;
private DownloadStatus status;
public MediaHandlerThread(DownloadStatus status, DownloadRequest request) {
Validate.notNull(status);
Validate.notNull(request);
public MediaHandlerThread(@NonNull DownloadStatus status,
@NonNull DownloadRequest request) {
this.status = status;
this.request = request;
}

View File

@ -1,8 +1,7 @@
package de.danoeh.antennapod.core.service.download;
import android.database.Cursor;
import org.apache.commons.lang3.Validate;
import android.support.annotation.NonNull;
import java.util.Date;
@ -62,10 +61,8 @@ public class DownloadStatus {
this.feedfileType = feedfileType;
}
public DownloadStatus(DownloadRequest request, DownloadError reason,
public DownloadStatus(@NonNull DownloadRequest request, DownloadError reason,
boolean successful, boolean cancelled, String reasonDetailed) {
Validate.notNull(request);
this.title = request.getTitle();
this.feedfileId = request.getFeedfileId();
this.feedfileType = request.getFeedfileType();
@ -77,10 +74,8 @@ public class DownloadStatus {
}
/** Constructor for creating new completed downloads. */
public DownloadStatus(FeedFile feedfile, String title, DownloadError reason,
boolean successful, String reasonDetailed) {
Validate.notNull(feedfile);
public DownloadStatus(@NonNull FeedFile feedfile, String title, DownloadError reason,
boolean successful, String reasonDetailed) {
this.title = title;
this.done = true;
this.feedfileId = feedfile.getId();

View File

@ -1,5 +1,6 @@
package de.danoeh.antennapod.core.service.download;
import android.text.TextUtils;
import android.util.Log;
import com.squareup.okhttp.OkHttpClient;
@ -10,7 +11,6 @@ import com.squareup.okhttp.ResponseBody;
import com.squareup.okhttp.internal.http.HttpDate;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpStatus;
import java.io.BufferedInputStream;
@ -86,7 +86,7 @@ public class HttpDownloader extends Downloader {
String credentials = encodeCredentials(parts[0], parts[1], "ISO-8859-1");
httpReq.header("Authorization", credentials);
}
} else if (!StringUtils.isEmpty(request.getUsername()) && request.getPassword() != null) {
} else if (!TextUtils.isEmpty(request.getUsername()) && request.getPassword() != null) {
String credentials = encodeCredentials(request.getUsername(), request.getPassword(),
"ISO-8859-1");
httpReq.header("Authorization", credentials);
@ -114,7 +114,10 @@ public class HttpDownloader extends Downloader {
}
responseBody = response.body();
String contentEncodingHeader = response.header("Content-Encoding");
boolean isGzip = StringUtils.equalsIgnoreCase(contentEncodingHeader, "gzip");
boolean isGzip = false;
if(!TextUtils.isEmpty(contentEncodingHeader)) {
isGzip = TextUtils.equals(contentEncodingHeader.toLowerCase(), "gzip");
}
Log.d(TAG, "Response code is " + response.code());
@ -126,7 +129,7 @@ public class HttpDownloader extends Downloader {
String credentials = encodeCredentials(parts[0], parts[1], "UTF-8");
httpReq.header("Authorization", credentials);
}
} else if (!StringUtils.isEmpty(request.getUsername()) && request.getPassword() != null) {
} else if (!TextUtils.isEmpty(request.getUsername()) && request.getPassword() != null) {
String credentials = encodeCredentials(request.getUsername(), request.getPassword(),
"UTF-8");
httpReq.header("Authorization", credentials);
@ -134,7 +137,9 @@ public class HttpDownloader extends Downloader {
response = httpClient.newCall(httpReq.build()).execute();
responseBody = response.body();
contentEncodingHeader = response.header("Content-Encoding");
isGzip = StringUtils.equalsIgnoreCase(contentEncodingHeader, "gzip");
if(!TextUtils.isEmpty(contentEncodingHeader)) {
isGzip = TextUtils.equals(contentEncodingHeader.toLowerCase(), "gzip");
}
}
if(!response.isSuccessful() && response.code() == HttpURLConnection.HTTP_NOT_MODIFIED) {
@ -167,7 +172,7 @@ public class HttpDownloader extends Downloader {
String contentRangeHeader = (fileExists) ? response.header("Content-Range") : null;
if (fileExists && response.code() == HttpStatus.SC_PARTIAL_CONTENT
&& !StringUtils.isEmpty(contentRangeHeader)) {
&& !TextUtils.isEmpty(contentRangeHeader)) {
String start = contentRangeHeader.substring("bytes ".length(),
contentRangeHeader.indexOf("-"));
request.setSoFar(Long.valueOf(start));

View File

@ -20,6 +20,7 @@ import android.os.IBinder;
import android.os.Vibrator;
import android.preference.PreferenceManager;
import android.support.v4.app.NotificationCompat;
import android.text.TextUtils;
import android.util.Log;
import android.util.Pair;
import android.view.KeyEvent;
@ -28,8 +29,6 @@ import android.widget.Toast;
import com.bumptech.glide.Glide;
import org.apache.commons.lang3.StringUtils;
import java.util.List;
import java.util.concurrent.ExecutionException;
@ -1019,7 +1018,7 @@ public class PlaybackService extends Service {
@Override
public void onReceive(Context context, Intent intent) {
if (StringUtils.equals(intent.getAction(), Intent.ACTION_HEADSET_PLUG)) {
if (TextUtils.equals(intent.getAction(), Intent.ACTION_HEADSET_PLUG)) {
int state = intent.getIntExtra("state", -1);
if (state != -1) {
Log.d(TAG, "Headset plug event. State is " + state);
@ -1041,7 +1040,7 @@ public class PlaybackService extends Service {
@Override
public void onReceive(Context context, Intent intent) {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
if (StringUtils.equals(intent.getAction(), BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED)) {
if (TextUtils.equals(intent.getAction(), BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED)) {
int state = intent.getIntExtra(BluetoothA2dp.EXTRA_STATE, -1);
if (state == BluetoothA2dp.STATE_CONNECTED) {
Log.d(TAG, "Received bluetooth connection intent");
@ -1102,7 +1101,7 @@ public class PlaybackService extends Service {
@Override
public void onReceive(Context context, Intent intent) {
if (StringUtils.equals(intent.getAction(), ACTION_SHUTDOWN_PLAYBACK_SERVICE)) {
if (TextUtils.equals(intent.getAction(), ACTION_SHUTDOWN_PLAYBACK_SERVICE)) {
stopSelf();
}
}
@ -1112,7 +1111,7 @@ public class PlaybackService extends Service {
private final BroadcastReceiver skipCurrentEpisodeReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (StringUtils.equals(intent.getAction(), ACTION_SKIP_CURRENT_EPISODE)) {
if (TextUtils.equals(intent.getAction(), ACTION_SKIP_CURRENT_EPISODE)) {
Log.d(TAG, "Received SKIP_CURRENT_EPISODE intent");
mediaPlayer.endPlayback(true);
}
@ -1122,7 +1121,7 @@ public class PlaybackService extends Service {
private final BroadcastReceiver pauseResumeCurrentEpisodeReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (StringUtils.equals(intent.getAction(), ACTION_RESUME_PLAY_CURRENT_EPISODE)) {
if (TextUtils.equals(intent.getAction(), ACTION_RESUME_PLAY_CURRENT_EPISODE)) {
Log.d(TAG, "Received RESUME_PLAY_CURRENT_EPISODE intent");
mediaPlayer.resume();
}
@ -1132,7 +1131,7 @@ public class PlaybackService extends Service {
private final BroadcastReceiver pausePlayCurrentEpisodeReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (StringUtils.equals(intent.getAction(), ACTION_PAUSE_PLAY_CURRENT_EPISODE)) {
if (TextUtils.equals(intent.getAction(), ACTION_PAUSE_PLAY_CURRENT_EPISODE)) {
Log.d(TAG, "Received PAUSE_PLAY_CURRENT_EPISODE intent");
mediaPlayer.pause(false, false);
}

View File

@ -10,6 +10,7 @@ import android.media.AudioManager;
import android.net.wifi.WifiManager;
import android.os.PowerManager;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.v4.media.MediaMetadataCompat;
import android.support.v4.media.session.MediaSessionCompat;
import android.support.v4.media.session.PlaybackStateCompat;
@ -23,8 +24,6 @@ import android.view.SurfaceHolder;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.Target;
import org.apache.commons.lang3.Validate;
import java.io.IOException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.LinkedBlockingDeque;
@ -92,10 +91,8 @@ public class PlaybackServiceMediaPlayer implements SharedPreferences.OnSharedPre
*/
private WifiManager.WifiLock wifiLock;
public PlaybackServiceMediaPlayer(Context context, PSMPCallback callback) {
Validate.notNull(context);
Validate.notNull(callback);
public PlaybackServiceMediaPlayer(@NonNull Context context,
@NonNull PSMPCallback callback) {
this.context = context;
this.callback = callback;
this.audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
@ -175,9 +172,7 @@ public class PlaybackServiceMediaPlayer implements SharedPreferences.OnSharedPre
* for playback immediately (see 'prepareImmediately' parameter for more details)
* @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) {
Validate.notNull(playable);
public void playMediaObject(@NonNull final Playable playable, final boolean stream, final boolean startWhenPrepared, final boolean prepareImmediately) {
Log.d(TAG, "playMediaObject(...)");
executor.submit(new Runnable() {
@Override
@ -203,8 +198,7 @@ public class PlaybackServiceMediaPlayer implements SharedPreferences.OnSharedPre
*
* @see #playMediaObject(de.danoeh.antennapod.core.util.playback.Playable, boolean, boolean, boolean)
*/
private void playMediaObject(final Playable playable, final boolean forceReset, final boolean stream, final boolean startWhenPrepared, final boolean prepareImmediately) {
Validate.notNull(playable);
private void playMediaObject(@NonNull final Playable playable, final boolean forceReset, final boolean stream, final boolean startWhenPrepared, final boolean prepareImmediately) {
if (!playerLock.isHeldByCurrentThread()) {
throw new IllegalStateException("method requires playerLock");
}
@ -573,9 +567,7 @@ public class PlaybackServiceMediaPlayer implements SharedPreferences.OnSharedPre
/**
* Seek to the start of the specified chapter.
*/
public void seekToChapter(Chapter c) {
Validate.notNull(c);
public void seekToChapter(@NonNull Chapter c) {
seekTo((int) c.getStart());
}
@ -840,9 +832,7 @@ public class PlaybackServiceMediaPlayer implements SharedPreferences.OnSharedPre
* @param newStatus The new PlayerStatus. This must not be null.
* @param newMedia The new playable object of the PSMP object. This can be null.
*/
private synchronized void setPlayerStatus(PlayerStatus newStatus, Playable newMedia) {
Validate.notNull(newStatus);
private synchronized void setPlayerStatus(@NonNull PlayerStatus newStatus, Playable newMedia) {
Log.d(TAG, "Setting player status to " + newStatus);
this.playerStatus = newStatus;

View File

@ -2,10 +2,9 @@ package de.danoeh.antennapod.core.service.playback;
import android.content.Context;
import android.os.Vibrator;
import android.support.annotation.NonNull;
import android.util.Log;
import org.apache.commons.lang3.Validate;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
@ -15,8 +14,8 @@ import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.event.QueueEvent;
import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.storage.DBReader;
import de.danoeh.antennapod.core.util.playback.Playable;
import de.greenrobot.event.EventBus;
@ -62,10 +61,8 @@ public class PlaybackServiceTaskManager {
* @param context
* @param callback A PSTMCallback object for notifying the user about updates. Must not be null.
*/
public PlaybackServiceTaskManager(Context context, PSTMCallback callback) {
Validate.notNull(context);
Validate.notNull(callback);
public PlaybackServiceTaskManager(@NonNull Context context,
@NonNull PSTMCallback callback) {
this.context = context;
this.callback = callback;
schedExecutor = new ScheduledThreadPoolExecutor(SCHED_EX_POOL_SIZE, new ThreadFactory() {
@ -200,7 +197,9 @@ public class PlaybackServiceTaskManager {
* @throws java.lang.IllegalArgumentException if waitingTime <= 0
*/
public synchronized void setSleepTimer(long waitingTime, boolean shakeToReset, boolean vibrate) {
Validate.isTrue(waitingTime > 0, "Waiting time <= 0");
if(waitingTime <= 0) {
throw new IllegalArgumentException("Waiting time <= 0");
}
Log.d(TAG, "Setting sleep timer to " + Long.toString(waitingTime) + " milliseconds");
if (isSleepTimerActive()) {
@ -275,9 +274,7 @@ public class PlaybackServiceTaskManager {
* it will be cancelled first.
* On completion, the callback's onChapterLoaded method will be called.
*/
public synchronized void startChapterLoader(final Playable media) {
Validate.notNull(media);
public synchronized void startChapterLoader(@NonNull final Playable media) {
if (isChapterLoaderActive()) {
cancelChapterLoader();
}

View File

@ -3,12 +3,12 @@ package de.danoeh.antennapod.core.storage;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.util.Log;
import android.webkit.URLUtil;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
import java.io.File;
import java.util.Map;
@ -71,10 +71,8 @@ public class DownloadRequester {
* call will return false.
* @return True if the download request was accepted, false otherwise.
*/
public synchronized boolean download(Context context, DownloadRequest request) {
Validate.notNull(context);
Validate.notNull(request);
public synchronized boolean download(@NonNull Context context,
@NonNull DownloadRequest request) {
if (downloads.containsKey(request.getSource())) {
if (BuildConfig.DEBUG) Log.i(TAG, "DownloadRequest is already stored.");
return false;
@ -145,7 +143,7 @@ public class DownloadRequester {
private boolean isFilenameAvailable(String path) {
for (String key : downloads.keySet()) {
DownloadRequest r = downloads.get(key);
if (StringUtils.equals(r.getDestination(), path)) {
if (TextUtils.equals(r.getDestination(), path)) {
if (BuildConfig.DEBUG)
Log.d(TAG, path
+ " is already used by another requested download");

View File

@ -14,8 +14,6 @@ import android.os.Build;
import android.text.TextUtils;
import android.util.Log;
import org.apache.commons.lang3.Validate;
import java.util.Arrays;
import java.util.List;
@ -1180,7 +1178,9 @@ public class PodDBAdapter {
* @throws IllegalArgumentException if limit < 0
*/
public final Cursor getCompletedMediaCursor(int limit) {
Validate.isTrue(limit >= 0, "Limit must be >= 0");
if(limit < 0) {
throw new IllegalArgumentException("Limit must be >= 0");
}
Cursor c = db.query(TABLE_NAME_FEED_MEDIA, null,
KEY_PLAYBACK_COMPLETION_DATE + " > 0", null, null,

View File

@ -3,8 +3,6 @@ package de.danoeh.antennapod.core.util;
import android.net.Uri;
import android.util.Log;
import org.apache.commons.lang3.StringUtils;
import de.danoeh.antennapod.core.BuildConfig;
/**
@ -32,19 +30,19 @@ public final class URLChecker {
* @return The prepared url
*/
public static String prepareURL(String url) {
url = StringUtils.trim(url);
url = url.trim();
if (url.startsWith("feed://")) {
if (BuildConfig.DEBUG) Log.d(TAG, "Replacing feed:// with http://");
return url.replaceFirst("feed://", "http://");
} else if (url.startsWith("pcast://")) {
if (BuildConfig.DEBUG) Log.d(TAG, "Removing pcast://");
return prepareURL(StringUtils.removeStart(url, "pcast://"));
return prepareURL(url.substring("pcast://".length()));
} else if (url.startsWith("itpc")) {
if (BuildConfig.DEBUG) Log.d(TAG, "Replacing itpc:// with http://");
return url.replaceFirst("itpc://", "http://");
} else if (url.startsWith(AP_SUBSCRIBE)) {
if (BuildConfig.DEBUG) Log.d(TAG, "Removing antennapod-subscribe://");
return prepareURL(StringUtils.removeStart(url, AP_SUBSCRIBE));
return prepareURL(url.substring(AP_SUBSCRIBE.length()));
} else if (!(url.startsWith("http://") || url.startsWith("https://"))) {
if (BuildConfig.DEBUG) Log.d(TAG, "Adding http:// at the beginning of the URL");
return "http://" + url;
@ -66,7 +64,7 @@ public final class URLChecker {
if (base == null) {
return prepareURL(url);
}
url = StringUtils.trim(url);
url = url.trim();
base = prepareURL(base);
Uri urlUri = Uri.parse(url);
Uri baseUri = Uri.parse(base);

View File

@ -8,9 +8,9 @@ import android.content.SharedPreferences;
import android.net.Uri;
import android.preference.PreferenceManager;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.util.Log;
import org.apache.commons.lang3.StringUtils;
import org.shredzone.flattr4j.FlattrService;
import org.shredzone.flattr4j.exception.FlattrException;
import org.shredzone.flattr4j.model.Flattr;
@ -78,8 +78,8 @@ public class FlattrUtils {
* Returns true if FLATTR_APP_KEY and FLATTR_APP_SECRET in BuildConfig are not null and not empty
*/
public static boolean hasAPICredentials() {
return StringUtils.isNotEmpty(ClientConfig.flattrCallbacks.getFlattrAppKey())
&& StringUtils.isNotEmpty(ClientConfig.flattrCallbacks.getFlattrAppSecret());
return !TextUtils.isEmpty(ClientConfig.flattrCallbacks.getFlattrAppKey())
&& !TextUtils.isEmpty(ClientConfig.flattrCallbacks.getFlattrAppSecret());
}
public static boolean hasToken() {

View File

@ -13,6 +13,8 @@ import android.media.MediaPlayer;
import android.os.AsyncTask;
import android.os.IBinder;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.util.Log;
import android.util.Pair;
import android.view.SurfaceHolder;
@ -22,9 +24,6 @@ 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 java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
@ -74,8 +73,7 @@ public abstract class PlaybackController {
*/
private boolean reinitOnPause;
public PlaybackController(Activity activity, boolean reinitOnPause) {
Validate.notNull(activity);
public PlaybackController(@NonNull Activity activity, boolean reinitOnPause) {
this.activity = activity;
this.reinitOnPause = reinitOnPause;
@ -360,7 +358,7 @@ public abstract class PlaybackController {
@Override
public void onReceive(Context context, Intent intent) {
if (isConnectedToPlaybackService()) {
if (StringUtils.equals(intent.getAction(),
if (TextUtils.equals(intent.getAction(),
PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE)) {
release();
onShutdownNotification();

View File

@ -2,10 +2,10 @@ package de.danoeh.antennapod.core.util.playback;
import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.NonNull;
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;
@ -158,8 +158,7 @@ public class Timeline {
}
public void setShownotesProvider(ShownotesProvider shownotesProvider) {
Validate.notNull(shownotesProvider);
public void setShownotesProvider(@NonNull ShownotesProvider shownotesProvider) {
this.shownotesProvider = shownotesProvider;
}
}

View File

@ -1,7 +1,8 @@
package de.danoeh.antennapod.core.util.syndication;
import android.net.Uri;
import org.apache.commons.lang3.StringUtils;
import android.text.TextUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
@ -50,7 +51,7 @@ public class FeedDiscoverer {
for (Element link : links) {
String rel = link.attr("rel");
String href = link.attr("href");
if (!StringUtils.isEmpty(href) &&
if (!TextUtils.isEmpty(href) &&
(rel.equals("alternate") || rel.equals("feed"))) {
String type = link.attr("type");
if (type.equals(MIME_RSS) || type.equals(MIME_ATOM)) {
@ -58,7 +59,7 @@ public class FeedDiscoverer {
String processedUrl = processURL(baseUrl, href);
if (processedUrl != null) {
res.put(processedUrl,
(StringUtils.isEmpty(title)) ? href : title);
(TextUtils.isEmpty(title)) ? href : title);
}
}
}