From 336f505ba5afdd79d53247bab91649edf4f5fc82 Mon Sep 17 00:00:00 2001 From: Yahor Berdnikau Date: Sun, 3 Dec 2017 14:14:01 +0100 Subject: [PATCH] Replace ServerTooOldException with more proper ApiNotSupportedException. --- .../api/subsonic/ApiNotSupportedException.kt | 11 +++++ .../ultrasonic/activity/PodcastsActivity.java | 27 ----------- .../activity/SelectPlaylistActivity.java | 7 +-- .../ultrasonic/activity/ShareActivity.java | 7 +-- .../ultrasonic/service/JukeboxService.java | 3 +- .../ultrasonic/service/RESTMusicService.java | 3 +- .../service/ServerTooOldException.java | 48 ------------------- 7 files changed, 23 insertions(+), 83 deletions(-) create mode 100644 subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/ApiNotSupportedException.kt delete mode 100644 ultrasonic/src/main/java/org/moire/ultrasonic/service/ServerTooOldException.java diff --git a/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/ApiNotSupportedException.kt b/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/ApiNotSupportedException.kt new file mode 100644 index 00000000..fce439a6 --- /dev/null +++ b/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/ApiNotSupportedException.kt @@ -0,0 +1,11 @@ +package org.moire.ultrasonic.api.subsonic + +import java.io.IOException + +/** + * Special [IOException] to indicate that called api is not yet supported + * by current server api version. + */ +class ApiNotSupportedException( + serverApiVersion: SubsonicAPIVersions) + : IOException("Server api $serverApiVersion does not support this call") diff --git a/ultrasonic/src/main/java/org/moire/ultrasonic/activity/PodcastsActivity.java b/ultrasonic/src/main/java/org/moire/ultrasonic/activity/PodcastsActivity.java index 74f9a223..2b7e3958 100644 --- a/ultrasonic/src/main/java/org/moire/ultrasonic/activity/PodcastsActivity.java +++ b/ultrasonic/src/main/java/org/moire/ultrasonic/activity/PodcastsActivity.java @@ -19,47 +19,20 @@ package org.moire.ultrasonic.activity; -import android.app.AlertDialog; -import android.app.ListActivity; import android.content.Context; -import android.content.DialogInterface; import android.content.Intent; -import android.os.AsyncTask; import android.os.Bundle; -import android.text.Editable; -import android.text.Spannable; -import android.text.SpannableString; -import android.text.method.LinkMovementMethod; -import android.text.util.Linkify; -import android.view.ContextMenu; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; -import android.widget.CheckBox; -import android.widget.EditText; import android.widget.ListView; -import android.widget.TextView; - -import com.handmark.pulltorefresh.library.PullToRefreshBase; -import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener; -import com.handmark.pulltorefresh.library.PullToRefreshListView; import org.moire.ultrasonic.R; -import org.moire.ultrasonic.domain.Playlist; import org.moire.ultrasonic.domain.PodcastsChannel; import org.moire.ultrasonic.service.MusicService; import org.moire.ultrasonic.service.MusicServiceFactory; -import org.moire.ultrasonic.service.OfflineException; -import org.moire.ultrasonic.service.ServerTooOldException; import org.moire.ultrasonic.util.BackgroundTask; -import org.moire.ultrasonic.util.CacheCleaner; import org.moire.ultrasonic.util.Constants; -import org.moire.ultrasonic.util.LoadingTask; import org.moire.ultrasonic.util.TabActivityBackgroundTask; -import org.moire.ultrasonic.util.Util; -import org.moire.ultrasonic.view.PlaylistAdapter; import org.moire.ultrasonic.view.PodcastsChannelsAdapter; import java.util.List; diff --git a/ultrasonic/src/main/java/org/moire/ultrasonic/activity/SelectPlaylistActivity.java b/ultrasonic/src/main/java/org/moire/ultrasonic/activity/SelectPlaylistActivity.java index b0874491..5777f65e 100644 --- a/ultrasonic/src/main/java/org/moire/ultrasonic/activity/SelectPlaylistActivity.java +++ b/ultrasonic/src/main/java/org/moire/ultrasonic/activity/SelectPlaylistActivity.java @@ -43,12 +43,13 @@ import android.widget.TextView; import com.handmark.pulltorefresh.library.PullToRefreshBase; import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener; import com.handmark.pulltorefresh.library.PullToRefreshListView; + import org.moire.ultrasonic.R; +import org.moire.ultrasonic.api.subsonic.ApiNotSupportedException; import org.moire.ultrasonic.domain.Playlist; import org.moire.ultrasonic.service.MusicService; import org.moire.ultrasonic.service.MusicServiceFactory; import org.moire.ultrasonic.service.OfflineException; -import org.moire.ultrasonic.service.ServerTooOldException; import org.moire.ultrasonic.util.BackgroundTask; import org.moire.ultrasonic.util.CacheCleaner; import org.moire.ultrasonic.util.Constants; @@ -271,7 +272,7 @@ public class SelectPlaylistActivity extends SubsonicTabActivity implements Adapt protected void error(Throwable error) { String msg; - msg = error instanceof OfflineException || error instanceof ServerTooOldException ? getErrorMessage(error) : String.format("%s %s", getResources().getString(R.string.menu_deleted_playlist_error, playlist.getName()), getErrorMessage(error)); + msg = error instanceof OfflineException || error instanceof ApiNotSupportedException ? getErrorMessage(error) : String.format("%s %s", getResources().getString(R.string.menu_deleted_playlist_error, playlist.getName()), getErrorMessage(error)); Util.toast(SelectPlaylistActivity.this, msg, false); } @@ -360,7 +361,7 @@ public class SelectPlaylistActivity extends SubsonicTabActivity implements Adapt protected void error(Throwable error) { String msg; - msg = error instanceof OfflineException || error instanceof ServerTooOldException ? getErrorMessage(error) : String.format("%s %s", getResources().getString(R.string.playlist_updated_info_error, playlist.getName()), getErrorMessage(error)); + msg = error instanceof OfflineException || error instanceof ApiNotSupportedException ? getErrorMessage(error) : String.format("%s %s", getResources().getString(R.string.playlist_updated_info_error, playlist.getName()), getErrorMessage(error)); Util.toast(SelectPlaylistActivity.this, msg, false); } diff --git a/ultrasonic/src/main/java/org/moire/ultrasonic/activity/ShareActivity.java b/ultrasonic/src/main/java/org/moire/ultrasonic/activity/ShareActivity.java index 65670e11..d7a2d237 100644 --- a/ultrasonic/src/main/java/org/moire/ultrasonic/activity/ShareActivity.java +++ b/ultrasonic/src/main/java/org/moire/ultrasonic/activity/ShareActivity.java @@ -44,12 +44,13 @@ import android.widget.TextView; import com.handmark.pulltorefresh.library.PullToRefreshBase; import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener; import com.handmark.pulltorefresh.library.PullToRefreshListView; + import org.moire.ultrasonic.R; +import org.moire.ultrasonic.api.subsonic.ApiNotSupportedException; import org.moire.ultrasonic.domain.Share; import org.moire.ultrasonic.service.MusicService; import org.moire.ultrasonic.service.MusicServiceFactory; import org.moire.ultrasonic.service.OfflineException; -import org.moire.ultrasonic.service.ServerTooOldException; import org.moire.ultrasonic.util.BackgroundTask; import org.moire.ultrasonic.util.Constants; import org.moire.ultrasonic.util.LoadingTask; @@ -251,7 +252,7 @@ public class ShareActivity extends SubsonicTabActivity implements AdapterView.On protected void error(Throwable error) { String msg; - msg = error instanceof OfflineException || error instanceof ServerTooOldException ? getErrorMessage(error) : String.format("%s %s", getResources().getString(R.string.menu_deleted_share_error, share.getName()), getErrorMessage(error)); + msg = error instanceof OfflineException || error instanceof ApiNotSupportedException ? getErrorMessage(error) : String.format("%s %s", getResources().getString(R.string.menu_deleted_share_error, share.getName()), getErrorMessage(error)); Util.toast(ShareActivity.this, msg, false); } @@ -356,7 +357,7 @@ public class ShareActivity extends SubsonicTabActivity implements AdapterView.On protected void error(Throwable error) { String msg; - msg = error instanceof OfflineException || error instanceof ServerTooOldException ? getErrorMessage(error) : String.format("%s %s", getResources().getString(R.string.playlist_updated_info_error, share.getName()), getErrorMessage(error)); + msg = error instanceof OfflineException || error instanceof ApiNotSupportedException ? getErrorMessage(error) : String.format("%s %s", getResources().getString(R.string.playlist_updated_info_error, share.getName()), getErrorMessage(error)); Util.toast(ShareActivity.this, msg, false); } diff --git a/ultrasonic/src/main/java/org/moire/ultrasonic/service/JukeboxService.java b/ultrasonic/src/main/java/org/moire/ultrasonic/service/JukeboxService.java index a43e0b98..849d73ac 100644 --- a/ultrasonic/src/main/java/org/moire/ultrasonic/service/JukeboxService.java +++ b/ultrasonic/src/main/java/org/moire/ultrasonic/service/JukeboxService.java @@ -28,6 +28,7 @@ import android.widget.ProgressBar; import android.widget.Toast; import org.moire.ultrasonic.R; +import org.moire.ultrasonic.api.subsonic.ApiNotSupportedException; import org.moire.ultrasonic.domain.JukeboxStatus; import org.moire.ultrasonic.domain.PlayerState; import org.moire.ultrasonic.service.parser.SubsonicRESTException; @@ -185,7 +186,7 @@ public class JukeboxService private void onError(JukeboxTask task, Throwable x) { - if (x instanceof ServerTooOldException && !(task instanceof Stop)) + if (x instanceof ApiNotSupportedException && !(task instanceof Stop)) { disableJukeboxOnError(x, R.string.download_jukebox_server_too_old); } diff --git a/ultrasonic/src/main/java/org/moire/ultrasonic/service/RESTMusicService.java b/ultrasonic/src/main/java/org/moire/ultrasonic/service/RESTMusicService.java index f6fe612e..18d8df3e 100644 --- a/ultrasonic/src/main/java/org/moire/ultrasonic/service/RESTMusicService.java +++ b/ultrasonic/src/main/java/org/moire/ultrasonic/service/RESTMusicService.java @@ -26,6 +26,7 @@ import android.support.annotation.StringRes; import android.util.Log; import org.moire.ultrasonic.R; +import org.moire.ultrasonic.api.subsonic.ApiNotSupportedException; import org.moire.ultrasonic.api.subsonic.SubsonicAPIClient; import org.moire.ultrasonic.api.subsonic.models.AlbumListType; import org.moire.ultrasonic.api.subsonic.models.JukeboxAction; @@ -339,7 +340,7 @@ public class RESTMusicService implements MusicService { Util.getShouldUseId3Tags(context) ? search3(criteria, context, progressListener) : search2(criteria, context, progressListener); - } catch (ServerTooOldException x) { + } catch (ApiNotSupportedException ignored) { // Ensure backward compatibility with REST 1.3. return searchOld(criteria, context, progressListener); } diff --git a/ultrasonic/src/main/java/org/moire/ultrasonic/service/ServerTooOldException.java b/ultrasonic/src/main/java/org/moire/ultrasonic/service/ServerTooOldException.java deleted file mode 100644 index b0c2bd0f..00000000 --- a/ultrasonic/src/main/java/org/moire/ultrasonic/service/ServerTooOldException.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - This file is part of Subsonic. - - Subsonic is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Subsonic is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Subsonic. If not, see . - - Copyright 2009 (C) Sindre Mehus - */ -package org.moire.ultrasonic.service; - -/** - * Thrown if the REST API version implemented by the server is too old. - * - * @author Sindre Mehus - * @version $Id$ - */ -public class ServerTooOldException extends Exception -{ - private static final long serialVersionUID = -7955245839000220002L; - - public ServerTooOldException(String text) - { - super(createMessage(text)); - } - - private static String createMessage(String text) - { - StringBuilder builder = new StringBuilder(25); - - if (text != null) - { - builder.append(text).append(' '); - } - - builder.append("Subsonic server version is too old. Please upgrade."); - return builder.toString(); - } -}