Example #1
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();
  }
Example #2
0
 private ImageView getButton(Mode mode) {
   return (ImageView) listActivity.findViewById(mode.buttonId);
 }