Exemple #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);
    }
  }
Exemple #2
0
  public FileChooser(Mode currMode, final TurtlePlayer tp, Player listActivity) {
    for (Mode mode : Mode.values()) {
      filtersAddWithMode.put(mode, new ArrayList<Filter<? super Tables.Tracks>>());
    }

    this.currMode = currMode;
    this.database = tp.db;
    this.preferences = tp.playlist.preferences;
    this.listActivity = listActivity;

    tp.playlist.preferences.addObserver(
        new PreferencesObserver() {
          public void changed(AbstractKey<?, ?> key) {
            if (key.equals(Keys.MEDIA_DIR)) {
              final String mediaDir = tp.playlist.preferences.get(Keys.MEDIA_DIR);
              getFilter()
                  .accept(
                      new TurtleFilterVisitor<Tables.Tracks, Void>() {
                        public Void visit(DirFilter dirFilter) {
                          if (!dirFilter.filtersInPath(mediaDir)) {
                            removeFilter(dirFilter);
                            update();
                          }
                          return null;
                        }

                        public <T, Z> Void visit(
                            FieldFilter<? super Tables.Tracks, Z, T> fieldFilter) {
                          return null;
                        }

                        public Void visit(FilterSet<? super Tables.Tracks> filterSet) {
                          return null;
                        }

                        public Void visit(NotFilter<? super Tables.Tracks> notFilter) {
                          return null;
                        }
                      });
            }
          }

          public String getId() {
            return "OutdatedFilterUpdater";
          }
        });

    filterList = (ListView) listActivity.findViewById(R.id.filterlist);
    filterListAdapter =
        new FilterListAdapter(
            listActivity.getApplicationContext(),
            new ArrayList<Filter<? super Tables.Tracks>>(getFilters())) {
          @Override
          protected void removeFilter(final Filter<? super Tables.Tracks> filter) {
            FileChooser.this.removeFilter(filter);
            update();
          }

          @Override
          protected void chooseFilter(Filter<? super Tables.Tracks> filter) {
            filterChoosen(filter);
          }
        };

    filterList.setAdapter(filterListAdapter);

    listAdapter =
        new DefaultAdapter<Instance>(
            listActivity.getApplicationContext(),
            new ArrayList<Instance>(),
            listActivity,
            false,
            InstanceFormatter.SHORT);

    listActivity.setListAdapter(listAdapter);

    change(currMode, null, false);

    init();
  }
Exemple #3
0
 private ImageView getButton(Mode mode) {
   return (ImageView) listActivity.findViewById(mode.buttonId);
 }