Search in sources :

Example 1 with Artist

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

the class SearchActivity method populateList.

private void populateList() {
    mergeAdapter = new MergeAdapter();
    mergeAdapter.addView(searchButton, true);
    if (searchResult != null) {
        List<Artist> artists = searchResult.getArtists();
        if (!artists.isEmpty()) {
            mergeAdapter.addView(artistsHeading);
            List<Artist> displayedArtists = new ArrayList<Artist>(artists.subList(0, Math.min(DEFAULT_ARTISTS, artists.size())));
            artistAdapter = new ArtistAdapter(this, displayedArtists);
            mergeAdapter.addAdapter(artistAdapter);
            if (artists.size() > DEFAULT_ARTISTS) {
                moreArtistsAdapter = mergeAdapter.addView(moreArtistsButton, true);
            }
        }
        List<MusicDirectory.Entry> albums = searchResult.getAlbums();
        if (!albums.isEmpty()) {
            mergeAdapter.addView(albumsHeading);
            List<MusicDirectory.Entry> displayedAlbums = new ArrayList<MusicDirectory.Entry>(albums.subList(0, Math.min(DEFAULT_ALBUMS, albums.size())));
            albumAdapter = new EntryAdapter(this, getImageLoader(), displayedAlbums, false);
            mergeAdapter.addAdapter(albumAdapter);
            if (albums.size() > DEFAULT_ALBUMS) {
                moreAlbumsAdapter = mergeAdapter.addView(moreAlbumsButton, true);
            }
        }
        List<MusicDirectory.Entry> songs = searchResult.getSongs();
        if (!songs.isEmpty()) {
            mergeAdapter.addView(songsHeading);
            List<MusicDirectory.Entry> displayedSongs = new ArrayList<MusicDirectory.Entry>(songs.subList(0, Math.min(DEFAULT_SONGS, songs.size())));
            songAdapter = new EntryAdapter(this, getImageLoader(), displayedSongs, false);
            mergeAdapter.addAdapter(songAdapter);
            if (songs.size() > DEFAULT_SONGS) {
                moreSongsAdapter = mergeAdapter.addView(moreSongsButton, true);
            }
        }
        boolean empty = searchResult.getArtists().isEmpty() && searchResult.getAlbums().isEmpty() && searchResult.getSongs().isEmpty();
        searchButton.setText(empty ? R.string.search_no_match : R.string.search_search);
    }
    list.setAdapter(mergeAdapter);
}
Also used : Artist(org.moire.ultrasonic.domain.Artist) Entry(org.moire.ultrasonic.domain.MusicDirectory.Entry) MusicDirectory(org.moire.ultrasonic.domain.MusicDirectory) ArtistAdapter(org.moire.ultrasonic.view.ArtistAdapter) MergeAdapter(org.moire.ultrasonic.util.MergeAdapter) EntryAdapter(org.moire.ultrasonic.view.EntryAdapter) ArrayList(java.util.ArrayList)

Example 2 with Artist

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

the class SelectArtistActivity method onItemClick.

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    if (view == folderButton) {
        selectFolder();
    } else {
        Artist artist = (Artist) parent.getItemAtPosition(position);
        if (artist != null) {
            Intent intent = new Intent(this, SelectAlbumActivity.class);
            intent.putExtra(Constants.INTENT_EXTRA_NAME_ID, artist.getId());
            intent.putExtra(Constants.INTENT_EXTRA_NAME_NAME, artist.getName());
            intent.putExtra(Constants.INTENT_EXTRA_NAME_PARENT_ID, artist.getId());
            intent.putExtra(Constants.INTENT_EXTRA_NAME_ARTIST, true);
            startActivityForResultWithoutTransition(this, intent);
        }
    }
}
Also used : Artist(org.moire.ultrasonic.domain.Artist) Intent(android.content.Intent)

Example 3 with Artist

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

the class SelectArtistActivity method onCreateContextMenu.

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, view, menuInfo);
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    if (artistListView.getItemAtPosition(info.position) instanceof Artist) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.select_artist_context, menu);
    } else if (info.position == 1) {
        String musicFolderId = Util.getSelectedMusicFolderId(this);
        MenuItem menuItem = menu.add(MENU_GROUP_MUSIC_FOLDER, -1, 0, R.string.select_artist_all_folders);
        if (musicFolderId == null) {
            menuItem.setChecked(true);
        }
        if (musicFolders != null) {
            for (int i = 0; i < musicFolders.size(); i++) {
                MusicFolder musicFolder = musicFolders.get(i);
                menuItem = menu.add(MENU_GROUP_MUSIC_FOLDER, i, i + 1, musicFolder.getName());
                if (musicFolder.getId().equals(musicFolderId)) {
                    menuItem.setChecked(true);
                }
            }
        }
        menu.setGroupCheckable(MENU_GROUP_MUSIC_FOLDER, true, true);
    }
    MenuItem downloadMenuItem = menu.findItem(R.id.artist_menu_download);
    if (downloadMenuItem != null) {
        downloadMenuItem.setVisible(!Util.isOffline(this));
    }
}
Also used : Artist(org.moire.ultrasonic.domain.Artist) MenuInflater(android.view.MenuInflater) AdapterView(android.widget.AdapterView) MenuItem(android.view.MenuItem) MusicFolder(org.moire.ultrasonic.domain.MusicFolder)

Example 4 with Artist

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

the class OfflineMusicService method getIndexes.

@Override
public Indexes getIndexes(String musicFolderId, boolean refresh, Context context, ProgressListener progressListener) throws Exception {
    List<Artist> artists = new ArrayList<Artist>();
    File root = FileUtil.getMusicDirectory(context);
    for (File file : FileUtil.listFiles(root)) {
        if (file.isDirectory()) {
            Artist artist = new Artist();
            artist.setId(file.getPath());
            artist.setIndex(file.getName().substring(0, 1));
            artist.setName(file.getName());
            artists.add(artist);
        }
    }
    String ignoredArticlesString = "The El La Los Las Le Les";
    final String[] ignoredArticles = COMPILE.split(ignoredArticlesString);
    Collections.sort(artists, new Comparator<Artist>() {

        @Override
        public int compare(Artist lhsArtist, Artist rhsArtist) {
            String lhs = lhsArtist.getName().toLowerCase();
            String rhs = rhsArtist.getName().toLowerCase();
            char lhs1 = lhs.charAt(0);
            char rhs1 = rhs.charAt(0);
            if (Character.isDigit(lhs1) && !Character.isDigit(rhs1)) {
                return 1;
            }
            if (Character.isDigit(rhs1) && !Character.isDigit(lhs1)) {
                return -1;
            }
            for (String article : ignoredArticles) {
                int index = lhs.indexOf(String.format("%s ", article.toLowerCase()));
                if (index == 0) {
                    lhs = lhs.substring(article.length() + 1);
                }
                index = rhs.indexOf(String.format("%s ", article.toLowerCase()));
                if (index == 0) {
                    rhs = rhs.substring(article.length() + 1);
                }
            }
            return lhs.compareTo(rhs);
        }
    });
    return new Indexes(0L, ignoredArticlesString, Collections.<Artist>emptyList(), artists);
}
Also used : Artist(org.moire.ultrasonic.domain.Artist) ArrayList(java.util.ArrayList) Indexes(org.moire.ultrasonic.domain.Indexes) File(java.io.File)

Example 5 with Artist

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

the class OfflineMusicService method search.

@Override
public SearchResult search(SearchCriteria criteria, Context context, ProgressListener progressListener) throws Exception {
    List<Artist> artists = new ArrayList<Artist>();
    List<MusicDirectory.Entry> albums = new ArrayList<MusicDirectory.Entry>();
    List<MusicDirectory.Entry> songs = new ArrayList<MusicDirectory.Entry>();
    File root = FileUtil.getMusicDirectory(context);
    int closeness;
    for (File artistFile : FileUtil.listFiles(root)) {
        String artistName = artistFile.getName();
        if (artistFile.isDirectory()) {
            if ((closeness = matchCriteria(criteria, artistName)) > 0) {
                Artist artist = new Artist();
                artist.setId(artistFile.getPath());
                artist.setIndex(artistFile.getName().substring(0, 1));
                artist.setName(artistName);
                artist.setCloseness(closeness);
                artists.add(artist);
            }
            recursiveAlbumSearch(artistName, artistFile, criteria, context, albums, songs);
        }
    }
    Collections.sort(artists, new Comparator<Artist>() {

        @Override
        public int compare(Artist lhs, Artist rhs) {
            if (lhs.getCloseness() == rhs.getCloseness()) {
                return 0;
            } else
                return lhs.getCloseness() > rhs.getCloseness() ? -1 : 1;
        }
    });
    Collections.sort(albums, new Comparator<MusicDirectory.Entry>() {

        @Override
        public int compare(MusicDirectory.Entry lhs, MusicDirectory.Entry rhs) {
            if (lhs.getCloseness() == rhs.getCloseness()) {
                return 0;
            } else
                return lhs.getCloseness() > rhs.getCloseness() ? -1 : 1;
        }
    });
    Collections.sort(songs, new Comparator<MusicDirectory.Entry>() {

        @Override
        public int compare(MusicDirectory.Entry lhs, MusicDirectory.Entry rhs) {
            if (lhs.getCloseness() == rhs.getCloseness()) {
                return 0;
            } else
                return lhs.getCloseness() > rhs.getCloseness() ? -1 : 1;
        }
    });
    return new SearchResult(artists, albums, songs);
}
Also used : Artist(org.moire.ultrasonic.domain.Artist) MusicDirectory(org.moire.ultrasonic.domain.MusicDirectory) ArrayList(java.util.ArrayList) SearchResult(org.moire.ultrasonic.domain.SearchResult) File(java.io.File)

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