From 0c67244749c8cda71daa1c13e4f51244f21d5f13 Mon Sep 17 00:00:00 2001 From: Andrew Rabert Date: Tue, 24 Apr 2018 20:20:20 -0400 Subject: [PATCH] Simplify conditionals --- .../audinaut/adapter/PlaylistAdapter.java | 2 +- .../fragments/NowPlayingFragment.java | 4 +- .../audinaut/fragments/SubsonicFragment.java | 4 +- .../audinaut/service/CachedMusicService.java | 12 +---- .../nullsum/audinaut/util/BackgroundTask.java | 4 -- .../nullsum/audinaut/util/ImageLoader.java | 4 +- .../nullsum/audinaut/util/Notifications.java | 54 +++++++------------ .../audinaut/util/ShufflePlayBuffer.java | 3 +- .../java/net/nullsum/audinaut/util/Util.java | 2 +- .../view/CacheLocationPreference.java | 19 +++---- .../nullsum/audinaut/view/SettingView.java | 5 -- 11 files changed, 35 insertions(+), 78 deletions(-) diff --git a/app/src/main/java/net/nullsum/audinaut/adapter/PlaylistAdapter.java b/app/src/main/java/net/nullsum/audinaut/adapter/PlaylistAdapter.java index 7ad551f..9e093a8 100644 --- a/app/src/main/java/net/nullsum/audinaut/adapter/PlaylistAdapter.java +++ b/app/src/main/java/net/nullsum/audinaut/adapter/PlaylistAdapter.java @@ -56,7 +56,7 @@ public class PlaylistAdapter extends SectionAdapter 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; diff --git a/app/src/main/java/net/nullsum/audinaut/fragments/NowPlayingFragment.java b/app/src/main/java/net/nullsum/audinaut/fragments/NowPlayingFragment.java index 98e6e63..5e7f201 100644 --- a/app/src/main/java/net/nullsum/audinaut/fragments/NowPlayingFragment.java +++ b/app/src/main/java/net/nullsum/audinaut/fragments/NowPlayingFragment.java @@ -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); } diff --git a/app/src/main/java/net/nullsum/audinaut/fragments/SubsonicFragment.java b/app/src/main/java/net/nullsum/audinaut/fragments/SubsonicFragment.java index da9710d..bd6bcc7 100644 --- a/app/src/main/java/net/nullsum/audinaut/fragments/SubsonicFragment.java +++ b/app/src/main/java/net/nullsum/audinaut/fragments/SubsonicFragment.java @@ -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; } diff --git a/app/src/main/java/net/nullsum/audinaut/service/CachedMusicService.java b/app/src/main/java/net/nullsum/audinaut/service/CachedMusicService.java index a06e1eb..ce5498f 100644 --- a/app/src/main/java/net/nullsum/audinaut/service/CachedMusicService.java +++ b/app/src/main/java/net/nullsum/audinaut/service/CachedMusicService.java @@ -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 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 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); } diff --git a/app/src/main/java/net/nullsum/audinaut/util/BackgroundTask.java b/app/src/main/java/net/nullsum/audinaut/util/BackgroundTask.java index f1b5ea5..2e5ffd9 100644 --- a/app/src/main/java/net/nullsum/audinaut/util/BackgroundTask.java +++ b/app/src/main/java/net/nullsum/audinaut/util/BackgroundTask.java @@ -242,10 +242,6 @@ public abstract class BackgroundTask implements ProgressListener { public void onDone(T result) { done(result); - - if (onCompletionListener != null) { - onCompletionListener.run(); - } } public void onError(Throwable t) { diff --git a/app/src/main/java/net/nullsum/audinaut/util/ImageLoader.java b/app/src/main/java/net/nullsum/audinaut/util/ImageLoader.java index 2f15110..e48f483 100644 --- a/app/src/main/java/net/nullsum/audinaut/util/ImageLoader.java +++ b/app/src/main/java/net/nullsum/audinaut/util/ImageLoader.java @@ -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); diff --git a/app/src/main/java/net/nullsum/audinaut/util/Notifications.java b/app/src/main/java/net/nullsum/audinaut/util/Notifications.java index 54e678b..ce3c721 100644 --- a/app/src/main/java/net/nullsum/audinaut/util/Notifications.java +++ b/app/src/main/java/net/nullsum/audinaut/util/Notifications.java @@ -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)); diff --git a/app/src/main/java/net/nullsum/audinaut/util/ShufflePlayBuffer.java b/app/src/main/java/net/nullsum/audinaut/util/ShufflePlayBuffer.java index 049cb73..ab229cb 100644 --- a/app/src/main/java/net/nullsum/audinaut/util/ShufflePlayBuffer.java +++ b/app/src/main/java/net/nullsum/audinaut/util/ShufflePlayBuffer.java @@ -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; diff --git a/app/src/main/java/net/nullsum/audinaut/util/Util.java b/app/src/main/java/net/nullsum/audinaut/util/Util.java index fc0a09e..efd2a16 100644 --- a/app/src/main/java/net/nullsum/audinaut/util/Util.java +++ b/app/src/main/java/net/nullsum/audinaut/util/Util.java @@ -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; diff --git a/app/src/main/java/net/nullsum/audinaut/view/CacheLocationPreference.java b/app/src/main/java/net/nullsum/audinaut/view/CacheLocationPreference.java index 3da78ca..b617e6c 100644 --- a/app/src/main/java/net/nullsum/audinaut/view/CacheLocationPreference.java +++ b/app/src/main/java/net/nullsum/audinaut/view/CacheLocationPreference.java @@ -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); diff --git a/app/src/main/java/net/nullsum/audinaut/view/SettingView.java b/app/src/main/java/net/nullsum/audinaut/view/SettingView.java index 17c092c..46ef648 100644 --- a/app/src/main/java/net/nullsum/audinaut/view/SettingView.java +++ b/app/src/main/java/net/nullsum/audinaut/view/SettingView.java @@ -51,7 +51,6 @@ public class SettingView extends UpdateView2 { item2 = false; } - int res = -1; if (setting instanceof MusicFolderSetting) { titleView.setText(((MusicFolderSetting) setting).getLabel()); } else { @@ -59,10 +58,6 @@ public class SettingView extends UpdateView2 { titleView.setText(name); } - if (res != -1) { - titleView.setText(res); - } - if (setting.getValue()) { checkBox.setChecked(setting.getValue()); } else {