Search in sources :

Example 6 with Artist

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

the class SearchActivity method onCreateContextMenu.

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, view, menuInfo);
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    Object selectedItem = list.getItemAtPosition(info.position);
    boolean isArtist = selectedItem instanceof Artist;
    boolean isAlbum = selectedItem instanceof MusicDirectory.Entry && ((MusicDirectory.Entry) selectedItem).isDirectory();
    if (!isArtist && !isAlbum) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.select_song_context, menu);
    } else {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.select_album_context, menu);
    }
    MenuItem shareButton = menu.findItem(R.id.menu_item_share);
    MenuItem downloadMenuItem = menu.findItem(R.id.album_menu_download);
    if (downloadMenuItem != null) {
        downloadMenuItem.setVisible(!Util.isOffline(this));
    }
    if (Util.isOffline(this) || isArtist) {
        if (shareButton != null) {
            shareButton.setVisible(false);
        }
    }
}
Also used : Artist(org.moire.ultrasonic.domain.Artist) MusicDirectory(org.moire.ultrasonic.domain.MusicDirectory) MenuInflater(android.view.MenuInflater) Entry(org.moire.ultrasonic.domain.MusicDirectory.Entry) AdapterView(android.widget.AdapterView) MenuItem(android.view.MenuItem)

Example 7 with Artist

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

the class SearchActivity method onContextItemSelected.

@Override
public boolean onContextItemSelected(MenuItem menuItem) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo();
    if (info == null) {
        return true;
    }
    Object selectedItem = list.getItemAtPosition(info.position);
    Artist artist = selectedItem instanceof Artist ? (Artist) selectedItem : null;
    Entry entry = selectedItem instanceof Entry ? (Entry) selectedItem : null;
    String entryId = null;
    if (entry != null) {
        entryId = entry.getId();
    }
    String id = artist != null ? artist.getId() : entryId;
    if (id == null) {
        return true;
    }
    List<Entry> songs = new ArrayList<Entry>(1);
    switch(menuItem.getItemId()) {
        case R.id.album_menu_play_now:
            downloadRecursively(id, false, false, true, false, false, false, false, false);
            break;
        case R.id.album_menu_play_next:
            downloadRecursively(id, false, true, false, true, false, true, false, false);
            break;
        case R.id.album_menu_play_last:
            downloadRecursively(id, false, true, false, false, false, false, false, false);
            break;
        case R.id.album_menu_pin:
            downloadRecursively(id, true, true, false, false, false, false, false, false);
            break;
        case R.id.album_menu_unpin:
            downloadRecursively(id, false, false, false, false, false, false, true, false);
            break;
        case R.id.album_menu_download:
            downloadRecursively(id, false, false, false, false, true, false, false, false);
            break;
        case R.id.song_menu_play_now:
            if (entry != null) {
                songs = new ArrayList<MusicDirectory.Entry>(1);
                songs.add(entry);
                download(false, false, true, false, false, songs);
            }
            break;
        case R.id.song_menu_play_next:
            if (entry != null) {
                songs = new ArrayList<MusicDirectory.Entry>(1);
                songs.add(entry);
                download(true, false, false, true, false, songs);
            }
            break;
        case R.id.song_menu_play_last:
            if (entry != null) {
                songs = new ArrayList<MusicDirectory.Entry>(1);
                songs.add(entry);
                download(true, false, false, false, false, songs);
            }
            break;
        case R.id.song_menu_pin:
            if (entry != null) {
                songs.add(entry);
                Util.toast(SearchActivity.this, getResources().getQuantityString(R.plurals.select_album_n_songs_pinned, songs.size(), songs.size()));
                downloadBackground(true, songs);
            }
            break;
        case R.id.song_menu_download:
            if (entry != null) {
                songs.add(entry);
                Util.toast(SearchActivity.this, getResources().getQuantityString(R.plurals.select_album_n_songs_downloaded, songs.size(), songs.size()));
                downloadBackground(false, songs);
            }
            break;
        case R.id.song_menu_unpin:
            if (entry != null) {
                songs.add(entry);
                Util.toast(SearchActivity.this, getResources().getQuantityString(R.plurals.select_album_n_songs_unpinned, songs.size(), songs.size()));
                getDownloadService().unpin(songs);
            }
            break;
        case R.id.menu_item_share:
            if (entry != null) {
                songs = new ArrayList<MusicDirectory.Entry>(1);
                songs.add(entry);
                createShare(songs);
            }
        default:
            return super.onContextItemSelected(menuItem);
    }
    return true;
}
Also used : Artist(org.moire.ultrasonic.domain.Artist) Entry(org.moire.ultrasonic.domain.MusicDirectory.Entry) ArrayList(java.util.ArrayList) AdapterView(android.widget.AdapterView)

Example 8 with Artist

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

the class SearchActivity method expandArtists.

private void expandArtists() {
    artistAdapter.clear();
    for (Artist artist : searchResult.getArtists()) {
        artistAdapter.add(artist);
    }
    artistAdapter.notifyDataSetChanged();
    mergeAdapter.removeAdapter(moreArtistsAdapter);
    mergeAdapter.notifyDataSetChanged();
}
Also used : Artist(org.moire.ultrasonic.domain.Artist)

Example 9 with Artist

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

the class SearchActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.search);
    setActionBarTitle(R.string.common_appname);
    setActionBarSubtitle(R.string.search_title);
    View searchMenuItem = findViewById(R.id.menu_search);
    menuDrawer.setActiveView(searchMenuItem);
    DEFAULT_ARTISTS = Util.getDefaultArtists(this);
    DEFAULT_ALBUMS = Util.getDefaultAlbums(this);
    DEFAULT_SONGS = Util.getDefaultSongs(this);
    View buttons = LayoutInflater.from(this).inflate(R.layout.search_buttons, null);
    if (buttons != null) {
        artistsHeading = buttons.findViewById(R.id.search_artists);
        albumsHeading = buttons.findViewById(R.id.search_albums);
        songsHeading = buttons.findViewById(R.id.search_songs);
        searchButton = (TextView) buttons.findViewById(R.id.search_search);
        moreArtistsButton = buttons.findViewById(R.id.search_more_artists);
        moreAlbumsButton = buttons.findViewById(R.id.search_more_albums);
        moreSongsButton = buttons.findViewById(R.id.search_more_songs);
    }
    list = (ListView) findViewById(R.id.search_list);
    list.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (view == searchButton) {
                onSearchRequested();
            } else if (view == moreArtistsButton) {
                expandArtists();
            } else if (view == moreAlbumsButton) {
                expandAlbums();
            } else if (view == moreSongsButton) {
                expandSongs();
            } else {
                Object item = parent.getItemAtPosition(position);
                if (item instanceof Artist) {
                    onArtistSelected((Artist) item);
                } else if (item instanceof MusicDirectory.Entry) {
                    MusicDirectory.Entry entry = (MusicDirectory.Entry) item;
                    if (entry.isDirectory()) {
                        onAlbumSelected(entry, false);
                    } else if (entry.isVideo()) {
                        onVideoSelected(entry);
                    } else {
                        onSongSelected(entry, false, true, true, false);
                    }
                }
            }
        }
    });
    registerForContextMenu(list);
    onNewIntent(getIntent());
}
Also used : Artist(org.moire.ultrasonic.domain.Artist) Entry(org.moire.ultrasonic.domain.MusicDirectory.Entry) MusicDirectory(org.moire.ultrasonic.domain.MusicDirectory) Entry(org.moire.ultrasonic.domain.MusicDirectory.Entry) AdapterView(android.widget.AdapterView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView)

Example 10 with Artist

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

the class SelectArtistActivity method onContextItemSelected.

@Override
public boolean onContextItemSelected(MenuItem menuItem) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo();
    if (info == null) {
        return true;
    }
    Artist artist = (Artist) artistListView.getItemAtPosition(info.position);
    if (artist != null) {
        switch(menuItem.getItemId()) {
            case R.id.artist_menu_play_now:
                downloadRecursively(artist.getId(), false, false, true, false, false, false, false, true);
                break;
            case R.id.artist_menu_play_next:
                downloadRecursively(artist.getId(), false, false, true, true, false, true, false, true);
                break;
            case R.id.artist_menu_play_last:
                downloadRecursively(artist.getId(), false, true, false, false, false, false, false, true);
                break;
            case R.id.artist_menu_pin:
                downloadRecursively(artist.getId(), true, true, false, false, false, false, false, true);
                break;
            case R.id.artist_menu_unpin:
                downloadRecursively(artist.getId(), false, false, false, false, false, false, true, true);
                break;
            case R.id.artist_menu_download:
                downloadRecursively(artist.getId(), false, false, false, false, true, false, false, true);
                break;
            default:
                return super.onContextItemSelected(menuItem);
        }
    } else if (info.position == 1) {
        MusicFolder selectedFolder = menuItem.getItemId() == -1 ? null : musicFolders.get(menuItem.getItemId());
        String musicFolderId = selectedFolder == null ? null : selectedFolder.getId();
        String musicFolderName = selectedFolder == null ? getString(R.string.select_artist_all_folders) : selectedFolder.getName();
        Util.setSelectedMusicFolderId(this, musicFolderId);
        folderName.setText(musicFolderName);
        refresh();
    }
    return true;
}
Also used : Artist(org.moire.ultrasonic.domain.Artist) AdapterView(android.widget.AdapterView) MusicFolder(org.moire.ultrasonic.domain.MusicFolder)

Aggregations

Artist (org.moire.ultrasonic.domain.Artist)11 AdapterView (android.widget.AdapterView)5 ArrayList (java.util.ArrayList)5 MusicDirectory (org.moire.ultrasonic.domain.MusicDirectory)4 Entry (org.moire.ultrasonic.domain.MusicDirectory.Entry)4 MusicFolder (org.moire.ultrasonic.domain.MusicFolder)3 MenuInflater (android.view.MenuInflater)2 MenuItem (android.view.MenuItem)2 File (java.io.File)2 Indexes (org.moire.ultrasonic.domain.Indexes)2 ArtistAdapter (org.moire.ultrasonic.view.ArtistAdapter)2 Intent (android.content.Intent)1 View (android.view.View)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 SearchResult (org.moire.ultrasonic.domain.SearchResult)1 MusicService (org.moire.ultrasonic.service.MusicService)1 MergeAdapter (org.moire.ultrasonic.util.MergeAdapter)1 TabActivityBackgroundTask (org.moire.ultrasonic.util.TabActivityBackgroundTask)1 EntryAdapter (org.moire.ultrasonic.view.EntryAdapter)1