Search in sources :

Example 6 with Playlist

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

the class PlaylistUtils method removeFromFavorites.

public static void removeFromFavorites(Context context) {
    Song song = MusicUtils.getSong();
    if (song == null) {
        return;
    }
    Observable.fromCallable(() -> {
        Playlist favoritesPlaylist = Playlist.favoritesPlaylist();
        if (favoritesPlaylist.id >= 0) {
            final Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external", favoritesPlaylist.id);
            return context.getContentResolver().delete(uri, MediaStore.Audio.Playlists.Members.AUDIO_ID + "=" + song.id, null);
        }
        return 0;
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(numTracksAdded -> {
        if (numTracksAdded > 0) {
            Toast.makeText(context, context.getResources().getString(R.string.song_removed_from_favourites, song.name), Toast.LENGTH_SHORT).show();
            LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent(MusicService.InternalIntents.FAVORITE_CHANGED));
        }
    });
}
Also used : Song(com.simplecity.amp_library.model.Song) Playlist(com.simplecity.amp_library.model.Playlist) Intent(android.content.Intent) Uri(android.net.Uri)

Example 7 with Playlist

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

the class PlaylistUtils method clearFavorites.

/**
     * Removes all entries from the 'favorites' playlist
     */
public static void clearFavorites(Context context) {
    Playlist favoritesPlaylist = Playlist.favoritesPlaylist();
    if (favoritesPlaylist.id >= 0) {
        final Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external", favoritesPlaylist.id);
        context.getContentResolver().delete(uri, null, null);
    }
}
Also used : Playlist(com.simplecity.amp_library.model.Playlist) Uri(android.net.Uri)

Example 8 with Playlist

use of com.simplecity.amp_library.model.Playlist 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 9 with Playlist

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

the class PlaylistFragment method refreshAdapterItems.

private void refreshAdapterItems() {
    PermissionUtils.RequestStoragePermissions(() -> {
        if (getActivity() != null && isAdded()) {
            Observable<List<Playlist>> defaultPlaylistsObservable = Observable.defer(() -> {
                List<Playlist> playlists = new ArrayList<>();
                Playlist podcastPlaylist = Playlist.podcastPlaylist();
                if (podcastPlaylist != null) {
                    playlists.add(podcastPlaylist);
                }
                playlists.add(Playlist.recentlyAddedPlaylist);
                playlists.add(Playlist.mostPlayedPlaylist);
                return Observable.just(playlists);
            });
            Observable<List<Playlist>> playlistsObservable = DataManager.getInstance().getPlaylistsRelay();
            disposable = Observable.combineLatest(defaultPlaylistsObservable, playlistsObservable, (defaultPlaylists, playlists) -> {
                List<Playlist> list = new ArrayList<>();
                list.addAll(defaultPlaylists);
                list.addAll(playlists);
                return list;
            }).debounce(150, TimeUnit.MILLISECONDS).subscribeOn(Schedulers.io()).map(playlists -> {
                PlaylistView.OnClickListener listener = new PlaylistView.OnClickListener() {

                    @Override
                    public void onPlaylistClick(int position, PlaylistView playlistView) {
                        if (playlistClickListener != null) {
                            playlistClickListener.onPlaylistClicked(playlistView.playlist);
                        }
                    }

                    @Override
                    public void onPlaylistOverflowClick(int position, View v, Playlist playlist) {
                        PopupMenu menu = new PopupMenu(PlaylistFragment.this.getActivity(), v);
                        MenuUtils.setupPlaylistMenu(menu, playlist);
                        menu.setOnMenuItemClickListener(MenuUtils.getPlaylistPopupMenuClickListener(getContext(), playlist, null));
                        menu.show();
                    }
                };
                return Stream.of(playlists).sorted((a, b) -> ComparisonUtils.compare(a.name, b.name)).sorted((a, b) -> ComparisonUtils.compareInt(a.type, b.type)).map(playlist -> {
                    PlaylistView playlistView = new PlaylistView(playlist);
                    playlistView.setListener(listener);
                    return (ViewModel) playlistView;
                }).toList();
            }).observeOn(AndroidSchedulers.mainThread()).subscribe(items -> {
                if (items.isEmpty()) {
                    adapter.setItems(Collections.singletonList(new EmptyView(R.string.empty_playlist)));
                } else {
                    adapter.setItems(items);
                }
            }, error -> LogUtils.logException(TAG, "Error refreshing adapter", error));
        }
    });
}
Also used : R(com.simplecity.amp_library.R) Context(android.content.Context) Bundle(android.os.Bundle) Stream(com.annimon.stream.Stream) RecyclerListener(com.simplecityapps.recycler_adapter.recyclerview.RecyclerListener) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) ViewModelAdapter(com.simplecityapps.recycler_adapter.adapter.ViewModelAdapter) ViewModel(com.simplecityapps.recycler_adapter.model.ViewModel) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) ArrayList(java.util.ArrayList) MenuUtils(com.simplecity.amp_library.utils.MenuUtils) PlaylistView(com.simplecity.amp_library.ui.modelviews.PlaylistView) View(android.view.View) Observable(io.reactivex.Observable) Schedulers(io.reactivex.schedulers.Schedulers) FastScrollRecyclerView(com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView) LogUtils(com.simplecity.amp_library.utils.LogUtils) LayoutInflater(android.view.LayoutInflater) Playlist(com.simplecity.amp_library.model.Playlist) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) PopupMenu(android.support.v7.widget.PopupMenu) ViewGroup(android.view.ViewGroup) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Disposable(io.reactivex.disposables.Disposable) PermissionUtils(com.simplecity.amp_library.utils.PermissionUtils) ComparisonUtils(com.simplecity.amp_library.utils.ComparisonUtils) DataManager(com.simplecity.amp_library.utils.DataManager) Nullable(android.support.annotation.Nullable) Collections(java.util.Collections) ArrayList(java.util.ArrayList) ViewModel(com.simplecityapps.recycler_adapter.model.ViewModel) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) PlaylistView(com.simplecity.amp_library.ui.modelviews.PlaylistView) View(android.view.View) FastScrollRecyclerView(com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView) Playlist(com.simplecity.amp_library.model.Playlist) PlaylistView(com.simplecity.amp_library.ui.modelviews.PlaylistView) ArrayList(java.util.ArrayList) List(java.util.List) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) PopupMenu(android.support.v7.widget.PopupMenu)

Example 10 with Playlist

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

the class MainActivity method handlePlaybackRequest.

@SuppressLint("CheckResult")
private void handlePlaybackRequest(Intent intent) {
    if (intent == null) {
        return;
    } else if (MusicServiceConnectionUtils.serviceBinder == null) {
        hasPendingPlaybackRequest = true;
        return;
    }
    final Uri uri = intent.getData();
    final String mimeType = intent.getType();
    if (uri != null && uri.toString().length() > 0) {
        MusicUtils.playFile(uri);
        // Make sure to process intent only once
        setIntent(new Intent());
    } else if (MediaStore.Audio.Playlists.CONTENT_TYPE.equals(mimeType)) {
        long id = parseIdFromIntent(intent, "playlistId", "playlist");
        if (id >= 0) {
            Query query = Playlist.getQuery();
            query.uri = ContentUris.withAppendedId(query.uri, id);
            SqlBriteUtils.createSingle(this, Playlist::new, query, null).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(playlist -> {
                MusicUtils.playAll(playlist.getSongsObservable().first(new ArrayList<>()), message -> Toast.makeText(this, message, Toast.LENGTH_SHORT).show());
                // Make sure to process intent only once
                setIntent(new Intent());
            }, error -> LogUtils.logException(TAG, "Error handling playback request", error));
        }
    }
    hasPendingPlaybackRequest = false;
}
Also used : R(com.simplecity.amp_library.R) MusicServiceConnectionUtils(com.simplecity.amp_library.utils.MusicServiceConnectionUtils) Bundle(android.os.Bundle) PlaylistUtils(com.simplecity.amp_library.utils.PlaylistUtils) Uri(android.net.Uri) Intent(android.content.Intent) NonNull(android.support.annotation.NonNull) AnalyticsManager(com.simplecity.amp_library.utils.AnalyticsManager) Single(io.reactivex.Single) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) IBinder(android.os.IBinder) ArrayList(java.util.ArrayList) GravityCompat(android.support.v4.view.GravityCompat) Inject(javax.inject.Inject) SuppressLint(android.annotation.SuppressLint) Aesthetic(com.afollestad.aesthetic.Aesthetic) ChangelogDialog(com.simplecity.amp_library.ui.dialog.ChangelogDialog) ThemeUtils(com.simplecity.amp_library.utils.ThemeUtils) MediaStore(android.provider.MediaStore) Toast(android.widget.Toast) View(android.view.View) MainController(com.simplecity.amp_library.ui.fragments.MainController) Schedulers(io.reactivex.schedulers.Schedulers) Build(android.os.Build) BackPressListener(test.com.androidnavigation.fragment.BackPressListener) DrawerLayout(android.support.v4.widget.DrawerLayout) Log(android.util.Log) LogUtils(com.simplecity.amp_library.utils.LogUtils) SqlBriteUtils(com.simplecity.amp_library.sql.sqlbrite.SqlBriteUtils) BackPressHandler(test.com.androidnavigation.fragment.BackPressHandler) ComponentName(android.content.ComponentName) Playlist(com.simplecity.amp_library.model.Playlist) DrawerProvider(com.simplecity.amp_library.ui.drawer.DrawerProvider) NavigationEventRelay(com.simplecity.amp_library.ui.drawer.NavigationEventRelay) BuildConfig(com.simplecity.amp_library.BuildConfig) SettingsManager(com.simplecity.amp_library.utils.SettingsManager) Query(com.simplecity.amp_library.model.Query) MusicUtils(com.simplecity.amp_library.utils.MusicUtils) TimeUnit(java.util.concurrent.TimeUnit) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) List(java.util.List) Toolbar(android.support.v7.widget.Toolbar) MusicService(com.simplecity.amp_library.playback.MusicService) Permiso(com.greysonparrelli.permiso.Permiso) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) ContentUris(android.content.ContentUris) Playlist(com.simplecity.amp_library.model.Playlist) Query(com.simplecity.amp_library.model.Query) Intent(android.content.Intent) Uri(android.net.Uri) SuppressLint(android.annotation.SuppressLint)

Aggregations

Playlist (com.simplecity.amp_library.model.Playlist)35 Intent (android.content.Intent)22 View (android.view.View)19 List (java.util.List)19 Uri (android.net.Uri)17 R (com.simplecity.amp_library.R)17 Song (com.simplecity.amp_library.model.Song)17 Context (android.content.Context)16 LayoutInflater (android.view.LayoutInflater)16 Toast (android.widget.Toast)16 SubMenu (android.view.SubMenu)15 Stream (com.annimon.stream.Stream)15 ContentUris (android.content.ContentUris)14 MediaStore (android.provider.MediaStore)14 TextView (android.widget.TextView)14 ArrayList (java.util.ArrayList)14 Query (com.simplecity.amp_library.model.Query)12 TimeUnit (java.util.concurrent.TimeUnit)12 NonNull (android.support.annotation.NonNull)11 Collections (java.util.Collections)11