Exemplo n.º 1
0
  private void init() {
    database.addObserver(this);

    for (final Mode currMode : Mode.values()) {
      getButton(currMode)
          .setOnClickListener(
              new View.OnClickListener() {
                public void onClick(View v) {
                  filters.clear();
                  filterListAdapter.clear();
                  for (Filter<? super Tables.Tracks> permanentFilter : permanentFilters) {
                    filterListAdapter.add(permanentFilter);
                  }
                  List<Filter<? super Tables.Tracks>> filtersToRemove =
                      new ArrayList<Filter<? super Tables.Tracks>>();
                  for (Filter<? super Tables.Tracks> filterAddedWithMode :
                      filtersAddWithMode.get(currMode)) {
                    if (!permanentFilters.contains(filterAddedWithMode)) {
                      filtersToRemove.add(filterAddedWithMode);
                    }
                  }

                  filtersAddWithMode.get(currMode).removeAll(filtersToRemove);

                  change(currMode, null, false);
                }
              });
    }
  }
Exemplo n.º 2
0
  /**
   * @param toMode
   * @param filter - filter to add, can be null
   */
  public void change(Mode toMode, final Filter<? super Tables.Tracks> filter, boolean permanant) {
    if (filter != null) {
      filtersAddWithMode.get(currMode).add(filter);
      addFilter(filter, permanant);
    }

    currMode = toMode;
    for (final Mode aMode : Mode.values()) {
      final ImageView button = getButton(aMode);
      button.post(
          new Runnable() {
            public void run() {
              button.setImageResource(
                  aMode.equals(currMode) ? aMode.drawableActive : aMode.drawable);
            }
          });
    }
    update();
  }
Exemplo n.º 3
0
 public boolean back() {
   Mode backMode;
   switch (currMode) {
     case Album:
       backMode = Mode.Artist;
       break;
     case Artist:
       backMode = Mode.Genre;
       break;
     case Genre:
       backMode = null;
       break;
     case Track:
       backMode = Mode.Album;
       break;
     case Dir:
       backMode = Mode.Dir;
       break;
     default:
       throw new RuntimeException(currMode.name() + " not expexted here");
   }
   final List<Filter<? super Tables.Tracks>> filtersAddedByBack = filtersAddWithMode.get(backMode);
   if (backMode == null || filtersAddedByBack.isEmpty()) {
     return true;
   } else {
     final Filter<? super Tables.Tracks> filterAddedByBack =
         filtersAddedByBack.remove(filtersAddedByBack.size() - 1);
     filterList.post(
         new Runnable() {
           public void run() {
             removeFilter(filterAddedByBack);
           }
         });
     change(backMode, null, false);
     return false;
   }
 }
Exemplo n.º 4
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();
  }