Ressource Cleanup
This commit is contained in:
parent
cfce92535b
commit
0982ace9e4
4 changed files with 100 additions and 196 deletions
|
|
@ -1,98 +0,0 @@
|
||||||
package com.kabouzeid.gramophone.lastfm.artist;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.view.View;
|
|
||||||
|
|
||||||
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 com.kabouzeid.gramophone.util.ImageLoaderUtil;
|
|
||||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
|
||||||
import com.nostra13.universalimageloader.core.assist.FailReason;
|
|
||||||
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
|
|
||||||
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by karim on 01.01.15.
|
|
||||||
*/
|
|
||||||
public class LastFMArtistImageLoader {
|
|
||||||
public static final String TAG = LastFMArtistImageLoader.class.getSimpleName();
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static void loadArtistImage(Context context, String queryArtist, ArtistImageLoaderCallback callback) {
|
|
||||||
loadArtistImage(context, queryArtist, false, callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void loadArtistImage(Context context, String queryArtist, boolean forceDownload, ArtistImageLoaderCallback callback) {
|
|
||||||
if (queryArtist != null) {
|
|
||||||
String artistJSON = ArtistJSONStore.getInstance(context).getArtistJSON(queryArtist);
|
|
||||||
if (artistJSON != null && !forceDownload) {
|
|
||||||
try {
|
|
||||||
loadArtistImageFromJSON(new JSONObject(artistJSON), callback);
|
|
||||||
} catch (JSONException e) {
|
|
||||||
Log.e(TAG, "Error while parsing string from cache to JSONObject", e);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
downloadArtistJSONAndStartImageDownload(context, queryArtist, callback);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void loadArtistImageFromJSON(JSONObject jsonObject, final ArtistImageLoaderCallback callback) {
|
|
||||||
String url = LastFMArtistInfoUtil.getArtistImageUrlFromJSON(jsonObject);
|
|
||||||
if (!url.trim().equals("")) {
|
|
||||||
ImageLoader.getInstance().loadImage(url, ImageLoaderUtil.getCacheOnDiskOptions(), new ImageLoadingListener() {
|
|
||||||
@Override
|
|
||||||
public void onLoadingStarted(String imageUri, View view) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
|
|
||||||
callback.onArtistImageLoaded(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
|
|
||||||
callback.onArtistImageLoaded(loadedImage);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLoadingCancelled(String imageUri, View view) {
|
|
||||||
callback.onArtistImageLoaded(null);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
callback.onArtistImageLoaded(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void downloadArtistJSONAndStartImageDownload(final Context context, final String artist, final ArtistImageLoaderCallback callback) {
|
|
||||||
App app = (App) context.getApplicationContext();
|
|
||||||
String artistUrl = LastFMArtistInfoUtil.getArtistUrl(artist);
|
|
||||||
JsonObjectRequest artistInfoJSONRequest = new JsonObjectRequest(0, artistUrl, null, new Response.Listener<JSONObject>() {
|
|
||||||
@Override
|
|
||||||
public void onResponse(JSONObject response) {
|
|
||||||
LastFMArtistInfoUtil.saveArtistJSONDataToCacheAndDisk(context, artist, response);
|
|
||||||
loadArtistImageFromJSON(response, callback);
|
|
||||||
}
|
|
||||||
}, new Response.ErrorListener() {
|
|
||||||
@Override
|
|
||||||
public void onErrorResponse(VolleyError error) {
|
|
||||||
Log.e(TAG, "Download failed!", error);
|
|
||||||
callback.onArtistImageLoaded(null);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
app.addToVolleyRequestQueue(artistInfoJSONRequest);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static interface ArtistImageLoaderCallback {
|
|
||||||
public void onArtistImageLoaded(Bitmap artistImage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,48 @@
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by karim on 01.01.15.
|
||||||
|
*/
|
||||||
|
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) {
|
||||||
|
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<JSONObject>() {
|
||||||
|
@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 static interface ArtistImageUrlLoaderCallback {
|
||||||
|
public void onArtistImageUrlLoaded(String url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,98 +0,0 @@
|
||||||
package com.kabouzeid.gramophone.lastfm.artist;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.view.View;
|
|
||||||
|
|
||||||
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 com.kabouzeid.gramophone.util.ImageLoaderUtil;
|
|
||||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
|
||||||
import com.nostra13.universalimageloader.core.assist.FailReason;
|
|
||||||
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
|
|
||||||
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by karim on 01.01.15.
|
|
||||||
*/
|
|
||||||
public class LastFMArtistThumbnailLoader {
|
|
||||||
public static final String TAG = LastFMArtistThumbnailLoader.class.getSimpleName();
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static void loadArtistThumbnail(Context context, String queryArtist, ArtistThumbnailLoaderCallback callback) {
|
|
||||||
loadArtistThumbnail(context, queryArtist, false, callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void loadArtistThumbnail(Context context, String queryArtist, boolean forceDownload, ArtistThumbnailLoaderCallback callback) {
|
|
||||||
if (queryArtist != null) {
|
|
||||||
String artistJSON = ArtistJSONStore.getInstance(context).getArtistJSON(queryArtist);
|
|
||||||
if (artistJSON != null && !forceDownload) {
|
|
||||||
try {
|
|
||||||
loadArtistThumbnailFromJSON(new JSONObject(artistJSON), callback);
|
|
||||||
} catch (JSONException e) {
|
|
||||||
Log.e(TAG, "Error while parsing string from cache to JSONObject", e);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
downloadArtistThumbnail(context, queryArtist, callback);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void loadArtistThumbnailFromJSON(JSONObject jsonObject, final ArtistThumbnailLoaderCallback callback) {
|
|
||||||
String url = LastFMArtistInfoUtil.getArtistThumbnailUrlFromJSON(jsonObject);
|
|
||||||
if (!url.trim().equals("")) {
|
|
||||||
ImageLoader.getInstance().loadImage(url, ImageLoaderUtil.getCacheOnDiskOptions(), new ImageLoadingListener() {
|
|
||||||
@Override
|
|
||||||
public void onLoadingStarted(String imageUri, View view) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
|
|
||||||
callback.onArtistThumbnailLoaded(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
|
|
||||||
callback.onArtistThumbnailLoaded(loadedImage);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLoadingCancelled(String imageUri, View view) {
|
|
||||||
callback.onArtistThumbnailLoaded(null);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
callback.onArtistThumbnailLoaded(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void downloadArtistThumbnail(final Context context, final String artist, final ArtistThumbnailLoaderCallback callback) {
|
|
||||||
App app = (App) context.getApplicationContext();
|
|
||||||
String artistUrl = LastFMArtistInfoUtil.getArtistUrl(artist);
|
|
||||||
JsonObjectRequest artistInfoJSONRequest = new JsonObjectRequest(0, artistUrl, null, new Response.Listener<JSONObject>() {
|
|
||||||
@Override
|
|
||||||
public void onResponse(JSONObject response) {
|
|
||||||
LastFMArtistInfoUtil.saveArtistJSONDataToCacheAndDisk(context, artist, response);
|
|
||||||
loadArtistThumbnailFromJSON(response, callback);
|
|
||||||
}
|
|
||||||
}, new Response.ErrorListener() {
|
|
||||||
@Override
|
|
||||||
public void onErrorResponse(VolleyError error) {
|
|
||||||
Log.e(TAG, "Download failed!", error);
|
|
||||||
callback.onArtistThumbnailLoaded(null);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
app.addToVolleyRequestQueue(artistInfoJSONRequest);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static interface ArtistThumbnailLoaderCallback {
|
|
||||||
public void onArtistThumbnailLoaded(Bitmap thumbnail);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,52 @@
|
||||||
|
package com.kabouzeid.gramophone.lastfm.artist;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.android.volley.Response;
|
||||||
|
import com.kabouzeid.gramophone.provider.ArtistJSONStore;
|
||||||
|
import com.squareup.picasso.Picasso;
|
||||||
|
import com.squareup.picasso.Target;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by karim on 01.01.15.
|
||||||
|
*/
|
||||||
|
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) {
|
||||||
|
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<JSONObject>() {
|
||||||
|
@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 static interface ArtistThumbnailUrlLoaderCallback {
|
||||||
|
public void onArtistThumbnailUrlLoaded(String url);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue