Search in sources :

Example 21 with Playlist

use of com.simplecity.amp_library.model.Playlist in project Shuttle by timusus.

the class MainActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case R.id.action_search:
            Intent intent = new Intent(MainActivity.this, SearchActivity.class);
            intent.putExtra(SearchManager.QUERY, "");
            startActivityForResult(intent, REQUEST_SEARCH);
            return true;
        case EQUALIZER:
            final Intent equalizerIntent = new Intent(this, EqualizerActivity.class);
            startActivity(equalizerIntent);
            return true;
        case GO_TO_ARTIST:
            long time = System.currentTimeMillis();
            Album currentAlbum = MusicUtils.getAlbum();
            if (currentAlbum != null) {
                DataManager.getInstance().getAlbumArtistsRelay().first().flatMap(Observable::from).filter(albumArtist -> albumArtist.name.equals(currentAlbum.albumArtistName) && com.annimon.stream.Stream.of(albumArtist.albums).anyMatch(album -> album.id == currentAlbum.id)).observeOn(AndroidSchedulers.mainThread()).subscribe(albumArtist -> {
                    swapFragments(DetailFragment.newInstance(albumArtist), true);
                    new Handler().postDelayed(() -> mSlidingUpPanelLayout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED, true), time - System.currentTimeMillis() + 250);
                });
            }
            return true;
        case GO_TO_ALBUM:
            time = System.currentTimeMillis();
            currentAlbum = MusicUtils.getAlbum();
            if (currentAlbum != null) {
                DataManager.getInstance().getAlbumsRelay().first().flatMap(Observable::from).filter(album -> album.id == currentAlbum.id).observeOn(AndroidSchedulers.mainThread()).subscribe(album -> {
                    swapFragments(DetailFragment.newInstance(album), true);
                    new Handler().postDelayed(() -> mSlidingUpPanelLayout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED, true), time - System.currentTimeMillis() + 250);
                });
            }
            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 = 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;
        case R.id.menu_favorite:
            PlaylistUtils.toggleFavorite(this);
            return true;
        case R.id.menu_share:
            DialogUtils.showShareDialog(MainActivity.this, MusicUtils.getSong());
            return true;
        case R.id.menu_queue:
            Fragment playingFragment = getSupportFragmentManager().findFragmentById(R.id.player_container);
            if (playingFragment != null) {
                ((PlayerFragment) playingFragment).toggleQueue();
            }
            return true;
        case android.R.id.home:
            playingFragment = getSupportFragmentManager().findFragmentById(R.id.player_container);
            if (playingFragment != null) {
                Fragment childFragment = playingFragment.getChildFragmentManager().findFragmentById(R.id.queue_container);
                if (childFragment != null && childFragment instanceof QueueFragment) {
                    ((PlayerFragment) playingFragment).toggleQueue();
                    toggleQueue(false);
                    return true;
                }
            }
            if (mSlidingUpPanelLayout != null) {
                if (mSlidingUpPanelLayout.getPanelState() != SlidingUpPanelLayout.PanelState.COLLAPSED && mSlidingUpPanelLayout.getPanelState() != SlidingUpPanelLayout.PanelState.HIDDEN) {
                    mSlidingUpPanelLayout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED, true);
                    return true;
                }
            }
            break;
    }
    return super.onOptionsItemSelected(item);
}
Also used : Album(com.simplecity.amp_library.model.Album) Handler(android.os.Handler) Intent(android.content.Intent) QueueFragment(com.simplecity.amp_library.ui.fragments.QueueFragment) FolderFragment(com.simplecity.amp_library.ui.fragments.FolderFragment) Fragment(android.support.v4.app.Fragment) QueuePagerFragment(com.simplecity.amp_library.ui.fragments.QueuePagerFragment) PlayerFragment(com.simplecity.amp_library.ui.fragments.PlayerFragment) QueueFragment(com.simplecity.amp_library.ui.fragments.QueueFragment) AlbumArtistFragment(com.simplecity.amp_library.ui.fragments.AlbumArtistFragment) NavigationDrawerFragment(com.simplecity.amp_library.ui.fragments.NavigationDrawerFragment) PlaylistFragment(com.simplecity.amp_library.ui.fragments.PlaylistFragment) GenreFragment(com.simplecity.amp_library.ui.fragments.GenreFragment) DetailFragment(com.simplecity.amp_library.ui.fragments.DetailFragment) SuggestedFragment(com.simplecity.amp_library.ui.fragments.SuggestedFragment) MainFragment(com.simplecity.amp_library.ui.fragments.MainFragment) AlbumFragment(com.simplecity.amp_library.ui.fragments.AlbumFragment) MiniPlayerFragment(com.simplecity.amp_library.ui.fragments.MiniPlayerFragment) DialogUtils(com.simplecity.amp_library.utils.DialogUtils) Song(com.simplecity.amp_library.model.Song) Playlist(com.simplecity.amp_library.model.Playlist) PlayerFragment(com.simplecity.amp_library.ui.fragments.PlayerFragment) MiniPlayerFragment(com.simplecity.amp_library.ui.fragments.MiniPlayerFragment)

Example 22 with Playlist

use of com.simplecity.amp_library.model.Playlist in project Shuttle by timusus.

the class DetailFragment method onActionItemClicked.

boolean onActionItemClicked(MenuItem item) {
    final ArrayList<Song> checkedSongs = getCheckedSongs();
    if (checkedSongs == null || checkedSongs.isEmpty()) {
        return true;
    }
    switch(item.getItemId()) {
        case NEW_PLAYLIST:
            PlaylistUtils.createPlaylistDialog(getActivity(), checkedSongs);
            return true;
        case PLAYLIST_SELECTED:
            Playlist playlist = (Playlist) item.getIntent().getSerializableExtra(ShuttleUtils.ARG_PLAYLIST);
            PlaylistUtils.addToPlaylist(getContext(), playlist, checkedSongs);
            return true;
        case R.id.delete:
            new DialogUtils.DeleteDialogBuilder().context(getContext()).singleMessageId(R.string.delete_song_desc).multipleMessage(R.string.delete_song_desc_multiple).itemNames(Stream.of(checkedSongs).map(song -> song.name).collect(Collectors.toList())).songsToDelete(Observable.just(checkedSongs)).build().show();
            return true;
        case R.id.menu_add_to_queue:
            MusicUtils.addToQueue(getActivity(), checkedSongs);
            return true;
    }
    return false;
}
Also used : ModalMultiSelectorCallback(com.bignerdranch.android.multiselector.ModalMultiSelectorCallback) R(com.simplecity.amp_library.R) Genre(com.simplecity.amp_library.model.Genre) Bundle(android.os.Bundle) SongView(com.simplecity.amp_library.ui.modelviews.SongView) CrashlyticsCore(com.crashlytics.android.core.CrashlyticsCore) PlaylistUtils(com.simplecity.amp_library.utils.PlaylistUtils) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) Random(java.util.Random) ItemAdapter(com.simplecity.amp_library.ui.adapters.ItemAdapter) ColorStateList(android.content.res.ColorStateList) Song(com.simplecity.amp_library.model.Song) Priority(com.bumptech.glide.Priority) RequestManager(com.bumptech.glide.RequestManager) HorizontalAlbumView(com.simplecity.amp_library.ui.modelviews.HorizontalAlbumView) MediaStore(android.provider.MediaStore) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) MenuUtils(com.simplecity.amp_library.utils.MenuUtils) Schedulers(rx.schedulers.Schedulers) View(android.view.View) DetailAdapter(com.simplecity.amp_library.ui.adapters.DetailAdapter) ResourceUtils(com.simplecity.amp_library.utils.ResourceUtils) ViewCompat(android.support.v4.view.ViewCompat) Transition(android.transition.Transition) PreferenceManager(android.preference.PreferenceManager) ItemTouchHelperCallback(com.simplecity.amp_library.ui.recyclerview.ItemTouchHelperCallback) FloatingActionButton(android.support.design.widget.FloatingActionButton) SortManager(com.simplecity.amp_library.utils.SortManager) ActionMode(android.support.v7.view.ActionMode) Playlist(com.simplecity.amp_library.model.Playlist) MainActivity(com.simplecity.amp_library.ui.activities.MainActivity) ObjectAnimator(android.animation.ObjectAnimator) IntentFilter(android.content.IntentFilter) PopupMenu(android.support.v7.widget.PopupMenu) SubMenu(android.view.SubMenu) BroadcastReceiver(android.content.BroadcastReceiver) AppCompatActivity(android.support.v7.app.AppCompatActivity) ViewGroup(android.view.ViewGroup) BaseAdaptableItem(com.simplecity.amp_library.ui.modelviews.BaseAdaptableItem) NonScrollImageButton(com.simplecity.amp_library.ui.views.NonScrollImageButton) Serializable(java.io.Serializable) MusicUtils(com.simplecity.amp_library.utils.MusicUtils) List(java.util.List) TextView(android.widget.TextView) PermissionUtils(com.simplecity.amp_library.utils.PermissionUtils) GlideUtils(com.simplecity.amp_library.glide.utils.GlideUtils) AdaptableItem(com.simplecity.amp_library.model.AdaptableItem) Subscription(rx.Subscription) Context(android.content.Context) Album(com.simplecity.amp_library.model.Album) Stream(com.annimon.stream.Stream) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) DrawableUtils(com.simplecity.amp_library.utils.DrawableUtils) Intent(android.content.Intent) StringUtils(com.simplecity.amp_library.utils.StringUtils) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) Observable(rx.Observable) ThemeUtils(com.simplecity.amp_library.utils.ThemeUtils) ColorUtils(com.simplecity.amp_library.utils.ColorUtils) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) DiskCacheStrategy(com.bumptech.glide.load.engine.DiskCacheStrategy) Menu(android.view.Menu) AnimatorSet(android.animation.AnimatorSet) WeakReference(java.lang.ref.WeakReference) ShuttleUtils(com.simplecity.amp_library.utils.ShuttleUtils) SharedElementCallback(android.support.v4.app.SharedElementCallback) AlwaysCrossFade(com.simplecity.amp_library.glide.utils.AlwaysCrossFade) ViewType(com.simplecity.amp_library.ui.modelviews.ViewType) Collectors(com.annimon.stream.Collectors) LayoutInflater(android.view.LayoutInflater) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DiscNumberView(com.simplecity.amp_library.ui.modelviews.DiscNumberView) DialogUtils(com.simplecity.amp_library.utils.DialogUtils) TimeUnit(java.util.concurrent.TimeUnit) CompositeSubscription(rx.subscriptions.CompositeSubscription) RecyclerView(android.support.v7.widget.RecyclerView) BlacklistHelper(com.simplecity.amp_library.sql.databases.BlacklistHelper) Glide(com.bumptech.glide.Glide) SharedPreferences(android.content.SharedPreferences) HorizontalRecyclerView(com.simplecity.amp_library.ui.modelviews.HorizontalRecyclerView) OvershootInterpolator(android.view.animation.OvershootInterpolator) MultiSelector(com.bignerdranch.android.multiselector.MultiSelector) ComparisonUtils(com.simplecity.amp_library.utils.ComparisonUtils) ViewTreeObserver(android.view.ViewTreeObserver) DataManager(com.simplecity.amp_library.utils.DataManager) AlbumArtist(com.simplecity.amp_library.model.AlbumArtist) Operators(com.simplecity.amp_library.utils.Operators) Collections(java.util.Collections) ContentUris(android.content.ContentUris) Song(com.simplecity.amp_library.model.Song) Playlist(com.simplecity.amp_library.model.Playlist) DialogUtils(com.simplecity.amp_library.utils.DialogUtils)

Example 23 with Playlist

use of com.simplecity.amp_library.model.Playlist 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;
    }
}
Also used : ModalMultiSelectorCallback(com.bignerdranch.android.multiselector.ModalMultiSelectorCallback) R(com.simplecity.amp_library.R) Genre(com.simplecity.amp_library.model.Genre) Bundle(android.os.Bundle) SongView(com.simplecity.amp_library.ui.modelviews.SongView) CrashlyticsCore(com.crashlytics.android.core.CrashlyticsCore) PlaylistUtils(com.simplecity.amp_library.utils.PlaylistUtils) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) Random(java.util.Random) ItemAdapter(com.simplecity.amp_library.ui.adapters.ItemAdapter) ColorStateList(android.content.res.ColorStateList) Song(com.simplecity.amp_library.model.Song) Priority(com.bumptech.glide.Priority) RequestManager(com.bumptech.glide.RequestManager) HorizontalAlbumView(com.simplecity.amp_library.ui.modelviews.HorizontalAlbumView) MediaStore(android.provider.MediaStore) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) MenuUtils(com.simplecity.amp_library.utils.MenuUtils) Schedulers(rx.schedulers.Schedulers) View(android.view.View) DetailAdapter(com.simplecity.amp_library.ui.adapters.DetailAdapter) ResourceUtils(com.simplecity.amp_library.utils.ResourceUtils) ViewCompat(android.support.v4.view.ViewCompat) Transition(android.transition.Transition) PreferenceManager(android.preference.PreferenceManager) ItemTouchHelperCallback(com.simplecity.amp_library.ui.recyclerview.ItemTouchHelperCallback) FloatingActionButton(android.support.design.widget.FloatingActionButton) SortManager(com.simplecity.amp_library.utils.SortManager) ActionMode(android.support.v7.view.ActionMode) Playlist(com.simplecity.amp_library.model.Playlist) MainActivity(com.simplecity.amp_library.ui.activities.MainActivity) ObjectAnimator(android.animation.ObjectAnimator) IntentFilter(android.content.IntentFilter) PopupMenu(android.support.v7.widget.PopupMenu) SubMenu(android.view.SubMenu) BroadcastReceiver(android.content.BroadcastReceiver) AppCompatActivity(android.support.v7.app.AppCompatActivity) ViewGroup(android.view.ViewGroup) BaseAdaptableItem(com.simplecity.amp_library.ui.modelviews.BaseAdaptableItem) NonScrollImageButton(com.simplecity.amp_library.ui.views.NonScrollImageButton) Serializable(java.io.Serializable) MusicUtils(com.simplecity.amp_library.utils.MusicUtils) List(java.util.List) TextView(android.widget.TextView) PermissionUtils(com.simplecity.amp_library.utils.PermissionUtils) GlideUtils(com.simplecity.amp_library.glide.utils.GlideUtils) AdaptableItem(com.simplecity.amp_library.model.AdaptableItem) Subscription(rx.Subscription) Context(android.content.Context) Album(com.simplecity.amp_library.model.Album) Stream(com.annimon.stream.Stream) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) DrawableUtils(com.simplecity.amp_library.utils.DrawableUtils) Intent(android.content.Intent) StringUtils(com.simplecity.amp_library.utils.StringUtils) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) Observable(rx.Observable) ThemeUtils(com.simplecity.amp_library.utils.ThemeUtils) ColorUtils(com.simplecity.amp_library.utils.ColorUtils) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) DiskCacheStrategy(com.bumptech.glide.load.engine.DiskCacheStrategy) Menu(android.view.Menu) AnimatorSet(android.animation.AnimatorSet) WeakReference(java.lang.ref.WeakReference) ShuttleUtils(com.simplecity.amp_library.utils.ShuttleUtils) SharedElementCallback(android.support.v4.app.SharedElementCallback) AlwaysCrossFade(com.simplecity.amp_library.glide.utils.AlwaysCrossFade) ViewType(com.simplecity.amp_library.ui.modelviews.ViewType) Collectors(com.annimon.stream.Collectors) LayoutInflater(android.view.LayoutInflater) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DiscNumberView(com.simplecity.amp_library.ui.modelviews.DiscNumberView) DialogUtils(com.simplecity.amp_library.utils.DialogUtils) TimeUnit(java.util.concurrent.TimeUnit) CompositeSubscription(rx.subscriptions.CompositeSubscription) RecyclerView(android.support.v7.widget.RecyclerView) BlacklistHelper(com.simplecity.amp_library.sql.databases.BlacklistHelper) Glide(com.bumptech.glide.Glide) SharedPreferences(android.content.SharedPreferences) HorizontalRecyclerView(com.simplecity.amp_library.ui.modelviews.HorizontalRecyclerView) OvershootInterpolator(android.view.animation.OvershootInterpolator) MultiSelector(com.bignerdranch.android.multiselector.MultiSelector) ComparisonUtils(com.simplecity.amp_library.utils.ComparisonUtils) ViewTreeObserver(android.view.ViewTreeObserver) DataManager(com.simplecity.amp_library.utils.DataManager) AlbumArtist(com.simplecity.amp_library.model.AlbumArtist) Operators(com.simplecity.amp_library.utils.Operators) Collections(java.util.Collections) ContentUris(android.content.ContentUris) AppCompatActivity(android.support.v7.app.AppCompatActivity) PopupMenu(android.support.v7.widget.PopupMenu)

Example 24 with Playlist

use of com.simplecity.amp_library.model.Playlist 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;
}
Also used : ModalMultiSelectorCallback(com.bignerdranch.android.multiselector.ModalMultiSelectorCallback) R(com.simplecity.amp_library.R) Genre(com.simplecity.amp_library.model.Genre) Bundle(android.os.Bundle) SongView(com.simplecity.amp_library.ui.modelviews.SongView) CrashlyticsCore(com.crashlytics.android.core.CrashlyticsCore) PlaylistUtils(com.simplecity.amp_library.utils.PlaylistUtils) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) Random(java.util.Random) ItemAdapter(com.simplecity.amp_library.ui.adapters.ItemAdapter) ColorStateList(android.content.res.ColorStateList) Song(com.simplecity.amp_library.model.Song) Priority(com.bumptech.glide.Priority) RequestManager(com.bumptech.glide.RequestManager) HorizontalAlbumView(com.simplecity.amp_library.ui.modelviews.HorizontalAlbumView) MediaStore(android.provider.MediaStore) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) MenuUtils(com.simplecity.amp_library.utils.MenuUtils) Schedulers(rx.schedulers.Schedulers) View(android.view.View) DetailAdapter(com.simplecity.amp_library.ui.adapters.DetailAdapter) ResourceUtils(com.simplecity.amp_library.utils.ResourceUtils) ViewCompat(android.support.v4.view.ViewCompat) Transition(android.transition.Transition) PreferenceManager(android.preference.PreferenceManager) ItemTouchHelperCallback(com.simplecity.amp_library.ui.recyclerview.ItemTouchHelperCallback) FloatingActionButton(android.support.design.widget.FloatingActionButton) SortManager(com.simplecity.amp_library.utils.SortManager) ActionMode(android.support.v7.view.ActionMode) Playlist(com.simplecity.amp_library.model.Playlist) MainActivity(com.simplecity.amp_library.ui.activities.MainActivity) ObjectAnimator(android.animation.ObjectAnimator) IntentFilter(android.content.IntentFilter) PopupMenu(android.support.v7.widget.PopupMenu) SubMenu(android.view.SubMenu) BroadcastReceiver(android.content.BroadcastReceiver) AppCompatActivity(android.support.v7.app.AppCompatActivity) ViewGroup(android.view.ViewGroup) BaseAdaptableItem(com.simplecity.amp_library.ui.modelviews.BaseAdaptableItem) NonScrollImageButton(com.simplecity.amp_library.ui.views.NonScrollImageButton) Serializable(java.io.Serializable) MusicUtils(com.simplecity.amp_library.utils.MusicUtils) List(java.util.List) TextView(android.widget.TextView) PermissionUtils(com.simplecity.amp_library.utils.PermissionUtils) GlideUtils(com.simplecity.amp_library.glide.utils.GlideUtils) AdaptableItem(com.simplecity.amp_library.model.AdaptableItem) Subscription(rx.Subscription) Context(android.content.Context) Album(com.simplecity.amp_library.model.Album) Stream(com.annimon.stream.Stream) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) DrawableUtils(com.simplecity.amp_library.utils.DrawableUtils) Intent(android.content.Intent) StringUtils(com.simplecity.amp_library.utils.StringUtils) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) Observable(rx.Observable) ThemeUtils(com.simplecity.amp_library.utils.ThemeUtils) ColorUtils(com.simplecity.amp_library.utils.ColorUtils) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) DiskCacheStrategy(com.bumptech.glide.load.engine.DiskCacheStrategy) Menu(android.view.Menu) AnimatorSet(android.animation.AnimatorSet) WeakReference(java.lang.ref.WeakReference) ShuttleUtils(com.simplecity.amp_library.utils.ShuttleUtils) SharedElementCallback(android.support.v4.app.SharedElementCallback) AlwaysCrossFade(com.simplecity.amp_library.glide.utils.AlwaysCrossFade) ViewType(com.simplecity.amp_library.ui.modelviews.ViewType) Collectors(com.annimon.stream.Collectors) LayoutInflater(android.view.LayoutInflater) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DiscNumberView(com.simplecity.amp_library.ui.modelviews.DiscNumberView) DialogUtils(com.simplecity.amp_library.utils.DialogUtils) TimeUnit(java.util.concurrent.TimeUnit) CompositeSubscription(rx.subscriptions.CompositeSubscription) RecyclerView(android.support.v7.widget.RecyclerView) BlacklistHelper(com.simplecity.amp_library.sql.databases.BlacklistHelper) Glide(com.bumptech.glide.Glide) SharedPreferences(android.content.SharedPreferences) HorizontalRecyclerView(com.simplecity.amp_library.ui.modelviews.HorizontalRecyclerView) OvershootInterpolator(android.view.animation.OvershootInterpolator) MultiSelector(com.bignerdranch.android.multiselector.MultiSelector) ComparisonUtils(com.simplecity.amp_library.utils.ComparisonUtils) ViewTreeObserver(android.view.ViewTreeObserver) DataManager(com.simplecity.amp_library.utils.DataManager) AlbumArtist(com.simplecity.amp_library.model.AlbumArtist) Operators(com.simplecity.amp_library.utils.Operators) Collections(java.util.Collections) ContentUris(android.content.ContentUris) SongView(com.simplecity.amp_library.ui.modelviews.SongView) AlwaysCrossFade(com.simplecity.amp_library.glide.utils.AlwaysCrossFade) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ItemTouchHelperCallback(com.simplecity.amp_library.ui.recyclerview.ItemTouchHelperCallback) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) RecyclerView(android.support.v7.widget.RecyclerView) HorizontalRecyclerView(com.simplecity.amp_library.ui.modelviews.HorizontalRecyclerView) ViewTreeObserver(android.view.ViewTreeObserver)

Example 25 with Playlist

use of com.simplecity.amp_library.model.Playlist in project Shuttle by timusus.

the class SearchActivity method onOverflowClick.

@Override
public void onOverflowClick(View v, int position, Object object) {
    PopupMenu menu = new PopupMenu(this, v);
    if (object instanceof AlbumArtist) {
        menu.getMenu().add(0, PLAY_SELECTION, 0, R.string.play_selection);
    } else if (object instanceof Album) {
        menu.getMenu().add(0, PLAY_SELECTION, 0, R.string.play_selection);
    } else if (object instanceof Song) {
        menu.getMenu().add(0, PLAY_NEXT, 0, R.string.play_next);
        menu.getMenu().add(0, USE_AS_RINGTONE, 4, R.string.ringtone_menu);
    }
    SubMenu sub = menu.getMenu().addSubMenu(0, ADD_TO_PLAYLIST, 1, R.string.add_to_playlist);
    PlaylistUtils.makePlaylistMenu(this, sub, 0);
    menu.getMenu().add(0, QUEUE, 2, R.string.add_to_queue);
    if (ShuttleUtils.isUpgraded()) {
        menu.getMenu().add(0, TAGGER, 3, R.string.edit_tags);
    }
    menu.getMenu().add(0, DELETE_ITEM, 6, R.string.delete_item);
    menu.setOnMenuItemClickListener(item -> {
        Observable<List<Song>> songsObservable = null;
        if (object instanceof Song) {
            songsObservable = Observable.just(Collections.singletonList((Song) object));
        } else if (object instanceof AlbumArtist) {
            songsObservable = ((AlbumArtist) object).getSongsObservable();
        } else if (object instanceof Album) {
            songsObservable = ((Album) object).getSongsObservable();
        }
        switch(item.getItemId()) {
            case PLAY_SELECTION:
                songsObservable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(songs -> MusicUtils.playAll(songs, () -> {
                    final String message = getString(R.string.emptyplaylist);
                    Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
                }));
                return true;
            case PLAY_NEXT:
                songsObservable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(songs -> MusicUtils.playNext(SearchActivity.this, songs));
                return true;
            case NEW_PLAYLIST:
                songsObservable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(songs -> PlaylistUtils.createPlaylistDialog(SearchActivity.this, songs));
                return true;
            case PLAYLIST_SELECTED:
                songsObservable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(songs -> {
                    Playlist playlist = (Playlist) item.getIntent().getSerializableExtra(ShuttleUtils.ARG_PLAYLIST);
                    PlaylistUtils.addToPlaylist(this, playlist, songs);
                });
                return true;
            case USE_AS_RINGTONE:
                ShuttleUtils.setRingtone(SearchActivity.this, ((Song) object));
                return true;
            case QUEUE:
                songsObservable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(songs -> MusicUtils.addToQueue(SearchActivity.this, songs));
                return true;
            case TAGGER:
                TaggerDialog.newInstance((Serializable) object).show(getSupportFragmentManager());
                return true;
            case DELETE_ITEM:
                DialogUtils.DeleteDialogBuilder builder = new DialogUtils.DeleteDialogBuilder().context(this).songsToDelete(songsObservable);
                if (object instanceof Song) {
                    builder.singleMessageId(R.string.delete_song_desc).multipleMessage(R.string.delete_song_desc_multiple).itemNames(Collections.singletonList(((Song) object).name));
                } else if (object instanceof AlbumArtist) {
                    builder.singleMessageId(R.string.delete_album_artist_desc).multipleMessage(R.string.delete_album_artist_desc_multiple).itemNames(Collections.singletonList(((AlbumArtist) object).name));
                } else if (object instanceof Album) {
                    builder.singleMessageId(R.string.delete_album_desc).multipleMessage(R.string.delete_album_desc_multiple).itemNames(Collections.singletonList(((Album) object).name));
                }
                builder.build().show();
                return true;
        }
        return false;
    });
    menu.show();
}
Also used : Serializable(java.io.Serializable) Album(com.simplecity.amp_library.model.Album) SubMenu(android.view.SubMenu) AlbumArtist(com.simplecity.amp_library.model.AlbumArtist) DialogUtils(com.simplecity.amp_library.utils.DialogUtils) Song(com.simplecity.amp_library.model.Song) Playlist(com.simplecity.amp_library.model.Playlist) List(java.util.List) ArrayList(java.util.ArrayList) PopupMenu(android.support.v7.widget.PopupMenu)

Aggregations

Playlist (com.simplecity.amp_library.model.Playlist)35 Intent (android.content.Intent)22 View (android.view.View)19 List (java.util.List)19 Uri (android.net.Uri)17 R (com.simplecity.amp_library.R)17 Song (com.simplecity.amp_library.model.Song)17 Context (android.content.Context)16 LayoutInflater (android.view.LayoutInflater)16 Toast (android.widget.Toast)16 SubMenu (android.view.SubMenu)15 Stream (com.annimon.stream.Stream)15 ContentUris (android.content.ContentUris)14 MediaStore (android.provider.MediaStore)14 TextView (android.widget.TextView)14 ArrayList (java.util.ArrayList)14 Query (com.simplecity.amp_library.model.Query)12 TimeUnit (java.util.concurrent.TimeUnit)12 NonNull (android.support.annotation.NonNull)11 Collections (java.util.Collections)11