Exemplo n.º 1
0
 /** Show the last element in the list of adapters */
 private void showList() {
   if (mAdapters.isEmpty() || mAdapters.getLast().isEmpty()) {
     mList.setEmptyView(mEmptyLibrary);
   } else {
     LibraryAdapter adapter = mAdapters.getLast();
     adapter.getFilter().filter(mLastFilter);
     mList.setAdapter(adapter);
     if (adapter.isEmpty() || adapter.getCount() == 0) {
       buildSubActionBar("", "");
     } else {
       MyLibraryItem item = adapter.getItem(0);
       switch (item.getLevel()) {
         case MyLibrary.LVL_ARTIST:
           buildSubActionBar("", "");
           break;
         case MyLibrary.LVL_ALBUM:
           buildSubActionBar(item.getArtist(), "");
           break;
         default:
           buildSubActionBar(item.getArtist(), item.getAlbum());
           break;
       }
     }
   }
 }
Exemplo n.º 2
0
 private boolean addSongsToPlaylist(MyLibraryItem libraryItem) {
   switch (libraryItem.getLevel()) {
     case MyLibrary.LVL_ARTIST:
       MyLibrary addArtist = new MyLibrary(getActivity());
       addArtist.addOnLibrarySelectFinishedListener(LibraryFragment.this);
       addArtist.getAllTitlesFromArtistAsync(libraryItem.getArtist());
       return true;
     case MyLibrary.LVL_ALBUM:
       MyLibrary addAlbums = new MyLibrary(getActivity());
       addAlbums.addOnLibrarySelectFinishedListener(LibraryFragment.this);
       addAlbums.getTitlesAsync(libraryItem.getArtist(), libraryItem.getAlbum());
       return true;
     case MyLibrary.LVL_TITLE:
       Message msg = Message.obtain();
       LinkedList<String> urls = new LinkedList<String>();
       urls.add(libraryItem.getUrl());
       msg.obj =
           ClementineMessageFactory.buildInsertUrl(
               App.mClementine.getPlaylistManager().getActivePlaylistId(), urls);
       App.mClementineConnection.mHandler.sendMessage(msg);
       return false;
     default:
       return false;
   }
 }
Exemplo n.º 3
0
  private void addSongsToPlaylist(LinkedList<MyLibraryItem> l) {
    Message msg = Message.obtain();
    LinkedList<String> urls = new LinkedList<String>();
    for (MyLibraryItem item : l) {
      urls.add(item.getUrl());
    }

    msg.obj =
        ClementineMessageFactory.buildInsertUrl(
            App.mClementine.getPlaylistManager().getActivePlaylistId(), urls);

    App.mClementineConnection.mHandler.sendMessage(msg);

    Toast.makeText(
            getActivity(),
            String.format(getString(R.string.library_songs_added), urls.size()),
            Toast.LENGTH_SHORT)
        .show();
  }
Exemplo n.º 4
0
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
          MyLibraryItem item = mAdapters.getLast().getItem(position);

          switch (item.getLevel()) {
            case MyLibrary.LVL_ARTIST:
              LibraryAdapter album =
                  new LibraryAdapter(
                      getActivity(),
                      mLibrary.getAlbums(item.getArtist()),
                      mLibrary,
                      MyLibrary.LVL_ALBUM);
              mAdapters.add(album);
              showList();
              break;
            case MyLibrary.LVL_ALBUM:
              LibraryAdapter title =
                  new LibraryAdapter(
                      getActivity(),
                      mLibrary.getTitles(item.getArtist(), item.getAlbum()),
                      mLibrary,
                      MyLibrary.LVL_TITLE);
              mAdapters.add(title);
              showList();
              break;
            case MyLibrary.LVL_TITLE:
              Message msg = Message.obtain();
              LinkedList<String> urls = new LinkedList<String>();
              urls.add(item.getUrl());
              msg.obj =
                  ClementineMessageFactory.buildInsertUrl(
                      App.mClementine.getPlaylistManager().getActivePlaylistId(), urls);
              App.mClementineConnection.mHandler.sendMessage(msg);

              Toast.makeText(
                      getActivity(),
                      String.format(getString(R.string.library_songs_added), 1),
                      Toast.LENGTH_SHORT)
                  .show();
              break;
            default:
              break;
          }
        }