Search in sources :

Example 1 with PlayerFragment

use of com.simplecity.amp_library.ui.fragments.PlayerFragment in project Shuttle by timusus.

the class MainActivity method onServiceConnected.

@Override
public void onServiceConnected(ComponentName name, IBinder obj) {
    super.onServiceConnected(name, obj);
    supportInvalidateOptionsMenu();
    if (mIsSlidingEnabled) {
        PlayerFragment playerFragment = (PlayerFragment) getSupportFragmentManager().findFragmentById(R.id.player_container);
        if (playerFragment != null) {
            playerFragment.update();
            // If the QueuePagerFragment's adapter is empty, it's because it was created before the service
            // was connected. We need to recreate it now that we know the service is connected.
            Fragment fragment = playerFragment.getChildFragmentManager().findFragmentById(R.id.main_container);
            if (fragment instanceof QueueFragment) {
                ((QueueFragment) fragment).scrollToCurrentItem();
            } else if (fragment instanceof QueuePagerFragment) {
                ((QueuePagerFragment) fragment).resetAdapter();
                ((QueuePagerFragment) fragment).updateQueuePosition();
            }
        }
    }
    handlePendingPlaybackRequest();
    togglePanelVisibility(!(MusicServiceConnectionUtils.sServiceBinder == null || MusicUtils.getSongId() == -1));
}
Also used : QueuePagerFragment(com.simplecity.amp_library.ui.fragments.QueuePagerFragment) 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) PlayerFragment(com.simplecity.amp_library.ui.fragments.PlayerFragment) MiniPlayerFragment(com.simplecity.amp_library.ui.fragments.MiniPlayerFragment)

Example 2 with PlayerFragment

use of com.simplecity.amp_library.ui.fragments.PlayerFragment in project Shuttle by timusus.

the class MainActivity method onCreate.

@SuppressLint("NewApi")
@Override
public void onCreate(Bundle savedInstanceState) {
    if (!ShuttleUtils.isUpgraded() && !ShuttleUtils.isAmazonBuild()) {
        IabManager.getInstance();
    }
    ThemeUtils.setTheme(this);
    if (!ShuttleUtils.hasLollipop() && ShuttleUtils.hasKitKat()) {
        getWindow().setFlags(FLAG_TRANSLUCENT_STATUS, FLAG_TRANSLUCENT_STATUS);
        mTintManager = new SystemBarTintManager(this);
    }
    if (ShuttleUtils.hasLollipop()) {
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
        getWindow().setStatusBarColor(Color.TRANSPARENT);
    }
    if (SettingsManager.getInstance().canTintNavBar()) {
        getWindow().setNavigationBarColor(ColorUtils.getPrimaryColorDark(this));
    }
    supportRequestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
    mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    // Now call super to ensure the theme was properly set
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mIsSlidingEnabled = getResources().getBoolean(R.bool.isSlidingEnabled);
    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    mDummyStatusBar = (FrameLayout) findViewById(R.id.dummyStatusBar);
    if (ShuttleUtils.hasKitKat()) {
        mDummyStatusBar.setVisibility(View.VISIBLE);
        mDummyStatusBar.setBackgroundColor(ColorUtils.getPrimaryColorDark(this));
        LinearLayout.LayoutParams statusBarParams = new LinearLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, (int) ActionBarUtils.getStatusBarHeight(this));
        mDummyStatusBar.setLayoutParams(statusBarParams);
    }
    setSupportActionBar(mToolbar);
    ThemeUtils.themeStatusBar(this, mTintManager);
    mNavigationDrawerFragment = (NavigationDrawerFragment) getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);
    mTitle = getString(R.string.library_title);
    mDrawerLayout = (CustomDrawerLayout) findViewById(R.id.drawer_layout);
    if (ShuttleUtils.hasLollipop() && ShuttleUtils.hasKitKat()) {
        getWindow().setStatusBarColor(Color.TRANSPARENT);
    }
    mDrawerLayout.setStatusBarBackgroundColor(ShuttleUtils.hasLollipop() ? ColorUtils.getPrimaryColorDark(this) : ColorUtils.getPrimaryColor());
    mNavigationDrawerFragment.setup((DrawerLayout) findViewById(R.id.drawer_layout));
    if (mIsSlidingEnabled) {
        mSlidingUpPanelLayout = (SlidingUpPanelLayout) findViewById(R.id.container);
        setDragView(null, false);
        //The second panel slide offset is mini player height + toolbar height + status bar height.
        //This gets our 'up next' sitting snugly underneath the toolbar
        int offset = (int) (ActionBarUtils.getActionBarHeight(this) + (ShuttleUtils.hasKitKat() ? ActionBarUtils.getStatusBarHeight(this) : 0) - getResources().getDimension(R.dimen.mini_player_height));
        mSlidingUpPanelLayout.setSlidePanelOffset(-offset);
        mSlidingUpPanelLayout.hidePanel();
        mSlidingUpPanelLayout.addPanelSlideListener(new SlidingUpPanelLayout.PanelSlideListener() {

            @Override
            public void onPanelSlide(View panel, float slideOffset) {
                setActionBarAlpha(slideOffset, false);
                boolean canChangeElevation = true;
                Fragment 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) {
                        canChangeElevation = false;
                    }
                }
                if (canChangeElevation) {
                    getSupportActionBar().setElevation(ResourceUtils.toPixels(4) * slideOffset);
                }
                mNavigationDrawerFragment.animateDrawerToggle(slideOffset);
            }

            @Override
            public void onPanelStateChanged(View panel, SlidingUpPanelLayout.PanelState previousState, SlidingUpPanelLayout.PanelState newState) {
                switch(newState) {
                    case COLLAPSED:
                        {
                            setDragView(null, false);
                            mTitle = getString(R.string.library_title);
                            supportInvalidateOptionsMenu();
                            toggleQueue(false);
                            mNavigationDrawerFragment.toggleDrawerLock(false);
                            break;
                        }
                    case EXPANDED:
                        {
                            Fragment playerFragment = getSupportFragmentManager().findFragmentById(R.id.player_container);
                            if (playerFragment != null && playerFragment instanceof PlayerFragment) {
                                setDragView(((PlayerFragment) playerFragment).getDragView(), true);
                                if (((PlayerFragment) playerFragment).isQueueShowing()) {
                                    toggleQueue(true);
                                }
                            }
                            mTitle = getString(R.string.nowplaying_title);
                            supportInvalidateOptionsMenu();
                            mNavigationDrawerFragment.toggleDrawerLock(true);
                            break;
                        }
                }
            }
        });
    }
    if (savedInstanceState != null && mIsSlidingEnabled) {
        if (savedInstanceState.getBoolean(ARG_EXPANDED, false)) {
            final ActionBar actionBar = getSupportActionBar();
            //If the sliding panel was previously expanded, expand it again.
            mSlidingUpPanelLayout.post(() -> {
                mSlidingUpPanelLayout.setPanelState(SlidingUpPanelLayout.PanelState.EXPANDED, false);
                setActionBarAlpha(1f, false);
            });
            mTitle = getString(R.string.nowplaying_title);
            if (actionBar != null) {
                actionBar.setTitle(mTitle);
            }
            Fragment 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) {
                    toggleQueue(true);
                }
            }
        }
    }
    if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction().add(R.id.main_container, MainFragment.newInstance()).commit();
        getSupportFragmentManager().beginTransaction().add(R.id.mini_player_container, MiniPlayerFragment.newInstance()).commit();
        if (mIsSlidingEnabled) {
            getSupportFragmentManager().beginTransaction().add(R.id.player_container, PlayerFragment.newInstance()).commit();
        }
    }
    themeTaskDescription();
    handleIntent(getIntent());
}
Also used : SlidingUpPanelLayout(com.sothree.slidinguppanel.SlidingUpPanelLayout) SystemBarTintManager(com.readystatesoftware.systembartint.SystemBarTintManager) QueueFragment(com.simplecity.amp_library.ui.fragments.QueueFragment) View(android.view.View) 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) SuppressLint(android.annotation.SuppressLint) LinearLayout(android.widget.LinearLayout) ActionBar(android.support.v7.app.ActionBar) PlayerFragment(com.simplecity.amp_library.ui.fragments.PlayerFragment) MiniPlayerFragment(com.simplecity.amp_library.ui.fragments.MiniPlayerFragment) SuppressLint(android.annotation.SuppressLint)

Example 3 with PlayerFragment

use of com.simplecity.amp_library.ui.fragments.PlayerFragment in project Shuttle by timusus.

the class MainActivity method onBackPressed.

@Override
public void onBackPressed() {
    Fragment 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;
        }
    }
    if (mIsSlidingEnabled) {
        if (mSlidingUpPanelLayout.getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED) {
            mSlidingUpPanelLayout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED, true);
            return;
        }
    }
    boolean isShowingFolders = false;
    Fragment containerFragment = getSupportFragmentManager().findFragmentById(R.id.main_container);
    if (containerFragment != null && containerFragment instanceof FolderFragment) {
        isShowingFolders = true;
    } else if (containerFragment instanceof MainFragment) {
        Fragment currentPagerFragment = ((MainFragment) containerFragment).getCurrentFragment();
        if (currentPagerFragment != null && currentPagerFragment instanceof FolderFragment) {
            isShowingFolders = true;
        }
    }
    if (isShowingFolders) {
        if (mBackPressListenerReference != null && mBackPressListenerReference.get() != null) {
            if (mBackPressListenerReference.get().onBackPressed()) {
                return;
            }
        }
    }
    super.onBackPressed();
    if (isShowingFolders || containerFragment instanceof MainFragment) {
        if (mNavigationDrawerFragment != null) {
            mNavigationDrawerFragment.setDrawerItem(0);
        }
        mTitle = getString(R.string.library_title);
        supportInvalidateOptionsMenu();
    }
}
Also used : FolderFragment(com.simplecity.amp_library.ui.fragments.FolderFragment) MainFragment(com.simplecity.amp_library.ui.fragments.MainFragment) 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) PlayerFragment(com.simplecity.amp_library.ui.fragments.PlayerFragment) MiniPlayerFragment(com.simplecity.amp_library.ui.fragments.MiniPlayerFragment)

Example 4 with PlayerFragment

use of com.simplecity.amp_library.ui.fragments.PlayerFragment 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)

Aggregations

Fragment (android.support.v4.app.Fragment)4 AlbumArtistFragment (com.simplecity.amp_library.ui.fragments.AlbumArtistFragment)4 AlbumFragment (com.simplecity.amp_library.ui.fragments.AlbumFragment)4 DetailFragment (com.simplecity.amp_library.ui.fragments.DetailFragment)4 FolderFragment (com.simplecity.amp_library.ui.fragments.FolderFragment)4 GenreFragment (com.simplecity.amp_library.ui.fragments.GenreFragment)4 MainFragment (com.simplecity.amp_library.ui.fragments.MainFragment)4 MiniPlayerFragment (com.simplecity.amp_library.ui.fragments.MiniPlayerFragment)4 NavigationDrawerFragment (com.simplecity.amp_library.ui.fragments.NavigationDrawerFragment)4 PlayerFragment (com.simplecity.amp_library.ui.fragments.PlayerFragment)4 PlaylistFragment (com.simplecity.amp_library.ui.fragments.PlaylistFragment)4 QueueFragment (com.simplecity.amp_library.ui.fragments.QueueFragment)4 QueuePagerFragment (com.simplecity.amp_library.ui.fragments.QueuePagerFragment)4 SuggestedFragment (com.simplecity.amp_library.ui.fragments.SuggestedFragment)4 SuppressLint (android.annotation.SuppressLint)1 Intent (android.content.Intent)1 Handler (android.os.Handler)1 ActionBar (android.support.v7.app.ActionBar)1 View (android.view.View)1 LinearLayout (android.widget.LinearLayout)1