Use new api getBookmarks() call.

Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
This commit is contained in:
Yahor Berdnikau 2017-11-18 21:37:11 +01:00
parent 6b2a682646
commit 59ff48860a
2 changed files with 11 additions and 89 deletions

View File

@ -58,6 +58,7 @@ import org.moire.ultrasonic.api.subsonic.SubsonicAPIClient;
import org.moire.ultrasonic.api.subsonic.models.AlbumListType;
import org.moire.ultrasonic.api.subsonic.models.JukeboxAction;
import org.moire.ultrasonic.api.subsonic.models.MusicDirectoryChild;
import org.moire.ultrasonic.api.subsonic.response.BookmarksResponse;
import org.moire.ultrasonic.api.subsonic.response.ChatMessagesResponse;
import org.moire.ultrasonic.api.subsonic.response.GenresResponse;
import org.moire.ultrasonic.api.subsonic.response.GetAlbumList2Response;
@ -87,6 +88,7 @@ import org.moire.ultrasonic.api.subsonic.response.StreamResponse;
import org.moire.ultrasonic.api.subsonic.response.SubsonicResponse;
import org.moire.ultrasonic.data.APIAlbumConverter;
import org.moire.ultrasonic.data.APIArtistConverter;
import org.moire.ultrasonic.data.APIBookmarkConverter;
import org.moire.ultrasonic.data.APIChatMessageConverter;
import org.moire.ultrasonic.data.APIIndexesConverter;
import org.moire.ultrasonic.data.APIJukeboxConverter;
@ -114,7 +116,6 @@ import org.moire.ultrasonic.domain.SearchResult;
import org.moire.ultrasonic.domain.Share;
import org.moire.ultrasonic.domain.UserInfo;
import org.moire.ultrasonic.domain.Version;
import org.moire.ultrasonic.service.parser.BookmarkParser;
import org.moire.ultrasonic.service.parser.ErrorParser;
import org.moire.ultrasonic.service.parser.MusicDirectoryParser;
import org.moire.ultrasonic.service.parser.SubsonicRESTException;
@ -1272,22 +1273,16 @@ public class RESTMusicService implements MusicService
checkResponseSuccessful(response);
}
@Override
public List<Bookmark> getBookmarks(Context context, ProgressListener progressListener) throws Exception
{
checkServerVersion(context, "1.9", "Bookmarks not supported.");
@Override
public List<Bookmark> getBookmarks(Context context,
ProgressListener progressListener) throws Exception {
updateProgressListener(progressListener, R.string.parser_reading);
Response<BookmarksResponse> response = subsonicAPIClient.getApi()
.getBookmarks().execute();
checkResponseSuccessful(response);
Reader reader = getReader(context, progressListener, "getBookmarks", null);
try
{
return new BookmarkParser(context).parse(reader, progressListener);
}
finally
{
Util.close(reader);
}
}
return APIBookmarkConverter.toDomainEntitiesList(response.body().getBookmarkList());
}
@Override
public void createBookmark(String id, int position, Context context, ProgressListener progressListener) throws Exception

View File

@ -1,73 +0,0 @@
package org.moire.ultrasonic.service.parser;
import android.content.Context;
import org.moire.ultrasonic.R;
import org.moire.ultrasonic.domain.Bookmark;
import org.moire.ultrasonic.util.ProgressListener;
import org.xmlpull.v1.XmlPullParser;
import java.io.Reader;
import java.util.ArrayList;
import java.util.List;
/**
* @author Joshua Bahnsen
*/
public class BookmarkParser extends MusicDirectoryEntryParser
{
public BookmarkParser(Context context)
{
super(context);
}
public List<Bookmark> parse(Reader reader, ProgressListener progressListener) throws Exception
{
updateProgress(progressListener, R.string.parser_reading);
init(reader);
List<Bookmark> dir = new ArrayList<Bookmark>();
Bookmark bookmark = null;
int eventType;
do
{
eventType = nextParseEvent();
if (eventType == XmlPullParser.START_TAG)
{
String name = getElementName();
if ("bookmark".equals(name))
{
bookmark = new Bookmark();
bookmark.setChanged(get("changed"));
bookmark.setCreated(get("created"));
bookmark.setComment(get("comment"));
bookmark.setPosition(getInteger("position"));
bookmark.setUsername(get("username"));
}
else if ("entry".equals(name))
{
if (bookmark != null)
{
bookmark.setEntry(parseEntry(null, false, bookmark.getPosition()));
dir.add(bookmark);
}
}
else if ("error".equals(name))
{
handleError();
}
}
} while (eventType != XmlPullParser.END_DOCUMENT);
validate();
updateProgress(progressListener, R.string.parser_reading_done);
return dir;
}
}