Beispiel #1
0
  public void updated(final Instance instance) {
    if (!Player.Slides.PLAYLIST.equals(listActivity.getCurrSlide())) {
      return;
    }

    Instance instanceToAdd =
        instance.accept(
            new InstanceVisitor<Instance>() {
              public Instance visit(Track track) {
                if (getFilter().accept(new MatchFilterVisitor<Track, Tables.Tracks>(track))) {
                  switch (currMode) {
                    case Album:
                      return track.GetAlbum() == AlbumDigest.NO_ALBUM ? track : track.GetAlbum();
                    case Artist:
                      return track.GetArtist() == ArtistDigest.NO_ARTIST
                          ? track
                          : track.GetArtist();
                    case Genre:
                      return track.GetGenre() == GenreDigest.NO_GENRE ? track : track.GetGenre();
                    case Track:
                      return track;
                    case Dir:
                      return track;
                    default:
                      throw new RuntimeException(currMode.name() + " not expexted here");
                  }
                }
                return null;
              }

              public Instance visit(SongDigest track) {
                throw new RuntimeException("not supported yet");
              }

              public Instance visit(Album album) {
                throw new RuntimeException("not supported yet");
              }

              public Instance visit(GenreDigest genre) {
                throw new RuntimeException("not supported yet");
              }

              public Instance visit(ArtistDigest artist) {
                throw new RuntimeException("not supported yet");
              }

              public Instance visit(FSobject dir) {
                return getDirFilter().accept(new MatchFilterVisitor<FSobject, Tables.Dirs>(dir))
                        && Mode.Dir.equals(currMode)
                    ? dir
                    : null;
              }
            });

    if (instanceToAdd != null) {
      listAdapter.add(instanceToAdd);
    }
  }
Beispiel #2
0
  /**
   * @param selection
   * @return null if no track was selected, track if trak was selected
   */
  public Track choose(Instance selection) {

    return selection.accept(
        new InstanceVisitor<Track>() {
          public Track visit(Track track) {
            return track;
          }

          public Track visit(SongDigest track) {
            Filter<Tables.SongsReadable> trackFilter =
                new FieldFilter<Tables.SongsReadable, Track, String>(
                    Tables.SongsReadable.TITLE, Operator.EQ, track.getSongName());
            return database
                .getTracks(new FilterSet<Tables.Tracks>(getFilter(), trackFilter))
                .iterator()
                .next();
          }

          public Track visit(Album album) {
            Filter<Tables.AlbumsReadable> filter =
                new FieldFilter<Tables.AlbumsReadable, Track, String>(
                    Tables.AlbumsReadable.ALBUM, Operator.EQ, album.getAlbumId());
            change(Mode.Track, filter, false);
            return null;
          }

          public Track visit(GenreDigest genre) {
            Filter<Tables.GenresReadable> filter =
                new FieldFilter<Tables.GenresReadable, Track, String>(
                    Tables.GenresReadable.GENRE, Operator.EQ, genre.getGenreId());
            change(Mode.Artist, filter, false);
            return null;
          }

          public Track visit(ArtistDigest artist) {
            Filter<Tables.ArtistsReadable> filter =
                new FieldFilter<Tables.ArtistsReadable, Track, String>(
                    Tables.ArtistsReadable.ARTIST, Operator.EQ, artist.getArtistId());
            change(Mode.Album, filter, false);
            return null;
          }

          public Track visit(FSobject FSobject) {
            Filter<Tables.FsObjects> filter =
                new DirFilter(Operator.LIKE, FSobject.getFullPath() + "/%");
            change(Mode.Dir, filter, true);
            return null;
          }
        });
  }