use of com.simplecity.amp_library.model.Genre 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.Genre 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.Genre 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.Genre in project Shuttle by timusus.
the class DetailFragment method onClick.
@Override
public void onClick(View v) {
switch(v.getId()) {
case R.id.fab:
if (albumArtist != null) {
MusicUtils.shuffleAll(getActivity(), albumArtist.getSongsObservable());
} else if (album != null) {
MusicUtils.shuffleAll(getActivity(), album.getSongsObservable());
} else if (genre != null) {
MusicUtils.shuffleAll(getActivity(), genre.getSongsObservable(getContext()));
} else if (playlist != null) {
MusicUtils.shuffleAll(getActivity(), playlist.getSongsObservable(getContext()));
}
break;
case R.id.btn_overflow:
final PopupMenu menu = new PopupMenu(getActivity(), v);
if (album != null) {
MenuUtils.addAlbumMenuOptions(getActivity(), menu);
MenuUtils.addClickHandler((AppCompatActivity) getActivity(), menu, album);
menu.getMenu().add(ALBUM_FRAGMENT_GROUP_ID, VIEW_INFO, Menu.NONE, R.string.info);
} else if (albumArtist != null) {
MenuUtils.addAlbumArtistMenuOptions(getActivity(), menu);
MenuUtils.addClickHandler((AppCompatActivity) getActivity(), menu, albumArtist);
menu.getMenu().add(ALBUM_FRAGMENT_GROUP_ID, VIEW_INFO, Menu.NONE, R.string.info);
} else if (genre != null) {
} else if (playlist != null) {
MenuUtils.addPlaylistMenuOptions(menu, playlist);
//Remove the delete menu option, since we're looking at the playlist we would delete.
if (menu.getMenu().findItem(MusicUtils.PlaylistMenuOrder.DELETE_PLAYLIST) != null) {
menu.getMenu().removeItem(MusicUtils.PlaylistMenuOrder.DELETE_PLAYLIST);
}
MenuUtils.addClickHandler(getActivity(), menu, playlist, (materialDialog, dialogAction) -> {
//The user might have changed the playlist name
lineOne.setText(playlist.name);
}, (materialDialog, dialogAction) -> {
//If the user clicked 'edit', they've probably set a new 'week' range. Restart the loader.
refreshAdapterItems();
});
}
menu.show();
break;
}
}
use of com.simplecity.amp_library.model.Genre in project Shuttle by timusus.
the class DetailFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_detail, container, false);
recyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerView.setAdapter(adapter);
if (canEdit()) {
itemTouchHelper = new ItemTouchHelper(new ItemTouchHelperCallback((from, to) -> {
long songViewCount = Stream.of(adapter.items).filter(adaptableItem -> adaptableItem instanceof SongView).count();
int offset = (int) (adapter.getItemCount() - songViewCount);
if (to >= offset) {
adapter.moveItem(from, to);
}
}, (from, to) -> {
// The 'offset' here is the number of items in the list which are not
// SongViews. We need this to determine the actual playlist positions of the items.
long songViewCount = Stream.of(adapter.items).filter(adaptableItem -> adaptableItem instanceof SongView).count();
int offset = (int) (adapter.getItemCount() - songViewCount);
from -= offset;
to -= offset;
try {
MediaStore.Audio.Playlists.Members.moveItem(getActivity().getContentResolver(), playlist.id, from, to);
} catch (IllegalArgumentException e) {
CrashlyticsCore.getInstance().log(String.format("Failed to move playlist item from %s to %s. Adapter count: %s. Error:%s", from, to, adapter.getItemCount(), e.getMessage()));
}
}, null));
itemTouchHelper.attachToRecyclerView(recyclerView);
}
fab = (FloatingActionButton) rootView.findViewById(R.id.fab);
fab.setOnClickListener(this);
lineOne = (TextView) rootView.findViewById(R.id.line_one);
lineTwo = (TextView) rootView.findViewById(R.id.line_two);
overflowButton = (NonScrollImageButton) rootView.findViewById(R.id.btn_overflow);
overflowButton.setOnClickListener(this);
if (albumArtist != null) {
lineOne.setText(albumArtist.name);
overflowButton.setContentDescription(getString(R.string.btn_options, albumArtist.name));
} else if (album != null) {
lineOne.setText(album.name);
overflowButton.setContentDescription(getString(R.string.btn_options, album.name));
} else if (genre != null) {
lineOne.setText(genre.name);
overflowButton.setVisibility(View.GONE);
} else if (playlist != null) {
lineOne.setText(playlist.name);
overflowButton.setContentDescription(getString(R.string.btn_options, playlist.name));
}
textProtectionScrim = rootView.findViewById(R.id.textProtectionScrim);
headerImageView = (ImageView) rootView.findViewById(R.id.background);
String transitionName = getArguments().getString(ARG_TRANSITION_NAME);
ViewCompat.setTransitionName(headerImageView, transitionName);
if (transitionName != null) {
textProtectionScrim.setVisibility(View.GONE);
fab.setVisibility(View.GONE);
}
int width = ResourceUtils.getScreenSize().width + ResourceUtils.toPixels(60);
int height = getResources().getDimensionPixelSize(R.dimen.header_view_height);
if (albumArtist != null || album != null) {
requestManager.load(albumArtist == null ? album : albumArtist).override(width, height).diskCacheStrategy(DiskCacheStrategy.SOURCE).priority(Priority.HIGH).placeholder(GlideUtils.getPlaceHolderDrawable(albumArtist == null ? album.name : albumArtist.name, false)).centerCrop().animate(new AlwaysCrossFade(false)).into(headerImageView);
}
actionMode = null;
//Set the RecyclerView HeaderView height equal to the headerItem height
headerView = rootView.findViewById(R.id.headerView);
headerView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
headerView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
DetailFragment.this.headerItem.height = headerView.getHeight();
}
});
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
headerTranslation = headerView.getTranslationY() - dy;
headerImageTranslation = headerImageView.getTranslationY() + dy / 2;
//the header translation.
if (headerTranslation == 0) {
headerImageTranslation = 0;
}
float ratio = Math.min(1, -headerTranslation / headerView.getHeight());
headerView.setTranslationY(headerTranslation);
headerImageView.setTranslationY(headerImageTranslation);
//when recreating this fragment.
if (getActivity() != null) {
if (((MainActivity) getActivity()).canSetAlpha()) {
((MainActivity) getActivity()).setActionBarAlpha(ratio, true);
}
}
}
});
themeUIComponents();
headerView.setTranslationY(headerTranslation);
headerImageView.setTranslationY(headerImageTranslation);
return rootView;
}
Aggregations