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));
}
});
}
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);
}
}
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);
}
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));
}
});
}
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;
}
Aggregations