Esempio n. 1
0
  @Override
  public void onItemClicked(UpdateView<Artist> updateView, Artist artist) {
    SubsonicFragment fragment = new SelectDirectoryFragment();
    Bundle args = new Bundle();
    args.putString(Constants.INTENT_EXTRA_NAME_ID, artist.getId());
    args.putString(Constants.INTENT_EXTRA_NAME_NAME, artist.getName());
    args.putBoolean(Constants.INTENT_EXTRA_NAME_ARTIST, true);
    fragment.setArguments(args);

    replaceFragment(fragment);
  }
  @Override
  public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Artist artist = (Artist) parent.getItemAtPosition(position);
    SubsonicFragment fragment = new SelectDirectoryFragment();
    Bundle args = new Bundle();
    args.putString(Constants.INTENT_EXTRA_NAME_ID, artist.getId());
    args.putString(Constants.INTENT_EXTRA_NAME_NAME, artist.getName());
    args.putBoolean(Constants.INTENT_EXTRA_NAME_ARTIST, true);
    fragment.setArguments(args);

    replaceFragment(fragment);
  }
Esempio n. 3
0
  public void toggleStarred(final Artist entry) {
    final boolean starred = !entry.isStarred();
    entry.setStarred(starred);

    new SilentBackgroundTask<Void>(this) {
      @Override
      protected Void doInBackground() throws Throwable {
        MusicService musicService = MusicServiceFactory.getMusicService(SubsonicTabActivity.this);
        musicService.setStarred(entry.getId(), starred, SubsonicTabActivity.this, null);
        return null;
      }

      @Override
      protected void done(Void result) {
        // UpdateView
        Util.toast(
            SubsonicTabActivity.this,
            getResources()
                .getString(
                    starred
                        ? R.string.starring_content_starred
                        : R.string.starring_content_unstarred,
                    entry.getName()));
      }

      @Override
      protected void error(Throwable error) {
        entry.setStarred(!starred);

        String msg;
        if (error instanceof OfflineException || error instanceof ServerTooOldException) {
          msg = getErrorMessage(error);
        } else {
          msg =
              getResources().getString(R.string.starring_content_error, entry.getName())
                  + " "
                  + getErrorMessage(error);
        }

        Util.toast(SubsonicTabActivity.this, msg, false);
      }
    }.execute();
  }
Esempio n. 4
0
  private Cursor createCursor(String query, SearchResult searchResult) {
    MatrixCursor cursor = new MatrixCursor(COLUMNS);
    if (searchResult == null) {
      return cursor;
    }

    // Add all results into one pot
    List<Object> results = new ArrayList<Object>();
    results.addAll(searchResult.getArtists());
    results.addAll(searchResult.getAlbums());
    results.addAll(searchResult.getSongs());

    // For each, calculate its string distance to the query
    for (Object obj : results) {
      if (obj instanceof Artist) {
        Artist artist = (Artist) obj;
        artist.setCloseness(Util.getStringDistance(query, artist.getName()));
      } else {
        MusicDirectory.Entry entry = (MusicDirectory.Entry) obj;
        entry.setCloseness(Util.getStringDistance(query, entry.getTitle()));
      }
    }

    // Sort based on the closeness paramater
    Collections.sort(
        results,
        new Comparator<Object>() {
          @Override
          public int compare(Object lhs, Object rhs) {
            // Get the closeness of the two objects
            int left, right;
            boolean leftArtist = lhs instanceof Artist;
            boolean rightArtist = rhs instanceof Artist;
            if (leftArtist) {
              left = ((Artist) lhs).getCloseness();
            } else {
              left = ((MusicDirectory.Entry) lhs).getCloseness();
            }
            if (rightArtist) {
              right = ((Artist) rhs).getCloseness();
            } else {
              right = ((MusicDirectory.Entry) rhs).getCloseness();
            }

            if (left == right) {
              if (leftArtist && rightArtist) {
                return 0;
              } else if (leftArtist) {
                return -1;
              } else if (rightArtist) {
                return 1;
              } else {
                return 0;
              }
            } else if (left > right) {
              return 1;
            } else {
              return -1;
            }
          }
        });

    // Done sorting, add results to cursor
    for (Object obj : results) {
      if (obj instanceof Artist) {
        Artist artist = (Artist) obj;
        String icon = RESOURCE_PREFIX + R.drawable.ic_action_artist;
        cursor.addRow(
            new Object[] {
              artist.getId().hashCode(),
              artist.getName(),
              null,
              "ar-" + artist.getId(),
              artist.getName(),
              icon
            });
      } else {
        MusicDirectory.Entry entry = (MusicDirectory.Entry) obj;

        if (entry.isDirectory()) {
          String icon = RESOURCE_PREFIX + R.drawable.ic_action_album;
          cursor.addRow(
              new Object[] {
                entry.getId().hashCode(),
                entry.getTitle(),
                entry.getArtist(),
                entry.getId(),
                entry.getTitle(),
                icon
              });
        } else {
          String icon = RESOURCE_PREFIX + R.drawable.ic_action_song;
          String id;
          if (Util.isTagBrowsing(getContext())) {
            id = entry.getAlbumId();
          } else {
            id = entry.getParent();
          }
          cursor.addRow(
              new Object[] {
                entry.getId().hashCode(),
                entry.getTitle(),
                entry.getArtist(),
                "so-" + id,
                entry.getTitle(),
                icon
              });
        }
      }
    }
    return cursor;
  }