use of com.simplecity.amp_library.model.Playlist in project Shuttle by timusus.
the class DetailFragment method refreshAdapterItems.
void refreshAdapterItems() {
PermissionUtils.RequestStoragePermissions(() -> {
if (getActivity() != null && isAdded()) {
boolean albumsAscending = getAlbumsAscending();
boolean songsAscending = getSongsAscending();
@SortManager.SongSort int songSort = getSongsSortOrder();
@SortManager.AlbumSort int albumSort = getAlbumsSortOrder();
Observable<List<Song>> observable = null;
if (albumArtist != null) {
observable = DataManager.getInstance().getSongsRelay().first().map(songs -> Stream.of(songs).filter(song -> Stream.of(albumArtist.albums).anyMatch(album1 -> album1.id == song.albumId)).collect(Collectors.toList()));
} else if (album != null) {
observable = DataManager.getInstance().getSongsRelay().first().map(songs -> Stream.of(songs).filter(song -> song.albumId == album.id).collect(Collectors.toList()));
} else if (genre != null) {
observable = genre.getSongsObservable(getContext());
} else if (playlist != null) {
observable = playlist.getSongsObservable(getContext());
}
subscriptions.add(observable.map(songs -> {
songs = Stream.of(songs).filter(song -> {
if (albumArtist != null) {
return Stream.of(albumArtist.albums).anyMatch(album -> album.id == song.albumId);
} else if (album != null) {
return song.albumId == album.id;
}
return true;
}).collect(Collectors.toList());
List<Album> albums = Stream.of(Operators.songsToAlbums(songs)).collect(Collectors.toList());
if (playlist != null && albumSort == SortManager.AlbumSort.DEFAULT) {
switch(playlist.type) {
case Playlist.Type.MOST_PLAYED:
Collections.sort(albums, (a, b) -> ComparisonUtils.compareInt(b.songPlayCount, a.songPlayCount));
break;
case Playlist.Type.RECENTLY_PLAYED:
Collections.sort(albums, (a, b) -> ComparisonUtils.compareLong(b.lastPlayed, a.lastPlayed));
break;
case Playlist.Type.RECENTLY_ADDED:
Collections.sort(albums, (a, b) -> ComparisonUtils.compareLong(b.dateAdded, a.dateAdded));
break;
case Playlist.Type.USER_CREATED:
case Playlist.Type.FAVORITES:
case Playlist.Type.PODCAST:
Collections.sort(albums, (a, b) -> ComparisonUtils.compare(a.name, b.name));
break;
}
} else {
SortManager.getInstance().sortAlbums(albums, albumSort);
if (!albumsAscending) {
Collections.reverse(albums);
}
}
if (playlist == null || songSort != SortManager.SongSort.DETAIL_DEFAULT) {
SortManager.getInstance().sortSongs(songs, songSort);
if (!songsAscending) {
Collections.reverse(songs);
}
}
if (album == null) {
List<AdaptableItem> items = Stream.of(albums).map(album -> new HorizontalAlbumView(album, requestManager)).collect(Collectors.toList());
horizontalRecyclerView.setItems(items);
}
List<AdaptableItem> songViews = Stream.of(songs).map(song -> {
SongView songView = new SongView(song, multiSelector, requestManager);
songView.setShowAlbumArt(false);
songView.setEditable(canEdit());
songView.setShowTrackNumber(album != null && (songSort == SortManager.SongSort.DETAIL_DEFAULT || songSort == SortManager.SongSort.TRACK_NUMBER));
return songView;
}).collect(Collectors.toList());
if (album != null && album.numDiscs > 1 && (songSort == SortManager.SongSort.DETAIL_DEFAULT || songSort == SortManager.SongSort.TRACK_NUMBER)) {
int discNumber = 0;
int length = songViews.size();
for (int i = 0; i < length; i++) {
SongView songView = (SongView) songViews.get(i);
if (discNumber != songView.song.discNumber) {
discNumber = songView.song.discNumber;
songViews.add(i, new DiscNumberView(discNumber));
}
}
}
List<AdaptableItem> adaptableItems = new ArrayList<>();
adaptableItems.add(headerItem);
if (album == null) {
adaptableItems.add(horizontalRecyclerView);
}
adaptableItems.addAll(songViews);
return adaptableItems;
}).observeOn(AndroidSchedulers.mainThread()).subscribe(adaptableItems -> {
if (adaptableItems.isEmpty()) {
adapter.setEmpty(new EmptyView(R.string.empty_songlist));
} else {
if (sortChanged) {
adapter.items.clear();
adapter.items = adaptableItems;
adapter.notifyDataSetChanged();
recyclerView.smoothScrollToPosition(0);
sortChanged = false;
} else {
adapter.setItems(adaptableItems);
}
}
int numSongs = (int) Stream.of(adaptableItems).filter(value -> value instanceof SongView).count();
int numAlbums = horizontalRecyclerView.getCount();
if (lineTwo != null) {
if (albumArtist != null) {
lineTwo.setText(StringUtils.makeAlbumAndSongsLabel(getActivity(), numAlbums, albumArtist.getNumSongs()));
} else if (album != null) {
lineTwo.setText(String.format("%s%s", album.getAlbumArtist().name, numSongs > 0 ? " | " + album.getNumSongsLabel() : ""));
} else if (genre != null) {
lineTwo.setText(StringUtils.makeAlbumAndSongsLabel(getActivity(), numAlbums, numSongs));
} else if (playlist != null) {
lineTwo.setText(StringUtils.makeAlbumAndSongsLabel(getActivity(), numAlbums, numSongs));
}
}
List<Album> albums = Stream.of(adaptableItems).filter(adaptableItem -> adaptableItem instanceof SongView).map(songView -> (Song) songView.getItem()).map(Song::getAlbum).distinct().collect(Collectors.toList());
if (playlist != null || genre != null && !albums.isEmpty()) {
if (slideShowObservable != null && !slideShowObservable.isUnsubscribed()) {
slideShowObservable.unsubscribe();
}
slideShowObservable = Observable.interval(8, TimeUnit.SECONDS).onBackpressureDrop().startWith(0L).map(aLong -> {
if (albums.isEmpty() || aLong == 0L && currentSlideShowAlbum != null) {
return null;
}
return albums.get(new Random().nextInt(albums.size()));
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(nextSlideShowAlbum -> {
if (nextSlideShowAlbum != null && nextSlideShowAlbum != currentSlideShowAlbum) {
requestManager.load(nextSlideShowAlbum).diskCacheStrategy(DiskCacheStrategy.SOURCE).priority(Priority.HIGH).error(GlideUtils.getPlaceHolderDrawable(nextSlideShowAlbum.name, true)).centerCrop().thumbnail(Glide.with(this).load(currentSlideShowAlbum).centerCrop()).animate(new AlwaysCrossFade(false)).into(headerImageView);
currentSlideShowAlbum = nextSlideShowAlbum;
}
});
subscriptions.add(slideShowObservable);
}
}));
}
});
}
use of com.simplecity.amp_library.model.Playlist in project Shuttle by timusus.
the class DetailFragment method onCreate.
@Override
public void onCreate(final Bundle icicle) {
super.onCreate(icicle);
setHasOptionsMenu(true);
setEnterSharedElementCallback(enterSharedElementCallback);
prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
Serializable object = getArguments().getSerializable(ARG_MODEL);
if (object instanceof AlbumArtist) {
albumArtist = (AlbumArtist) object;
} else if (object instanceof Album) {
album = (Album) object;
} else if (object instanceof Genre) {
genre = (Genre) object;
} else if (object instanceof Playlist) {
playlist = (Playlist) object;
}
if (adapter == null) {
adapter = new DetailAdapter();
adapter.setListener(this);
}
receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction() != null && intent.getAction().equals("restartLoader")) {
refreshAdapterItems();
}
}
};
sharedPreferenceChangeListener = (sharedPreferences, key) -> {
if (key.equals("pref_theme_highlight_color") || key.equals("pref_theme_accent_color") || key.equals("pref_theme_white_accent")) {
themeUIComponents();
} else if (key.equals("songWhitelist")) {
refreshAdapterItems();
}
};
prefs.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
if (requestManager == null) {
requestManager = Glide.with(this);
}
if (headerItem == null) {
headerItem = new HeaderView();
}
if (horizontalRecyclerView == null) {
horizontalRecyclerView = new HorizontalRecyclerView();
horizontalRecyclerView.setListener(this);
}
}
use of com.simplecity.amp_library.model.Playlist in project Shuttle by timusus.
the class PlayerActivity method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
return true;
}
if (item.getItemId() == R.id.menu_favorite) {
PlaylistUtils.toggleFavorite(this);
supportInvalidateOptionsMenu();
return true;
}
if (item.getItemId() == R.id.menu_list) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.setCustomAnimations(R.anim.abc_fade_in, R.anim.abc_fade_out, R.anim.abc_fade_in, R.anim.abc_fade_out);
//Remove the lyrics fragment
Fragment lyricsFragment = getSupportFragmentManager().findFragmentByTag(LYRICS_FRAGMENT);
if (lyricsFragment != null) {
ft.remove(lyricsFragment);
}
Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.queue_container);
if (fragment instanceof QueueFragment) {
ft.remove(getSupportFragmentManager().findFragmentByTag(QUEUE_FRAGMENT));
} else {
ft.add(R.id.queue_container, QueueFragment.newInstance(), QUEUE_FRAGMENT);
}
ft.commit();
return true;
}
switch(item.getItemId()) {
case EQUALIZER:
{
final Intent equalizerIntent = new Intent(this, EqualizerActivity.class);
startActivity(equalizerIntent);
return true;
}
case OPTIONS:
{
startActivity(new Intent(this, SettingsActivity.class));
return true;
}
case TIMER:
{
SleepTimer.createTimer(this, MusicUtils.getTimerActive(), MusicUtils.getTimeRemaining());
return true;
}
case DELETE_ITEM:
{
new DialogUtils.DeleteDialogBuilder().context(this).singleMessageId(R.string.delete_song_desc).multipleMessage(R.string.delete_song_desc_multiple).itemNames(Collections.singletonList(MusicUtils.getSongName())).songsToDelete(Observable.just(Collections.singletonList(MusicUtils.getSong()))).build().show();
return true;
}
case NEW_PLAYLIST:
{
PlaylistUtils.createPlaylistDialog(this, MusicUtils.getQueue());
return true;
}
case PLAYLIST_SELECTED:
{
List<Song> songs = MusicUtils.getQueue();
Playlist playlist = (Playlist) item.getIntent().getSerializableExtra(ShuttleUtils.ARG_PLAYLIST);
PlaylistUtils.addToPlaylist(this, playlist, songs);
return true;
}
case CLEAR_QUEUE:
{
MusicUtils.clearQueue();
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
return true;
}
case TAGGER:
{
TaggerDialog.newInstance(MusicUtils.getSong()).show(getSupportFragmentManager());
return true;
}
case VIEW_INFO:
{
DialogUtils.showSongInfoDialog(this, MusicUtils.getSong());
return true;
}
}
if (item.getItemId() == R.id.menu_share) {
String path = MusicUtils.getFilePath();
if (!TextUtils.isEmpty(path)) {
DialogUtils.showShareDialog(PlayerActivity.this, MusicUtils.getSong());
}
return true;
}
return false;
}
use of com.simplecity.amp_library.model.Playlist in project Shuttle by timusus.
the class NavigationDrawerAdapter method getRealChildView.
@Override
public View getRealChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
final ChildViewHolder viewHolder;
if (convertView == null) {
convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_drawer, parent, false);
viewHolder = new ChildViewHolder(convertView);
convertView.setTag(viewHolder);
} else {
viewHolder = (ChildViewHolder) convertView.getTag();
}
DrawerGroupItem groupItem = getGroup(groupPosition);
Playlist playlist = groupItem.children.get(childPosition);
if (playlist != null && mSelectedPlaylist != null) {
if (playlist.name.equals(mSelectedPlaylist.name)) {
if (ColorUtils.isPrimaryColorLowContrast(parent.getContext())) {
viewHolder.lineOne.setTextColor(ColorUtils.getAccentColor());
} else {
viewHolder.lineOne.setTextColor(ColorUtils.getPrimaryColor());
}
} else {
viewHolder.lineOne.setTextColor(ColorUtils.getTextColorPrimary());
}
}
convertView.setClickable(true);
viewHolder.groupPosition = groupPosition;
viewHolder.childPosition = childPosition;
viewHolder.expandableIcon.setVisibility(View.GONE);
viewHolder.lineOne.setText(playlist.name);
viewHolder.lineOne.setAlpha(0.54f);
return convertView;
}
use of com.simplecity.amp_library.model.Playlist in project Shuttle by timusus.
the class PlaylistUtils method renamePlaylistDialog.
public static void renamePlaylistDialog(final Context context, final Playlist playlist, final MaterialDialog.SingleButtonCallback listener) {
View customView = LayoutInflater.from(context).inflate(R.layout.dialog_playlist, null);
final CustomEditText editText = (CustomEditText) customView.findViewById(R.id.editText);
editText.setText(playlist.name);
MaterialDialog.Builder builder = DialogUtils.getBuilder(context).title(R.string.create_playlist_create_text_prompt).customView(customView, false).positiveText(R.string.save).onPositive((materialDialog, dialogAction) -> {
String name = editText.getText().toString();
if (name.length() > 0) {
ContentResolver resolver = context.getContentResolver();
ContentValues values = new ContentValues(1);
values.put(MediaStore.Audio.Playlists.NAME, name);
resolver.update(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, values, MediaStore.Audio.Playlists._ID + "=?", new String[] { Long.valueOf(playlist.id).toString() });
playlist.name = name;
Toast.makeText(context, R.string.playlist_renamed_message, Toast.LENGTH_SHORT).show();
}
if (listener != null) {
listener.onClick(materialDialog, dialogAction);
}
}).negativeText(R.string.cancel);
final MaterialDialog dialog = builder.build();
TextWatcher textWatcher = new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
// check if playlist with current name exists already, and warn the user if so.
setSaveButton(dialog, playlist, editText.getText().toString());
}
public void afterTextChanged(Editable s) {
}
};
editText.addTextChangedListener(textWatcher);
dialog.show();
}
Aggregations