Exemplo n.º 1
0
  /**
   * Retrieves an artist from the provider, and put it in the cache
   *
   * @param ref The reference to the artist
   * @param provider The provider from which retrieve the artist
   * @return The artist, or null if the provider says so
   */
  public Artist retrieveArtist(final String ref, final ProviderIdentifier provider) {
    if (ref == null) {
      // Force get stack trace
      try {
        throw new RuntimeException();
      } catch (RuntimeException e) {
        Log.e(TAG, "retrieveArtist called with a null reference", e);
      }
      return null;
    }

    // Try from cache
    Artist output = mCache.getArtist(ref);
    if (output == null && provider != null) {
      ProviderConnection pc = PluginsLookup.getDefault().getProvider(provider);
      if (pc != null) {
        IMusicProvider binder = pc.getBinder();

        if (binder != null) {
          try {
            output = binder.getArtist(ref);
            onArtistUpdate(provider, output);
          } catch (DeadObjectException e) {
            Log.e(TAG, "Provider died while retrieving artist");
            return null;
          } catch (RemoteException e) {
            Log.e(TAG, "Unable to retrieve the artist", e);
            return null;
          }
        }
      }
    }

    return output;
  }
Exemplo n.º 2
0
  /** Called by the providers when the details of a song have been updated. */
  @Override
  public void onSongUpdate(ProviderIdentifier provider, final Song s) throws RemoteException {
    if (s == null) {
      Log.w(TAG, "Provider " + provider.mName + " sent in a null songUpdate");
      return;
    }

    try {
      Song cached = mCache.getSong(s.getRef());
      boolean wasLoaded = false;
      boolean changed = false;

      if (cached == null) {
        mCache.putSong(provider, s);
        changed = true;
        cached = s;
      } else {
        wasLoaded = cached.isLoaded();
        if (s.isLoaded() && !cached.isIdentical(s)) {
          cached.setAlbum(s.getAlbum());
          cached.setArtist(s.getArtist());
          cached.setSourceLogo(s.getLogo());
          cached.setDuration(s.getDuration());
          cached.setTitle(s.getTitle());
          cached.setYear(s.getYear());
          cached.setOfflineStatus(s.getOfflineStatus());
          cached.setAvailable(s.isAvailable());
          cached.setIsLoaded(s.isLoaded());
          changed = true;
        }
      }

      if (!wasLoaded && cached.isLoaded()) {
        // Match the album with the artist
        Artist artist = mCache.getArtist(s.getArtist());
        if (artist == null && s.getArtist() != null) {
          artist = retrieveArtist(s.getArtist(), provider);
        }

        if (artist != null) {
          Album album = mCache.getAlbum(s.getAlbum());
          if (album == null && s.getAlbum() != null) {
            album = retrieveAlbum(s.getAlbum(), provider);
          }

          if (album != null) {
            artist.addAlbum(album.getRef());
          }
        }
      }

      if (changed) {
        postSongForUpdate(cached);
      }
    } catch (Exception e) {
      Log.e(TAG, "Exception while updating song data", e);
    }
  }
Exemplo n.º 3
0
  /** Called by the providers when the details of an artist have been updated. */
  @Override
  public void onArtistUpdate(ProviderIdentifier provider, Artist a) throws RemoteException {
    if (a == null) {
      Log.w(TAG, "Provider returned a null artist");
      return;
    }

    Artist cached = mCache.getArtist(a.getRef());

    if (cached == null) {
      mCache.putArtist(provider, a);
      postArtistForUpdate(a);
    } else if (!cached.isIdentical(a)) {
      cached.setName(a.getName());
      Iterator<String> it = a.albums();
      while (it.hasNext()) {
        cached.addAlbum(it.next());
      }
      cached.setIsLoaded(a.isLoaded());
      postArtistForUpdate(a);
    }
  }