Use new api getSongsByGenre call.

Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
This commit is contained in:
Yahor Berdnikau 2017-11-14 22:12:23 +01:00
parent 5ea9eb7818
commit 3b91f41cbe
2 changed files with 19 additions and 100 deletions

View File

@ -71,6 +71,7 @@ import org.moire.ultrasonic.api.subsonic.response.GetPlaylistResponse;
import org.moire.ultrasonic.api.subsonic.response.GetPlaylistsResponse;
import org.moire.ultrasonic.api.subsonic.response.GetPodcastsResponse;
import org.moire.ultrasonic.api.subsonic.response.GetRandomSongsResponse;
import org.moire.ultrasonic.api.subsonic.response.GetSongsByGenreResponse;
import org.moire.ultrasonic.api.subsonic.response.GetStarredResponse;
import org.moire.ultrasonic.api.subsonic.response.GetStarredTwoResponse;
import org.moire.ultrasonic.api.subsonic.response.JukeboxResponse;
@ -113,7 +114,6 @@ import org.moire.ultrasonic.service.parser.BookmarkParser;
import org.moire.ultrasonic.service.parser.ChatMessageParser;
import org.moire.ultrasonic.service.parser.ErrorParser;
import org.moire.ultrasonic.service.parser.MusicDirectoryParser;
import org.moire.ultrasonic.service.parser.RandomSongsParser;
import org.moire.ultrasonic.service.parser.SubsonicRESTException;
import org.moire.ultrasonic.service.parser.UserInfoParser;
import org.moire.ultrasonic.service.ssl.SSLSocketFactory;
@ -1207,35 +1207,26 @@ public class RESTMusicService implements MusicService
return ApiGenreConverter.toDomainEntityList(response.body().getGenresList());
}
@Override
public MusicDirectory getSongsByGenre(String genre, int count, int offset, Context context, ProgressListener progressListener) throws Exception
{
checkServerVersion(context, "1.9", "Genres not supported.");
@Override
public MusicDirectory getSongsByGenre(String genre,
int count,
int offset,
Context context,
ProgressListener progressListener) throws Exception {
if (genre == null) {
throw new IllegalArgumentException("Genre is null");
}
HttpParams params = new BasicHttpParams();
HttpConnectionParams.setSoTimeout(params, SOCKET_READ_TIMEOUT_GET_RANDOM_SONGS);
updateProgressListener(progressListener, R.string.parser_reading);
Response<GetSongsByGenreResponse> response = subsonicAPIClient.getApi()
.getSongsByGenre(genre, count, offset, null)
.execute();
checkResponseSuccessful(response);
List<String> parameterNames = new ArrayList<String>();
List<Object> parameterValues = new ArrayList<Object>();
parameterNames.add("genre");
parameterValues.add(genre);
parameterNames.add("count");
parameterValues.add(count);
parameterNames.add("offset");
parameterValues.add(offset);
Reader reader = getReader(context, progressListener, "getSongsByGenre", params, parameterNames, parameterValues);
try
{
return new RandomSongsParser(context).parse(reader, progressListener);
}
finally
{
Util.close(reader);
}
}
MusicDirectory result = new MusicDirectory();
result.addAll(APIMusicDirectoryConverter.toDomainEntityList(response.body().getSongsList()));
return result;
}
@Override
public UserInfo getUser(String username, Context context, ProgressListener progressListener) throws Exception

View File

@ -1,72 +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 <http://www.gnu.org/licenses/>.
Copyright 2009 (C) Sindre Mehus
*/
package org.moire.ultrasonic.service.parser;
import android.content.Context;
import org.moire.ultrasonic.R;
import org.moire.ultrasonic.domain.MusicDirectory;
import org.moire.ultrasonic.util.ProgressListener;
import org.xmlpull.v1.XmlPullParser;
import java.io.Reader;
/**
* @author Sindre Mehus
*/
public class RandomSongsParser extends MusicDirectoryEntryParser
{
public RandomSongsParser(Context context)
{
super(context);
}
public MusicDirectory parse(Reader reader, ProgressListener progressListener) throws Exception
{
updateProgress(progressListener, R.string.parser_reading);
init(reader);
MusicDirectory dir = new MusicDirectory();
int eventType;
do
{
eventType = nextParseEvent();
if (eventType == XmlPullParser.START_TAG)
{
String name = getElementName();
if ("song".equals(name))
{
dir.addChild(parseEntry("", false, 0));
}
else if ("error".equals(name))
{
handleError();
}
}
} while (eventType != XmlPullParser.END_DOCUMENT);
validate();
updateProgress(progressListener, R.string.parser_reading_done);
return dir;
}
}