From 3659a8bd2f40e4ba906fa73bfa7d75c29dc5990b Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sun, 9 Jun 2013 22:04:26 -0700 Subject: Abstracted out version checking --- .../daneren2005/dsub/fragments/SubsonicFragment.java | 10 +++------- .../dsub/service/parser/MusicDirectoryParser.java | 4 +--- .../src/github/daneren2005/dsub/util/Util.java | 14 ++++++++++++-- 3 files changed, 16 insertions(+), 12 deletions(-) (limited to 'subsonic-android') diff --git a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java index 44dc4325..77479424 100644 --- a/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/subsonic-android/src/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -387,11 +387,9 @@ public class SubsonicFragment extends SherlockFragment { final String oldStartYear = prefs.getString(Constants.PREFERENCES_KEY_SHUFFLE_START_YEAR, ""); final String oldEndYear = prefs.getString(Constants.PREFERENCES_KEY_SHUFFLE_END_YEAR, ""); final String oldGenre = prefs.getString(Constants.PREFERENCES_KEY_SHUFFLE_GENRE, ""); - - Version version = Util.getServerRestVersion(context); - Version genreVersion = new Version("1.9.0"); + boolean _useCombo = false; - if(version != null && version.compareTo(genreVersion) >= 0) { + if(Util.checkServerVersion(context, "1.9.0")) { genreBox.setVisibility(View.GONE); genreCombo.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { @@ -697,10 +695,8 @@ public class SubsonicFragment extends SherlockFragment { String playlistName = (getDownloadService() != null) ? getDownloadService().getSuggestedPlaylistName() : null; if (playlistName != null) { playlistNameView.setText(playlistName); - Version version = Util.getServerRestVersion(context); - Version updatePlaylistVersion = new Version("1.8.0"); try { - if(version.compareTo(updatePlaylistVersion) >= 0 && Integer.parseInt(getDownloadService().getSuggestedPlaylistId()) != -1) { + if(Util.checkServerVersion(context, "1.8.0") && Integer.parseInt(getDownloadService().getSuggestedPlaylistId()) != -1) { overwriteCheckBox.setChecked(true); overwriteCheckBox.setVisibility(View.VISIBLE); } diff --git a/subsonic-android/src/github/daneren2005/dsub/service/parser/MusicDirectoryParser.java b/subsonic-android/src/github/daneren2005/dsub/service/parser/MusicDirectoryParser.java index 038518c6..17b09805 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/parser/MusicDirectoryParser.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/parser/MusicDirectoryParser.java @@ -71,9 +71,7 @@ public class MusicDirectoryParser extends MusicDirectoryEntryParser { updateProgress(progressListener, R.string.parser_reading_done); // Only apply sorting on server version 4.7 and greater, where disc is supported - Version version = Util.getServerRestVersion(context); - Version discVersion = new Version("1.8.0"); - if(version.compareTo(discVersion) >= 0) { + if(Util.checkServerVersion(context, "1.8.0")) { dir.sortChildren(); } diff --git a/subsonic-android/src/github/daneren2005/dsub/util/Util.java b/subsonic-android/src/github/daneren2005/dsub/util/Util.java index bef836b5..650d071d 100644 --- a/subsonic-android/src/github/daneren2005/dsub/util/Util.java +++ b/subsonic-android/src/github/daneren2005/dsub/util/Util.java @@ -148,8 +148,8 @@ public final class Util { public static boolean isScrobblingEnabled(Context context) { if (isOffline(context)) { - return false; - } + return false; + } SharedPreferences prefs = getPreferences(context); return prefs.getBoolean(Constants.PREFERENCES_KEY_SCROBBLE, false); } @@ -167,6 +167,16 @@ public final class Util { return 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); + if(version != null && version.compareTo(required) >= 0) { + return true; + } else { + return false; + } + } + public static int getServerCount(Context context) { SharedPreferences prefs = getPreferences(context); return prefs.getInt(Constants.PREFERENCES_KEY_SERVER_COUNT, 1); -- cgit v1.2.3