aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2014-07-22 17:53:49 -0700
committerScott Jackson <daneren2005@gmail.com>2014-07-22 17:53:49 -0700
commit04ee05fd4174c8e35e5462c8f3a7e4697214d39d (patch)
treeeb97f3970a46e6930346bdc24d5e517774973888
parentfe3bb692f1b82fa1f5e37e7e095ce04876848717 (diff)
downloaddsub-04ee05fd4174c8e35e5462c8f3a7e4697214d39d.tar.gz
dsub-04ee05fd4174c8e35e5462c8f3a7e4697214d39d.tar.bz2
dsub-04ee05fd4174c8e35e5462c8f3a7e4697214d39d.zip
#357 Add Rescan Server option for Madsonic 5.1+
-rw-r--r--res/menu/main.xml6
-rw-r--r--res/values/strings.xml5
-rw-r--r--src/github/daneren2005/dsub/domain/ServerInfo.java30
-rw-r--r--src/github/daneren2005/dsub/fragments/MainFragment.java24
-rw-r--r--src/github/daneren2005/dsub/service/CachedMusicService.java7
-rw-r--r--src/github/daneren2005/dsub/service/MusicService.java2
-rw-r--r--src/github/daneren2005/dsub/service/OfflineMusicService.java7
-rw-r--r--src/github/daneren2005/dsub/service/RESTMusicService.java23
-rw-r--r--src/github/daneren2005/dsub/service/parser/ScanStatusParser.java56
9 files changed, 141 insertions, 19 deletions
diff --git a/res/menu/main.xml b/res/menu/main.xml
index 7d71a43a..549c5fb6 100644
--- a/res/menu/main.xml
+++ b/res/menu/main.xml
@@ -12,6 +12,12 @@
android:icon="?attr/shuffle"
android:title="@string/menu.shuffle"
compat:showAsAction="always|withText"/>
+
+ <group android:id="@+id/madsonic">
+ <item
+ android:id="@+id/menu_rescan"
+ android:title="@string/menu.rescan"/>
+ </group>
<item
android:id="@+id/menu_about"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index f2d48d86..d63d03c6 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -73,6 +73,7 @@
<string name="main.albums_year">Decades</string>
<string name="main.songs_genres">@string/main.albums_genres</string>
<string name="main.back_confirm">Press back again to exit</string>
+ <string name="main.scan_complete">Completed scan of Server</string>
<string name="menu.search">Search</string>
<string name="menu.shuffle">Shuffle</string>
@@ -101,6 +102,7 @@
<string name="menu.cast">Cast To Device</string>
<string name="menu.faq">FAQ</string>
<string name="menu.add_user">Add User</string>
+ <string name="menu.rescan">Rescan Server</string>
<string name="playlist.label">Playlists</string>
<string name="playlist.update_info">Update Information</string>
@@ -495,6 +497,7 @@
<string name="parser.not_authorized">Not authorized. Check user permissions in Subsonic server.</string>
<string name="parser.artist_count">Got %d artists.</string>
<string name="parser.server_error">Server error: %s</string>
+ <string name="parser.scan_count">Scanned %d entries</string>
<string name="select_artist.refresh">Refresh</string>
<string name="select_artist.folder">Select folder</string>
@@ -526,7 +529,7 @@
<string name="changelog_ok_button">OK</string>
<string name="changelog_show_full">Moreā€¦</string>
- <string name="chat.send_a_message">Send a message</string>
+ <string name="chat.send_a_message">Send a message</string>
<string name="changelog_version_format" xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">Version <xliff:g id="version_name">%s</xliff:g></string>
diff --git a/src/github/daneren2005/dsub/domain/ServerInfo.java b/src/github/daneren2005/dsub/domain/ServerInfo.java
index eb644cf7..0cce774e 100644
--- a/src/github/daneren2005/dsub/domain/ServerInfo.java
+++ b/src/github/daneren2005/dsub/domain/ServerInfo.java
@@ -152,6 +152,36 @@ public class ServerInfo implements Serializable {
Version required = new Version(requiredVersion);
return version.compareTo(required) >= 0;
}
+
+ public static int getServerType(Context context) {
+ return getServerType(context, Util.getActiveServer(context));
+ }
+ public static int getServerType(Context context, int instance) {
+ if(Util.isOffline(context)) {
+ return 0;
+ }
+
+ ServerInfo server = getServerInfo(context, instance);
+ if(server == null) {
+ return 0;
+ }
+
+ return server.getRestType();
+ }
+
+ public static boolean isStockSubsonic(Context context) {
+ return isStockSubsonic(context, Util.getActiveServer(context));
+ }
+ public static boolean isStockSubsonic(Context context, int instance) {
+ return getServerType(context, instance) == TYPE_SUBSONIC;
+ }
+
+ public static boolean isMadsonic(Context context) {
+ return isMadsonic(context, Util.getActiveServer(context));
+ }
+ public static boolean isMadsonic(Context context, int instance) {
+ return getServerType(context, instance) == TYPE_MADSONIC;
+ }
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/fragments/MainFragment.java b/src/github/daneren2005/dsub/fragments/MainFragment.java
index 561e32c4..da0711ef 100644
--- a/src/github/daneren2005/dsub/fragments/MainFragment.java
+++ b/src/github/daneren2005/dsub/fragments/MainFragment.java
@@ -21,6 +21,7 @@ import android.widget.CheckBox;
import android.widget.ListView;
import android.widget.TextView;
import github.daneren2005.dsub.R;
+import github.daneren2005.dsub.domain.ServerInfo;
import github.daneren2005.dsub.service.DownloadService;
import github.daneren2005.dsub.util.Constants;
import github.daneren2005.dsub.util.FileUtil;
@@ -73,6 +74,10 @@ public class MainFragment extends SubsonicFragment {
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {
menuInflater.inflate(R.menu.main, menu);
+
+ if(!ServerInfo.isMadsonic(context) || !UserUtil.isCurrentAdmin()) {
+ menu.setGroupVisible(R.id.madsonic, false);
+ }
}
@Override
@@ -95,6 +100,9 @@ public class MainFragment extends SubsonicFragment {
case R.id.menu_faq:
showFAQDialog();
return true;
+ case R.id.menu_rescan:
+ rescanServer();
+ return true;
}
return false;
@@ -366,6 +374,22 @@ public class MainFragment extends SubsonicFragment {
Util.showHTMLDialog(context, R.string.main_faq_title, R.string.main_faq_text);
}
+ private void rescanServer() {
+ new LoadingTask<Void>(context, false) {
+ @Override
+ protected Void doInBackground() throws Throwable {
+ MusicService musicService = MusicServiceFactory.getMusicService(context);
+ musicService.startRescan(context, this);
+ return null;
+ }
+
+ @Override
+ protected void done(Void value) {
+ Util.toast(context, R.string.main_scan_complete);
+ }
+ }.execute();
+ }
+
private void getLogs() {
try {
final String version = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
diff --git a/src/github/daneren2005/dsub/service/CachedMusicService.java b/src/github/daneren2005/dsub/service/CachedMusicService.java
index 31280b19..86ad44f7 100644
--- a/src/github/daneren2005/dsub/service/CachedMusicService.java
+++ b/src/github/daneren2005/dsub/service/CachedMusicService.java
@@ -118,7 +118,12 @@ public class CachedMusicService implements MusicService {
return result;
}
- @Override
+ @Override
+ public void startRescan(Context context, ProgressListener listener) throws Exception {
+ musicService.startRescan(context, listener);
+ }
+
+ @Override
public Indexes getIndexes(String musicFolderId, boolean refresh, Context context, ProgressListener progressListener) throws Exception {
checkSettingsChanged(context);
if (refresh) {
diff --git a/src/github/daneren2005/dsub/service/MusicService.java b/src/github/daneren2005/dsub/service/MusicService.java
index cefd0c23..318873da 100644
--- a/src/github/daneren2005/dsub/service/MusicService.java
+++ b/src/github/daneren2005/dsub/service/MusicService.java
@@ -54,6 +54,8 @@ public interface MusicService {
List<MusicFolder> getMusicFolders(boolean refresh, Context context, ProgressListener progressListener) throws Exception;
+ void startRescan(Context context, ProgressListener listener) throws Exception;
+
Indexes getIndexes(String musicFolderId, boolean refresh, Context context, ProgressListener progressListener) throws Exception;
MusicDirectory getMusicDirectory(String id, String name, boolean refresh, Context context, ProgressListener progressListener) throws Exception;
diff --git a/src/github/daneren2005/dsub/service/OfflineMusicService.java b/src/github/daneren2005/dsub/service/OfflineMusicService.java
index 05d17444..8a520c8a 100644
--- a/src/github/daneren2005/dsub/service/OfflineMusicService.java
+++ b/src/github/daneren2005/dsub/service/OfflineMusicService.java
@@ -272,7 +272,12 @@ public class OfflineMusicService implements MusicService {
throw new OfflineException(ERRORMSG);
}
- @Override
+ @Override
+ public void startRescan(Context context, ProgressListener listener) throws Exception {
+ throw new OfflineException(ERRORMSG);
+ }
+
+ @Override
public SearchResult search(SearchCritera criteria, Context context, ProgressListener progressListener) throws Exception {
List<Artist> artists = new ArrayList<Artist>();
List<MusicDirectory.Entry> albums = new ArrayList<MusicDirectory.Entry>();
diff --git a/src/github/daneren2005/dsub/service/RESTMusicService.java b/src/github/daneren2005/dsub/service/RESTMusicService.java
index 15f06a3e..0129bf22 100644
--- a/src/github/daneren2005/dsub/service/RESTMusicService.java
+++ b/src/github/daneren2005/dsub/service/RESTMusicService.java
@@ -84,6 +84,7 @@ import github.daneren2005.dsub.service.parser.PlaylistsParser;
import github.daneren2005.dsub.service.parser.PodcastChannelParser;
import github.daneren2005.dsub.service.parser.PodcastEntryParser;
import github.daneren2005.dsub.service.parser.RandomSongsParser;
+import github.daneren2005.dsub.service.parser.ScanStatusParser;
import github.daneren2005.dsub.service.parser.SearchResult2Parser;
import github.daneren2005.dsub.service.parser.SearchResultParser;
import github.daneren2005.dsub.service.parser.ShareParser;
@@ -210,10 +211,10 @@ public class RESTMusicService implements MusicService {
// Now check if still running
boolean done = false;
while(!done) {
- reader = getReader(context, listener, "scanstatus", null);
+ reader = getReader(context, null, "scanstatus", null);
try {
- ScanStatus status = new ScanStatusParser(context).parse(reader);
- if(status.isRunning()) {
+ boolean running = new ScanStatusParser(context).parse(reader, listener);
+ if(running) {
// Don't run system ragged trying to query too much
Thread.sleep(100L);
} else {
@@ -234,18 +235,6 @@ public class RESTMusicService implements MusicService {
return cachedIndexes;
}
- // If manual refresh, try to start server scan for madsonic servers
- /*if(refresh) {
- Reader reader = getReader(context, progressListener, "startRescan", null);
- try {
- new ErrorParser(context).parse(reader);
- } catch(Exception e) {
- // Probably not madsonic, don't care
- } finally {
- Util.close(reader);
- }
- }*/
-
long lastModified = (cachedIndexes == null || refresh) ? 0L : cachedIndexes.getLastModified();
List<String> parameterNames = new ArrayList<String>();
@@ -1548,7 +1537,9 @@ public class RESTMusicService implements MusicService {
List<String> parameterNames, List<Object> parameterValues,
List<Header> headers, ProgressListener progressListener, SilentBackgroundTask task) throws Exception {
// Strip out sensitive information from log
- Log.i(TAG, stripUrlInfo(url));
+ if(url.indexOf("scanstatus") == -1) {
+ Log.i(TAG, stripUrlInfo(url));
+ }
SharedPreferences prefs = Util.getPreferences(context);
int networkTimeout = Integer.parseInt(prefs.getString(Constants.PREFERENCES_KEY_NETWORK_TIMEOUT, "15000"));
diff --git a/src/github/daneren2005/dsub/service/parser/ScanStatusParser.java b/src/github/daneren2005/dsub/service/parser/ScanStatusParser.java
new file mode 100644
index 00000000..e26b0562
--- /dev/null
+++ b/src/github/daneren2005/dsub/service/parser/ScanStatusParser.java
@@ -0,0 +1,56 @@
+/*
+ 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 <http://www.gnu.org/licenses/>.
+ Copyright 2014 (C) Scott Jackson
+*/
+
+package github.daneren2005.dsub.service.parser;
+
+import android.content.Context;
+import org.xmlpull.v1.XmlPullParser;
+
+import java.io.Reader;
+
+import github.daneren2005.dsub.R;
+import github.daneren2005.dsub.util.ProgressListener;
+
+public class ScanStatusParser extends AbstractParser {
+
+ public ScanStatusParser(Context context) {
+ super(context);
+ }
+
+ public boolean parse(Reader reader, ProgressListener progressListener) throws Exception {
+ init(reader);
+
+ Boolean started = null;
+ int eventType;
+ do {
+ eventType = nextParseEvent();
+ if (eventType == XmlPullParser.START_TAG) {
+ String name = getElementName();
+ if("status".equals(name)) {
+ started = getBoolean("started");
+
+ String msg = context.getResources().getString(R.string.parser_scan_count, getInteger("count"));
+ progressListener.updateProgress(msg);
+ } else if ("error".equals(name)) {
+ handleError();
+ }
+ }
+ } while (eventType != XmlPullParser.END_DOCUMENT);
+
+ validate();
+
+ return started != null && started;
+ }
+} \ No newline at end of file