Simplify conditionals

This commit is contained in:
Andrew Rabert 2018-04-24 20:20:20 -04:00
parent ff8862c723
commit 0c67244749
11 changed files with 35 additions and 78 deletions

View File

@ -56,7 +56,7 @@ public class PlaylistAdapter extends SectionAdapter<Playlist> implements FastScr
@Override
public String getTextToShowInBubble(int position) {
Object item = getItemForPosition(position);
if (item instanceof Playlist) {
if (item != null) {
return getNameIndex(((Playlist) item).getName());
} else {
return null;

View File

@ -329,7 +329,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
if (downloadService != null) {
SharedPreferences prefs = Util.getPreferences(context);
boolean equalizerOn = prefs.getBoolean(Constants.PREFERENCES_EQUALIZER_ON, false);
if (equalizerOn && downloadService != null) {
if (equalizerOn) {
if (downloadService.getEqualizerController() != null && downloadService.getEqualizerController().isEnabled()) {
menu.findItem(R.id.menu_equalizer).setChecked(true);
}
@ -517,7 +517,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
startFlipped = false;
}
if (currentPlaying == null && downloadService != null && currentPlaying == downloadService.getCurrentPlaying()) {
if (currentPlaying == null && downloadService != null && null == downloadService.getCurrentPlaying()) {
getImageLoader().loadBlurImage(albumArtBackgroundView, null, true, false);
getImageLoader().loadImage(albumArtImageView, null, true, false);
}

View File

@ -531,9 +531,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
gridLayoutManager.setSpanSizeLookup(spanSizeLookup);
}
RecyclerView.ItemDecoration itemDecoration = getItemDecoration();
if (itemDecoration != null) {
recyclerView.addItemDecoration(itemDecoration);
}
recyclerView.addItemDecoration(itemDecoration);
return gridLayoutManager;
}

View File

@ -186,7 +186,7 @@ public class CachedMusicService implements MusicService {
@Override
protected Void doInBackground() throws Throwable {
refreshed = musicService.getArtist(id, name, refresh, context, null);
refreshed = musicService.getArtist(id, name, false, context, null);
cached.updateMetadata(refreshed);
deleteRemovedEntries(context, refreshed, cached);
FileUtil.serialize(context, refreshed, getCacheName(context, "artist", id));
@ -235,7 +235,7 @@ public class CachedMusicService implements MusicService {
@Override
protected Void doInBackground() throws Throwable {
refreshed = musicService.getAlbum(id, name, refresh, context, null);
refreshed = musicService.getAlbum(id, name, false, context, null);
updateAllSongs(context, refreshed);
metadataUpdated = cached.updateMetadata(refreshed);
deleteRemovedEntries(context, refreshed, cached);
@ -368,17 +368,9 @@ public class CachedMusicService implements MusicService {
@Override
public void updateResult(List<Entry> objects, Entry result) {
// Make sure this playlist is supposed to be synced
boolean supposedToUnpin = false;
// Remove in reverse order so indexes are still correct as we iterate through
for (ListIterator<Integer> iterator = toRemove.listIterator(toRemove.size()); iterator.hasPrevious(); ) {
int index = iterator.previous();
if (supposedToUnpin) {
Entry entry = objects.get(index);
DownloadFile file = new DownloadFile(context, entry, true);
file.unpin();
}
objects.remove(index);
}

View File

@ -242,10 +242,6 @@ public abstract class BackgroundTask<T> implements ProgressListener {
public void onDone(T result) {
done(result);
if (onCompletionListener != null) {
onCompletionListener.run();
}
}
public void onError(Throwable t) {

View File

@ -201,7 +201,7 @@ public class ImageLoader {
cache.get(key);
}
if (bitmap != null && bitmap.isRecycled()) {
if (bitmap.isRecycled()) {
bitmap = null;
}
return bitmap;
@ -310,7 +310,7 @@ public class ImageLoader {
TransitionDrawable tmp = (TransitionDrawable) existingDrawable;
existingDrawable = tmp.getDrawable(tmp.getNumberOfLayers() - 1);
}
if (existingDrawable != null && drawable != null) {
if (existingDrawable != null) {
Drawable[] layers = new Drawable[]{existingDrawable, drawable};
final TransitionDrawable transitionDrawable = new TransitionDrawable(layers);
imageView.setImageDrawable(transitionDrawable);

View File

@ -165,7 +165,7 @@ public final class Notifications {
// Create actions for media buttons
PendingIntent pendingIntent;
int previous = 0, pause, next, close = 0, rewind = 0, fastForward = 0;
int previous = 0, pause, next, close = 0;
if (persistent && !expanded) {
pause = R.id.control_previous;
next = R.id.control_pause;
@ -188,42 +188,24 @@ public final class Notifications {
pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0);
rv.setOnClickPendingIntent(previous, pendingIntent);
}
if (rewind > 0) {
Intent rewindIntent = new Intent("KEYCODE_MEDIA_REWIND");
rewindIntent.setComponent(new ComponentName(context, DownloadService.class));
rewindIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_REWIND));
pendingIntent = PendingIntent.getService(context, 0, rewindIntent, 0);
rv.setOnClickPendingIntent(rewind, pendingIntent);
}
if (pause > 0) {
if (playing) {
Intent pauseIntent = new Intent("KEYCODE_MEDIA_PLAY_PAUSE");
pauseIntent.setComponent(new ComponentName(context, DownloadService.class));
pauseIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE));
pendingIntent = PendingIntent.getService(context, 0, pauseIntent, 0);
rv.setOnClickPendingIntent(pause, pendingIntent);
} else {
Intent prevIntent = new Intent("KEYCODE_MEDIA_START");
prevIntent.setComponent(new ComponentName(context, DownloadService.class));
prevIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_PLAY));
pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0);
rv.setOnClickPendingIntent(pause, pendingIntent);
}
}
if (next > 0) {
Intent nextIntent = new Intent("KEYCODE_MEDIA_NEXT");
nextIntent.setComponent(new ComponentName(context, DownloadService.class));
nextIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_NEXT));
pendingIntent = PendingIntent.getService(context, 0, nextIntent, 0);
rv.setOnClickPendingIntent(next, pendingIntent);
}
if (fastForward > 0) {
Intent fastForwardIntent = new Intent("KEYCODE_MEDIA_FAST_FORWARD");
fastForwardIntent.setComponent(new ComponentName(context, DownloadService.class));
fastForwardIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_FAST_FORWARD));
pendingIntent = PendingIntent.getService(context, 0, fastForwardIntent, 0);
rv.setOnClickPendingIntent(fastForward, pendingIntent);
if (playing) {
Intent pauseIntent = new Intent("KEYCODE_MEDIA_PLAY_PAUSE");
pauseIntent.setComponent(new ComponentName(context, DownloadService.class));
pauseIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE));
pendingIntent = PendingIntent.getService(context, 0, pauseIntent, 0);
rv.setOnClickPendingIntent(pause, pendingIntent);
} else {
Intent prevIntent = new Intent("KEYCODE_MEDIA_START");
prevIntent.setComponent(new ComponentName(context, DownloadService.class));
prevIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_PLAY));
pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0);
rv.setOnClickPendingIntent(pause, pendingIntent);
}
Intent nextIntent = new Intent("KEYCODE_MEDIA_NEXT");
nextIntent.setComponent(new ComponentName(context, DownloadService.class));
nextIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_NEXT));
pendingIntent = PendingIntent.getService(context, 0, nextIntent, 0);
rv.setOnClickPendingIntent(next, pendingIntent);
if (close > 0) {
Intent prevIntent = new Intent("KEYCODE_MEDIA_STOP");
prevIntent.setComponent(new ComponentName(context, DownloadService.class));

View File

@ -127,8 +127,7 @@ public class ShufflePlayBuffer {
// Get capacity based
int n = capacity - buffer.size();
String folder = null;
MusicDirectory songs = service.getRandomSongs(n, folder, genre, startYear, endYear, context, null);
MusicDirectory songs = service.getRandomSongs(n, null, genre, startYear, endYear, context, null);
synchronized (buffer) {
lastCount = 0;

View File

@ -302,7 +302,7 @@ public final class Util {
String currentSSID = Util.getSSID(context);
String[] ssidParts = SSID.split(",");
if ("".equals(SSID) || SSID.equals(currentSSID) || Arrays.asList(ssidParts).contains(currentSSID)) {
if (SSID.equals(currentSSID) || Arrays.asList(ssidParts).contains(currentSSID)) {
String internalUrl = prefs.getString(Constants.PREFERENCES_KEY_SERVER_INTERNAL_URL + instance, null);
if (internalUrl != null && !"".equals(internalUrl) && !"http://".equals(internalUrl)) {
serverUrl = internalUrl;

View File

@ -78,14 +78,11 @@ public class CacheLocationPreference extends EditTextPreference {
try {
if (dir != null) {
if (Environment.isExternalStorageRemovable(dir)) {
if (externalDir != null) {
externalDir = dir;
}
} else {
internalDir = dir;
}
if (internalDir != null && externalDir != null) {
if (internalDir != null && null != null) {
break;
}
}
@ -96,12 +93,10 @@ public class CacheLocationPreference extends EditTextPreference {
}
// Before 5.0, we have to guess. Most of the time the SD card is last
if (externalDir == null) {
for (int i = dirs.length - 1; i >= 0; i--) {
if (dirs[i] != null) {
externalDir = dirs[i];
break;
}
for (int i = dirs.length - 1; i >= 0; i--) {
if (dirs[i] != null) {
externalDir = dirs[i];
break;
}
}
if (internalDir == null) {
@ -115,7 +110,7 @@ public class CacheLocationPreference extends EditTextPreference {
final File finalInternalDir = new File(internalDir, "music");
final File finalExternalDir = new File(externalDir, "music");
if (finalInternalDir != null && (finalInternalDir.exists() || finalInternalDir.mkdirs())) {
if (finalInternalDir.exists() || finalInternalDir.mkdirs()) {
internalLocation.setOnClickListener(v -> {
String path = finalInternalDir.getPath();
editText.setText(path);
@ -124,7 +119,7 @@ public class CacheLocationPreference extends EditTextPreference {
internalLocation.setEnabled(false);
}
if (finalExternalDir != null && !finalInternalDir.equals(finalExternalDir) && (finalExternalDir.exists() || finalExternalDir.mkdirs())) {
if (!finalInternalDir.equals(finalExternalDir) && (finalExternalDir.exists() || finalExternalDir.mkdirs())) {
externalLocation.setOnClickListener(v -> {
String path = finalExternalDir.getPath();
editText.setText(path);

View File

@ -51,7 +51,6 @@ public class SettingView extends UpdateView2<Setting, Boolean> {
item2 = false;
}
int res = -1;
if (setting instanceof MusicFolderSetting) {
titleView.setText(((MusicFolderSetting) setting).getLabel());
} else {
@ -59,10 +58,6 @@ public class SettingView extends UpdateView2<Setting, Boolean> {
titleView.setText(name);
}
if (res != -1) {
titleView.setText(res);
}
if (setting.getValue()) {
checkBox.setChecked(setting.getValue());
} else {