Write converters for xml/gzip data and update data. Fill out initial classes for deserialization.
This commit is contained in:
@@ -2,8 +2,12 @@ package com.magnatune.eyecreate.companionformagnatune;
|
|||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
|
|
||||||
|
import com.magnatune.eyecreate.companionformagnatune.api.MagnatuneAlbumsConverterFactory;
|
||||||
|
import com.magnatune.eyecreate.companionformagnatune.api.ToStringConverterFactory;
|
||||||
import com.magnatune.eyecreate.companionformagnatune.api.data_api;
|
import com.magnatune.eyecreate.companionformagnatune.api.data_api;
|
||||||
|
|
||||||
|
import retrofit.Retrofit;
|
||||||
|
|
||||||
public class MagnatuneCompainionApplication extends Application {
|
public class MagnatuneCompainionApplication extends Application {
|
||||||
|
|
||||||
private static MagnatuneCompainionApplication instance;
|
private static MagnatuneCompainionApplication instance;
|
||||||
@@ -19,7 +23,11 @@ public class MagnatuneCompainionApplication extends Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static data_api getDataApi() {
|
public static data_api getDataApi() {
|
||||||
//TODO:implement
|
Retrofit api = new Retrofit.Builder()
|
||||||
return null;
|
.addConverterFactory(new MagnatuneAlbumsConverterFactory())
|
||||||
|
.addConverterFactory(new ToStringConverterFactory())
|
||||||
|
.baseUrl("http://he3.magnatune.com")
|
||||||
|
.build();
|
||||||
|
return api.create(data_api.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,14 +3,25 @@ package com.magnatune.eyecreate.companionformagnatune.api;
|
|||||||
import com.magnatune.eyecreate.companionformagnatune.model.AlbumResponse;
|
import com.magnatune.eyecreate.companionformagnatune.model.AlbumResponse;
|
||||||
import com.squareup.okhttp.ResponseBody;
|
import com.squareup.okhttp.ResponseBody;
|
||||||
|
|
||||||
|
import org.simpleframework.xml.Serializer;
|
||||||
|
import org.simpleframework.xml.core.Persister;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.zip.GZIPInputStream;
|
||||||
|
|
||||||
import retrofit.Converter;
|
import retrofit.Converter;
|
||||||
|
|
||||||
public class MagnatuneAlbumsConverter implements Converter<ResponseBody,AlbumResponse> {
|
public class MagnatuneAlbumsConverter implements Converter<ResponseBody,AlbumResponse> {
|
||||||
@Override
|
@Override
|
||||||
public AlbumResponse convert(ResponseBody value) throws IOException {
|
public AlbumResponse convert(ResponseBody value) throws IOException {
|
||||||
//TODO:convert from zip to xml to object
|
GZIPInputStream compressedStream = new GZIPInputStream(value.byteStream());
|
||||||
return null;
|
Serializer serializer = new Persister();
|
||||||
|
AlbumResponse conversion = null;
|
||||||
|
try {
|
||||||
|
conversion = serializer.read(AlbumResponse.class,compressedStream);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return conversion;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package com.magnatune.eyecreate.companionformagnatune.api;
|
||||||
|
|
||||||
|
import com.squareup.okhttp.MediaType;
|
||||||
|
import com.squareup.okhttp.RequestBody;
|
||||||
|
import com.squareup.okhttp.ResponseBody;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.lang.annotation.Annotation;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
|
||||||
|
import retrofit.Converter;
|
||||||
|
|
||||||
|
public class ToStringConverterFactory extends Converter.Factory {
|
||||||
|
private static final MediaType MEDIA_TYPE = MediaType.parse("text/plain");
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Converter<ResponseBody, ?> fromResponseBody(Type type, Annotation[] annotations) {
|
||||||
|
if (String.class.equals(type)) {
|
||||||
|
return new Converter<ResponseBody, String>() {
|
||||||
|
@Override public String convert(ResponseBody value) throws IOException {
|
||||||
|
return value.string();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public Converter<?, RequestBody> toRequestBody(Type type, Annotation[] annotations) {
|
||||||
|
if (String.class.equals(type)) {
|
||||||
|
return new Converter<String, RequestBody>() {
|
||||||
|
@Override public RequestBody convert(String value) throws IOException {
|
||||||
|
return RequestBody.create(MEDIA_TYPE, value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,9 @@ import retrofit.Call;
|
|||||||
import retrofit.http.GET;
|
import retrofit.http.GET;
|
||||||
|
|
||||||
public interface data_api {
|
public interface data_api {
|
||||||
@GET("/info/album_info.xml")
|
@GET("/info/album_info_xml.gz")
|
||||||
Call<AlbumResponse> getAlbumList();
|
Call<AlbumResponse> getAlbumList();
|
||||||
|
|
||||||
|
@GET("/info/changed.txt")
|
||||||
|
Call<String> getUpdateChecksum();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,14 @@
|
|||||||
package com.magnatune.eyecreate.companionformagnatune.model;
|
package com.magnatune.eyecreate.companionformagnatune.model;
|
||||||
|
|
||||||
|
import org.simpleframework.xml.ElementList;
|
||||||
|
import org.simpleframework.xml.Root;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Root(name="AllAlbums")
|
||||||
public class AlbumResponse {
|
public class AlbumResponse {
|
||||||
//TODO:fill
|
|
||||||
|
@ElementList(inline=true)
|
||||||
|
public List<Album> albums;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package com.magnatune.eyecreate.companionformagnatune.model.xml;
|
||||||
|
|
||||||
|
import org.simpleframework.xml.Element;
|
||||||
|
import org.simpleframework.xml.ElementList;
|
||||||
|
import org.simpleframework.xml.Root;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Root
|
||||||
|
public class Album {
|
||||||
|
|
||||||
|
@Element
|
||||||
|
public String artist;
|
||||||
|
|
||||||
|
@Element
|
||||||
|
public String artistdesc;
|
||||||
|
|
||||||
|
@Element
|
||||||
|
public String cover_small;
|
||||||
|
|
||||||
|
@Element
|
||||||
|
public String artistphoto;
|
||||||
|
|
||||||
|
@Element
|
||||||
|
public String albumname;
|
||||||
|
|
||||||
|
@Element
|
||||||
|
public int year;
|
||||||
|
|
||||||
|
@Element
|
||||||
|
public String album_notes;
|
||||||
|
|
||||||
|
@Element
|
||||||
|
public String mp3genre;
|
||||||
|
|
||||||
|
@Element
|
||||||
|
public String home;
|
||||||
|
|
||||||
|
@Element
|
||||||
|
public String magnatunegenres;
|
||||||
|
|
||||||
|
@Element
|
||||||
|
public Date launchdate;
|
||||||
|
|
||||||
|
@ElementList(inline=true)
|
||||||
|
public List<Track> tracks;
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package com.magnatune.eyecreate.companionformagnatune.model.xml;
|
||||||
|
|
||||||
|
import org.simpleframework.xml.Element;
|
||||||
|
import org.simpleframework.xml.Root;
|
||||||
|
|
||||||
|
@Root
|
||||||
|
public class Track {
|
||||||
|
@Element
|
||||||
|
public String artist;
|
||||||
|
|
||||||
|
@Element
|
||||||
|
public String artistbio;
|
||||||
|
|
||||||
|
@Element
|
||||||
|
public String albumname;
|
||||||
|
|
||||||
|
@Element
|
||||||
|
public String trackname;
|
||||||
|
|
||||||
|
@Element
|
||||||
|
public int tracknum;
|
||||||
|
|
||||||
|
@Element
|
||||||
|
public int year;
|
||||||
|
|
||||||
|
@Element
|
||||||
|
public String mp3genre;
|
||||||
|
|
||||||
|
@Element
|
||||||
|
public String magnatunegenres;
|
||||||
|
|
||||||
|
@Element
|
||||||
|
public String license;
|
||||||
|
|
||||||
|
@Element
|
||||||
|
public long seconds;
|
||||||
|
|
||||||
|
@Element
|
||||||
|
public String url;
|
||||||
|
|
||||||
|
@Element
|
||||||
|
public String mp3lofi;
|
||||||
|
|
||||||
|
@Element
|
||||||
|
public String oggurl;
|
||||||
|
|
||||||
|
@Element
|
||||||
|
public String isrc;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user