5 package com.andrew.apollo.tasks;
\r
7 import java.lang.ref.WeakReference;
\r
8 import java.util.Iterator;
\r
10 import android.content.Context;
\r
11 import android.os.AsyncTask;
\r
13 import com.andrew.apollo.Constants;
\r
14 import com.andrew.apollo.lastfm.api.Artist;
\r
15 import com.andrew.apollo.lastfm.api.Image;
\r
16 import com.andrew.apollo.lastfm.api.ImageSize;
\r
17 import com.andrew.apollo.lastfm.api.PaginatedResult;
\r
18 import com.andrew.apollo.utils.ApolloUtils;
\r
19 import com.androidquery.AQuery;
\r
22 * @author Andrew Neal
\r
23 * @returns A convenient image size that's perfect for a GridView.
\r
25 public class LastfmGetArtistImages extends AsyncTask<String, Integer, String> implements Constants {
\r
28 private String url = null;
\r
30 private PaginatedResult<Image> artist;
\r
33 private final AQuery aq;
\r
35 private final WeakReference<Context> contextReference;
\r
37 public LastfmGetArtistImages(Context context) {
\r
38 contextReference = new WeakReference<Context>(context);
\r
41 aq = new AQuery(contextReference.get());
\r
45 protected String doInBackground(String... artistname) {
\r
46 if (ApolloUtils.isOnline(contextReference.get()) && artistname[0] != null) {
\r
48 artist = Artist.getImages(artistname[0], 1, 1, LASTFM_API_KEY);
\r
49 Iterator<Image> iterator = artist.getPageResults().iterator();
\r
50 while (iterator.hasNext()) {
\r
51 Image mTemp = iterator.next();
\r
52 url = mTemp.getImageURL(ImageSize.LARGESQUARE);
\r
55 ApolloUtils.setImageURL(artistname[0], url, ARTIST_IMAGE, contextReference.get());
\r
57 } catch (Exception e) {
\r
61 url = ApolloUtils.getImageURL(artistname[0], ARTIST_IMAGE, contextReference.get());
\r