aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2014-07-22 07:00:39 -0700
committerScott Jackson <daneren2005@gmail.com>2014-07-22 07:00:39 -0700
commit35ed56188ab450f14703e39db7c70f5beb18d00a (patch)
treebe6e469edab55852e2b9cb6be546de8b25c46023 /src
parenta51e0cb467d3b1b73ed6406edcb66b5adab5db4f (diff)
downloaddsub-35ed56188ab450f14703e39db7c70f5beb18d00a.tar.gz
dsub-35ed56188ab450f14703e39db7c70f5beb18d00a.tar.bz2
dsub-35ed56188ab450f14703e39db7c70f5beb18d00a.zip
Finish up moving everything to use ServerInfo for info queries
Diffstat (limited to 'src')
-rw-r--r--src/github/daneren2005/dsub/domain/ServerInfo.java25
-rw-r--r--src/github/daneren2005/dsub/domain/Version.java4
-rw-r--r--src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java3
-rw-r--r--src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java5
-rw-r--r--src/github/daneren2005/dsub/fragments/SubsonicFragment.java9
-rw-r--r--src/github/daneren2005/dsub/fragments/UserFragment.java5
-rw-r--r--src/github/daneren2005/dsub/service/RESTMusicService.java4
-rw-r--r--src/github/daneren2005/dsub/service/parser/AbstractParser.java3
-rw-r--r--src/github/daneren2005/dsub/service/parser/MusicDirectoryParser.java3
-rw-r--r--src/github/daneren2005/dsub/util/Util.java34
-rw-r--r--src/github/daneren2005/dsub/view/AlbumListAdapter.java3
11 files changed, 48 insertions, 50 deletions
diff --git a/src/github/daneren2005/dsub/domain/ServerInfo.java b/src/github/daneren2005/dsub/domain/ServerInfo.java
index 0109ab30..eb644cf7 100644
--- a/src/github/daneren2005/dsub/domain/ServerInfo.java
+++ b/src/github/daneren2005/dsub/domain/ServerInfo.java
@@ -18,6 +18,15 @@
*/
package github.daneren2005.dsub.domain;
+import android.content.Context;
+
+import java.io.Serializable;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import github.daneren2005.dsub.util.FileUtil;
+import github.daneren2005.dsub.util.Util;
+
/**
* Information about the Subsonic server.
*
@@ -68,7 +77,7 @@ public class ServerInfo implements Serializable {
@Override
public boolean equals(Object o) {
- if(this == 0) {
+ if(this == o) {
return true;
} else if(o == null || getClass() != o.getClass()) {
return false;
@@ -114,6 +123,18 @@ public class ServerInfo implements Serializable {
return current;
}
+ public static Version getServerVersion(Context context) {
+ return getServerVersion(context, Util.getActiveServer(context));
+ }
+ public static Version getServerVersion(Context context, int instance) {
+ ServerInfo server = getServerInfo(context, instance);
+ if(server == null) {
+ return null;
+ }
+
+ return server.getRestVersion();
+ }
+
public static boolean checkServerVersion(Context context, String requiredVersion) {
return checkServerVersion(context, requiredVersion, Util.getActiveServer(context));
}
@@ -132,7 +153,7 @@ public class ServerInfo implements Serializable {
return version.compareTo(required) >= 0;
}
- private static String getCacheName(context, instance) {
+ private static String getCacheName(Context context, int instance) {
return "server-" + Util.getRestUrl(context, null, instance, false).hashCode() + ".ser";
}
}
diff --git a/src/github/daneren2005/dsub/domain/Version.java b/src/github/daneren2005/dsub/domain/Version.java
index 8cf338f1..75221cd5 100644
--- a/src/github/daneren2005/dsub/domain/Version.java
+++ b/src/github/daneren2005/dsub/domain/Version.java
@@ -18,13 +18,15 @@
*/
package github.daneren2005.dsub.domain;
+import java.io.Serializable;
+
/**
* Represents the version number of the Subsonic Android app.
*
* @author Sindre Mehus
* @version $Revision: 1.3 $ $Date: 2006/01/20 21:25:16 $
*/
-public class Version implements Comparable<Version> {
+public class Version implements Comparable<Version>, Serializable {
private int major;
private int minor;
private int beta;
diff --git a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java
index f0497703..14b83317 100644
--- a/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java
+++ b/src/github/daneren2005/dsub/fragments/SelectDirectoryFragment.java
@@ -23,6 +23,7 @@ import android.widget.ListView;
import android.widget.TextView;
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.domain.MusicDirectory;
+import github.daneren2005.dsub.domain.ServerInfo;
import github.daneren2005.dsub.domain.Share;
import github.daneren2005.dsub.util.ImageLoader;
import github.daneren2005.dsub.view.AlbumGridAdapter;
@@ -584,7 +585,7 @@ public class SelectDirectoryFragment extends SubsonicFragment implements Adapter
MusicDirectory result;
if ("starred".equals(albumListType)) {
result = service.getStarredList(context, this);
- } else if(("genres".equals(albumListType) && Util.checkServerVersion(context, "1.10.0")) || "years".equals(albumListType)) {
+ } else if(("genres".equals(albumListType) && ServerInfo.checkServerVersion(context, "1.10.0")) || "years".equals(albumListType)) {
result = service.getAlbumList(albumListType, albumListExtra, size, 0, context, this);
if(result.getChildrenSize() == 0 && "genres".equals(albumListType)) {
SelectDirectoryFragment.this.albumListType = "genres-songs";
diff --git a/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java b/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java
index 7f6de2d8..694c6d19 100644
--- a/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java
+++ b/src/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java
@@ -16,6 +16,7 @@ import android.widget.EditText;
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.domain.MusicDirectory;
import github.daneren2005.dsub.domain.Playlist;
+import github.daneren2005.dsub.domain.ServerInfo;
import github.daneren2005.dsub.service.DownloadFile;
import github.daneren2005.dsub.service.MusicService;
import github.daneren2005.dsub.service.MusicServiceFactory;
@@ -54,7 +55,7 @@ public class SelectPlaylistFragment extends SelectListFragment<Playlist> {
menu.removeItem(R.id.playlist_menu_stop_sync);
}
- if(!Util.checkServerVersion(context, "1.8")) {
+ if(!ServerInfo.checkServerVersion(context, "1.8")) {
menu.removeItem(R.id.playlist_update_info);
} else if(playlist.getPublic() != null && playlist.getPublic() == true && playlist.getId().indexOf(".m3u") == -1 && !UserUtil.getCurrentUsername(context).equals(playlist.getOwner())) {
menu.removeItem(R.id.playlist_update_info);
@@ -155,7 +156,7 @@ public class SelectPlaylistFragment extends SelectListFragment<Playlist> {
Bundle args = new Bundle();
args.putString(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID, playlist.getId());
args.putString(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME, playlist.getName());
- if(Util.checkServerVersion(context, "1.8") && playlist.getOwner() != null && playlist.getOwner().equals(UserUtil.getCurrentUsername(context))) {
+ if(ServerInfo.checkServerVersion(context, "1.8") && playlist.getOwner() != null && playlist.getOwner().equals(UserUtil.getCurrentUsername(context))) {
args.putBoolean(Constants.INTENT_EXTRA_NAME_PLAYLIST_OWNER, true);
}
fragment.setArguments(args);
diff --git a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java
index b935f065..d3e152c3 100644
--- a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java
+++ b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java
@@ -52,6 +52,7 @@ import github.daneren2005.dsub.domain.Genre;
import github.daneren2005.dsub.domain.MusicDirectory;
import github.daneren2005.dsub.domain.Playlist;
import github.daneren2005.dsub.domain.PodcastEpisode;
+import github.daneren2005.dsub.domain.ServerInfo;
import github.daneren2005.dsub.domain.Share;
import github.daneren2005.dsub.service.DownloadFile;
import github.daneren2005.dsub.service.DownloadService;
@@ -211,11 +212,11 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
}
protected void hideMenuItems(ContextMenu menu) {
- if(!Util.checkServerVersion(context, "1.8")) {
+ if(!ServerInfo.checkServerVersion(context, "1.8")) {
menu.setGroupVisible(R.id.server_1_8, false);
menu.setGroupVisible(R.id.hide_star, false);
}
- if(!Util.checkServerVersion(context, "1.10.1")) {
+ if(!ServerInfo.checkServerVersion(context, "1.10.1")) {
menu.setGroupVisible(R.id.server_1_10, false);
}
@@ -543,7 +544,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
final String oldGenre = prefs.getString(Constants.PREFERENCES_KEY_SHUFFLE_GENRE, "");
boolean _useCombo = false;
- if(Util.checkServerVersion(context, "1.9.0")) {
+ if(ServerInfo.checkServerVersion(context, "1.9.0")) {
genreBox.setVisibility(View.GONE);
genreCombo.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
@@ -931,7 +932,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR
if (playlistName != null) {
playlistNameView.setText(playlistName);
try {
- if(Util.checkServerVersion(context, "1.8.0") && Integer.parseInt(getDownloadService().getSuggestedPlaylistId()) != -1) {
+ if(ServerInfo.checkServerVersion(context, "1.8.0") && Integer.parseInt(getDownloadService().getSuggestedPlaylistId()) != -1) {
overwriteCheckBox.setChecked(true);
overwriteCheckBox.setVisibility(View.VISIBLE);
}
diff --git a/src/github/daneren2005/dsub/fragments/UserFragment.java b/src/github/daneren2005/dsub/fragments/UserFragment.java
index 9bf26baf..2391762e 100644
--- a/src/github/daneren2005/dsub/fragments/UserFragment.java
+++ b/src/github/daneren2005/dsub/fragments/UserFragment.java
@@ -32,6 +32,7 @@ import android.widget.TextView;
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.activity.SubsonicActivity;
+import github.daneren2005.dsub.domain.ServerInfo;
import github.daneren2005.dsub.domain.User;
import github.daneren2005.dsub.service.MusicService;
import github.daneren2005.dsub.service.MusicServiceFactory;
@@ -60,7 +61,7 @@ public class UserFragment extends SubsonicFragment{
listView = (ListView)rootView.findViewById(R.id.fragment_list);
createHeader();
- listView.setAdapter(new SettingsAdapter(context, user.getSettings(), UserUtil.isCurrentAdmin() && Util.checkServerVersion(context, "1.10")));
+ listView.setAdapter(new SettingsAdapter(context, user.getSettings(), UserUtil.isCurrentAdmin() && ServerInfo.checkServerVersion(context, "1.10")));
setTitle(user.getUsername());
@@ -80,7 +81,7 @@ public class UserFragment extends SubsonicFragment{
return;
}
- if(UserUtil.isCurrentAdmin() && Util.checkServerVersion(context, "1.10")) {
+ if(UserUtil.isCurrentAdmin() && ServerInfo.checkServerVersion(context, "1.10")) {
menuInflater.inflate(R.menu.user, menu);
} else if(UserUtil.isCurrentRole(User.SETTINGS)) {
menuInflater.inflate(R.menu.user_user, menu);
diff --git a/src/github/daneren2005/dsub/service/RESTMusicService.java b/src/github/daneren2005/dsub/service/RESTMusicService.java
index 43d443d2..74b78b97 100644
--- a/src/github/daneren2005/dsub/service/RESTMusicService.java
+++ b/src/github/daneren2005/dsub/service/RESTMusicService.java
@@ -626,7 +626,7 @@ public class RESTMusicService implements MusicService {
}
private void checkServerVersion(Context context, String version, String text) throws ServerTooOldException {
- Version serverVersion = Util.getServerRestVersion(context);
+ Version serverVersion = ServerInfo.getServerVersion(context);
Version requiredVersion = new Version(version);
boolean ok = serverVersion == null || serverVersion.compareTo(requiredVersion) >= 0;
@@ -1302,7 +1302,7 @@ public class RESTMusicService implements MusicService {
@Override
public Bitmap getAvatar(String username, int size, Context context, ProgressListener progressListener) throws Exception {
// Return silently if server is too old
- if (!Util.checkServerVersion(context, "1.8")) {
+ if (!ServerInfo.checkServerVersion(context, "1.8")) {
return null;
}
diff --git a/src/github/daneren2005/dsub/service/parser/AbstractParser.java b/src/github/daneren2005/dsub/service/parser/AbstractParser.java
index 7d43728a..56382bf4 100644
--- a/src/github/daneren2005/dsub/service/parser/AbstractParser.java
+++ b/src/github/daneren2005/dsub/service/parser/AbstractParser.java
@@ -25,6 +25,7 @@ import org.xmlpull.v1.XmlPullParser;
import android.content.Context;
import android.util.Xml;
import github.daneren2005.dsub.R;
+import github.daneren2005.dsub.domain.ServerInfo;
import github.daneren2005.dsub.domain.Version;
import github.daneren2005.dsub.util.ProgressListener;
import github.daneren2005.dsub.util.Util;
@@ -127,7 +128,7 @@ public abstract class AbstractParser {
rootElementFound = true;
String version = get("version");
if (version != null) {
- ServerInfo server = new Server();
+ ServerInfo server = new ServerInfo();
server.setRestVersion(new Version(version));
if("madsonic".equals(get("type"))) {
diff --git a/src/github/daneren2005/dsub/service/parser/MusicDirectoryParser.java b/src/github/daneren2005/dsub/service/parser/MusicDirectoryParser.java
index 95ee1744..7a953593 100644
--- a/src/github/daneren2005/dsub/service/parser/MusicDirectoryParser.java
+++ b/src/github/daneren2005/dsub/service/parser/MusicDirectoryParser.java
@@ -22,6 +22,7 @@ import android.content.Context;
import android.util.Log;
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.domain.MusicDirectory;
+import github.daneren2005.dsub.domain.ServerInfo;
import github.daneren2005.dsub.util.Constants;
import github.daneren2005.dsub.util.ProgressListener;
import github.daneren2005.dsub.util.Util;
@@ -97,7 +98,7 @@ public class MusicDirectoryParser extends MusicDirectoryEntryParser {
validate();
// Only apply sorting on server version 4.7 and greater, where disc is supported
- if(Util.checkServerVersion(context, "1.8.0")) {
+ if(ServerInfo.checkServerVersion(context, "1.8.0")) {
dir.sortChildren(Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_CUSTOM_SORT_ENABLED, true));
}
diff --git a/src/github/daneren2005/dsub/util/Util.java b/src/github/daneren2005/dsub/util/Util.java
index eceb5d46..a4ed527e 100644
--- a/src/github/daneren2005/dsub/util/Util.java
+++ b/src/github/daneren2005/dsub/util/Util.java
@@ -62,6 +62,7 @@ import github.daneren2005.dsub.activity.SubsonicFragmentActivity;
import github.daneren2005.dsub.domain.MusicDirectory;
import github.daneren2005.dsub.domain.PlayerState;
import github.daneren2005.dsub.domain.RepeatMode;
+import github.daneren2005.dsub.domain.ServerInfo;
import github.daneren2005.dsub.domain.User;
import github.daneren2005.dsub.domain.Version;
import github.daneren2005.dsub.provider.DSubWidgetProvider;
@@ -116,8 +117,6 @@ public final class Util {
private static boolean pauseFocus = false;
private static boolean lowerFocus = false;
- private static final Map<Integer, Version> SERVER_REST_VERSIONS = new ConcurrentHashMap<Integer, Version>();
-
// Used by hexEncode()
private static final char[] HEX_DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
@@ -172,12 +171,6 @@ public final class Util {
return prefs.getBoolean(Constants.PREFERENCES_KEY_OFFLINE, false) ? 0 : prefs.getInt(Constants.PREFERENCES_KEY_SERVER_INSTANCE, 1);
}
- public static boolean checkServerVersion(Context context, String requiredVersion) {
- Version version = Util.getServerRestVersion(context);
- Version required = new Version(requiredVersion);
- return version != null && version.compareTo(required) >= 0;
- }
-
public static int getServerCount(Context context) {
SharedPreferences prefs = getPreferences(context);
return prefs.getInt(Constants.PREFERENCES_KEY_SERVER_COUNT, 1);
@@ -229,31 +222,6 @@ public final class Util {
return prefs.getString(Constants.PREFERENCES_KEY_SERVER_NAME + instance, null);
}
- public static void setServerRestVersion(Context context, Version version) {
- int instance = getActiveServer(context);
- Version current = SERVER_REST_VERSIONS.get(instance);
- if(current != version) {
- SERVER_REST_VERSIONS.put(instance, version);
- SharedPreferences.Editor editor = getPreferences(context).edit();
- editor.putString(Constants.PREFERENCES_KEY_SERVER_VERSION + instance, version.getVersion());
- editor.commit();
- }
- }
-
- public static Version getServerRestVersion(Context context) {
- int instance = getActiveServer(context);
- Version version = SERVER_REST_VERSIONS.get(instance);
- if(version == null) {
- SharedPreferences prefs = getPreferences(context);
- String versionString = prefs.getString(Constants.PREFERENCES_KEY_SERVER_VERSION + instance, null);
- if(versionString != null && versionString != "") {
- version = new Version(versionString);
- SERVER_REST_VERSIONS.put(instance, version);
- }
- }
- return version;
- }
-
public static void setSelectedMusicFolderId(Context context, String musicFolderId) {
int instance = getActiveServer(context);
SharedPreferences prefs = getPreferences(context);
diff --git a/src/github/daneren2005/dsub/view/AlbumListAdapter.java b/src/github/daneren2005/dsub/view/AlbumListAdapter.java
index 308eb7d7..6c3b2f73 100644
--- a/src/github/daneren2005/dsub/view/AlbumListAdapter.java
+++ b/src/github/daneren2005/dsub/view/AlbumListAdapter.java
@@ -26,6 +26,7 @@ import android.widget.ArrayAdapter;
import com.commonsware.cwac.endless.EndlessAdapter;
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.domain.MusicDirectory;
+import github.daneren2005.dsub.domain.ServerInfo;
import github.daneren2005.dsub.service.MusicService;
import github.daneren2005.dsub.service.MusicServiceFactory;
import github.daneren2005.dsub.util.Util;
@@ -55,7 +56,7 @@ public class AlbumListAdapter extends EndlessAdapter {
protected boolean cacheInBackground() throws Exception {
MusicService service = MusicServiceFactory.getMusicService(context);
MusicDirectory result;
- if(("genres".equals(type) && Util.checkServerVersion(context, "1.10.0")) || "years".equals(type)) {
+ if(("genres".equals(type) && ServerInfo.checkServerVersion(context, "1.10.0")) || "years".equals(type)) {
result = service.getAlbumList(type, extra, size, offset, context, null);
} else if("genres".equals(type) || "genres-songs".equals(type)) {
result = service.getSongsByGenre(extra, size, offset, context, null);