use of com.simplecity.amp_library.ui.fragments.QueueFragment 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));
}
use of com.simplecity.amp_library.ui.fragments.QueueFragment 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());
}
use of com.simplecity.amp_library.ui.fragments.QueueFragment 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();
}
}
use of com.simplecity.amp_library.ui.fragments.QueueFragment in project Shuttle by timusus.
the class PlayerActivity method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
return true;
}
if (item.getItemId() == R.id.menu_favorite) {
PlaylistUtils.toggleFavorite(this);
supportInvalidateOptionsMenu();
return true;
}
if (item.getItemId() == R.id.menu_list) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.setCustomAnimations(R.anim.abc_fade_in, R.anim.abc_fade_out, R.anim.abc_fade_in, R.anim.abc_fade_out);
//Remove the lyrics fragment
Fragment lyricsFragment = getSupportFragmentManager().findFragmentByTag(LYRICS_FRAGMENT);
if (lyricsFragment != null) {
ft.remove(lyricsFragment);
}
Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.queue_container);
if (fragment instanceof QueueFragment) {
ft.remove(getSupportFragmentManager().findFragmentByTag(QUEUE_FRAGMENT));
} else {
ft.add(R.id.queue_container, QueueFragment.newInstance(), QUEUE_FRAGMENT);
}
ft.commit();
return true;
}
switch(item.getItemId()) {
case EQUALIZER:
{
final Intent equalizerIntent = new Intent(this, EqualizerActivity.class);
startActivity(equalizerIntent);
return true;
}
case OPTIONS:
{
startActivity(new Intent(this, SettingsActivity.class));
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 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;
}
}
if (item.getItemId() == R.id.menu_share) {
String path = MusicUtils.getFilePath();
if (!TextUtils.isEmpty(path)) {
DialogUtils.showShareDialog(PlayerActivity.this, MusicUtils.getSong());
}
return true;
}
return false;
}
use of com.simplecity.amp_library.ui.fragments.QueueFragment 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);
}
Aggregations