Search in sources :

Example 1 with AlbumArtist

use of com.simplecity.amp_library.model.AlbumArtist in project Shuttle by timusus.

the class Operators method albumsToAlbumArtists.

public static List<AlbumArtist> albumsToAlbumArtists(List<Album> albums) {
    HashMap<String, AlbumArtist> albumArtistMap = new HashMap<>();
    for (Album album : albums) {
        //Create an album-artist representing the album-artist this album belongs to
        AlbumArtist albumArtist = album.getAlbumArtist();
        //Check if there's already an equivalent album-artist in our albumArtistMap
        AlbumArtist oldAlbumArtist = albumArtistMap.get(albumArtist.name);
        if (oldAlbumArtist != null) {
            //Add this album to the album artist's albums
            if (!oldAlbumArtist.albums.contains(album)) {
                oldAlbumArtist.albums.add(album);
            }
        } else {
            albumArtistMap.put(albumArtist.name, albumArtist);
        }
    }
    return new ArrayList<>(albumArtistMap.values());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Album(com.simplecity.amp_library.model.Album) AlbumArtist(com.simplecity.amp_library.model.AlbumArtist)

Example 2 with AlbumArtist

use of com.simplecity.amp_library.model.AlbumArtist in project Shuttle by timusus.

the class SearchActivity method refreshAdapterItems.

private void refreshAdapterItems() {
    subscriptions.add(DataManager.getInstance().getSongsRelay().first().map(songs -> {
        char[] prefix = filterString.toUpperCase().toCharArray();
        List<Album> albums = Operators.songsToAlbums(songs);
        Collections.sort(albums, Album::compareTo);
        List<AlbumArtist> albumArtists = Operators.albumsToAlbumArtists(albums);
        Collections.sort(albumArtists, AlbumArtist::compareTo);
        List<AdaptableItem> adaptableItems = Stream.of(albumArtists).filter(album -> album.name != null).map(albumArtist -> new SearchUtils.JaroWinklerObject<>(albumArtist, filterString, albumArtist.name)).filter(jaroWinklerObject -> jaroWinklerObject.score > SCORE_THRESHOLD || TextUtils.isEmpty(filterString)).sorted((a, b) -> a.object.compareTo(b.object)).sorted((a, b) -> Double.compare(b.score, a.score)).map(jaroWinklerObject -> jaroWinklerObject.object).map(albumArtist -> {
            AlbumArtistView albumArtistView = new AlbumArtistView(albumArtist, ViewType.ARTIST_LIST, requestManager);
            albumArtistView.setPrefix(prefixHighlighter, prefix);
            return (AdaptableItem) albumArtistView;
        }).collect(Collectors.toList());
        if (!adaptableItems.isEmpty()) {
            adaptableItems.add(0, artistsHeader);
        }
        List<AdaptableItem> albumItems = Stream.of(albums).filter(album -> album.name != null).map(album -> new SearchUtils.JaroWinklerObject<>(album, filterString, album.name, album.albumArtistName)).filter(jaroWinklerObject -> jaroWinklerObject.score > SCORE_THRESHOLD || TextUtils.isEmpty(filterString)).sorted((a, b) -> a.object.compareTo(b.object)).sorted((a, b) -> Double.compare(b.score, a.score)).map(jaroWinklerObject -> jaroWinklerObject.object).map(album -> {
            AlbumView albumView = new AlbumView(album, ViewType.ALBUM_LIST, requestManager);
            albumView.setPrefix(prefixHighlighter, prefix);
            return albumView;
        }).collect(Collectors.toList());
        if (!albumItems.isEmpty()) {
            albumItems.add(0, albumsHeader);
        }
        adaptableItems.addAll(albumItems);
        songs = Stream.of(songs).filter(song -> song.name != null).map(song -> new SearchUtils.JaroWinklerObject<>(song, filterString, song.name, song.albumName, song.artistName, song.albumArtistName)).filter(jaroWinklerObject -> jaroWinklerObject.score > SCORE_THRESHOLD || TextUtils.isEmpty(filterString)).sorted((a, b) -> a.object.compareTo(b.object)).sorted((a, b) -> Double.compare(b.score, a.score)).map(jaroWinklerObject -> jaroWinklerObject.object).collect(Collectors.toList());
        List<AdaptableItem> songItems = Stream.of(songs).map(song -> {
            SongView songView = new SongView(song, dummySelector, requestManager);
            songView.setPrefix(prefixHighlighter, prefix);
            return songView;
        }).collect(Collectors.toList());
        if (!songItems.isEmpty()) {
            songItems.add(0, songsHeader);
        }
        adaptableItems.addAll(songItems);
        return adaptableItems;
    }).observeOn(AndroidSchedulers.mainThread()).subscribe(adaptableItems -> {
        if (setItemsSubscription != null) {
            setItemsSubscription.unsubscribe();
        }
        setItemsSubscription = adapter.setItems(adaptableItems);
        recyclerView.scrollToPosition(0);
    }));
}
Also used : R(com.simplecity.amp_library.R) Bundle(android.os.Bundle) SongView(com.simplecity.amp_library.ui.modelviews.SongView) SearchView(android.support.v7.widget.SearchView) PlaylistUtils(com.simplecity.amp_library.utils.PlaylistUtils) WindowManager(android.view.WindowManager) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) Song(com.simplecity.amp_library.model.Song) RequestManager(com.bumptech.glide.RequestManager) Schedulers(rx.schedulers.Schedulers) View(android.view.View) SearchAdapter(com.simplecity.amp_library.ui.adapters.SearchAdapter) Header(com.simplecity.amp_library.model.Header) Playlist(com.simplecity.amp_library.model.Playlist) MenuItemCompat(android.support.v4.view.MenuItemCompat) SearchableInfo(android.app.SearchableInfo) PopupMenu(android.support.v7.widget.PopupMenu) SubMenu(android.view.SubMenu) SettingsManager(com.simplecity.amp_library.utils.SettingsManager) Serializable(java.io.Serializable) MusicUtils(com.simplecity.amp_library.utils.MusicUtils) List(java.util.List) AdaptableItem(com.simplecity.amp_library.model.AdaptableItem) SearchManager(android.app.SearchManager) Subscription(rx.Subscription) Context(android.content.Context) Album(com.simplecity.amp_library.model.Album) Stream(com.annimon.stream.Stream) Intent(android.content.Intent) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) Observable(rx.Observable) AlbumArtistView(com.simplecity.amp_library.ui.modelviews.AlbumArtistView) SuppressLint(android.annotation.SuppressLint) PrefixHighlighter(com.simplecity.amp_library.format.PrefixHighlighter) ThemeUtils(com.simplecity.amp_library.utils.ThemeUtils) ColorUtils(com.simplecity.amp_library.utils.ColorUtils) Toast(android.widget.Toast) Menu(android.view.Menu) SystemBarTintManager(com.readystatesoftware.systembartint.SystemBarTintManager) ActionBar(android.support.v7.app.ActionBar) ShuttleUtils(com.simplecity.amp_library.utils.ShuttleUtils) FastScrollRecyclerView(com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView) TaggerDialog(com.simplecity.amp_library.tagger.TaggerDialog) ViewType(com.simplecity.amp_library.ui.modelviews.ViewType) Collectors(com.annimon.stream.Collectors) SearchUtils(com.simplecity.amp_library.utils.SearchUtils) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) TextUtils(android.text.TextUtils) AlbumView(com.simplecity.amp_library.ui.modelviews.AlbumView) FLAG_TRANSLUCENT_STATUS(android.view.WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) DialogUtils(com.simplecity.amp_library.utils.DialogUtils) TimeUnit(java.util.concurrent.TimeUnit) CompositeSubscription(rx.subscriptions.CompositeSubscription) RecyclerView(android.support.v7.widget.RecyclerView) Glide(com.bumptech.glide.Glide) Toolbar(android.support.v7.widget.Toolbar) MultiSelector(com.bignerdranch.android.multiselector.MultiSelector) DataManager(com.simplecity.amp_library.utils.DataManager) RxSearchView(com.jakewharton.rxbinding.support.v7.widget.RxSearchView) AlbumArtist(com.simplecity.amp_library.model.AlbumArtist) SearchHeaderView(com.simplecity.amp_library.ui.modelviews.SearchHeaderView) Operators(com.simplecity.amp_library.utils.Operators) Activity(android.app.Activity) Collections(java.util.Collections) SongView(com.simplecity.amp_library.ui.modelviews.SongView) AlbumArtistView(com.simplecity.amp_library.ui.modelviews.AlbumArtistView) AlbumView(com.simplecity.amp_library.ui.modelviews.AlbumView) AdaptableItem(com.simplecity.amp_library.model.AdaptableItem) List(java.util.List) ArrayList(java.util.ArrayList)

Example 3 with AlbumArtist

use of com.simplecity.amp_library.model.AlbumArtist in project Shuttle by timusus.

the class SearchActivity method onItemClick.

@Override
public void onItemClick(View v, int position, Object item) {
    if (item instanceof AlbumArtist || item instanceof Album) {
        Intent intent = new Intent();
        intent.putExtra(MainActivity.ARG_MODEL, (Serializable) item);
        setResult(Activity.RESULT_OK, intent);
        finish();
    } else if (item instanceof Song) {
        List<Song> songs = new ArrayList<>();
        int curPos = 0;
        for (int i = 0, count = adapter.getItemCount(); i < count; i++) {
            Object aModel = adapter.getItem(i);
            if (aModel != null && aModel instanceof Song) {
                songs.add((Song) aModel);
                if (aModel.equals(item)) {
                    curPos = songs.size() - 1;
                }
            }
        }
        MusicUtils.playAll(songs, curPos, false, () -> {
            final String message = getString(R.string.emptyplaylist);
            Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
        });
        finish();
    }
}
Also used : Song(com.simplecity.amp_library.model.Song) Album(com.simplecity.amp_library.model.Album) Intent(android.content.Intent) List(java.util.List) ArrayList(java.util.ArrayList) AlbumArtist(com.simplecity.amp_library.model.AlbumArtist)

Example 4 with AlbumArtist

use of com.simplecity.amp_library.model.AlbumArtist in project Shuttle by timusus.

the class TaggerDialog method onCreate.

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Serializable model = getArguments().getSerializable(ARG_MODEL);
    if (model instanceof AlbumArtist) {
        albumArtist = (AlbumArtist) model;
        originalSongPaths = Stream.of(albumArtist.albums).flatMap(value -> Stream.of(value.paths)).collect(Collectors.toList());
        showAlbum = false;
        showTrack = false;
    } else if (model instanceof Album) {
        album = (Album) model;
        originalSongPaths = album.paths;
        showTrack = false;
    } else if (model instanceof Song) {
        song = (Song) model;
        originalSongPaths.add(song.path);
    }
    if (originalSongPaths == null || originalSongPaths.isEmpty()) {
        dismiss();
        //Todo: refine & extract
        Toast.makeText(getContext(), R.string.tag_retrieve_error, Toast.LENGTH_LONG).show();
    }
}
Also used : Serializable(java.io.Serializable) Song(com.simplecity.amp_library.model.Song) Album(com.simplecity.amp_library.model.Album) AlbumArtist(com.simplecity.amp_library.model.AlbumArtist)

Example 5 with AlbumArtist

use of com.simplecity.amp_library.model.AlbumArtist in project Shuttle by timusus.

the class AlbumArtistAdapter method getSectionName.

@NonNull
@Override
public String getSectionName(int position) {
    if (!(items.get(position) instanceof AlbumArtistView)) {
        return "";
    }
    int sortOrder = SortManager.getInstance().getArtistsSortOrder();
    AlbumArtist albumArtist = ((AlbumArtistView) items.get(position)).albumArtist;
    String string = null;
    switch(sortOrder) {
        case SortManager.ArtistSort.DEFAULT:
            string = StringUtils.keyFor(albumArtist.name);
            break;
        case SortManager.AlbumSort.ARTIST_NAME:
            string = albumArtist.name;
            break;
    }
    if (!TextUtils.isEmpty(string)) {
        string = string.substring(0, 1).toUpperCase();
    } else {
        string = " ";
    }
    return string;
}
Also used : AlbumArtistView(com.simplecity.amp_library.ui.modelviews.AlbumArtistView) AlbumArtist(com.simplecity.amp_library.model.AlbumArtist) NonNull(android.support.annotation.NonNull)

Aggregations

AlbumArtist (com.simplecity.amp_library.model.AlbumArtist)11 Album (com.simplecity.amp_library.model.Album)10 Song (com.simplecity.amp_library.model.Song)8 Serializable (java.io.Serializable)7 ArrayList (java.util.ArrayList)7 Intent (android.content.Intent)6 PopupMenu (android.support.v7.widget.PopupMenu)6 Playlist (com.simplecity.amp_library.model.Playlist)6 List (java.util.List)6 Context (android.content.Context)5 SubMenu (android.view.SubMenu)5 DialogUtils (com.simplecity.amp_library.utils.DialogUtils)5 BroadcastReceiver (android.content.BroadcastReceiver)4 Bundle (android.os.Bundle)4 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)4 RecyclerView (android.support.v7.widget.RecyclerView)4 Menu (android.view.Menu)4 MenuItem (android.view.MenuItem)4 View (android.view.View)4 AppCompatActivity (android.support.v7.app.AppCompatActivity)3