From e5702c1761d0b7771d28558f74eaa985969f9149 Mon Sep 17 00:00:00 2001 From: Andrew Rabert Date: Mon, 3 Dec 2018 20:08:27 -0500 Subject: [PATCH] Misc refactor --- .../audinaut/activity/SubsonicActivity.java | 2 +- .../activity/SubsonicFragmentActivity.java | 12 +++++----- .../audinaut/fragments/DownloadFragment.java | 4 ++-- .../audinaut/fragments/MainFragment.java | 2 +- .../fragments/NowPlayingFragment.java | 22 +++++++++---------- .../fragments/SelectRecyclerFragment.java | 2 +- .../fragments/SelectYearFragment.java | 2 +- .../audinaut/fragments/SettingsFragment.java | 2 +- .../audinaut/fragments/SubsonicFragment.java | 6 ++--- .../audinaut/service/CachedMusicService.java | 2 +- .../audinaut/service/OfflineMusicService.java | 14 ++++++------ .../audinaut/service/RESTMusicService.java | 2 +- .../service/sync/AuthenticatorService.java | 11 +++++----- .../util/DownloadFileItemHelperCallback.java | 2 +- .../nullsum/audinaut/util/ImageLoader.java | 2 +- 15 files changed, 43 insertions(+), 44 deletions(-) diff --git a/app/src/main/java/net/nullsum/audinaut/activity/SubsonicActivity.java b/app/src/main/java/net/nullsum/audinaut/activity/SubsonicActivity.java index 4280175..31a1163 100644 --- a/app/src/main/java/net/nullsum/audinaut/activity/SubsonicActivity.java +++ b/app/src/main/java/net/nullsum/audinaut/activity/SubsonicActivity.java @@ -827,7 +827,7 @@ public class SubsonicActivity extends AppCompatActivity implements OnItemSelecte if (service != null) { new SilentBackgroundTask(this) { @Override - protected Void doInBackground() throws Throwable { + protected Void doInBackground() { service.clearIncomplete(); return null; } diff --git a/app/src/main/java/net/nullsum/audinaut/activity/SubsonicFragmentActivity.java b/app/src/main/java/net/nullsum/audinaut/activity/SubsonicFragmentActivity.java index bab8dcf..f353dd3 100644 --- a/app/src/main/java/net/nullsum/audinaut/activity/SubsonicFragmentActivity.java +++ b/app/src/main/java/net/nullsum/audinaut/activity/SubsonicFragmentActivity.java @@ -233,7 +233,7 @@ public class SubsonicFragmentActivity extends SubsonicActivity implements Downlo rewindButton = findViewById(R.id.download_rewind); rewindButton.setOnClickListener(v -> new SilentBackgroundTask(SubsonicFragmentActivity.this) { @Override - protected Void doInBackground() throws Throwable { + protected Void doInBackground() { if (getDownloadService() != null) { getDownloadService().rewind(); } @@ -244,7 +244,7 @@ public class SubsonicFragmentActivity extends SubsonicActivity implements Downlo previousButton = findViewById(R.id.download_previous); previousButton.setOnClickListener(v -> new SilentBackgroundTask(SubsonicFragmentActivity.this) { @Override - protected Void doInBackground() throws Throwable { + protected Void doInBackground() { if (getDownloadService() != null) { getDownloadService().previous(); } @@ -255,7 +255,7 @@ public class SubsonicFragmentActivity extends SubsonicActivity implements Downlo startButton = findViewById(R.id.download_start); startButton.setOnClickListener(v -> new SilentBackgroundTask(SubsonicFragmentActivity.this) { @Override - protected Void doInBackground() throws Throwable { + protected Void doInBackground() { PlayerState state = getDownloadService().getPlayerState(); if (state == PlayerState.STARTED) { getDownloadService().pause(); @@ -269,7 +269,7 @@ public class SubsonicFragmentActivity extends SubsonicActivity implements Downlo nextButton = findViewById(R.id.download_next); nextButton.setOnClickListener(v -> new SilentBackgroundTask(SubsonicFragmentActivity.this) { @Override - protected Void doInBackground() throws Throwable { + protected Void doInBackground() { if (getDownloadService() != null) { getDownloadService().next(); } @@ -280,7 +280,7 @@ public class SubsonicFragmentActivity extends SubsonicActivity implements Downlo fastforwardButton = findViewById(R.id.download_fastforward); fastforwardButton.setOnClickListener(v -> new SilentBackgroundTask(SubsonicFragmentActivity.this) { @Override - protected Void doInBackground() throws Throwable { + protected Void doInBackground() { if (getDownloadService() == null) { return null; } @@ -613,7 +613,7 @@ public class SubsonicFragmentActivity extends SubsonicActivity implements Downlo new SilentBackgroundTask(this) { @Override - protected Void doInBackground() throws Throwable { + protected Void doInBackground() { AccountManager accountManager = (AccountManager) context.getSystemService(ACCOUNT_SERVICE); Account account = new Account(Constants.SYNC_ACCOUNT_NAME, Constants.SYNC_ACCOUNT_TYPE); accountManager.addAccountExplicitly(account, null, null); diff --git a/app/src/main/java/net/nullsum/audinaut/fragments/DownloadFragment.java b/app/src/main/java/net/nullsum/audinaut/fragments/DownloadFragment.java index 1ae3976..39ba840 100644 --- a/app/src/main/java/net/nullsum/audinaut/fragments/DownloadFragment.java +++ b/app/src/main/java/net/nullsum/audinaut/fragments/DownloadFragment.java @@ -91,7 +91,7 @@ public class DownloadFragment extends SelectRecyclerFragment imple } @Override - public List getObjects(MusicService musicService, boolean refresh, ProgressListener listener) throws Exception { + public List getObjects(MusicService musicService, boolean refresh, ProgressListener listener) { DownloadService downloadService = getDownloadService(); if (downloadService == null) { return new ArrayList<>(); @@ -139,7 +139,7 @@ public class DownloadFragment extends SelectRecyclerFragment imple case R.id.menu_remove_all: Util.confirmDialog(context, R.string.download_menu_remove_all, "", (dialog, which) -> new SilentBackgroundTask(context) { @Override - protected Void doInBackground() throws Throwable { + protected Void doInBackground() { getDownloadService().clearBackground(); return null; } diff --git a/app/src/main/java/net/nullsum/audinaut/fragments/MainFragment.java b/app/src/main/java/net/nullsum/audinaut/fragments/MainFragment.java index 1a5c76c..2330ee0 100644 --- a/app/src/main/java/net/nullsum/audinaut/fragments/MainFragment.java +++ b/app/src/main/java/net/nullsum/audinaut/fragments/MainFragment.java @@ -65,7 +65,7 @@ public class MainFragment extends SelectRecyclerFragment { } @Override - public List getObjects(MusicService musicService, boolean refresh, ProgressListener listener) throws Exception { + public List getObjects(MusicService musicService, boolean refresh, ProgressListener listener) { return Collections.singletonList(0); } 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 a624006..38a8ef7 100644 --- a/app/src/main/java/net/nullsum/audinaut/fragments/NowPlayingFragment.java +++ b/app/src/main/java/net/nullsum/audinaut/fragments/NowPlayingFragment.java @@ -191,7 +191,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis warnIfStorageUnavailable(); new SilentBackgroundTask(context) { @Override - protected Void doInBackground() throws Throwable { + protected Void doInBackground() { getDownloadService().previous(); return null; } @@ -204,7 +204,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis warnIfStorageUnavailable(); new SilentBackgroundTask(context) { @Override - protected Boolean doInBackground() throws Throwable { + protected Boolean doInBackground() { getDownloadService().next(); return true; } @@ -222,7 +222,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis pauseButton.setOnClickListener(view -> new SilentBackgroundTask(context) { @Override - protected Void doInBackground() throws Throwable { + protected Void doInBackground() { getDownloadService().pause(); return null; } @@ -230,7 +230,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis stopButton.setOnClickListener(view -> new SilentBackgroundTask(context) { @Override - protected Void doInBackground() throws Throwable { + protected Void doInBackground() { getDownloadService().reset(); return null; } @@ -240,7 +240,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis warnIfStorageUnavailable(); new SilentBackgroundTask(context) { @Override - protected Void doInBackground() throws Throwable { + protected Void doInBackground() { start(); return null; } @@ -286,7 +286,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis public void onStopTrackingTouch(final SeekBar seekBar) { new SilentBackgroundTask(context) { @Override - protected Void doInBackground() throws Throwable { + protected Void doInBackground() { getDownloadService().seekTo(progressBar.getProgress()); return null; } @@ -421,7 +421,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis case R.id.menu_remove_all: Util.confirmDialog(context, R.string.download_menu_remove_all, "", (dialog, which) -> new SilentBackgroundTask(context) { @Override - protected Void doInBackground() throws Throwable { + protected Void doInBackground() { getDownloadService().setShufflePlayEnabled(false); getDownloadService().clear(); return null; @@ -444,7 +444,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis case R.id.menu_shuffle: new SilentBackgroundTask(context) { @Override - protected Void doInBackground() throws Throwable { + protected Void doInBackground() { getDownloadService().shuffle(); return null; } @@ -674,7 +674,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis int seekTo; @Override - protected Void doInBackground() throws Throwable { + protected Void doInBackground() { if (rewind) { seekTo = downloadService.rewind(); } else { @@ -726,7 +726,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis warnIfStorageUnavailable(); new SilentBackgroundTask(context) { @Override - protected Void doInBackground() throws Throwable { + protected Void doInBackground() { switch (performAction) { case ACTION_NEXT: downloadService.next(); @@ -774,7 +774,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis warnIfStorageUnavailable(); new SilentBackgroundTask(context) { @Override - protected Void doInBackground() throws Throwable { + protected Void doInBackground() { getDownloadService().play(item); return null; } diff --git a/app/src/main/java/net/nullsum/audinaut/fragments/SelectRecyclerFragment.java b/app/src/main/java/net/nullsum/audinaut/fragments/SelectRecyclerFragment.java index 1434d9b..6c4b91e 100644 --- a/app/src/main/java/net/nullsum/audinaut/fragments/SelectRecyclerFragment.java +++ b/app/src/main/java/net/nullsum/audinaut/fragments/SelectRecyclerFragment.java @@ -176,7 +176,7 @@ public abstract class SelectRecyclerFragment extends SubsonicFragment impleme } @Override - public List doInBackground() throws Exception { + public List doInBackground() { MusicService musicService = MusicServiceFactory.getMusicService(context); objects = new ArrayList<>(); diff --git a/app/src/main/java/net/nullsum/audinaut/fragments/SelectYearFragment.java b/app/src/main/java/net/nullsum/audinaut/fragments/SelectYearFragment.java index e1b9b25..beeb002 100644 --- a/app/src/main/java/net/nullsum/audinaut/fragments/SelectYearFragment.java +++ b/app/src/main/java/net/nullsum/audinaut/fragments/SelectYearFragment.java @@ -51,7 +51,7 @@ public class SelectYearFragment extends SelectRecyclerFragment { } @Override - public List getObjects(MusicService musicService, boolean refresh, ProgressListener listener) throws Exception { + public List getObjects(MusicService musicService, boolean refresh, ProgressListener listener) { List decades = new ArrayList<>(); for (int i = 2010; i >= 1800; i -= 10) { decades.add(String.valueOf(i)); diff --git a/app/src/main/java/net/nullsum/audinaut/fragments/SettingsFragment.java b/app/src/main/java/net/nullsum/audinaut/fragments/SettingsFragment.java index c791cb4..2747e8e 100644 --- a/app/src/main/java/net/nullsum/audinaut/fragments/SettingsFragment.java +++ b/app/src/main/java/net/nullsum/audinaut/fragments/SettingsFragment.java @@ -224,7 +224,7 @@ public class SettingsFragment extends PreferenceCompatFragment implements Shared this.findPreference("clearCache").setOnPreferenceClickListener(preference -> { Util.confirmDialog(context, (dialog, which) -> new LoadingTask(context, false) { @Override - protected Void doInBackground() throws Throwable { + protected Void doInBackground() { FileUtil.deleteMusicDirectory(context); FileUtil.deleteSerializedCache(context); FileUtil.deleteArtworkCache(context); 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 90b1499..e5caa07 100644 --- a/app/src/main/java/net/nullsum/audinaut/fragments/SubsonicFragment.java +++ b/app/src/main/java/net/nullsum/audinaut/fragments/SubsonicFragment.java @@ -1151,7 +1151,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR new LoadingTask(context) { @Override - protected Void doInBackground() throws Throwable { + protected Void doInBackground() { MediaStoreService mediaStore = new MediaStoreService(context); FileUtil.recursiveDelete(dir, mediaStore); return null; @@ -1176,7 +1176,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR private void deleteSongs(final List songs) { new LoadingTask(context) { @Override - protected Void doInBackground() throws Throwable { + protected Void doInBackground() { getDownloadService().delete(songs); return null; } @@ -1287,7 +1287,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR private void playNow(final List entries, final Entry song, final String playlistName, final String playlistId) { new LoadingTask(context) { @Override - protected Void doInBackground() throws Throwable { + protected Void doInBackground() { playNowInTask(entries, song, playlistName, playlistId); return null; } 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 ce5498f..a5c7118 100644 --- a/app/src/main/java/net/nullsum/audinaut/service/CachedMusicService.java +++ b/app/src/main/java/net/nullsum/audinaut/service/CachedMusicService.java @@ -617,7 +617,7 @@ public class CachedMusicService implements MusicService { } @Override - public User getUser(boolean refresh, String username, Context context, ProgressListener progressListener) throws Exception { + public User getUser(boolean refresh, String username, Context context, ProgressListener progressListener) { User result = null; try { diff --git a/app/src/main/java/net/nullsum/audinaut/service/OfflineMusicService.java b/app/src/main/java/net/nullsum/audinaut/service/OfflineMusicService.java index 1a1c19d..82e0967 100644 --- a/app/src/main/java/net/nullsum/audinaut/service/OfflineMusicService.java +++ b/app/src/main/java/net/nullsum/audinaut/service/OfflineMusicService.java @@ -62,12 +62,12 @@ public class OfflineMusicService implements MusicService { private static final Random random = new Random(); @Override - public void ping(Context context, ProgressListener progressListener) throws Exception { + public void ping(Context context, ProgressListener progressListener) { } @Override - public Indexes getIndexes(String musicFolderId, boolean refresh, Context context, ProgressListener progressListener) throws Exception { + public Indexes getIndexes(String musicFolderId, boolean refresh, Context context, ProgressListener progressListener) { List artists = new ArrayList<>(); List entries = new ArrayList<>(); File root = FileUtil.getMusicDirectory(context); @@ -91,7 +91,7 @@ public class OfflineMusicService implements MusicService { return getMusicDirectory(id, context); } - private MusicDirectory getMusicDirectory(String id, Context context) throws Exception { + private MusicDirectory getMusicDirectory(String id, Context context) { File dir = new File(id); MusicDirectory result = new MusicDirectory(); result.setName(dir.getName()); @@ -186,7 +186,7 @@ public class OfflineMusicService implements MusicService { } @Override - public Bitmap getCoverArt(Context context, Entry entry, int size, ProgressListener progressListener, SilentBackgroundTask task) throws Exception { + public Bitmap getCoverArt(Context context, Entry entry, int size, ProgressListener progressListener, SilentBackgroundTask task) { try { return FileUtil.getAlbumArtBitmap(context, entry, size); } catch (Exception e) { @@ -205,7 +205,7 @@ public class OfflineMusicService implements MusicService { } @Override - public SearchResult search(SearchCritera criteria, Context context, ProgressListener progressListener) throws Exception { + public SearchResult search(SearchCritera criteria, Context context, ProgressListener progressListener) { List artists = new ArrayList<>(); List albums = new ArrayList<>(); List songs = new ArrayList<>(); @@ -294,7 +294,7 @@ public class OfflineMusicService implements MusicService { } @Override - public List getPlaylists(boolean refresh, Context context, ProgressListener progressListener) throws Exception { + public List getPlaylists(boolean refresh, Context context, ProgressListener progressListener) { List playlists = new ArrayList<>(); File root = FileUtil.getPlaylistDirectory(context); String lastServer = null; @@ -481,7 +481,7 @@ public class OfflineMusicService implements MusicService { } @Override - public MusicDirectory getRandomSongs(int size, String folder, String genre, String startYear, String endYear, Context context, ProgressListener progressListener) throws Exception { + public MusicDirectory getRandomSongs(int size, String folder, String genre, String startYear, String endYear, Context context, ProgressListener progressListener) { File root = FileUtil.getMusicDirectory(context); List children = new LinkedList<>(); listFilesRecursively(root, children); diff --git a/app/src/main/java/net/nullsum/audinaut/service/RESTMusicService.java b/app/src/main/java/net/nullsum/audinaut/service/RESTMusicService.java index 8a40781..7a706f5 100644 --- a/app/src/main/java/net/nullsum/audinaut/service/RESTMusicService.java +++ b/app/src/main/java/net/nullsum/audinaut/service/RESTMusicService.java @@ -729,7 +729,7 @@ public class RESTMusicService implements MusicService { } @Override - public void setInstance(Integer instance) throws Exception { + public void setInstance(Integer instance) { this.instance = instance; } diff --git a/app/src/main/java/net/nullsum/audinaut/service/sync/AuthenticatorService.java b/app/src/main/java/net/nullsum/audinaut/service/sync/AuthenticatorService.java index a55601e..eedbd47 100644 --- a/app/src/main/java/net/nullsum/audinaut/service/sync/AuthenticatorService.java +++ b/app/src/main/java/net/nullsum/audinaut/service/sync/AuthenticatorService.java @@ -22,7 +22,6 @@ package net.nullsum.audinaut.service.sync; import android.accounts.AbstractAccountAuthenticator; import android.accounts.Account; import android.accounts.AccountAuthenticatorResponse; -import android.accounts.NetworkErrorException; import android.app.Service; import android.content.Context; import android.content.Intent; @@ -58,17 +57,17 @@ public class AuthenticatorService extends Service { } @Override - public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType, String[] requiredFeatures, Bundle options) throws NetworkErrorException { + public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType, String[] requiredFeatures, Bundle options) { return null; } @Override - public Bundle confirmCredentials(AccountAuthenticatorResponse response, Account account, Bundle options) throws NetworkErrorException { + public Bundle confirmCredentials(AccountAuthenticatorResponse response, Account account, Bundle options) { return null; } @Override - public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options) throws NetworkErrorException { + public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options) { return null; } @@ -78,12 +77,12 @@ public class AuthenticatorService extends Service { } @Override - public Bundle updateCredentials(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options) throws NetworkErrorException { + public Bundle updateCredentials(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options) { return null; } @Override - public Bundle hasFeatures(AccountAuthenticatorResponse response, Account account, String[] features) throws NetworkErrorException { + public Bundle hasFeatures(AccountAuthenticatorResponse response, Account account, String[] features) { return null; } } diff --git a/app/src/main/java/net/nullsum/audinaut/util/DownloadFileItemHelperCallback.java b/app/src/main/java/net/nullsum/audinaut/util/DownloadFileItemHelperCallback.java index 4bd2958..3bca028 100644 --- a/app/src/main/java/net/nullsum/audinaut/util/DownloadFileItemHelperCallback.java +++ b/app/src/main/java/net/nullsum/audinaut/util/DownloadFileItemHelperCallback.java @@ -68,7 +68,7 @@ public class DownloadFileItemHelperCallback extends ItemTouchHelper.SimpleCallba pendingTask = new SilentBackgroundTask(downloadService) { @Override - protected Void doInBackground() throws Throwable { + protected Void doInBackground() { boolean running = true; while (running) { Object nextOperation = null; 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 e48f483..19f7fcf 100644 --- a/app/src/main/java/net/nullsum/audinaut/util/ImageLoader.java +++ b/app/src/main/java/net/nullsum/audinaut/util/ImageLoader.java @@ -99,7 +99,7 @@ public class ImageLoader { nowPlayingSmall = null; new SilentBackgroundTask(context) { @Override - protected Void doInBackground() throws Throwable { + protected Void doInBackground() { clearingCache = true; cache.evictAll(); clearingCache = false;