use of android.view.SubMenu in project Shuttle by timusus.
the class QueueFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_queue, container, false);
unbinder = ButterKnife.bind(this, rootView);
toolbar.setNavigationOnClickListener(v -> getActivity().onBackPressed());
toolbar.inflateMenu(R.menu.menu_queue);
SubMenu sub = toolbar.getMenu().addSubMenu(0, MusicUtils.Defs.ADD_TO_PLAYLIST, 1, R.string.save_as_playlist);
disposables.add(PlaylistUtils.createUpdatingPlaylistMenu(sub).subscribe());
toolbar.setOnMenuItemClickListener(toolbarListener);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerView.setRecyclerListener(new RecyclerListener());
recyclerView.setAdapter(adapter);
itemTouchHelper = new ItemTouchHelper(new ItemTouchHelperCallback((fromPosition, toPosition) -> adapter.moveItem(fromPosition, toPosition), MusicUtils::moveQueueItem, () -> {
// Nothing to do
}));
itemTouchHelper.attachToRecyclerView(recyclerView);
disposables.add(Aesthetic.get(getContext()).colorPrimary().subscribe(color -> {
boolean isLight = Util.isColorLight(color);
lineOne.setTextColor(isLight ? Color.BLACK : Color.WHITE);
lineTwo.setTextColor(isLight ? Color.BLACK : Color.WHITE);
}));
// In landscape, we need to adjust the status bar's translation depending on the slide offset of the sheet
if (ShuttleUtils.isLandscape()) {
statusBarView.setTranslationY(ResourceUtils.toPixels(16));
disposables.add(multiSheetSlideEventRelay.getEvents().filter(multiSheetEvent -> multiSheetEvent.sheet == MultiSheetView.Sheet.SECOND).filter(multiSheetEvent -> multiSheetEvent.slideOffset >= 0).subscribe(multiSheetEvent -> {
statusBarView.setTranslationY((1 - multiSheetEvent.slideOffset) * ResourceUtils.toPixels(16));
}));
}
setupContextualToolbar();
queuePresenter = new QueuePresenter(requestManager, cabHelper);
return rootView;
}
use of android.view.SubMenu in project Shuttle by timusus.
the class SongFragment method setupContextualToolbar.
private void setupContextualToolbar() {
ContextualToolbar contextualToolbar = ContextualToolbar.findContextualToolbar(this);
if (contextualToolbar != null) {
contextualToolbar.getMenu().clear();
contextualToolbar.inflateMenu(R.menu.context_menu_general);
SubMenu sub = contextualToolbar.getMenu().findItem(R.id.addToPlaylist).getSubMenu();
if (playlistMenuDisposable != null) {
playlistMenuDisposable.dispose();
}
playlistMenuDisposable = PlaylistUtils.createUpdatingPlaylistMenu(sub).subscribe();
contextualToolbarHelper = new ContextualToolbarHelper<>(contextualToolbar, new ContextualToolbarHelper.Callback() {
@Override
public void notifyItemChanged(int position, SelectableViewModel viewModel) {
adapter.notifyItemChanged(position, 0);
}
@Override
public void notifyDatasetChanged() {
adapter.notifyItemRangeChanged(0, adapter.items.size(), 0);
}
});
contextualToolbar.setOnMenuItemClickListener(MenuUtils.getSongMenuClickListener(getContext(), Single.fromCallable(() -> contextualToolbarHelper.getItems()), deleteDialog -> deleteDialog.show(getChildFragmentManager()), () -> contextualToolbarHelper.finish()));
}
}
use of android.view.SubMenu in project Shuttle by timusus.
the class BaseDetailFragment method setupToolbarMenu.
protected void setupToolbarMenu(Toolbar toolbar) {
toolbar.inflateMenu(R.menu.menu_detail_sort);
setupCastMenu(toolbar.getMenu());
toolbar.setOnMenuItemClickListener(this);
// Create playlist menu
final SubMenu sub = toolbar.getMenu().findItem(R.id.addToPlaylist).getSubMenu();
disposables.add(PlaylistUtils.createUpdatingPlaylistMenu(sub).subscribe());
// Inflate sorting menus
MenuItem item = toolbar.getMenu().findItem(R.id.sorting);
if (showAlbumMenu()) {
getActivity().getMenuInflater().inflate(R.menu.menu_detail_sort_albums, item.getSubMenu());
}
getActivity().getMenuInflater().inflate(R.menu.menu_detail_sort_songs, item.getSubMenu());
updateMenuItems(toolbar);
}
use of android.view.SubMenu in project Shuttle by timusus.
the class BaseDetailFragment method setupContextualToolbar.
private void setupContextualToolbar() {
ContextualToolbar contextualToolbar = ContextualToolbar.findContextualToolbar(this);
if (contextualToolbar != null) {
contextualToolbar.setTransparentBackground(true);
contextualToolbar.getMenu().clear();
contextualToolbar.inflateMenu(R.menu.context_menu_general);
SubMenu sub = contextualToolbar.getMenu().findItem(R.id.addToPlaylist).getSubMenu();
disposables.add(PlaylistUtils.createUpdatingPlaylistMenu(sub).subscribe());
contextualToolbar.setOnMenuItemClickListener(MenuUtils.getSongMenuClickListener(getContext(), Single.defer(() -> Operators.reduceSongSingles(contextualToolbarHelper.getItems())), deleteDialog -> deleteDialog.show(getChildFragmentManager()), () -> contextualToolbarHelper.finish()));
contextualToolbarHelper = new ContextualToolbarHelper<Single<List<Song>>>(contextualToolbar, new ContextualToolbarHelper.Callback() {
@Override
public void notifyItemChanged(int position, SelectableViewModel viewModel) {
if (adapter.items.contains(viewModel)) {
adapter.notifyItemChanged(position, 0);
} else if (horizontalRecyclerView.viewModelAdapter.items.contains(viewModel)) {
horizontalRecyclerView.viewModelAdapter.notifyItemChanged(position);
}
}
@Override
public void notifyDatasetChanged() {
adapter.notifyItemRangeChanged(0, adapter.items.size(), 0);
horizontalRecyclerView.viewModelAdapter.notifyItemRangeChanged(0, horizontalRecyclerView.viewModelAdapter.items.size(), 0);
}
}) {
@Override
public void start() {
super.start();
// Need to hide the collapsed text, as it overlaps the contextual toolbar
collapsingToolbarTextColor = toolbarLayout.getCollapsedTitleTextColor();
collapsingToolbarSubTextColor = toolbarLayout.getCollapsedSubTextColor();
toolbarLayout.setCollapsedTitleTextColor(0x01FFFFFF);
toolbarLayout.setCollapsedSubTextColor(0x01FFFFFF);
toolbar.setVisibility(View.GONE);
}
@Override
public void finish() {
if (toolbarLayout != null) {
toolbarLayout.setCollapsedTitleTextColor(collapsingToolbarTextColor);
toolbarLayout.setCollapsedSubTextColor(collapsingToolbarSubTextColor);
}
if (toolbar != null) {
toolbar.setVisibility(View.VISIBLE);
}
super.finish();
}
};
}
}
use of android.view.SubMenu in project Shuttle by timusus.
the class SearchFragment method setupContextualToolbar.
private void setupContextualToolbar() {
ContextualToolbar contextualToolbar = ContextualToolbar.findContextualToolbar(this);
if (contextualToolbar != null) {
contextualToolbar.getMenu().clear();
contextualToolbar.inflateMenu(R.menu.context_menu_general);
SubMenu sub = contextualToolbar.getMenu().findItem(R.id.addToPlaylist).getSubMenu();
disposables.add(PlaylistUtils.createUpdatingPlaylistMenu(sub).subscribe());
contextualToolbar.setOnMenuItemClickListener(MenuUtils.getSongMenuClickListener(getContext(), Single.defer(() -> Operators.reduceSongSingles(contextualToolbarHelper.getItems())), deleteDialog -> deleteDialog.show(getChildFragmentManager()), () -> contextualToolbarHelper.finish()));
contextualToolbarHelper = new ContextualToolbarHelper<Single<List<Song>>>(contextualToolbar, new ContextualToolbarHelper.Callback() {
@Override
public void notifyItemChanged(int position, SelectableViewModel viewModel) {
adapter.notifyItemChanged(position, 0);
}
@Override
public void notifyDatasetChanged() {
adapter.notifyItemRangeChanged(0, adapter.items.size(), 0);
}
}) {
@Override
public void start() {
super.start();
toolbar.setVisibility(View.GONE);
}
@Override
public void finish() {
if (toolbar != null) {
toolbar.setVisibility(View.VISIBLE);
}
super.finish();
}
};
searchPresenter.setContextualToolbarHelper(contextualToolbarHelper);
}
}
Aggregations