use of com.simplecity.amp_library.model.Song 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();
}
}
use of com.simplecity.amp_library.model.Song 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();
}
}
use of com.simplecity.amp_library.model.Song 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.Song in project Shuttle by timusus.
the class DrawerHeaderFragment method updateTrackInfo.
void updateTrackInfo() {
Song song = MusicUtils.getSong();
if (song != null) {
TextView trackNameView = (TextView) mRootView.findViewById(R.id.line1);
TextView artistNameView = (TextView) mRootView.findViewById(R.id.line2);
TextView placeholderText = (TextView) mRootView.findViewById(R.id.placeholder_text);
trackNameView.setText(song.name);
artistNameView.setText(String.format("%s - %s", song.albumArtistName, song.albumName));
placeholderText.setText(R.string.app_name);
Glide.with(getContext()).load(song).diskCacheStrategy(DiskCacheStrategy.ALL).error(mBackgroundDrawable).fallback(mBackgroundDrawable).into(mBackgroundImage);
Glide.with(getContext()).load(song.getAlbumArtist()).diskCacheStrategy(DiskCacheStrategy.ALL).placeholder(GlideUtils.getMediumPlaceHolderResId()).into(mArtistImage);
if (song.name == null || (song.albumName == null && song.albumArtistName == null)) {
placeholderText.setVisibility(View.VISIBLE);
trackNameView.setVisibility(View.GONE);
artistNameView.setVisibility(View.GONE);
} else {
placeholderText.setVisibility(View.GONE);
trackNameView.setVisibility(View.VISIBLE);
artistNameView.setVisibility(View.VISIBLE);
}
}
}
use of com.simplecity.amp_library.model.Song in project Shuttle by timusus.
the class FolderFragment method onItemClick.
@Override
public void onItemClick(View v, int position, BaseFileObject fileObject) {
if (!mInActionMode) {
if (fileObject.fileType == FileType.FILE) {
FileHelper.getSongList(new File(fileObject.path), false, true).observeOn(AndroidSchedulers.mainThread()).subscribe(songs -> {
int index = -1;
for (int i = 0, songsSize = songs.size(); i < songsSize; i++) {
Song song = songs.get(i);
if (song.path.contains(fileObject.path)) {
index = i;
break;
}
}
MusicUtils.playAll(songs, index, () -> {
final String message = getContext().getString(R.string.emptyplaylist);
Toast.makeText(getContext(), message, Toast.LENGTH_SHORT).show();
});
});
} else {
changeDir(new File(fileObject.path));
}
} else if (fileObject.fileType != FileType.FILE) {
changeDir(new File(fileObject.path));
}
}
Aggregations