Search in sources :

Example 6 with AlbumArtist

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

the class MainController method onResume.

@Override
public void onResume() {
    super.onResume();
    if (delayHandler != null) {
        delayHandler.removeCallbacksAndMessages(null);
    }
    delayHandler = new Handler();
    disposables.add(navigationEventRelay.getEvents().observeOn(AndroidSchedulers.mainThread()).filter(NavigationEventRelay.NavigationEvent::isActionable).subscribe(navigationEvent -> {
        switch(navigationEvent.type) {
            case NavigationEventRelay.NavigationEvent.Type.LIBRARY_SELECTED:
                popToRootViewController();
                break;
            case NavigationEventRelay.NavigationEvent.Type.FOLDERS_SELECTED:
                delayHandler.postDelayed(() -> pushViewController(FolderFragment.newInstance(getString(R.string.folders_title), false), "FolderFragment"), 250);
                break;
            case NavigationEventRelay.NavigationEvent.Type.SLEEP_TIMER_SELECTED:
                UnsafeAction showToast = () -> Toast.makeText(getContext(), R.string.sleep_timer_started, Toast.LENGTH_SHORT).show();
                SleepTimer.getInstance().getDialog(getContext(), () -> SleepTimer.getInstance().showMinutesDialog(getContext(), showToast), showToast).show();
                break;
            case NavigationEventRelay.NavigationEvent.Type.EQUALIZER_SELECTED:
                delayHandler.postDelayed(() -> multiSheetEventRelay.sendEvent(new MultiSheetEventRelay.MultiSheetEvent(MultiSheetEventRelay.MultiSheetEvent.Action.HIDE, MultiSheetView.Sheet.FIRST)), 100);
                delayHandler.postDelayed(() -> pushViewController(EqualizerFragment.newInstance(), "EqualizerFragment"), 250);
                break;
            case NavigationEventRelay.NavigationEvent.Type.SETTINGS_SELECTED:
                delayHandler.postDelayed(() -> multiSheetEventRelay.sendEvent(new MultiSheetEventRelay.MultiSheetEvent(MultiSheetEventRelay.MultiSheetEvent.Action.HIDE, MultiSheetView.Sheet.FIRST)), 100);
                delayHandler.postDelayed(() -> pushViewController(SettingsParentFragment.newInstance(R.xml.settings_headers, R.string.settings), "Settings Fragment"), 250);
                break;
            case NavigationEventRelay.NavigationEvent.Type.SUPPORT_SELECTED:
                delayHandler.postDelayed(() -> multiSheetEventRelay.sendEvent(new MultiSheetEventRelay.MultiSheetEvent(MultiSheetEventRelay.MultiSheetEvent.Action.HIDE, MultiSheetView.Sheet.FIRST)), 100);
                delayHandler.postDelayed(() -> pushViewController(SettingsParentFragment.newInstance(R.xml.settings_support, R.string.pref_title_support), "Support Fragment"), 250);
                break;
            case NavigationEventRelay.NavigationEvent.Type.PLAYLIST_SELECTED:
                delayHandler.postDelayed(() -> pushViewController(PlaylistDetailFragment.newInstance((Playlist) navigationEvent.data), "PlaylistDetailFragment"), 250);
                break;
            case NavigationEventRelay.NavigationEvent.Type.GO_TO_ARTIST:
                multiSheetView.goToSheet(MultiSheetView.Sheet.NONE);
                AlbumArtist albumArtist = (AlbumArtist) navigationEvent.data;
                delayHandler.postDelayed(() -> {
                    popToRootViewController();
                    pushViewController(ArtistDetailFragment.newInstance(albumArtist, null), "ArtistDetailFragment");
                }, 250);
                break;
            case NavigationEventRelay.NavigationEvent.Type.GO_TO_ALBUM:
                multiSheetView.goToSheet(MultiSheetView.Sheet.NONE);
                Album album = (Album) navigationEvent.data;
                delayHandler.postDelayed(() -> {
                    popToRootViewController();
                    pushViewController(AlbumDetailFragment.newInstance(album, null), "AlbumDetailFragment");
                }, 250);
                break;
            case NavigationEventRelay.NavigationEvent.Type.GO_TO_GENRE:
                multiSheetView.goToSheet(MultiSheetView.Sheet.NONE);
                Genre genre = (Genre) navigationEvent.data;
                delayHandler.postDelayed(() -> {
                    popToRootViewController();
                    pushViewController(GenreDetailFragment.newInstance(genre), "GenreDetailFragment");
                }, 250);
                break;
        }
    }));
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(MusicService.InternalIntents.SERVICE_CONNECTED);
    intentFilter.addAction(MusicService.InternalIntents.QUEUE_CHANGED);
    disposables.add(RxBroadcast.fromBroadcast(getContext(), intentFilter).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(intent -> toggleBottomSheetVisibility(true, true)));
    DrawerLockManager.getInstance().setDrawerLockController(this);
}
Also used : R(com.simplecity.amp_library.R) Genre(com.simplecity.amp_library.model.Genre) Bundle(android.os.Bundle) SettingsParentFragment(com.simplecity.amp_library.ui.settings.SettingsParentFragment) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) BindView(butterknife.BindView) Handler(android.os.Handler) View(android.view.View) Schedulers(io.reactivex.schedulers.Schedulers) UnsafeAction(com.simplecity.amp_library.rx.UnsafeAction) LogUtils(com.simplecity.amp_library.utils.LogUtils) BackPressHandler(test.com.androidnavigation.fragment.BackPressHandler) Playlist(com.simplecity.amp_library.model.Playlist) IntentFilter(android.content.IntentFilter) Fragment(android.support.v4.app.Fragment) FragmentInfo(test.com.androidnavigation.fragment.FragmentInfo) CustomMultiSheetView(com.simplecity.amp_library.ui.views.multisheet.CustomMultiSheetView) RxBroadcast(com.cantrowitz.rxbroadcast.RxBroadcast) GenreDetailFragment(com.simplecity.amp_library.ui.detail.GenreDetailFragment) ViewGroup(android.view.ViewGroup) MusicUtils(com.simplecity.amp_library.utils.MusicUtils) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Nullable(android.support.annotation.Nullable) ArtistDetailFragment(com.simplecity.amp_library.ui.detail.ArtistDetailFragment) Album(com.simplecity.amp_library.model.Album) ButterKnife(butterknife.ButterKnife) AlbumDetailFragment(com.simplecity.amp_library.ui.detail.AlbumDetailFragment) DrawerLockManager(com.simplecity.amp_library.ui.drawer.DrawerLockManager) NonNull(android.support.annotation.NonNull) DrawerLockController(com.simplecity.amp_library.ui.drawer.DrawerLockController) UpNextView(com.simplecity.amp_library.ui.views.UpNextView) Inject(javax.inject.Inject) MultiSheetEventRelay(com.simplecity.amp_library.ui.views.multisheet.MultiSheetEventRelay) SleepTimer(com.simplecity.amp_library.utils.SleepTimer) Toast(android.widget.Toast) DrawerLayout(android.support.v4.widget.DrawerLayout) MiniPlayerLockManager(com.simplecity.amp_library.ui.drawer.MiniPlayerLockManager) MultiSheetView(com.simplecity.multisheetview.ui.view.MultiSheetView) LayoutInflater(android.view.LayoutInflater) DrawerProvider(com.simplecity.amp_library.ui.drawer.DrawerProvider) NavigationEventRelay(com.simplecity.amp_library.ui.drawer.NavigationEventRelay) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) MusicService(com.simplecity.amp_library.playback.MusicService) Pair(android.support.v4.util.Pair) PlaylistDetailFragment(com.simplecity.amp_library.ui.detail.PlaylistDetailFragment) AlbumArtist(com.simplecity.amp_library.model.AlbumArtist) BaseNavigationController(test.com.androidnavigation.fragment.BaseNavigationController) FragmentTransaction(android.support.v4.app.FragmentTransaction) IntentFilter(android.content.IntentFilter) UnsafeAction(com.simplecity.amp_library.rx.UnsafeAction) Playlist(com.simplecity.amp_library.model.Playlist) MultiSheetEventRelay(com.simplecity.amp_library.ui.views.multisheet.MultiSheetEventRelay) Handler(android.os.Handler) BackPressHandler(test.com.androidnavigation.fragment.BackPressHandler) Album(com.simplecity.amp_library.model.Album) Genre(com.simplecity.amp_library.model.Genre) AlbumArtist(com.simplecity.amp_library.model.AlbumArtist)

Example 7 with AlbumArtist

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

the class SearchPresenter method onAlbumArtistOverflowClicked.

@Override
public void onAlbumArtistOverflowClicked(View v, AlbumArtist albumArtist) {
    PopupMenu menu = new PopupMenu(v.getContext(), v);
    menu.inflate(R.menu.menu_artist);
    menu.setOnMenuItemClickListener(MenuUtils.getAlbumArtistClickListener(v.getContext(), albumArtist, taggerDialog -> {
        SearchView searchView = getView();
        if (searchView != null) {
            searchView.showTaggerDialog(taggerDialog);
        }
    }, deleteDialog -> {
        SearchView searchView = getView();
        if (searchView != null) {
            searchView.showDeleteDialog(deleteDialog);
        }
    }, null, () -> {
        SearchView searchView = getView();
        if (searchView != null) {
            searchView.showUpgradeDialog();
        }
    }));
    menu.show();
}
Also used : R(com.simplecity.amp_library.R) Album(com.simplecity.amp_library.model.Album) Stream(com.annimon.stream.Stream) SongView(com.simplecity.amp_library.ui.modelviews.SongView) ViewModel(com.simplecityapps.recycler_adapter.model.ViewModel) NonNull(android.support.annotation.NonNull) ViewType(com.simplecity.amp_library.ui.adapters.ViewType) StringUtils(com.simplecity.amp_library.utils.StringUtils) Single(io.reactivex.Single) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Song(com.simplecity.amp_library.model.Song) AlbumArtistView(com.simplecity.amp_library.ui.modelviews.AlbumArtistView) PrefixHighlighter(com.simplecity.amp_library.format.PrefixHighlighter) RequestManager(com.bumptech.glide.RequestManager) MenuUtils(com.simplecity.amp_library.utils.MenuUtils) View(android.view.View) ShuttleUtils(com.simplecity.amp_library.utils.ShuttleUtils) Header(com.simplecity.amp_library.model.Header) LogUtils(com.simplecity.amp_library.utils.LogUtils) ContextualToolbarHelper(com.simplecity.amp_library.utils.ContextualToolbarHelper) Collectors(com.annimon.stream.Collectors) SingleOperator(io.reactivex.SingleOperator) PopupMenu(android.support.v7.widget.PopupMenu) TextUtils(android.text.TextUtils) AlbumView(com.simplecity.amp_library.ui.modelviews.AlbumView) SettingsManager(com.simplecity.amp_library.utils.SettingsManager) Presenter(com.simplecity.amp_library.ui.presenters.Presenter) MusicUtils(com.simplecity.amp_library.utils.MusicUtils) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) List(java.util.List) Disposable(io.reactivex.disposables.Disposable) SingleObserver(io.reactivex.SingleObserver) DataManager(com.simplecity.amp_library.utils.DataManager) AlbumArtist(com.simplecity.amp_library.model.AlbumArtist) SearchHeaderView(com.simplecity.amp_library.ui.modelviews.SearchHeaderView) Nullable(android.support.annotation.Nullable) Operators(com.simplecity.amp_library.utils.Operators) Collections(java.util.Collections) PopupMenu(android.support.v7.widget.PopupMenu)

Example 8 with AlbumArtist

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

the class VoiceSearchActivity method searchAndPlaySongs.

private void searchAndPlaySongs() {
    DataManager.getInstance().getAlbumArtistsRelay().first(Collections.emptyList()).flatMapObservable(Observable::fromIterable).filter(albumArtist -> albumArtist.name.toLowerCase(Locale.getDefault()).contains(filterString.toLowerCase())).flatMapSingle(AlbumArtist::getSongsSingle).map(songs -> {
        Collections.sort(songs, (a, b) -> a.getAlbumArtist().compareTo(b.getAlbumArtist()));
        Collections.sort(songs, (a, b) -> a.getAlbum().compareTo(b.getAlbum()));
        Collections.sort(songs, (a, b) -> ComparisonUtils.compareInt(a.track, b.track));
        Collections.sort(songs, (a, b) -> ComparisonUtils.compareInt(a.discNumber, b.discNumber));
        return songs;
    });
    // Search for album-artists, albums & songs matching our filter. Then, create an Observable emitting List<Song> for each type of result.
    // Then we concat the results, and return the first one which is non-empty. Order is important here, we want album-artist first, if it's
    // available, then albums, then songs.
    Observable.concat(// If we have an album artist matching our query, then play the songs by that album artist
    DataManager.getInstance().getAlbumArtistsRelay().first(Collections.emptyList()).flatMapObservable(Observable::fromIterable).filter(albumArtist -> albumArtist.name.toLowerCase(Locale.getDefault()).contains(filterString.toLowerCase())).flatMapSingle(AlbumArtist::getSongsSingle).map(songs -> {
        Collections.sort(songs, (a, b) -> a.getAlbumArtist().compareTo(b.getAlbumArtist()));
        Collections.sort(songs, (a, b) -> a.getAlbum().compareTo(b.getAlbum()));
        Collections.sort(songs, (a, b) -> ComparisonUtils.compareInt(a.track, b.track));
        Collections.sort(songs, (a, b) -> ComparisonUtils.compareInt(a.discNumber, b.discNumber));
        return songs;
    }), // If we have an album matching our query, then play the songs from that album
    DataManager.getInstance().getAlbumsRelay().first(Collections.emptyList()).flatMapObservable(Observable::fromIterable).filter(album -> containsIgnoreCase(album.name, filterString) || containsIgnoreCase(album.name, filterString) || (Stream.of(album.artists).anyMatch(artist -> containsIgnoreCase(artist.name, filterString))) || containsIgnoreCase(album.albumArtistName, filterString)).flatMapSingle(Album::getSongsSingle).map(songs -> {
        Collections.sort(songs, (a, b) -> a.getAlbum().compareTo(b.getAlbum()));
        Collections.sort(songs, (a, b) -> ComparisonUtils.compareInt(a.track, b.track));
        Collections.sort(songs, (a, b) -> ComparisonUtils.compareInt(a.discNumber, b.discNumber));
        return songs;
    }), // If have a song, play that song, as well as others from the same album.
    DataManager.getInstance().getSongsRelay().first(Collections.emptyList()).flatMapObservable(Observable::fromIterable).filter(song -> containsIgnoreCase(song.name, filterString) || containsIgnoreCase(song.albumName, filterString) || containsIgnoreCase(song.artistName, filterString) || containsIgnoreCase(song.albumArtistName, filterString)).flatMapSingle(song -> song.getAlbum().getSongsSingle().map(songs -> {
        Collections.sort(songs, (a, b) -> ComparisonUtils.compareInt(a.track, b.track));
        Collections.sort(songs, (a, b) -> ComparisonUtils.compareInt(a.discNumber, b.discNumber));
        position = songs.indexOf(song);
        return songs;
    }))).filter(songs -> !songs.isEmpty()).firstOrError().observeOn(AndroidSchedulers.mainThread()).subscribe(songs -> {
        if (songs != null) {
            MusicUtils.playAll(songs, position, true, (String message) -> Toast.makeText(this, message, Toast.LENGTH_SHORT).show());
            startActivity(new Intent(this, MainActivity.class));
        }
        finish();
    }, error -> {
        LogUtils.logException(TAG, "Error attempting to playAll()", error);
        startActivity(new Intent(this, MainActivity.class));
        finish();
    });
}
Also used : LogUtils(com.simplecity.amp_library.utils.LogUtils) BaseActivity(com.simplecity.amp_library.ui.activities.BaseActivity) Bundle(android.os.Bundle) Album(com.simplecity.amp_library.model.Album) Stream(com.annimon.stream.Stream) ComponentName(android.content.ComponentName) MainActivity(com.simplecity.amp_library.ui.activities.MainActivity) Intent(android.content.Intent) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) IBinder(android.os.IBinder) MusicUtils(com.simplecity.amp_library.utils.MusicUtils) StringUtils.containsIgnoreCase(com.simplecity.amp_library.utils.StringUtils.containsIgnoreCase) Locale(java.util.Locale) Toast(android.widget.Toast) ComparisonUtils(com.simplecity.amp_library.utils.ComparisonUtils) DataManager(com.simplecity.amp_library.utils.DataManager) AlbumArtist(com.simplecity.amp_library.model.AlbumArtist) Observable(io.reactivex.Observable) SearchManager(android.app.SearchManager) Collections(java.util.Collections) Album(com.simplecity.amp_library.model.Album) Intent(android.content.Intent) MainActivity(com.simplecity.amp_library.ui.activities.MainActivity) Observable(io.reactivex.Observable) AlbumArtist(com.simplecity.amp_library.model.AlbumArtist)

Example 9 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)).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 10 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)

Aggregations

AlbumArtist (com.simplecity.amp_library.model.AlbumArtist)17 Album (com.simplecity.amp_library.model.Album)13 Song (com.simplecity.amp_library.model.Song)10 MusicUtils (com.simplecity.amp_library.utils.MusicUtils)10 Bundle (android.os.Bundle)9 PopupMenu (android.support.v7.widget.PopupMenu)9 View (android.view.View)9 R (com.simplecity.amp_library.R)9 DataManager (com.simplecity.amp_library.utils.DataManager)9 Collections (java.util.Collections)9 Stream (com.annimon.stream.Stream)8 Context (android.content.Context)7 LayoutInflater (android.view.LayoutInflater)7 MenuItem (android.view.MenuItem)7 SubMenu (android.view.SubMenu)7 ViewGroup (android.view.ViewGroup)7 Toast (android.widget.Toast)7 RequestManager (com.bumptech.glide.RequestManager)7 Playlist (com.simplecity.amp_library.model.Playlist)7 Menu (android.view.Menu)6