From cdba76c933e73c9636b9d8157849bb4edd2d7168 Mon Sep 17 00:00:00 2001 From: Karim Abou Zeid Date: Mon, 29 Jun 2015 21:38:09 +0200 Subject: [PATCH] Switched from Volley to RetroFit + OkHttp for performance and simplicity --- app/build.gradle | 3 +- app/proguard-rules.pro | 12 +- .../java/com/kabouzeid/gramophone/App.java | 17 -- .../gramophone/adapter/ArtistAdapter.java | 49 ++++- .../gramophone/adapter/SearchAdapter.java | 44 ++-- .../gramophone/lastfm/LastFMUtil.java | 9 - .../album/LastFMAlbumImageUrlLoader.java | 58 ----- .../lastfm/album/LastFMAlbumInfoUtil.java | 109 ---------- .../artist/LastFMArtistBiographyLoader.java | 61 ------ .../artist/LastFMArtistImageUrlLoader.java | 48 ----- .../lastfm/artist/LastFMArtistInfoUtil.java | 119 ---------- .../LastFMArtistThumbnailUrlLoader.java | 48 ----- .../lastfm/rest/LastFMRestClient.java | 49 +++++ .../lastfm/rest/model/albuminfo/Album.java | 204 ++++++++++++++++++ .../rest/model/albuminfo/AlbumInfo.java | 25 +++ .../lastfm/rest/model/albuminfo/Artist.java | 57 +++++ .../lastfm/rest/model/albuminfo/Attr.java | 25 +++ .../lastfm/rest/model/albuminfo/Image.java | 43 ++++ .../rest/model/albuminfo/Streamable.java | 43 ++++ .../lastfm/rest/model/albuminfo/Tag.java | 41 ++++ .../lastfm/rest/model/albuminfo/Toptags.java | 28 +++ .../lastfm/rest/model/albuminfo/Track.java | 123 +++++++++++ .../lastfm/rest/model/albuminfo/Tracks.java | 28 +++ .../lastfm/rest/model/albuminfo/Wiki.java | 57 +++++ .../lastfm/rest/model/artistinfo/Artist.java | 172 +++++++++++++++ .../rest/model/artistinfo/ArtistInfo.java | 25 +++ .../lastfm/rest/model/artistinfo/Artist_.java | 60 ++++++ .../lastfm/rest/model/artistinfo/Bio.java | 105 +++++++++ .../rest/model/artistinfo/Formation.java | 41 ++++ .../rest/model/artistinfo/Formationlist.java | 25 +++ .../lastfm/rest/model/artistinfo/Image.java | 43 ++++ .../lastfm/rest/model/artistinfo/Image_.java | 43 ++++ .../lastfm/rest/model/artistinfo/Link.java | 59 +++++ .../lastfm/rest/model/artistinfo/Links.java | 25 +++ .../lastfm/rest/model/artistinfo/Similar.java | 28 +++ .../lastfm/rest/model/artistinfo/Stats.java | 41 ++++ .../lastfm/rest/model/artistinfo/Tag.java | 41 ++++ .../lastfm/rest/model/artistinfo/Tags.java | 28 +++ .../lastfm/rest/service/LastFMService.java | 25 +++ .../ui/activities/ArtistDetailActivity.java | 104 ++++++--- .../tageditor/AlbumTagEditorActivity.java | 76 ++++--- app/src/main/res/values-cs/strings.xml | 2 +- app/src/main/res/values-de/strings.xml | 2 +- app/src/main/res/values-es-rES/strings.xml | 2 +- app/src/main/res/values-fr/strings.xml | 2 +- app/src/main/res/values-hr/strings.xml | 2 +- app/src/main/res/values-it/strings.xml | 2 +- app/src/main/res/values-ja/strings.xml | 2 +- app/src/main/res/values-ko/strings.xml | 2 +- app/src/main/res/values-nl/strings.xml | 2 +- app/src/main/res/values-pl/strings.xml | 2 +- app/src/main/res/values-pt-rBR/strings.xml | 2 +- app/src/main/res/values-tr/strings.xml | 2 +- app/src/main/res/values-zh-rCN/strings.xml | 2 +- app/src/main/res/values/strings.xml | 4 +- 55 files changed, 1701 insertions(+), 570 deletions(-) delete mode 100644 app/src/main/java/com/kabouzeid/gramophone/lastfm/LastFMUtil.java delete mode 100644 app/src/main/java/com/kabouzeid/gramophone/lastfm/album/LastFMAlbumImageUrlLoader.java delete mode 100644 app/src/main/java/com/kabouzeid/gramophone/lastfm/album/LastFMAlbumInfoUtil.java delete mode 100644 app/src/main/java/com/kabouzeid/gramophone/lastfm/artist/LastFMArtistBiographyLoader.java delete mode 100644 app/src/main/java/com/kabouzeid/gramophone/lastfm/artist/LastFMArtistImageUrlLoader.java delete mode 100644 app/src/main/java/com/kabouzeid/gramophone/lastfm/artist/LastFMArtistInfoUtil.java delete mode 100644 app/src/main/java/com/kabouzeid/gramophone/lastfm/artist/LastFMArtistThumbnailUrlLoader.java create mode 100644 app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/LastFMRestClient.java create mode 100644 app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/albuminfo/Album.java create mode 100644 app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/albuminfo/AlbumInfo.java create mode 100644 app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/albuminfo/Artist.java create mode 100644 app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/albuminfo/Attr.java create mode 100644 app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/albuminfo/Image.java create mode 100644 app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/albuminfo/Streamable.java create mode 100644 app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/albuminfo/Tag.java create mode 100644 app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/albuminfo/Toptags.java create mode 100644 app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/albuminfo/Track.java create mode 100644 app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/albuminfo/Tracks.java create mode 100644 app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/albuminfo/Wiki.java create mode 100644 app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Artist.java create mode 100644 app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/ArtistInfo.java create mode 100644 app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Artist_.java create mode 100644 app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Bio.java create mode 100644 app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Formation.java create mode 100644 app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Formationlist.java create mode 100644 app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Image.java create mode 100644 app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Image_.java create mode 100644 app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Link.java create mode 100644 app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Links.java create mode 100644 app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Similar.java create mode 100644 app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Stats.java create mode 100644 app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Tag.java create mode 100644 app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Tags.java create mode 100644 app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/service/LastFMService.java diff --git a/app/build.gradle b/app/build.gradle index 23cb6ee3..f8cb9a32 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -60,7 +60,8 @@ dependencies { compile 'com.github.ksoichiro:android-observablescrollview:1.5.1' compile 'asia.ivity.android:drag-sort-listview:1.0' - compile 'com.mcxiaoke.volley:library:1.0.16' + compile 'com.squareup.retrofit:retrofit:1.9.0' + compile 'com.squareup.okhttp:okhttp:2.4.0' compile 'com.squareup:otto:1.3.7' compile 'de.hdodenhof:circleimageview:1.3.0' compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.4' diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index eef77cc6..b62dec78 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -16,11 +16,13 @@ # public *; #} +# RetroFit +-dontwarn retrofit.** +-keep class retrofit.** { *; } +-keepattributes Signature +-keepattributes Exceptions + -keep class !android.support.v7.internal.view.menu.**,** {*;} --keep public class * implements com.bumptech.glide.module.GlideModule --keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** { - **[] $VALUES; - public *; -} + -dontwarn -ignorewarnings \ No newline at end of file diff --git a/app/src/main/java/com/kabouzeid/gramophone/App.java b/app/src/main/java/com/kabouzeid/gramophone/App.java index bd4d5d16..e5e7613b 100644 --- a/app/src/main/java/com/kabouzeid/gramophone/App.java +++ b/app/src/main/java/com/kabouzeid/gramophone/App.java @@ -2,9 +2,6 @@ package com.kabouzeid.gramophone; import android.app.Application; -import com.android.volley.Request; -import com.android.volley.RequestQueue; -import com.android.volley.toolbox.Volley; import com.crashlytics.android.Crashlytics; import com.kabouzeid.gramophone.helper.MusicPlayerRemote; import com.nostra13.universalimageloader.core.ImageLoader; @@ -24,8 +21,6 @@ public class App extends Application { public static final String TAG = App.class.getSimpleName(); public static final Bus bus = new Bus(ThreadEnforcer.MAIN); - private RequestQueue requestQueue; - @Override public void onCreate() { super.onCreate(); @@ -39,16 +34,4 @@ public class App extends Application { TagOptionSingleton.getInstance().isAndroid(); } - - public void addToVolleyRequestQueue(Request request) { - request.setTag(TAG); - getVolleyRequestQueue().add(request); - } - - public RequestQueue getVolleyRequestQueue() { - if (requestQueue == null) { - requestQueue = Volley.newRequestQueue(this); - } - return requestQueue; - } } diff --git a/app/src/main/java/com/kabouzeid/gramophone/adapter/ArtistAdapter.java b/app/src/main/java/com/kabouzeid/gramophone/adapter/ArtistAdapter.java index c63e0352..db055c9b 100644 --- a/app/src/main/java/com/kabouzeid/gramophone/adapter/ArtistAdapter.java +++ b/app/src/main/java/com/kabouzeid/gramophone/adapter/ArtistAdapter.java @@ -17,7 +17,9 @@ import com.kabouzeid.gramophone.dialogs.AddToPlaylistDialog; import com.kabouzeid.gramophone.dialogs.DeleteSongsDialog; import com.kabouzeid.gramophone.helper.MusicPlayerRemote; import com.kabouzeid.gramophone.interfaces.CabHolder; -import com.kabouzeid.gramophone.lastfm.artist.LastFMArtistThumbnailUrlLoader; +import com.kabouzeid.gramophone.lastfm.rest.LastFMRestClient; +import com.kabouzeid.gramophone.lastfm.rest.model.artistinfo.ArtistInfo; +import com.kabouzeid.gramophone.lastfm.rest.model.artistinfo.Image; import com.kabouzeid.gramophone.loader.ArtistLoader; import com.kabouzeid.gramophone.loader.ArtistSongLoader; import com.kabouzeid.gramophone.model.Artist; @@ -33,16 +35,22 @@ import com.squareup.otto.Subscribe; import java.util.ArrayList; import java.util.List; +import retrofit.Callback; +import retrofit.RetrofitError; +import retrofit.client.Response; + /** * @author Karim Abou Zeid (kabouzeid) */ public class ArtistAdapter extends AbsMultiSelectAdapter { protected final AppCompatActivity activity; protected List dataSet; + protected final LastFMRestClient lastFMRestClient; public ArtistAdapter(AppCompatActivity activity, @Nullable CabHolder cabHolder) { super(activity, cabHolder, R.menu.menu_media_selection); this.activity = activity; + lastFMRestClient = new LastFMRestClient(activity); loadDataSet(); } @@ -62,23 +70,42 @@ public class ArtistAdapter extends AbsMultiSelectAdapter() { @Override - public void onArtistThumbnailUrlLoaded(final String url) { - ImageLoader.getInstance().displayImage(url, - holder.artistImage, - new DisplayImageOptions.Builder() - .cacheInMemory(true) - .cacheOnDisk(true) - .build() - ); + public void success(ArtistInfo artistInfo, Response response) { + if (artistInfo.getArtist() != null) { + int thumbnailIndex = 0; + List images = artistInfo.getArtist().getImage(); + if (images.size() > 2) { + thumbnailIndex = 2; + } else if (images.size() > 1) { + thumbnailIndex = 1; + } + ImageLoader.getInstance().displayImage(images.get(thumbnailIndex).getText(), + holder.artistImage, + new DisplayImageOptions.Builder() + .cacheInMemory(true) + .cacheOnDisk(true) + .build() + ); + } else { + setDefaultArtistImage(holder); + } + } + + @Override + public void failure(RetrofitError error) { + setDefaultArtistImage(holder); } }); } + private void setDefaultArtistImage(ViewHolder holder) { + holder.artistImage.setImageResource(R.drawable.default_artist_image); + } + @Override public int getItemCount() { return dataSet.size(); diff --git a/app/src/main/java/com/kabouzeid/gramophone/adapter/SearchAdapter.java b/app/src/main/java/com/kabouzeid/gramophone/adapter/SearchAdapter.java index b12f9551..78d9e1f5 100644 --- a/app/src/main/java/com/kabouzeid/gramophone/adapter/SearchAdapter.java +++ b/app/src/main/java/com/kabouzeid/gramophone/adapter/SearchAdapter.java @@ -15,7 +15,8 @@ import com.kabouzeid.gramophone.App; import com.kabouzeid.gramophone.R; import com.kabouzeid.gramophone.helper.MenuItemClickHelper; import com.kabouzeid.gramophone.helper.MusicPlayerRemote; -import com.kabouzeid.gramophone.lastfm.artist.LastFMArtistThumbnailUrlLoader; +import com.kabouzeid.gramophone.lastfm.rest.LastFMRestClient; +import com.kabouzeid.gramophone.lastfm.rest.model.artistinfo.ArtistInfo; import com.kabouzeid.gramophone.loader.AlbumLoader; import com.kabouzeid.gramophone.loader.ArtistLoader; import com.kabouzeid.gramophone.loader.SongLoader; @@ -33,6 +34,10 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import retrofit.Callback; +import retrofit.RetrofitError; +import retrofit.client.Response; + /** * @author Karim Abou Zeid (kabouzeid) */ @@ -45,6 +50,7 @@ public class SearchAdapter extends RecyclerView.Adapter() { @Override - public void onArtistThumbnailUrlLoaded(final String url) { - ImageLoader.getInstance().displayImage(url, - holder.image, - new DisplayImageOptions.Builder() - .cacheInMemory(true) - .cacheOnDisk(true) - .showImageOnFail(R.drawable.default_artist_image) - .resetViewBeforeLoading(true) - .build() - ); + public void success(ArtistInfo artistInfo, Response response) { + if (artistInfo.getArtist() != null) { + ImageLoader.getInstance().displayImage(artistInfo.getArtist().getImage().get(0).getText(), + holder.image, + new DisplayImageOptions.Builder() + .cacheInMemory(true) + .cacheOnDisk(true) + .showImageOnFail(R.drawable.default_artist_image) + .resetViewBeforeLoading(true) + .build() + ); + } else { + setDefaultArtistImage(); + } + } + + @Override + public void failure(RetrofitError error) { + setDefaultArtistImage(); + } + + private void setDefaultArtistImage() { + holder.image.setImageResource(R.drawable.default_artist_image); } }); break; diff --git a/app/src/main/java/com/kabouzeid/gramophone/lastfm/LastFMUtil.java b/app/src/main/java/com/kabouzeid/gramophone/lastfm/LastFMUtil.java deleted file mode 100644 index ace2b1ac..00000000 --- a/app/src/main/java/com/kabouzeid/gramophone/lastfm/LastFMUtil.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.kabouzeid.gramophone.lastfm; - -/** - * @author Karim Abou Zeid (kabouzeid) - */ -public class LastFMUtil { - public static final String BASE_URL = "ws.audioscrobbler.com"; - public static final String API_KEY = "bd9c6ea4d55ec9ed3af7d276e5ece304"; -} diff --git a/app/src/main/java/com/kabouzeid/gramophone/lastfm/album/LastFMAlbumImageUrlLoader.java b/app/src/main/java/com/kabouzeid/gramophone/lastfm/album/LastFMAlbumImageUrlLoader.java deleted file mode 100644 index cffc39f1..00000000 --- a/app/src/main/java/com/kabouzeid/gramophone/lastfm/album/LastFMAlbumImageUrlLoader.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.kabouzeid.gramophone.lastfm.album; - -import android.content.Context; -import android.util.Log; - -import com.android.volley.Response; -import com.android.volley.VolleyError; -import com.kabouzeid.gramophone.provider.AlbumJSONStore; - -import org.json.JSONException; -import org.json.JSONObject; - -/** - * @author Karim Abou Zeid (kabouzeid) - */ -public class LastFMAlbumImageUrlLoader { - public static final String TAG = LastFMAlbumImageUrlLoader.class.getSimpleName(); - - public static void loadAlbumImageUrl(Context context, String queryAlbum, String queryArtist, final AlbumImageUrlLoaderCallback callback) { - if (queryAlbum != null) { - String albumJSON = AlbumJSONStore.getInstance(context).getJSONData(queryAlbum + queryArtist); - if (albumJSON != null) { - try { - loadAlbumImageUrlFromJSON(new JSONObject(albumJSON), callback); - } catch (JSONException e) { - Log.e(TAG, "Error while parsing string from cache to JSONObject", e); - } - } else { - LastFMAlbumInfoUtil.downloadAlbumInfoJSON(context, queryAlbum, queryArtist, new Response.Listener() { - @Override - public void onResponse(JSONObject response) { - loadAlbumImageUrlFromJSON(response, callback); - } - }, new Response.ErrorListener() { - @Override - public void onErrorResponse(VolleyError error) { - callback.onError(); - } - }); - } - } - } - - private static void loadAlbumImageUrlFromJSON(final JSONObject jsonObject, final AlbumImageUrlLoaderCallback callback) { - String url = LastFMAlbumInfoUtil.getAlbumImageUrlFromJSON(jsonObject); - if (!url.trim().equals("")) { - callback.onAlbumImageUrlLoaded(url); - } else { - callback.onError(); - } - } - - public interface AlbumImageUrlLoaderCallback { - void onAlbumImageUrlLoaded(String url); - - void onError(); - } -} diff --git a/app/src/main/java/com/kabouzeid/gramophone/lastfm/album/LastFMAlbumInfoUtil.java b/app/src/main/java/com/kabouzeid/gramophone/lastfm/album/LastFMAlbumInfoUtil.java deleted file mode 100644 index cc771fb6..00000000 --- a/app/src/main/java/com/kabouzeid/gramophone/lastfm/album/LastFMAlbumInfoUtil.java +++ /dev/null @@ -1,109 +0,0 @@ -package com.kabouzeid.gramophone.lastfm.album; - -import android.content.Context; -import android.net.Uri; -import android.util.Log; - -import com.android.volley.Response; -import com.android.volley.VolleyError; -import com.android.volley.toolbox.JsonObjectRequest; -import com.kabouzeid.gramophone.App; -import com.kabouzeid.gramophone.lastfm.LastFMUtil; -import com.kabouzeid.gramophone.provider.AlbumJSONStore; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -/** - * @author Karim Abou Zeid (kabouzeid) - */ -public class LastFMAlbumInfoUtil { - public static final String TAG = LastFMAlbumInfoUtil.class.getSimpleName(); - - private static final String AUTO_CORRECT = "1"; - - public static String getAlbumUrl(String album, String artist) { - if (album != null) { - Uri.Builder builder = new Uri.Builder(); - builder.scheme("http") - .authority(LastFMUtil.BASE_URL) - .appendPath("2.0") - .appendQueryParameter("method", "album.getinfo") - .appendQueryParameter("album", album) - .appendQueryParameter("artist", artist) - //.appendQueryParameter("lang", "de") - .appendQueryParameter("autocorrect", AUTO_CORRECT) - .appendQueryParameter("api_key", LastFMUtil.API_KEY) - .appendQueryParameter("format", "json"); - return builder.build().toString(); - } - return ""; - } - - public static String getAlbumNameFromJSON(JSONObject rootJSON) { - try { - return rootJSON.getJSONObject("album").getString("name"); - } catch (JSONException e) { - //Log.e(TAG, "Error while getting album name from JSON_DATA parameter!", e); - return ""; - } - } - - public static String getAlbumThumbnailUrlFromJSON(JSONObject rootJSON) { - try { - JSONArray images = getAlbumImageArrayFromJSON(rootJSON); - if (images.length() > 2) { - return images.getJSONObject(2).getString("#text"); - } else if (images.length() > 1) { - return images.getJSONObject(1).getString("#text"); - } - return images.getJSONObject(0).getString("#text"); - } catch (JSONException | NullPointerException e) { - //Log.e(TAG, "Error while getting album thumbnail image from JSON_DATA parameter!", e); - return ""; - } - } - - public static JSONArray getAlbumImageArrayFromJSON(JSONObject rootJSON) { - try { - return rootJSON.getJSONObject("album").getJSONArray("image"); - } catch (JSONException e) { - //Log.e(TAG, "Error while getting album image array from JSON_DATA parameter!", e); - return null; - } - } - - public static String getAlbumImageUrlFromJSON(JSONObject rootJSON) { - try { - JSONArray images = getAlbumImageArrayFromJSON(rootJSON); - return images.getJSONObject(images.length() - 1).getString("#text"); - } catch (JSONException | NullPointerException e) { - //Log.e(TAG, "Error while getting album image from JSON_DATA parameter!", e); - return ""; - } - } - - public static void downloadAlbumInfoJSON(final Context context, final String album, final String artist, final Response.Listener callbackSuccess, final Response.ErrorListener callbackError) { - App app = (App) context.getApplicationContext(); - String albumUrl = LastFMAlbumInfoUtil.getAlbumUrl(album, artist); - JsonObjectRequest albumInfoJSONRequest = new JsonObjectRequest(0, albumUrl, (JSONObject) null, new Response.Listener() { - @Override - public void onResponse(JSONObject response) { - LastFMAlbumInfoUtil.saveAlbumJSONDataToCacheAndDisk(context, album, artist, response); - callbackSuccess.onResponse(response); - } - }, new Response.ErrorListener() { - @Override - public void onErrorResponse(VolleyError error) { - Log.e(TAG, "Download failed!", error); - callbackError.onErrorResponse(error); - } - }); - app.addToVolleyRequestQueue(albumInfoJSONRequest); - } - - public static void saveAlbumJSONDataToCacheAndDisk(Context context, String album, String artist, JSONObject jsonObject) { - AlbumJSONStore.getInstance(context).addAlbumJSON(album + artist, jsonObject.toString()); - } -} diff --git a/app/src/main/java/com/kabouzeid/gramophone/lastfm/artist/LastFMArtistBiographyLoader.java b/app/src/main/java/com/kabouzeid/gramophone/lastfm/artist/LastFMArtistBiographyLoader.java deleted file mode 100644 index c8f60f3d..00000000 --- a/app/src/main/java/com/kabouzeid/gramophone/lastfm/artist/LastFMArtistBiographyLoader.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.kabouzeid.gramophone.lastfm.artist; - -import android.content.Context; -import android.util.Log; - -import com.android.volley.Response; -import com.android.volley.VolleyError; -import com.android.volley.toolbox.JsonObjectRequest; -import com.kabouzeid.gramophone.App; -import com.kabouzeid.gramophone.provider.ArtistJSONStore; - -import org.json.JSONException; -import org.json.JSONObject; - -/** - * @author Karim Abou Zeid (kabouzeid) - */ -public class LastFMArtistBiographyLoader { - public static final String TAG = LastFMArtistBiographyLoader.class.getSimpleName(); - - public static void loadArtistBio(Context context, String queryArtist, ArtistBioLoaderCallback callback) { - if (queryArtist != null) { - String artistJSON = ArtistJSONStore.getInstance(context).getArtistJSON(queryArtist); - if (artistJSON != null) { - try { - JSONObject json = new JSONObject(artistJSON); - String bio = LastFMArtistInfoUtil.getArtistBiographyFromJSON(json); - callback.onArtistBioLoaded(bio); - } catch (JSONException e) { - Log.e(TAG, "Error while parsing bio from cache to JSONObject", e); - } - } else { - downloadArtistBio(context, queryArtist, callback); - } - } - } - - private static void downloadArtistBio(final Context context, final String artist, final ArtistBioLoaderCallback callback) { - App app = (App) context.getApplicationContext(); - String artistUrl = LastFMArtistInfoUtil.getArtistUrl(artist); - JsonObjectRequest artistInfoJSONRequest = new JsonObjectRequest(0, artistUrl, (JSONObject) null, new Response.Listener() { - @Override - public void onResponse(JSONObject response) { - LastFMArtistInfoUtil.saveArtistJSONDataToCacheAndDisk(context, artist, response); - String bio = LastFMArtistInfoUtil.getArtistBiographyFromJSON(response); - callback.onArtistBioLoaded(bio); - } - }, new Response.ErrorListener() { - @Override - public void onErrorResponse(VolleyError error) { - Log.e(TAG, "Download failed!", error); - callback.onArtistBioLoaded(""); - } - }); - app.addToVolleyRequestQueue(artistInfoJSONRequest); - } - - public interface ArtistBioLoaderCallback { - void onArtistBioLoaded(String bio); - } -} diff --git a/app/src/main/java/com/kabouzeid/gramophone/lastfm/artist/LastFMArtistImageUrlLoader.java b/app/src/main/java/com/kabouzeid/gramophone/lastfm/artist/LastFMArtistImageUrlLoader.java deleted file mode 100644 index 924f5115..00000000 --- a/app/src/main/java/com/kabouzeid/gramophone/lastfm/artist/LastFMArtistImageUrlLoader.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.kabouzeid.gramophone.lastfm.artist; - -import android.content.Context; -import android.util.Log; - -import com.android.volley.Response; -import com.kabouzeid.gramophone.provider.ArtistJSONStore; - -import org.json.JSONException; -import org.json.JSONObject; - -/** - * @author Karim Abou Zeid (kabouzeid) - */ -public class LastFMArtistImageUrlLoader { - public static final String TAG = LastFMArtistImageUrlLoader.class.getSimpleName(); - - public static void loadArtistImageUrl(final Context context, String queryArtist, boolean forceDownload, final ArtistImageUrlLoaderCallback callback) { - if (queryArtist != null && !queryArtist.trim().equals("")) { - String artistJSON = ArtistJSONStore.getInstance(context).getArtistJSON(queryArtist); - if (artistJSON != null && !forceDownload) { - try { - loadArtistImageUrlFromJSON(new JSONObject(artistJSON), callback); - } catch (JSONException e) { - Log.e(TAG, "Error while parsing string from cache to JSONObject", e); - } - } else { - LastFMArtistInfoUtil.downloadArtistJSON(context, queryArtist, new Response.Listener() { - @Override - public void onResponse(JSONObject response) { - loadArtistImageUrlFromJSON(response, callback); - } - }); - } - } - } - - private static void loadArtistImageUrlFromJSON(JSONObject jsonObject, final ArtistImageUrlLoaderCallback callback) { - String url = LastFMArtistInfoUtil.getArtistImageUrlFromJSON(jsonObject); - if (!url.trim().equals("")) { - callback.onArtistImageUrlLoaded(url); - } - } - - public interface ArtistImageUrlLoaderCallback { - void onArtistImageUrlLoaded(String url); - } -} diff --git a/app/src/main/java/com/kabouzeid/gramophone/lastfm/artist/LastFMArtistInfoUtil.java b/app/src/main/java/com/kabouzeid/gramophone/lastfm/artist/LastFMArtistInfoUtil.java deleted file mode 100644 index de8651a3..00000000 --- a/app/src/main/java/com/kabouzeid/gramophone/lastfm/artist/LastFMArtistInfoUtil.java +++ /dev/null @@ -1,119 +0,0 @@ -package com.kabouzeid.gramophone.lastfm.artist; - -import android.content.Context; -import android.net.Uri; -import android.util.Log; - -import com.android.volley.Response; -import com.android.volley.VolleyError; -import com.android.volley.toolbox.JsonObjectRequest; -import com.kabouzeid.gramophone.App; -import com.kabouzeid.gramophone.lastfm.LastFMUtil; -import com.kabouzeid.gramophone.provider.ArtistJSONStore; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -/** - * @author Karim Abou Zeid (kabouzeid) - */ -public class LastFMArtistInfoUtil { - - public static final String TAG = LastFMArtistInfoUtil.class.getSimpleName(); - @SuppressWarnings("FieldCanBeLocal") - private static final String AUTO_CORRECT = "1"; - - public static String getArtistUrl(String artist) { - if (artist != null) { - Uri.Builder builder = new Uri.Builder(); - builder.scheme("http") - .authority(LastFMUtil.BASE_URL) - .appendPath("2.0") - .appendQueryParameter("method", "artist.getinfo") - .appendQueryParameter("artist", artist) - //.appendQueryParameter("lang", "de") - .appendQueryParameter("autocorrect", AUTO_CORRECT) - .appendQueryParameter("api_key", LastFMUtil.API_KEY) - .appendQueryParameter("format", "json"); - return builder.build().toString(); - } - return ""; - } - - public static String getArtistNameFromJSON(JSONObject rootJSON) { - try { - return rootJSON.getJSONObject("artist").getString("name"); - } catch (JSONException e) { - //Log.e(TAG, "Error while getting artist name from JSON_DATA parameter!", e); - return ""; - } - } - - public static String getArtistThumbnailUrlFromJSON(JSONObject rootJSON) { - try { - JSONArray images = getArtistImageArrayFromJSON(rootJSON); - if (images.length() > 2) { - return images.getJSONObject(2).getString("#text"); - } else if (images.length() > 1) { - return images.getJSONObject(1).getString("#text"); - } - return images.getJSONObject(0).getString("#text"); - } catch (JSONException | NullPointerException e) { - //Log.e(TAG, "Error while getting artist thumbnail image from JSON_DATA parameter!", e); - return ""; - } - } - - public static JSONArray getArtistImageArrayFromJSON(JSONObject rootJSON) { - try { - return rootJSON.getJSONObject("artist").getJSONArray("image"); - } catch (JSONException e) { - //Log.e(TAG, "Error while getting artist image array from JSON_DATA parameter!", e); - return null; - } - } - - public static String getArtistImageUrlFromJSON(JSONObject rootJSON) { - try { - JSONArray images = getArtistImageArrayFromJSON(rootJSON); - return images.getJSONObject(images.length() - 1).getString("#text"); - } catch (JSONException | NullPointerException e) { - //Log.e(TAG, "Error while getting artist image from JSON_DATA parameter!", e); - return ""; - } - } - - public static String getArtistBiographyFromJSON(JSONObject rootJSON) { - try { - return rootJSON.getJSONObject("artist").getJSONObject("bio").getString("content"); - } catch (JSONException e) { - //Log.e(TAG, "Error while getting artist biography from JSON_DATA parameter!", e); - return ""; - } - } - - public static void saveArtistJSONDataToCacheAndDisk(Context context, String artist, JSONObject jsonObject) { - ArtistJSONStore.getInstance(context).removeArtistJSON(artist); - ArtistJSONStore.getInstance(context).addArtistJSON(artist, jsonObject.toString()); - } - - public static void downloadArtistJSON(final Context context, final String artist, final Response.Listener callback) { - App app = (App) context.getApplicationContext(); - String artistUrl = LastFMArtistInfoUtil.getArtistUrl(artist); - JsonObjectRequest artistInfoJSONRequest = new JsonObjectRequest(0, artistUrl, (JSONObject) null, new Response.Listener() { - @Override - public void onResponse(JSONObject response) { - LastFMArtistInfoUtil.saveArtistJSONDataToCacheAndDisk(context, artist, response); - callback.onResponse(response); - } - }, new Response.ErrorListener() { - @Override - public void onErrorResponse(VolleyError error) { - Log.e(TAG, "Download failed!", error); - } - }); - app.addToVolleyRequestQueue(artistInfoJSONRequest); - } - -} diff --git a/app/src/main/java/com/kabouzeid/gramophone/lastfm/artist/LastFMArtistThumbnailUrlLoader.java b/app/src/main/java/com/kabouzeid/gramophone/lastfm/artist/LastFMArtistThumbnailUrlLoader.java deleted file mode 100644 index 94c201ec..00000000 --- a/app/src/main/java/com/kabouzeid/gramophone/lastfm/artist/LastFMArtistThumbnailUrlLoader.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.kabouzeid.gramophone.lastfm.artist; - -import android.content.Context; -import android.util.Log; - -import com.android.volley.Response; -import com.kabouzeid.gramophone.provider.ArtistJSONStore; - -import org.json.JSONException; -import org.json.JSONObject; - -/** - * @author Karim Abou Zeid (kabouzeid) - */ -public class LastFMArtistThumbnailUrlLoader { - public static final String TAG = LastFMArtistThumbnailUrlLoader.class.getSimpleName(); - - public static void loadArtistThumbnailUrl(final Context context, String queryArtist, boolean forceDownload, final ArtistThumbnailUrlLoaderCallback callback) { - if (queryArtist != null && !queryArtist.trim().equals("")) { - String artistJSON = ArtistJSONStore.getInstance(context).getArtistJSON(queryArtist); - if (artistJSON != null && !forceDownload) { - try { - loadArtistThumbnailUrlFromJSON(new JSONObject(artistJSON), callback); - } catch (JSONException e) { - Log.e(TAG, "Error while parsing string from cache to JSONObject", e); - } - } else { - LastFMArtistInfoUtil.downloadArtistJSON(context, queryArtist, new Response.Listener() { - @Override - public void onResponse(JSONObject response) { - loadArtistThumbnailUrlFromJSON(response, callback); - } - }); - } - } - } - - private static void loadArtistThumbnailUrlFromJSON(final JSONObject jsonObject, final ArtistThumbnailUrlLoaderCallback callback) { - String url = LastFMArtistInfoUtil.getArtistThumbnailUrlFromJSON(jsonObject); - if (!url.trim().equals("")) { - callback.onArtistThumbnailUrlLoaded(url); - } - } - - public interface ArtistThumbnailUrlLoaderCallback { - void onArtistThumbnailUrlLoaded(String url); - } -} diff --git a/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/LastFMRestClient.java b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/LastFMRestClient.java new file mode 100644 index 00000000..a4a96473 --- /dev/null +++ b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/LastFMRestClient.java @@ -0,0 +1,49 @@ +package com.kabouzeid.gramophone.lastfm.rest; + +import android.content.Context; + +import com.kabouzeid.gramophone.lastfm.rest.service.LastFMService; +import com.squareup.okhttp.Cache; +import com.squareup.okhttp.OkHttpClient; + +import java.io.File; + +import retrofit.RequestInterceptor; +import retrofit.RestAdapter; +import retrofit.client.OkClient; + +/** + * @author Karim Abou Zeid (kabouzeid) + */ +public class LastFMRestClient { + public static final String BASE_URL = "http://ws.audioscrobbler.com/2.0"; + + private LastFMService apiService; + + public LastFMRestClient(Context context) { + OkHttpClient okHttpClient = new OkHttpClient(); + + File cacheDir = new File(context.getCacheDir().getAbsolutePath(), "/okhttp-lastfm/"); + if (cacheDir.mkdirs() || cacheDir.isDirectory()) { + okHttpClient.setCache(new Cache(cacheDir, 1024 * 1024 * 10)); + } + + RestAdapter restAdapter = new RestAdapter.Builder() + .setLogLevel(RestAdapter.LogLevel.FULL) + .setEndpoint(BASE_URL) + .setClient(new OkClient(okHttpClient)) + .setRequestInterceptor(new RequestInterceptor() { + @Override + public void intercept(RequestInterceptor.RequestFacade request) { + request.addHeader("Cache-Control", String.format("max-age=%d, max-stale=%d", 31536000, 31536000)); + } + }) + .build(); + + apiService = restAdapter.create(LastFMService.class); + } + + public LastFMService getApiService() { + return apiService; + } +} diff --git a/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/albuminfo/Album.java b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/albuminfo/Album.java new file mode 100644 index 00000000..59eeedb2 --- /dev/null +++ b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/albuminfo/Album.java @@ -0,0 +1,204 @@ + +package com.kabouzeid.gramophone.lastfm.rest.model.albuminfo; + +import com.google.gson.annotations.Expose; + +import java.util.ArrayList; +import java.util.List; + +public class Album { + + @Expose + private String name; + @Expose + private String artist; + @Expose + private String id; + @Expose + private String mbid; + @Expose + private String url; + @Expose + private String releasedate; + @Expose + private List image = new ArrayList(); + @Expose + private String listeners; + @Expose + private String playcount; + @Expose + private Tracks tracks; + @Expose + private Toptags toptags; + @Expose + private Wiki wiki; + + /** + * @return The name + */ + public String getName() { + return name; + } + + /** + * @param name The name + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return The artist + */ + public String getArtist() { + return artist; + } + + /** + * @param artist The artist + */ + public void setArtist(String artist) { + this.artist = artist; + } + + /** + * @return The id + */ + public String getId() { + return id; + } + + /** + * @param id The id + */ + public void setId(String id) { + this.id = id; + } + + /** + * @return The mbid + */ + public String getMbid() { + return mbid; + } + + /** + * @param mbid The mbid + */ + public void setMbid(String mbid) { + this.mbid = mbid; + } + + /** + * @return The url + */ + public String getUrl() { + return url; + } + + /** + * @param url The url + */ + public void setUrl(String url) { + this.url = url; + } + + /** + * @return The releasedate + */ + public String getReleasedate() { + return releasedate; + } + + /** + * @param releasedate The releasedate + */ + public void setReleasedate(String releasedate) { + this.releasedate = releasedate; + } + + /** + * @return The image + */ + public List getImage() { + return image; + } + + /** + * @param image The image + */ + public void setImage(List image) { + this.image = image; + } + + /** + * @return The listeners + */ + public String getListeners() { + return listeners; + } + + /** + * @param listeners The listeners + */ + public void setListeners(String listeners) { + this.listeners = listeners; + } + + /** + * @return The playcount + */ + public String getPlaycount() { + return playcount; + } + + /** + * @param playcount The playcount + */ + public void setPlaycount(String playcount) { + this.playcount = playcount; + } + + /** + * @return The tracks + */ + public Tracks getTracks() { + return tracks; + } + + /** + * @param tracks The tracks + */ + public void setTracks(Tracks tracks) { + this.tracks = tracks; + } + + /** + * @return The toptags + */ + public Toptags getToptags() { + return toptags; + } + + /** + * @param toptags The toptags + */ + public void setToptags(Toptags toptags) { + this.toptags = toptags; + } + + /** + * @return The wiki + */ + public Wiki getWiki() { + return wiki; + } + + /** + * @param wiki The wiki + */ + public void setWiki(Wiki wiki) { + this.wiki = wiki; + } + +} diff --git a/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/albuminfo/AlbumInfo.java b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/albuminfo/AlbumInfo.java new file mode 100644 index 00000000..e2b74ca6 --- /dev/null +++ b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/albuminfo/AlbumInfo.java @@ -0,0 +1,25 @@ + +package com.kabouzeid.gramophone.lastfm.rest.model.albuminfo; + +import com.google.gson.annotations.Expose; + +public class AlbumInfo { + + @Expose + private Album album; + + /** + * @return The album + */ + public Album getAlbum() { + return album; + } + + /** + * @param album The album + */ + public void setAlbum(Album album) { + this.album = album; + } + +} diff --git a/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/albuminfo/Artist.java b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/albuminfo/Artist.java new file mode 100644 index 00000000..ef9a5bee --- /dev/null +++ b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/albuminfo/Artist.java @@ -0,0 +1,57 @@ + +package com.kabouzeid.gramophone.lastfm.rest.model.albuminfo; + +import com.google.gson.annotations.Expose; + +public class Artist { + + @Expose + private String name; + @Expose + private String mbid; + @Expose + private String url; + + /** + * @return The name + */ + public String getName() { + return name; + } + + /** + * @param name The name + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return The mbid + */ + public String getMbid() { + return mbid; + } + + /** + * @param mbid The mbid + */ + public void setMbid(String mbid) { + this.mbid = mbid; + } + + /** + * @return The url + */ + public String getUrl() { + return url; + } + + /** + * @param url The url + */ + public void setUrl(String url) { + this.url = url; + } + +} diff --git a/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/albuminfo/Attr.java b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/albuminfo/Attr.java new file mode 100644 index 00000000..69d6d6c2 --- /dev/null +++ b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/albuminfo/Attr.java @@ -0,0 +1,25 @@ + +package com.kabouzeid.gramophone.lastfm.rest.model.albuminfo; + +import com.google.gson.annotations.Expose; + +public class Attr { + + @Expose + private String rank; + + /** + * @return The rank + */ + public String getRank() { + return rank; + } + + /** + * @param rank The rank + */ + public void setRank(String rank) { + this.rank = rank; + } + +} diff --git a/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/albuminfo/Image.java b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/albuminfo/Image.java new file mode 100644 index 00000000..1d825384 --- /dev/null +++ b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/albuminfo/Image.java @@ -0,0 +1,43 @@ + +package com.kabouzeid.gramophone.lastfm.rest.model.albuminfo; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class Image { + + @SerializedName("#text") + @Expose + private String Text; + @Expose + private String size; + + /** + * @return The Text + */ + public String getText() { + return Text; + } + + /** + * @param Text The #text + */ + public void setText(String Text) { + this.Text = Text; + } + + /** + * @return The size + */ + public String getSize() { + return size; + } + + /** + * @param size The size + */ + public void setSize(String size) { + this.size = size; + } + +} diff --git a/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/albuminfo/Streamable.java b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/albuminfo/Streamable.java new file mode 100644 index 00000000..be352d70 --- /dev/null +++ b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/albuminfo/Streamable.java @@ -0,0 +1,43 @@ + +package com.kabouzeid.gramophone.lastfm.rest.model.albuminfo; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class Streamable { + + @SerializedName("#text") + @Expose + private String Text; + @Expose + private String fulltrack; + + /** + * @return The Text + */ + public String getText() { + return Text; + } + + /** + * @param Text The #text + */ + public void setText(String Text) { + this.Text = Text; + } + + /** + * @return The fulltrack + */ + public String getFulltrack() { + return fulltrack; + } + + /** + * @param fulltrack The fulltrack + */ + public void setFulltrack(String fulltrack) { + this.fulltrack = fulltrack; + } + +} diff --git a/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/albuminfo/Tag.java b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/albuminfo/Tag.java new file mode 100644 index 00000000..6e11c420 --- /dev/null +++ b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/albuminfo/Tag.java @@ -0,0 +1,41 @@ + +package com.kabouzeid.gramophone.lastfm.rest.model.albuminfo; + +import com.google.gson.annotations.Expose; + +public class Tag { + + @Expose + private String name; + @Expose + private String url; + + /** + * @return The name + */ + public String getName() { + return name; + } + + /** + * @param name The name + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return The url + */ + public String getUrl() { + return url; + } + + /** + * @param url The url + */ + public void setUrl(String url) { + this.url = url; + } + +} diff --git a/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/albuminfo/Toptags.java b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/albuminfo/Toptags.java new file mode 100644 index 00000000..61bb7bdd --- /dev/null +++ b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/albuminfo/Toptags.java @@ -0,0 +1,28 @@ + +package com.kabouzeid.gramophone.lastfm.rest.model.albuminfo; + +import com.google.gson.annotations.Expose; + +import java.util.ArrayList; +import java.util.List; + +public class Toptags { + + @Expose + private List tag = new ArrayList(); + + /** + * @return The tag + */ + public List getTag() { + return tag; + } + + /** + * @param tag The tag + */ + public void setTag(List tag) { + this.tag = tag; + } + +} diff --git a/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/albuminfo/Track.java b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/albuminfo/Track.java new file mode 100644 index 00000000..27f53529 --- /dev/null +++ b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/albuminfo/Track.java @@ -0,0 +1,123 @@ + +package com.kabouzeid.gramophone.lastfm.rest.model.albuminfo; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class Track { + + @Expose + private String name; + @Expose + private String duration; + @Expose + private String mbid; + @Expose + private String url; + @Expose + private Streamable streamable; + @Expose + private Artist artist; + @SerializedName("@attr") + @Expose + private com.kabouzeid.gramophone.lastfm.rest.model.albuminfo.Attr Attr; + + /** + * @return The name + */ + public String getName() { + return name; + } + + /** + * @param name The name + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return The duration + */ + public String getDuration() { + return duration; + } + + /** + * @param duration The duration + */ + public void setDuration(String duration) { + this.duration = duration; + } + + /** + * @return The mbid + */ + public String getMbid() { + return mbid; + } + + /** + * @param mbid The mbid + */ + public void setMbid(String mbid) { + this.mbid = mbid; + } + + /** + * @return The url + */ + public String getUrl() { + return url; + } + + /** + * @param url The url + */ + public void setUrl(String url) { + this.url = url; + } + + /** + * @return The streamable + */ + public Streamable getStreamable() { + return streamable; + } + + /** + * @param streamable The streamable + */ + public void setStreamable(Streamable streamable) { + this.streamable = streamable; + } + + /** + * @return The artist + */ + public Artist getArtist() { + return artist; + } + + /** + * @param artist The artist + */ + public void setArtist(Artist artist) { + this.artist = artist; + } + + /** + * @return The Attr + */ + public com.kabouzeid.gramophone.lastfm.rest.model.albuminfo.Attr getAttr() { + return Attr; + } + + /** + * @param Attr The @attr + */ + public void setAttr(com.kabouzeid.gramophone.lastfm.rest.model.albuminfo.Attr Attr) { + this.Attr = Attr; + } + +} diff --git a/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/albuminfo/Tracks.java b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/albuminfo/Tracks.java new file mode 100644 index 00000000..6e9ecbe5 --- /dev/null +++ b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/albuminfo/Tracks.java @@ -0,0 +1,28 @@ + +package com.kabouzeid.gramophone.lastfm.rest.model.albuminfo; + +import com.google.gson.annotations.Expose; + +import java.util.ArrayList; +import java.util.List; + +public class Tracks { + + @Expose + private List track = new ArrayList(); + + /** + * @return The track + */ + public List getTrack() { + return track; + } + + /** + * @param track The track + */ + public void setTrack(List track) { + this.track = track; + } + +} diff --git a/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/albuminfo/Wiki.java b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/albuminfo/Wiki.java new file mode 100644 index 00000000..09a2b8f8 --- /dev/null +++ b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/albuminfo/Wiki.java @@ -0,0 +1,57 @@ + +package com.kabouzeid.gramophone.lastfm.rest.model.albuminfo; + +import com.google.gson.annotations.Expose; + +public class Wiki { + + @Expose + private String published; + @Expose + private String summary; + @Expose + private String content; + + /** + * @return The published + */ + public String getPublished() { + return published; + } + + /** + * @param published The published + */ + public void setPublished(String published) { + this.published = published; + } + + /** + * @return The summary + */ + public String getSummary() { + return summary; + } + + /** + * @param summary The summary + */ + public void setSummary(String summary) { + this.summary = summary; + } + + /** + * @return The content + */ + public String getContent() { + return content; + } + + /** + * @param content The content + */ + public void setContent(String content) { + this.content = content; + } + +} diff --git a/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Artist.java b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Artist.java new file mode 100644 index 00000000..7b4eb6bf --- /dev/null +++ b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Artist.java @@ -0,0 +1,172 @@ + +package com.kabouzeid.gramophone.lastfm.rest.model.artistinfo; + +import com.google.gson.annotations.Expose; + +import java.util.ArrayList; +import java.util.List; + +public class Artist { + + @Expose + private String name; + @Expose + private String mbid; + @Expose + private String url; + @Expose + private List image = new ArrayList(); + @Expose + private String streamable; + @Expose + private String ontour; + @Expose + private Stats stats; + @Expose + private Similar similar; + @Expose + private Tags tags; + @Expose + private Bio bio; + + /** + * @return The name + */ + public String getName() { + return name; + } + + /** + * @param name The name + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return The mbid + */ + public String getMbid() { + return mbid; + } + + /** + * @param mbid The mbid + */ + public void setMbid(String mbid) { + this.mbid = mbid; + } + + /** + * @return The url + */ + public String getUrl() { + return url; + } + + /** + * @param url The url + */ + public void setUrl(String url) { + this.url = url; + } + + /** + * @return The image + */ + public List getImage() { + return image; + } + + /** + * @param image The image + */ + public void setImage(List image) { + this.image = image; + } + + /** + * @return The streamable + */ + public String getStreamable() { + return streamable; + } + + /** + * @param streamable The streamable + */ + public void setStreamable(String streamable) { + this.streamable = streamable; + } + + /** + * @return The ontour + */ + public String getOntour() { + return ontour; + } + + /** + * @param ontour The ontour + */ + public void setOntour(String ontour) { + this.ontour = ontour; + } + + /** + * @return The stats + */ + public Stats getStats() { + return stats; + } + + /** + * @param stats The stats + */ + public void setStats(Stats stats) { + this.stats = stats; + } + + /** + * @return The similar + */ + public Similar getSimilar() { + return similar; + } + + /** + * @param similar The similar + */ + public void setSimilar(Similar similar) { + this.similar = similar; + } + + /** + * @return The tags + */ + public Tags getTags() { + return tags; + } + + /** + * @param tags The tags + */ + public void setTags(Tags tags) { + this.tags = tags; + } + + /** + * @return The bio + */ + public Bio getBio() { + return bio; + } + + /** + * @param bio The bio + */ + public void setBio(Bio bio) { + this.bio = bio; + } + +} diff --git a/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/ArtistInfo.java b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/ArtistInfo.java new file mode 100644 index 00000000..4c489ad1 --- /dev/null +++ b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/ArtistInfo.java @@ -0,0 +1,25 @@ + +package com.kabouzeid.gramophone.lastfm.rest.model.artistinfo; + +import com.google.gson.annotations.Expose; + +public class ArtistInfo { + + @Expose + private Artist artist; + + /** + * @return The artist + */ + public Artist getArtist() { + return artist; + } + + /** + * @param artist The artist + */ + public void setArtist(Artist artist) { + this.artist = artist; + } + +} diff --git a/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Artist_.java b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Artist_.java new file mode 100644 index 00000000..9ce2676a --- /dev/null +++ b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Artist_.java @@ -0,0 +1,60 @@ + +package com.kabouzeid.gramophone.lastfm.rest.model.artistinfo; + +import com.google.gson.annotations.Expose; + +import java.util.ArrayList; +import java.util.List; + +public class Artist_ { + + @Expose + private String name; + @Expose + private String url; + @Expose + private List image = new ArrayList(); + + /** + * @return The name + */ + public String getName() { + return name; + } + + /** + * @param name The name + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return The url + */ + public String getUrl() { + return url; + } + + /** + * @param url The url + */ + public void setUrl(String url) { + this.url = url; + } + + /** + * @return The image + */ + public List getImage() { + return image; + } + + /** + * @param image The image + */ + public void setImage(List image) { + this.image = image; + } + +} diff --git a/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Bio.java b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Bio.java new file mode 100644 index 00000000..7c9c4caa --- /dev/null +++ b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Bio.java @@ -0,0 +1,105 @@ + +package com.kabouzeid.gramophone.lastfm.rest.model.artistinfo; + +import com.google.gson.annotations.Expose; + +public class Bio { + + @Expose + private Links links; + @Expose + private String published; + @Expose + private String summary; + @Expose + private String content; + @Expose + private String yearformed; + @Expose + private Formationlist formationlist; + + /** + * @return The links + */ + public Links getLinks() { + return links; + } + + /** + * @param links The links + */ + public void setLinks(Links links) { + this.links = links; + } + + /** + * @return The published + */ + public String getPublished() { + return published; + } + + /** + * @param published The published + */ + public void setPublished(String published) { + this.published = published; + } + + /** + * @return The summary + */ + public String getSummary() { + return summary; + } + + /** + * @param summary The summary + */ + public void setSummary(String summary) { + this.summary = summary; + } + + /** + * @return The content + */ + public String getContent() { + return content; + } + + /** + * @param content The content + */ + public void setContent(String content) { + this.content = content; + } + + /** + * @return The yearformed + */ + public String getYearformed() { + return yearformed; + } + + /** + * @param yearformed The yearformed + */ + public void setYearformed(String yearformed) { + this.yearformed = yearformed; + } + + /** + * @return The formationlist + */ + public Formationlist getFormationlist() { + return formationlist; + } + + /** + * @param formationlist The formationlist + */ + public void setFormationlist(Formationlist formationlist) { + this.formationlist = formationlist; + } + +} diff --git a/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Formation.java b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Formation.java new file mode 100644 index 00000000..e3720767 --- /dev/null +++ b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Formation.java @@ -0,0 +1,41 @@ + +package com.kabouzeid.gramophone.lastfm.rest.model.artistinfo; + +import com.google.gson.annotations.Expose; + +public class Formation { + + @Expose + private String yearfrom; + @Expose + private String yearto; + + /** + * @return The yearfrom + */ + public String getYearfrom() { + return yearfrom; + } + + /** + * @param yearfrom The yearfrom + */ + public void setYearfrom(String yearfrom) { + this.yearfrom = yearfrom; + } + + /** + * @return The yearto + */ + public String getYearto() { + return yearto; + } + + /** + * @param yearto The yearto + */ + public void setYearto(String yearto) { + this.yearto = yearto; + } + +} diff --git a/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Formationlist.java b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Formationlist.java new file mode 100644 index 00000000..ebc28369 --- /dev/null +++ b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Formationlist.java @@ -0,0 +1,25 @@ + +package com.kabouzeid.gramophone.lastfm.rest.model.artistinfo; + +import com.google.gson.annotations.Expose; + +public class Formationlist { + + @Expose + private Formation formation; + + /** + * @return The formation + */ + public Formation getFormation() { + return formation; + } + + /** + * @param formation The formation + */ + public void setFormation(Formation formation) { + this.formation = formation; + } + +} diff --git a/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Image.java b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Image.java new file mode 100644 index 00000000..59f3b908 --- /dev/null +++ b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Image.java @@ -0,0 +1,43 @@ + +package com.kabouzeid.gramophone.lastfm.rest.model.artistinfo; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class Image { + + @SerializedName("#text") + @Expose + private String Text; + @Expose + private String size; + + /** + * @return The Text + */ + public String getText() { + return Text; + } + + /** + * @param Text The #text + */ + public void setText(String Text) { + this.Text = Text; + } + + /** + * @return The size + */ + public String getSize() { + return size; + } + + /** + * @param size The size + */ + public void setSize(String size) { + this.size = size; + } + +} diff --git a/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Image_.java b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Image_.java new file mode 100644 index 00000000..4972461d --- /dev/null +++ b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Image_.java @@ -0,0 +1,43 @@ + +package com.kabouzeid.gramophone.lastfm.rest.model.artistinfo; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class Image_ { + + @SerializedName("#text") + @Expose + private String Text; + @Expose + private String size; + + /** + * @return The Text + */ + public String getText() { + return Text; + } + + /** + * @param Text The #text + */ + public void setText(String Text) { + this.Text = Text; + } + + /** + * @return The size + */ + public String getSize() { + return size; + } + + /** + * @param size The size + */ + public void setSize(String size) { + this.size = size; + } + +} diff --git a/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Link.java b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Link.java new file mode 100644 index 00000000..1cc1e58d --- /dev/null +++ b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Link.java @@ -0,0 +1,59 @@ + +package com.kabouzeid.gramophone.lastfm.rest.model.artistinfo; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class Link { + + @SerializedName("#text") + @Expose + private String Text; + @Expose + private String rel; + @Expose + private String href; + + /** + * @return The Text + */ + public String getText() { + return Text; + } + + /** + * @param Text The #text + */ + public void setText(String Text) { + this.Text = Text; + } + + /** + * @return The rel + */ + public String getRel() { + return rel; + } + + /** + * @param rel The rel + */ + public void setRel(String rel) { + this.rel = rel; + } + + /** + * @return The href + */ + public String getHref() { + return href; + } + + /** + * @param href The href + */ + public void setHref(String href) { + this.href = href; + } + +} diff --git a/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Links.java b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Links.java new file mode 100644 index 00000000..a412b3dc --- /dev/null +++ b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Links.java @@ -0,0 +1,25 @@ + +package com.kabouzeid.gramophone.lastfm.rest.model.artistinfo; + +import com.google.gson.annotations.Expose; + +public class Links { + + @Expose + private Link link; + + /** + * @return The link + */ + public Link getLink() { + return link; + } + + /** + * @param link The link + */ + public void setLink(Link link) { + this.link = link; + } + +} diff --git a/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Similar.java b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Similar.java new file mode 100644 index 00000000..3cd5083f --- /dev/null +++ b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Similar.java @@ -0,0 +1,28 @@ + +package com.kabouzeid.gramophone.lastfm.rest.model.artistinfo; + +import com.google.gson.annotations.Expose; + +import java.util.ArrayList; +import java.util.List; + +public class Similar { + + @Expose + private List artist = new ArrayList(); + + /** + * @return The artist + */ + public List getArtist() { + return artist; + } + + /** + * @param artist The artist + */ + public void setArtist(List artist) { + this.artist = artist; + } + +} diff --git a/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Stats.java b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Stats.java new file mode 100644 index 00000000..18a8fd4e --- /dev/null +++ b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Stats.java @@ -0,0 +1,41 @@ + +package com.kabouzeid.gramophone.lastfm.rest.model.artistinfo; + +import com.google.gson.annotations.Expose; + +public class Stats { + + @Expose + private String listeners; + @Expose + private String playcount; + + /** + * @return The listeners + */ + public String getListeners() { + return listeners; + } + + /** + * @param listeners The listeners + */ + public void setListeners(String listeners) { + this.listeners = listeners; + } + + /** + * @return The playcount + */ + public String getPlaycount() { + return playcount; + } + + /** + * @param playcount The playcount + */ + public void setPlaycount(String playcount) { + this.playcount = playcount; + } + +} diff --git a/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Tag.java b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Tag.java new file mode 100644 index 00000000..97e30274 --- /dev/null +++ b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Tag.java @@ -0,0 +1,41 @@ + +package com.kabouzeid.gramophone.lastfm.rest.model.artistinfo; + +import com.google.gson.annotations.Expose; + +public class Tag { + + @Expose + private String name; + @Expose + private String url; + + /** + * @return The name + */ + public String getName() { + return name; + } + + /** + * @param name The name + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return The url + */ + public String getUrl() { + return url; + } + + /** + * @param url The url + */ + public void setUrl(String url) { + this.url = url; + } + +} diff --git a/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Tags.java b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Tags.java new file mode 100644 index 00000000..b145e344 --- /dev/null +++ b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/model/artistinfo/Tags.java @@ -0,0 +1,28 @@ + +package com.kabouzeid.gramophone.lastfm.rest.model.artistinfo; + +import com.google.gson.annotations.Expose; + +import java.util.ArrayList; +import java.util.List; + +public class Tags { + + @Expose + private List tag = new ArrayList(); + + /** + * @return The tag + */ + public List getTag() { + return tag; + } + + /** + * @param tag The tag + */ + public void setTag(List tag) { + this.tag = tag; + } + +} diff --git a/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/service/LastFMService.java b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/service/LastFMService.java new file mode 100644 index 00000000..0a2ab729 --- /dev/null +++ b/app/src/main/java/com/kabouzeid/gramophone/lastfm/rest/service/LastFMService.java @@ -0,0 +1,25 @@ +package com.kabouzeid.gramophone.lastfm.rest.service; + +import android.support.annotation.Nullable; + +import com.kabouzeid.gramophone.lastfm.rest.model.albuminfo.AlbumInfo; +import com.kabouzeid.gramophone.lastfm.rest.model.artistinfo.ArtistInfo; + +import retrofit.Callback; +import retrofit.http.GET; +import retrofit.http.Header; +import retrofit.http.Query; + +/** + * @author Karim Abou Zeid (kabouzeid) + */ +public interface LastFMService { + String API_KEY = "bd9c6ea4d55ec9ed3af7d276e5ece304"; + String BASE_QUERY_PARAMETERS = "/?format=json&autocorrect=1&api_key=" + API_KEY; + + @GET(BASE_QUERY_PARAMETERS + "&method=album.getinfo") + void getAlbumInfo(@Query("album") String albumName, @Query("artist") String artistName, Callback callback); + + @GET(BASE_QUERY_PARAMETERS + "&method=artist.getinfo") + void getArtistInfo(@Query("artist") String artistName, @Nullable @Header("Cache-Control") String cacheControl, Callback callback); +} \ No newline at end of file diff --git a/app/src/main/java/com/kabouzeid/gramophone/ui/activities/ArtistDetailActivity.java b/app/src/main/java/com/kabouzeid/gramophone/ui/activities/ArtistDetailActivity.java index 3ece3c54..4f6ed337 100644 --- a/app/src/main/java/com/kabouzeid/gramophone/ui/activities/ArtistDetailActivity.java +++ b/app/src/main/java/com/kabouzeid/gramophone/ui/activities/ArtistDetailActivity.java @@ -37,8 +37,9 @@ import com.kabouzeid.gramophone.helper.MusicPlayerRemote; import com.kabouzeid.gramophone.helper.bitmapblur.StackBlurManager; import com.kabouzeid.gramophone.interfaces.CabHolder; import com.kabouzeid.gramophone.interfaces.PaletteColorHolder; -import com.kabouzeid.gramophone.lastfm.artist.LastFMArtistBiographyLoader; -import com.kabouzeid.gramophone.lastfm.artist.LastFMArtistImageUrlLoader; +import com.kabouzeid.gramophone.lastfm.rest.LastFMRestClient; +import com.kabouzeid.gramophone.lastfm.rest.model.artistinfo.ArtistInfo; +import com.kabouzeid.gramophone.lastfm.rest.model.artistinfo.Image; import com.kabouzeid.gramophone.loader.ArtistAlbumLoader; import com.kabouzeid.gramophone.loader.ArtistLoader; import com.kabouzeid.gramophone.loader.ArtistSongLoader; @@ -62,9 +63,14 @@ import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListene import com.squareup.otto.Subscribe; import java.util.ArrayList; +import java.util.List; import butterknife.ButterKnife; import butterknife.InjectView; +import hugo.weaving.DebugLog; +import retrofit.Callback; +import retrofit.RetrofitError; +import retrofit.client.Response; /** * A lot of hackery is done in this activity. Changing things may will brake the whole activity. @@ -108,6 +114,10 @@ public class ArtistDetailActivity extends AbsFabActivity implements PaletteColor private ArrayList songs; private ArrayList albums; + private LastFMRestClient lastFMRestClient; + + private StackBlurManager defaultArtistImageBlurManager; + @Override protected void onCreate(Bundle savedInstanceState) { setStatusBarTransparent(); @@ -123,6 +133,8 @@ public class ArtistDetailActivity extends AbsFabActivity implements PaletteColor setNavigationBarColor(DialogUtils.resolveColor(this, R.attr.default_bar_color)); } + lastFMRestClient = new LastFMRestClient(this); + getIntentExtras(); initViews(); setUpObservableListViewParams(); @@ -261,15 +273,21 @@ public class ArtistDetailActivity extends AbsFabActivity implements PaletteColor } private void loadBiography() { - LastFMArtistBiographyLoader.loadArtistBio(this, artist.name, new LastFMArtistBiographyLoader.ArtistBioLoaderCallback() { + lastFMRestClient.getApiService().getArtistInfo(artist.name, null, new Callback() { @Override - public void onArtistBioLoaded(String bio) { + public void success(ArtistInfo artistInfo, Response response) { + String bio = artistInfo.getArtist().getBio().getContent(); if (bio != null && !bio.trim().equals("")) { biography = Html.fromHtml(bio); } else { biography = null; } } + + @Override + public void failure(RetrofitError error) { + biography = null; + } }); } @@ -284,36 +302,68 @@ public class ArtistDetailActivity extends AbsFabActivity implements PaletteColor private void setUpArtistImageAndApplyPalette(final boolean forceDownload) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 2; - final StackBlurManager defaultArtistImageBlurManager = new StackBlurManager(BitmapFactory.decodeResource(getResources(), R.drawable.default_artist_image, options)); - LastFMArtistImageUrlLoader.loadArtistImageUrl(this, artist.name, forceDownload, new LastFMArtistImageUrlLoader.ArtistImageUrlLoaderCallback() { + if (defaultArtistImageBlurManager == null) { + defaultArtistImageBlurManager = new StackBlurManager(BitmapFactory.decodeResource(getResources(), R.drawable.default_artist_image, options)); + } + lastFMRestClient.getApiService().getArtistInfo(artist.name, forceDownload ? "no-cache" : null, new Callback() { + @DebugLog @Override - public void onArtistImageUrlLoaded(final String url) { - ImageLoader.getInstance().displayImage(url, - artistImage, - new DisplayImageOptions.Builder() - .cacheInMemory(true) - .cacheOnDisk(true) - .showImageOnFail(R.drawable.default_artist_image) - .resetViewBeforeLoading(true) - .build(), - new SimpleImageLoadingListener() { - @Override - public void onLoadingFailed(String imageUri, View view, FailReason failReason) { - applyPalette(null); - artistImageBackground.setImageBitmap(defaultArtistImageBlurManager.process(10)); - } + public void success(ArtistInfo artistInfo, Response response) { + if (artistInfo.getArtist() != null) { + List images = artistInfo.getArtist().getImage(); + int lastElementIndex = images.size() - 1; + ImageLoader.getInstance().displayImage(images.get(lastElementIndex).getText(), + artistImage, + new DisplayImageOptions.Builder() + .cacheInMemory(true) + .cacheOnDisk(true) + .showImageOnFail(R.drawable.default_artist_image) + .resetViewBeforeLoading(true) + .build(), + new SimpleImageLoadingListener() { + @DebugLog + @Override + public void onLoadingFailed(String imageUri, View view, FailReason failReason) { + resetPaletteAndArtistImageBackground(); + toastUpdatedArtistImageIfDownloadWasForced(); + } - @Override - public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { - applyPalette(loadedImage); - artistImageBackground.setImageBitmap(new StackBlurManager(loadedImage).process(10)); + @DebugLog + @Override + public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { + applyPalette(loadedImage); + artistImageBackground.setImageBitmap(new StackBlurManager(loadedImage).process(10)); + toastUpdatedArtistImageIfDownloadWasForced(); + } + + private void toastUpdatedArtistImageIfDownloadWasForced() { + if (forceDownload) { + Toast.makeText(ArtistDetailActivity.this, getString(R.string.updated_artist_image), Toast.LENGTH_SHORT).show(); + } + } } - } - ); + ); + } + } + + @DebugLog + @Override + public void failure(RetrofitError error) { + if (forceDownload) { + Toast.makeText(ArtistDetailActivity.this, getString(R.string.could_not_update_artist_image), Toast.LENGTH_SHORT).show(); + } else { + artistImage.setImageResource(R.drawable.default_artist_image); + resetPaletteAndArtistImageBackground(); + } } }); } + private void resetPaletteAndArtistImageBackground() { + applyPalette(null); + artistImageBackground.setImageBitmap(defaultArtistImageBlurManager.process(10)); + } + private void applyPalette(Bitmap bitmap) { if (bitmap != null) { Palette.from(bitmap) diff --git a/app/src/main/java/com/kabouzeid/gramophone/ui/activities/tageditor/AlbumTagEditorActivity.java b/app/src/main/java/com/kabouzeid/gramophone/ui/activities/tageditor/AlbumTagEditorActivity.java index 528d8e4b..33c65472 100644 --- a/app/src/main/java/com/kabouzeid/gramophone/ui/activities/tageditor/AlbumTagEditorActivity.java +++ b/app/src/main/java/com/kabouzeid/gramophone/ui/activities/tageditor/AlbumTagEditorActivity.java @@ -11,7 +11,9 @@ import android.widget.EditText; import android.widget.Toast; import com.kabouzeid.gramophone.R; -import com.kabouzeid.gramophone.lastfm.album.LastFMAlbumImageUrlLoader; +import com.kabouzeid.gramophone.lastfm.rest.LastFMRestClient; +import com.kabouzeid.gramophone.lastfm.rest.model.albuminfo.AlbumInfo; +import com.kabouzeid.gramophone.lastfm.rest.model.albuminfo.Image; import com.kabouzeid.gramophone.loader.AlbumSongLoader; import com.kabouzeid.gramophone.loader.SongFilePathLoader; import com.kabouzeid.gramophone.model.Song; @@ -35,6 +37,9 @@ import java.util.Map; import butterknife.ButterKnife; import butterknife.InjectView; +import retrofit.Callback; +import retrofit.RetrofitError; +import retrofit.client.Response; public class AlbumTagEditorActivity extends AbsTagEditorActivity implements TextWatcher { @@ -51,12 +56,15 @@ public class AlbumTagEditorActivity extends AbsTagEditorActivity implements Text private Bitmap albumArtBitmap; private boolean deleteAlbumArt; + private LastFMRestClient lastFMRestClient; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ButterKnife.inject(this); + lastFMRestClient = new LastFMRestClient(this); + setUpViews(); } @@ -95,36 +103,44 @@ public class AlbumTagEditorActivity extends AbsTagEditorActivity implements Text Toast.makeText(this, getResources().getString(R.string.album_or_artist_empty), Toast.LENGTH_SHORT).show(); return; } - LastFMAlbumImageUrlLoader.loadAlbumImageUrl(this, albumTitleStr, albumArtistNameStr, new LastFMAlbumImageUrlLoader.AlbumImageUrlLoaderCallback() { - @Override - public void onAlbumImageUrlLoaded(String url) { - ImageLoader.getInstance().loadImage(url, - new ImageSize(500, 500), - new SimpleImageLoadingListener() { - @Override - public void onLoadingFailed(String imageUri, View view, FailReason failReason) { - Toast.makeText(AlbumTagEditorActivity.this, - R.string.failed_to_download_album_art, Toast.LENGTH_SHORT).show(); - } + lastFMRestClient.getApiService().getAlbumInfo(albumTitleStr, albumArtistNameStr, new Callback() { + @Override + public void success(AlbumInfo albumInfo, Response response) { + if (albumInfo.getAlbum() != null) { + List images = albumInfo.getAlbum().getImage(); + int lastIndexOfImages = images.size() - 1; + ImageLoader.getInstance().loadImage(images.get(lastIndexOfImages).getText(), + new ImageSize(500, 500), + new SimpleImageLoadingListener() { + @Override + public void onLoadingFailed(String imageUri, View view, FailReason failReason) { + toastLoadingFailed(); + } - @Override - public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { - albumArtBitmap = loadedImage; - setImageBitmap(albumArtBitmap); - deleteAlbumArt = false; - dataChanged(); - setResult(RESULT_OK); - } - }); - } - - @Override - public void onError() { - Toast.makeText(AlbumTagEditorActivity.this, - R.string.failed_to_download_album_art, Toast.LENGTH_SHORT).show(); - } + @Override + public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { + albumArtBitmap = loadedImage; + setImageBitmap(albumArtBitmap); + deleteAlbumArt = false; + dataChanged(); + setResult(RESULT_OK); + } + }); + } else { + toastLoadingFailed(); } - ); + } + + @Override + public void failure(RetrofitError error) { + toastLoadingFailed(); + } + + private void toastLoadingFailed() { + Toast.makeText(AlbumTagEditorActivity.this, + R.string.could_not_download_album_cover, Toast.LENGTH_SHORT).show(); + } + }); } @Override @@ -190,7 +206,7 @@ public class AlbumTagEditorActivity extends AbsTagEditorActivity implements Text @Override public void onLoadingFailed(String imageUri, View view, FailReason failReason) { Toast.makeText(AlbumTagEditorActivity.this, - R.string.failed_to_download_album_art, Toast.LENGTH_SHORT).show(); + R.string.could_not_download_album_cover, Toast.LENGTH_SHORT).show(); } @Override diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index 7b850600..d7f5f8b9 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -135,7 +135,7 @@ "Názvy alb v mřížce jsou obarvena podle jejich obalu." "Notifikace jsou zbarvena podle obalu alba." "Odstraní ticho mezi skladbami. Deaktivace může vyřešit problémy s přehráváním." - "Nebylo možné stáhnout obrázek obalu alba" + "Nebylo možné stáhnout obrázek obalu alba" Vyhledat zvukové soubory... Kontrola médií... Oblíbené diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index dc931e31..74b634ef 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -158,7 +158,7 @@ Die Bar unter dem Album Cover wo sich der Titel und Interpret befinden ist höher. Benutzt einen Balken als Progress Slider anstatt dem normalen Progress Slider. Zeigt eine Karte hinter der Wiedergabesteuerung - "Das Album Cover konnte nicht heruntergeladen werden." + "Das Album Cover konnte nicht heruntergeladen werden." Durchsuche deine Mediathek Medien neu scannen... Favoriten diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml index fba83bb2..732d6a4f 100644 --- a/app/src/main/res/values-es-rES/strings.xml +++ b/app/src/main/res/values-es-rES/strings.xml @@ -160,7 +160,7 @@ La caja detrás de la tapa del álbum donde se encuentra el título de la canción y el artista es mas largo que su altura. Usa una barra de progreso que no cubre la tapa del álbum en vez de la barra normal de progreso. Mostrar tarjeta detrás de los botones de control de reproducción (reproducir/pausar, etc). - "No se puede descargar la técnica para éste álbum" + "No se puede descargar la técnica para éste álbum" Buscar en librería... Escaneando contenido... Favoritos diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 8159d0db..e3c49f76 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -155,7 +155,7 @@ La boîte en dessous de la vignette de l\'album où se trouvent le titre de la musique et l\'artiste est plus large dans sa hauteur. Utilise une barre de progression qui ne recouvre pas la vignette de l\'album à la place de la barre de progression normale. Affiche une carte derrière les boutons de lecture (lecture/pause etc.) - "Impossible de télécharger la pochette pour cet album." + "Impossible de télécharger la pochette pour cet album." Rechercher votre bibliothèque... Réanalyse des médias… Favoris diff --git a/app/src/main/res/values-hr/strings.xml b/app/src/main/res/values-hr/strings.xml index 0223ac6d..18ace5e9 100644 --- a/app/src/main/res/values-hr/strings.xml +++ b/app/src/main/res/values-hr/strings.xml @@ -155,7 +155,7 @@ Okvir ispod omota albuma gdje su prikazani naslov pjesme i izvođač je viši. Koristi se traka napretka koja ne prekriva omot albuma umjesto zadanog klizača. Prikazuje karticu ispod gumbića koji služe za kontrolu reprodukcije (pokreni/pauziraj itd.). - "Neuspjelo skidanje omota ovog albuma." + "Neuspjelo skidanje omota ovog albuma." Pretraži fonoteku Ponovno skeniram medijske datoteke Favoriti diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index e729e114..88a8b474 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -158,7 +158,7 @@ Il riquadro al di sotto della copertina in cui sono visualizzati il titolo del brano e l\'artista è più grande in altezza. Usa una barra di scorrimento che non copre la copertina invece del normale cursore. Visualizza un contorno in stile card dietro i controlli di riproduzione (play, pausa ecc.). - "Impossibile scaricare la copertina per questo album." + "Impossibile scaricare la copertina per questo album." Cerca nella tua libreria... Nuova scannerizzazione media in corso... Preferiti diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 31d42277..e04875c6 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -158,7 +158,7 @@ アルバムアート下のタイトルとアーティスト名を大きく表示します アルバムアートに被らないシークバーに変更します 再生コントロールキー(l◀, ▶/ll, ▶l など)をカードの上に表示します - "アルバムアートのダウンロードに失敗しました" + "アルバムアートのダウンロードに失敗しました" ライブラリ内を検索… メディアの再スキャン中… お気に入り diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml index 7acb0089..cbb871c8 100644 --- a/app/src/main/res/values-ko/strings.xml +++ b/app/src/main/res/values-ko/strings.xml @@ -156,7 +156,7 @@ 앨범 아트 밑에 있는 제목 바의 높이를 커지게 합니다. 보통의 조절 슬라이더 대신 앨범 아트를 가리지 않는 대체 조절 슬라이더를 사용합니다. 지금 재생 중 화면에서 컨트롤 부분(재생, 일시정지 등의 버튼이 있는 곳)을 카드로 표시합니다. - "이 앨범의 앨범 커버를 다운로드할 수 없습니다." + "이 앨범의 앨범 커버를 다운로드할 수 없습니다." 저장소 검색... 미디어 재스캐닝 중... 좋아하는 곡들 diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index f0380ef2..8c08c753 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -158,7 +158,7 @@ De kader onder de albumhoes, waar de artiest en titel worden getoond, is groter. Gebruikt een progressiebalk die de albumhoes niet bedekt, in plaats van de standaard progressiecirkel. Weergeeft een kaart onder de bedieningsknoppen (afspelen/pauze etc.). - "Niet in staat deze albumhoes te downloaden." + "Niet in staat deze albumhoes te downloaden." Zoek in je bibliotheek... Media herscannen... Favorieten diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 3e6b3666..d8d9d5d3 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -158,7 +158,7 @@ Zaznacz, a pole nazwy utworu i wykonawcy pod okładką albumu będzie większe Zaznacz, a w odróżnieniu od domyślnego suwaka, pasek postępu nie zasłoni okładki albumu Zaznacz, a pod przyciskami sterującymi odtwarzaczem (odtwarzanie/pauza, itp.) zostanie wyświetlona karta - "Nie można pobrać okładki dla tego albumu" + "Nie można pobrać okładki dla tego albumu" Szukaj w bibliotece... Ponowny skan nośnika... Ulubione diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index c535a154..6dbffc89 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -158,7 +158,7 @@ A caixa embaixo da capa do álbum onde o titulo da musica e o artista são mostrados é mais largo na sua altura. Usa uma barra de progresso que não cobre a capa do álbum substituindo a barra padrão. Mostra um cartão abaixo dos controles de reprodução (tocar/pausar etc.) - "Não foi possível baixar a imagem para este álbum." + "Não foi possível baixar a imagem para este álbum." Pesquisar na sua biblioteca... Verificando mídia novamente... Favoritos diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index 3c99b8be..2b1185e8 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -155,7 +155,7 @@ Şarkı başlığı ve sanatçıya giden albüm kapağı altındaki kutusunun yüksekliğini büyültür. Varsayılan ilerleme çubuğu yerine albüm kapağına taşan ilerleme çubuğu kullanılır. Oynatma kontrol düğmelerinin altında bir kart görüntüler (oynat/duraklat, vb.). - "Bu albüm için kapak indirilemiyor." + "Bu albüm için kapak indirilemiyor." Kütüphaneniz taranıyor... Medyayı yeniden tara Favoriler diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 3a83d92f..c0d0afc9 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -158,7 +158,7 @@ 增加专辑封面下方用于显示歌曲名称和艺术家区域的高度 使用不会遮挡专辑封面的进度条替代正常的进度滑块。 在播放控制按钮(播放/暂停等)下方显示卡片背景 - "专辑信息下载失败" + "专辑信息下载失败" 正在扫描 正在重新扫描媒体库… 收藏夹 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0035aa4b..00d53799 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -59,6 +59,8 @@ "Phonograph is a completely free material designed music player by" No results Update artist image + Updated artist image. + Could not update artist image. Updating… "Added 1 title to the playing queue." Added %1$d titles to the playing queue. @@ -158,7 +160,7 @@ The box below the album art where the song title and artist goes is larger in its height. Uses a progressbar which does not cover the album art instead of the default progress slider. Displays a card below the playback controller buttons (play/pause etc.). - "Unable to download the art for this album." + "Could not download a matching album cover." Search your library… Rescanning media… Favorites