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 @Override
public String getTextToShowInBubble(int position) { public String getTextToShowInBubble(int position) {
Object item = getItemForPosition(position); Object item = getItemForPosition(position);
if (item instanceof Playlist) { if (item != null) {
return getNameIndex(((Playlist) item).getName()); return getNameIndex(((Playlist) item).getName());
} else { } else {
return null; return null;

View File

@ -329,7 +329,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
if (downloadService != null) { if (downloadService != null) {
SharedPreferences prefs = Util.getPreferences(context); SharedPreferences prefs = Util.getPreferences(context);
boolean equalizerOn = prefs.getBoolean(Constants.PREFERENCES_EQUALIZER_ON, false); boolean equalizerOn = prefs.getBoolean(Constants.PREFERENCES_EQUALIZER_ON, false);
if (equalizerOn && downloadService != null) { if (equalizerOn) {
if (downloadService.getEqualizerController() != null && downloadService.getEqualizerController().isEnabled()) { if (downloadService.getEqualizerController() != null && downloadService.getEqualizerController().isEnabled()) {
menu.findItem(R.id.menu_equalizer).setChecked(true); menu.findItem(R.id.menu_equalizer).setChecked(true);
} }
@ -517,7 +517,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
startFlipped = false; 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().loadBlurImage(albumArtBackgroundView, null, true, false);
getImageLoader().loadImage(albumArtImageView, 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); gridLayoutManager.setSpanSizeLookup(spanSizeLookup);
} }
RecyclerView.ItemDecoration itemDecoration = getItemDecoration(); RecyclerView.ItemDecoration itemDecoration = getItemDecoration();
if (itemDecoration != null) { recyclerView.addItemDecoration(itemDecoration);
recyclerView.addItemDecoration(itemDecoration);
}
return gridLayoutManager; return gridLayoutManager;
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -78,14 +78,11 @@ public class CacheLocationPreference extends EditTextPreference {
try { try {
if (dir != null) { if (dir != null) {
if (Environment.isExternalStorageRemovable(dir)) { if (Environment.isExternalStorageRemovable(dir)) {
if (externalDir != null) {
externalDir = dir;
}
} else { } else {
internalDir = dir; internalDir = dir;
} }
if (internalDir != null && externalDir != null) { if (internalDir != null && null != null) {
break; 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 // 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--) {
for (int i = dirs.length - 1; i >= 0; i--) { if (dirs[i] != null) {
if (dirs[i] != null) { externalDir = dirs[i];
externalDir = dirs[i]; break;
break;
}
} }
} }
if (internalDir == null) { if (internalDir == null) {
@ -115,7 +110,7 @@ public class CacheLocationPreference extends EditTextPreference {
final File finalInternalDir = new File(internalDir, "music"); final File finalInternalDir = new File(internalDir, "music");
final File finalExternalDir = new File(externalDir, "music"); final File finalExternalDir = new File(externalDir, "music");
if (finalInternalDir != null && (finalInternalDir.exists() || finalInternalDir.mkdirs())) { if (finalInternalDir.exists() || finalInternalDir.mkdirs()) {
internalLocation.setOnClickListener(v -> { internalLocation.setOnClickListener(v -> {
String path = finalInternalDir.getPath(); String path = finalInternalDir.getPath();
editText.setText(path); editText.setText(path);
@ -124,7 +119,7 @@ public class CacheLocationPreference extends EditTextPreference {
internalLocation.setEnabled(false); internalLocation.setEnabled(false);
} }
if (finalExternalDir != null && !finalInternalDir.equals(finalExternalDir) && (finalExternalDir.exists() || finalExternalDir.mkdirs())) { if (!finalInternalDir.equals(finalExternalDir) && (finalExternalDir.exists() || finalExternalDir.mkdirs())) {
externalLocation.setOnClickListener(v -> { externalLocation.setOnClickListener(v -> {
String path = finalExternalDir.getPath(); String path = finalExternalDir.getPath();
editText.setText(path); editText.setText(path);

View File

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