Search in sources :

Example 1 with Playlist

use of org.moire.ultrasonic.domain.Playlist in project ultrasonic by ultrasonic.

the class SelectPlaylistActivity method load.

private void load() {
    BackgroundTask<List<Playlist>> task = new TabActivityBackgroundTask<List<Playlist>>(this, true) {

        @Override
        protected List<Playlist> doInBackground() throws Throwable {
            MusicService musicService = MusicServiceFactory.getMusicService(SelectPlaylistActivity.this);
            boolean refresh = getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_REFRESH, false);
            List<Playlist> playlists = musicService.getPlaylists(refresh, SelectPlaylistActivity.this, this);
            if (!Util.isOffline(SelectPlaylistActivity.this))
                new CacheCleaner(SelectPlaylistActivity.this, getDownloadService()).cleanPlaylists(playlists);
            return playlists;
        }

        @Override
        protected void done(List<Playlist> result) {
            playlistsListView.setAdapter(playlistAdapter = new PlaylistAdapter(SelectPlaylistActivity.this, result));
            emptyTextView.setVisibility(result.isEmpty() ? View.VISIBLE : View.GONE);
        }
    };
    task.execute();
}
Also used : Playlist(org.moire.ultrasonic.domain.Playlist) TabActivityBackgroundTask(org.moire.ultrasonic.util.TabActivityBackgroundTask) MusicService(org.moire.ultrasonic.service.MusicService) PlaylistAdapter(org.moire.ultrasonic.view.PlaylistAdapter) List(java.util.List) CacheCleaner(org.moire.ultrasonic.util.CacheCleaner)

Example 2 with Playlist

use of org.moire.ultrasonic.domain.Playlist in project ultrasonic by ultrasonic.

the class SelectPlaylistActivity method onItemClick.

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Playlist playlist = (Playlist) parent.getItemAtPosition(position);
    if (playlist == null) {
        return;
    }
    Intent intent = new Intent(SelectPlaylistActivity.this, SelectAlbumActivity.class);
    intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID, playlist.getId());
    intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME, playlist.getName());
    startActivityForResultWithoutTransition(SelectPlaylistActivity.this, intent);
}
Also used : Playlist(org.moire.ultrasonic.domain.Playlist) Intent(android.content.Intent)

Example 3 with Playlist

use of org.moire.ultrasonic.domain.Playlist in project ultrasonic by ultrasonic.

the class OfflineMusicService method getPlaylists.

@Override
public List<Playlist> getPlaylists(boolean refresh, Context context, ProgressListener progressListener) throws Exception {
    List<Playlist> playlists = new ArrayList<Playlist>();
    File root = FileUtil.getPlaylistDirectory();
    String lastServer = null;
    boolean removeServer = true;
    for (File folder : FileUtil.listFiles(root)) {
        if (folder.isDirectory()) {
            String server = folder.getName();
            SortedSet<File> fileList = FileUtil.listFiles(folder);
            for (File file : fileList) {
                if (FileUtil.isPlaylistFile(file)) {
                    String id = file.getName();
                    String filename = server + ": " + FileUtil.getBaseName(id);
                    Playlist playlist = new Playlist(server, filename);
                    playlists.add(playlist);
                }
            }
            if (!server.equals(lastServer) && !fileList.isEmpty()) {
                if (lastServer != null) {
                    removeServer = false;
                }
                lastServer = server;
            }
        } else {
            // Delete legacy playlist files
            try {
                folder.delete();
            } catch (Exception e) {
                Log.w(TAG, String.format("Failed to delete old playlist file: %s", folder.getName()));
            }
        }
    }
    if (removeServer) {
        for (Playlist playlist : playlists) {
            playlist.setName(playlist.getName().substring(playlist.getId().length() + 2));
        }
    }
    return playlists;
}
Also used : Playlist(org.moire.ultrasonic.domain.Playlist) ArrayList(java.util.ArrayList) File(java.io.File)

Example 4 with Playlist

use of org.moire.ultrasonic.domain.Playlist in project ultrasonic by ultrasonic.

the class PlaylistAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    Playlist entry = getItem(position);
    PlaylistView view;
    if (convertView != null && convertView instanceof PlaylistView) {
        PlaylistView currentView = (PlaylistView) convertView;
        ViewHolder viewHolder = (ViewHolder) convertView.getTag();
        view = currentView;
        view.setViewHolder(viewHolder);
    } else {
        view = new PlaylistView(activity);
        view.setLayout();
    }
    view.setPlaylist(entry);
    return view;
}
Also used : Playlist(org.moire.ultrasonic.domain.Playlist)

Example 5 with Playlist

use of org.moire.ultrasonic.domain.Playlist in project ultrasonic by ultrasonic.

the class SelectPlaylistActivity method onContextItemSelected.

@Override
public boolean onContextItemSelected(MenuItem menuItem) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo();
    if (info == null) {
        return false;
    }
    Playlist playlist = (Playlist) playlistsListView.getItemAtPosition(info.position);
    if (playlist == null) {
        return false;
    }
    Intent intent;
    switch(menuItem.getItemId()) {
        case R.id.playlist_menu_pin:
            downloadPlaylist(playlist.getId(), playlist.getName(), true, true, false, false, true, false, false);
            break;
        case R.id.playlist_menu_unpin:
            downloadPlaylist(playlist.getId(), playlist.getName(), false, false, false, false, true, false, true);
            break;
        case R.id.playlist_menu_download:
            downloadPlaylist(playlist.getId(), playlist.getName(), false, false, false, false, true, false, false);
            break;
        case R.id.playlist_menu_play_now:
            intent = new Intent(SelectPlaylistActivity.this, SelectAlbumActivity.class);
            intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID, playlist.getId());
            intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME, playlist.getName());
            intent.putExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, true);
            startActivityForResultWithoutTransition(SelectPlaylistActivity.this, intent);
            break;
        case R.id.playlist_menu_play_shuffled:
            intent = new Intent(SelectPlaylistActivity.this, SelectAlbumActivity.class);
            intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID, playlist.getId());
            intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME, playlist.getName());
            intent.putExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, true);
            intent.putExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, true);
            startActivityForResultWithoutTransition(SelectPlaylistActivity.this, intent);
            break;
        case R.id.playlist_menu_delete:
            deletePlaylist(playlist);
            break;
        case R.id.playlist_info:
            displayPlaylistInfo(playlist);
            break;
        case R.id.playlist_update_info:
            updatePlaylistInfo(playlist);
            break;
        default:
            return super.onContextItemSelected(menuItem);
    }
    return true;
}
Also used : Playlist(org.moire.ultrasonic.domain.Playlist) AdapterView(android.widget.AdapterView) Intent(android.content.Intent)

Aggregations

Playlist (org.moire.ultrasonic.domain.Playlist)5 Intent (android.content.Intent)2 AdapterView (android.widget.AdapterView)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 MusicService (org.moire.ultrasonic.service.MusicService)1 CacheCleaner (org.moire.ultrasonic.util.CacheCleaner)1 TabActivityBackgroundTask (org.moire.ultrasonic.util.TabActivityBackgroundTask)1 PlaylistAdapter (org.moire.ultrasonic.view.PlaylistAdapter)1